Skip to content

Commit

Permalink
file-chooser: Allow disabling state restoration
Browse files Browse the repository at this point in the history
Add a new parameter to celluloid_file_chooser_new() that controls
whether or not the state, i.e. the last opened folder, would be
restored. This has priority over the last-folder-enable GSettings key,
meaning both the parameter and the GSettings key have to be set to TRUE
for the last folder to be restored.
  • Loading branch information
gnome-mpv committed Oct 27, 2023
1 parent a61b476 commit 3f143bb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/celluloid-file-chooser-button.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ celluloid_file_chooser_button_init(CelluloidFileChooserButton *self)
celluloid_file_chooser_new
( _("Open File…"),
NULL,
GTK_FILE_CHOOSER_ACTION_OPEN );
GTK_FILE_CHOOSER_ACTION_OPEN,
TRUE );
self->label = gtk_label_new(_("(None)"));
self->file = NULL;
self->title = NULL;
Expand Down
5 changes: 3 additions & 2 deletions src/celluloid-file-chooser.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ response_handler(GtkDialog *dialog, gint response_id, gpointer data)
CelluloidFileChooser *
celluloid_file_chooser_new( const gchar *title,
GtkWindow *parent,
GtkFileChooserAction action )
GtkFileChooserAction action,
gboolean restore_state )
{
CelluloidFileChooser *chooser;
GSettings *main_config;
Expand All @@ -99,7 +100,7 @@ celluloid_file_chooser_new( const gchar *title,
last_folder_enable = g_settings_get_boolean
(main_config, "last-folder-enable");

if(last_folder_enable)
if(restore_state && last_folder_enable)
{
load_last_folder(GTK_FILE_CHOOSER(chooser));
}
Expand Down
3 changes: 2 additions & 1 deletion src/celluloid-file-chooser.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ G_BEGIN_DECLS
CelluloidFileChooser *
celluloid_file_chooser_new( const gchar *title,
GtkWindow *parent,
GtkFileChooserAction action );
GtkFileChooserAction action,
gboolean restore_state );

void
celluloid_file_chooser_destroy(CelluloidFileChooser *chooser);
Expand Down
10 changes: 7 additions & 3 deletions src/celluloid-plugins-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,13 @@ add_handler(GtkButton *button, gpointer data)
GtkFileFilter *filter;
GtkFileChooser *chooser;

dialog = celluloid_file_chooser_new( _("Add Plugin"),
pmgr->parent_window,
GTK_FILE_CHOOSER_ACTION_OPEN );
dialog =
celluloid_file_chooser_new
( _("Add Plugin"),
pmgr->parent_window,
GTK_FILE_CHOOSER_ACTION_OPEN,
TRUE );

filter = NULL;
chooser = GTK_FILE_CHOOSER(dialog);

Expand Down
11 changes: 8 additions & 3 deletions src/celluloid-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,8 @@ show_open_track_dialog(CelluloidView *view, TrackType type)
CelluloidFileChooser *chooser = celluloid_file_chooser_new
( title,
GTK_WINDOW(view),
GTK_FILE_CHOOSER_ACTION_OPEN );
GTK_FILE_CHOOSER_ACTION_OPEN,
TRUE );

g_object_set_data( G_OBJECT(chooser),
"track-type",
Expand Down Expand Up @@ -1493,7 +1494,10 @@ celluloid_view_show_open_dialog( CelluloidView *view,
action = GTK_FILE_CHOOSER_ACTION_OPEN;
}

chooser = celluloid_file_chooser_new(title, GTK_WINDOW(view), action);
chooser =
celluloid_file_chooser_new
(title, GTK_WINDOW(view), action, TRUE);

args = g_ptr_array_new();
append_buf = g_malloc(sizeof(gboolean));
*append_buf = append;
Expand Down Expand Up @@ -1570,7 +1574,8 @@ celluloid_view_show_save_playlist_dialog(CelluloidView *view)
file_chooser = celluloid_file_chooser_new
( _("Save Playlist"),
GTK_WINDOW(view),
GTK_FILE_CHOOSER_ACTION_SAVE );
GTK_FILE_CHOOSER_ACTION_SAVE,
TRUE );
gtk_chooser = GTK_FILE_CHOOSER(file_chooser);

gtk_file_chooser_set_current_name(gtk_chooser, "playlist.m3u");
Expand Down

0 comments on commit 3f143bb

Please sign in to comment.