Skip to content

Commit

Permalink
Apply Colomban's patch allowing to remember selected file filter
Browse files Browse the repository at this point in the history
  • Loading branch information
techee committed Jun 9, 2024
1 parent 2337e3e commit 7a259e8
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ static gboolean open_file_dialog_handle_response(GtkFileChooser *dialog, gint re
GtkWidget *encoding_combo = ui_lookup_widget(GTK_WIDGET(dialog), "encoding_combo");

filesel_state.open.more_options_visible = gtk_expander_get_expanded(GTK_EXPANDER(expander));
filesel_state.open.filter_idx = file_chooser_get_filter_idx(GTK_FILE_CHOOSER(dialog));
filesel_state.open.filetype_idx = filetype_combo_box_get_active_filetype(GTK_COMBO_BOX(filetype_combo));
filesel_state.open.encoding_idx = ui_encodings_combo_box_get_active_encoding(GTK_COMBO_BOX(encoding_combo));
}
filesel_state.open.filter_idx = file_chooser_get_filter_idx(dialog);

/* ignore detect from file item */
if (filesel_state.open.filetype_idx >= 0)
Expand Down Expand Up @@ -429,29 +429,34 @@ static GtkFileChooser *create_open_file_dialog(void)
}


static void open_file_dialog_apply_settings(GtkWidget *dialog)
static void open_file_dialog_apply_settings(GtkFileChooser *dialog)
{
static gboolean initialized = FALSE;
GtkWidget *check_hidden = ui_lookup_widget(dialog, "check_hidden");
GtkWidget *filetype_combo = ui_lookup_widget(dialog, "filetype_combo");
GtkWidget *encoding_combo = ui_lookup_widget(dialog, "encoding_combo");
GtkWidget *expander = ui_lookup_widget(dialog, "more_options_expander");

/* we can't know the initial position of combo boxes, so retrieve it the first time */
if (! initialized)
{
filesel_state.open.filter_idx = file_chooser_get_filter_idx(GTK_FILE_CHOOSER(dialog));
filesel_state.open.filter_idx = file_chooser_get_filter_idx(dialog);

initialized = TRUE;
}
else
{
file_chooser_set_filter_idx(GTK_FILE_CHOOSER(dialog), filesel_state.open.filter_idx);
file_chooser_set_filter_idx(dialog, filesel_state.open.filter_idx);
}

if (!GTK_IS_NATIVE_DIALOG(dialog))
{
GtkWidget *check_hidden = ui_lookup_widget(GTK_WIDGET(dialog), "check_hidden");
GtkWidget *filetype_combo = ui_lookup_widget(GTK_WIDGET(dialog), "filetype_combo");
GtkWidget *encoding_combo = ui_lookup_widget(GTK_WIDGET(dialog), "encoding_combo");
GtkWidget *expander = ui_lookup_widget(GTK_WIDGET(dialog), "more_options_expander");

gtk_expander_set_expanded(GTK_EXPANDER(expander), filesel_state.open.more_options_visible);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_hidden), filesel_state.open.show_hidden);
ui_encodings_combo_box_set_active_encoding(GTK_COMBO_BOX(encoding_combo), filesel_state.open.encoding_idx);
filetype_combo_box_set_active_filetype(GTK_COMBO_BOX(filetype_combo), filesel_state.open.filetype_idx);
}
gtk_expander_set_expanded(GTK_EXPANDER(expander), filesel_state.open.more_options_visible);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_hidden), filesel_state.open.show_hidden);
ui_encodings_combo_box_set_active_encoding(GTK_COMBO_BOX(encoding_combo), filesel_state.open.encoding_idx);
filetype_combo_box_set_active_filetype(GTK_COMBO_BOX(filetype_combo), filesel_state.open.filetype_idx);
}


Expand Down Expand Up @@ -490,8 +495,7 @@ void dialogs_show_open_file(void)
SETPTR(initdir, utils_get_locale_from_utf8(initdir));

dialog = create_open_file_dialog();
if (!GTK_IS_NATIVE_DIALOG(dialog))
open_file_dialog_apply_settings(GTK_WIDGET(dialog));
open_file_dialog_apply_settings(dialog);

if (initdir != NULL && g_path_is_absolute(initdir))
gtk_file_chooser_set_current_folder(dialog, initdir);
Expand Down

0 comments on commit 7a259e8

Please sign in to comment.