From 6764448975ff1f22262962195f27c53fd44b655c Mon Sep 17 00:00:00 2001 From: Eric Koegel Date: Thu, 5 Apr 2012 16:28:25 +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 | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 51 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..ec71e65 100644 --- a/settings/main.c +++ b/settings/main.c @@ -874,6 +874,27 @@ xfdesktop_settings_save_backdrop_list(AppearancePanel *panel, return ret; } +static gchar* +get_folder_uri_for_property(XfconfChannel *channel, + const gchar *property) +{ + gchar *image_location = NULL, *image_uri = NULL, *dir_name = NULL; + + image_location = xfconf_channel_get_string(channel, property, NULL); + + if(image_location == NULL) + return NULL; + + /* trim it down to just the path, convert that to a uri */ + dir_name = g_path_get_dirname(image_location); + image_uri = g_filename_to_uri(dir_name, NULL, NULL); + + g_free(image_location); + g_free(dir_name); + + return image_uri; +} + static void add_file_button_clicked(GtkWidget *button, gpointer user_data) @@ -881,6 +902,15 @@ add_file_button_clicked(GtkWidget *button, AppearancePanel *panel = user_data; GtkWidget *chooser; GtkFileFilter *filter; + gchar last_file_added_prop[1024], last_image_prop[1024]; + gchar *directory_uri; + + g_snprintf(last_file_added_prop, sizeof(last_file_added_prop), + PER_SCREEN_PROP_FORMAT "/last-file-added", + panel->screen, panel->monitor); + g_snprintf(last_image_prop, sizeof(last_image_prop), + PER_SCREEN_PROP_FORMAT "/last-image", + panel->screen, panel->monitor); chooser = gtk_file_chooser_dialog_new(_("Add Image File(s)"), GTK_WINDOW(gtk_widget_get_toplevel(button)), @@ -903,6 +933,17 @@ add_file_button_clicked(GtkWidget *button, exo_gtk_file_chooser_add_thumbnail_preview(GTK_FILE_CHOOSER(chooser)); + directory_uri = get_folder_uri_for_property(panel->channel, last_file_added_prop); + + /* try the last-image set if the last-file-added path isn't valid */ + if(directory_uri == NULL) + directory_uri = get_folder_uri_for_property(panel->channel, last_image_prop); + + if(directory_uri != NULL) { + gtk_file_chooser_set_current_folder_uri(GTK_FILE_CHOOSER(chooser), directory_uri); + g_free(directory_uri); + } + 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 +956,12 @@ 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_added_prop, l->data); } } } -- 1.7.5.4