From 146982ed71ce8e2b07ea9c85ab59fc6352fbd364 Mon Sep 17 00:00:00 2001 From: Eric Koegel Date: Thu, 5 Apr 2012 14:15:48 +0300 Subject: [PATCH] Remember the directory of the last image added in the settings app. (Bug #8618) The patch adds a last-file-added property to keep track of the directory last used and defaults to it on future uses. If that property isn't set it will default to using the base directory of the last-image property and use the gtk recent docs directory should both fail. --- doc/README.xfconf | 7 +++++++ settings/main.c | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletions(-) diff --git a/doc/README.xfconf b/doc/README.xfconf index 74bf96e..71df0ce 100644 --- a/doc/README.xfconf +++ b/doc/README.xfconf @@ -12,6 +12,8 @@ property is listd after the name. + + @@ -19,6 +21,11 @@ property is listd after the name. + + + + + diff --git a/settings/main.c b/settings/main.c index 74e7172..d3f16dd 100644 --- a/settings/main.c +++ b/settings/main.c @@ -881,6 +881,8 @@ add_file_button_clicked(GtkWidget *button, AppearancePanel *panel = user_data; GtkWidget *chooser; GtkFileFilter *filter; + gchar last_file_prop[1024], last_image_prop[1024]; + gchar *last_image = NULL, *image_uri = NULL; chooser = gtk_file_chooser_dialog_new(_("Add Image File(s)"), GTK_WINDOW(gtk_widget_get_toplevel(button)), @@ -903,6 +905,34 @@ add_file_button_clicked(GtkWidget *button, exo_gtk_file_chooser_add_thumbnail_preview(GTK_FILE_CHOOSER(chooser)); + g_snprintf(last_file_prop, sizeof(last_file_prop), + PER_SCREEN_PROP_FORMAT "/last-file-added", + panel->screen, panel->monitor); + last_image = xfconf_channel_get_string(panel->channel, last_file_prop, NULL); + + if(last_image == NULL) { + /* If we failed to get the last-file-added property try the last image + * the user loaded. */ + g_snprintf(last_image_prop, sizeof(last_image_prop), + PER_SCREEN_PROP_FORMAT "/last-image", + panel->screen, panel->monitor); + last_image = xfconf_channel_get_string(panel->channel, last_image_prop, NULL); + } + + if(last_image != NULL) { + /* Now that we have the location of the last image used, we need to + * trim it down to just the path, convert it to a uri, and set it */ + gchar *dir_name = g_path_get_dirname(last_image); + image_uri = g_filename_to_uri(dir_name, NULL, NULL); + if(image_uri != NULL) { + gtk_file_chooser_set_current_folder_uri(GTK_FILE_CHOOSER(chooser), image_uri); + g_free(image_uri); + } + + g_free(last_image); + g_free(dir_name); + } + if(gtk_dialog_run(GTK_DIALOG(chooser)) == GTK_RESPONSE_ACCEPT) { GSList *filenames = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(chooser)); GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(panel->image_treeview)); @@ -915,10 +945,11 @@ add_file_button_clicked(GtkWidget *button, if(iter) { pdata->iters = g_slist_prepend(pdata->iters, iter); - /* auto-select the first one added */ + /* auto-select the first one added and save its location */ if(l == filenames) { GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(panel->image_treeview)); gtk_tree_selection_select_iter(sel, iter); + xfconf_channel_set_string(panel->channel, last_file_prop, l->data); } } } -- 1.7.5.4