From 2476d351427debdffa830bdcac7dc8e8b15b85cb Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Mon, 5 Sep 2011 13:19:50 -0500 Subject: [PATCH] Menu item to visit the selected files in recent-files mode This will take you to the file's folder and select the file in question. The menu item is only available in Recently-used and Search modes, so that you can go from files in them to the 'normal' browsing mode. Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 31 ++++++++++++++++++++++++++++--- gtk/gtkfilechooserprivate.h | 1 + 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 8ff819695..d7c1ebf22 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -3894,7 +3894,28 @@ copy_file_location_cb (GtkMenuItem *item, } } -/* Callback used when the "Show Hidden Files" menu item is toggled */ +/* Callback used when the "Visit this file" menu item is activated */ +static void +visit_file_cb (GtkMenuItem *item, + GtkFileChooserDefault *impl) +{ + GSList *files; + + files = search_get_selected_files (impl); + + /* Sigh, just use the first one */ + if (files) + { + GFile *file = files->data; + + gtk_file_chooser_default_select_file (impl, file, NULL); /* NULL-GError */ + } + + g_slist_foreach (files, (GFunc) g_object_unref, NULL); + g_slist_free (files); +} + +/* callback used when the "Show Hidden Files" menu item is toggled */ static void show_hidden_toggled_cb (GtkCheckMenuItem *item, GtkFileChooserDefault *impl) @@ -4147,6 +4168,9 @@ file_list_build_popup_menu (GtkFileChooserDefault *impl) impl->browse_files_tree_view, popup_menu_detach_cb); + impl->browse_files_popup_menu_visit_file_item = file_list_add_image_menu_item (impl, GTK_STOCK_DIRECTORY, _("_Visit this file"), + G_CALLBACK (visit_file_cb)); + impl->browse_files_popup_menu_copy_file_location_item = file_list_add_image_menu_item (impl, GTK_STOCK_COPY, _("_Copy file's location"), G_CALLBACK (copy_file_location_cb)); @@ -4173,12 +4197,13 @@ file_list_update_popup_menu (GtkFileChooserDefault *impl) { file_list_build_popup_menu (impl); - /* FIXME - handle OPERATION_MODE_SEARCH and OPERATION_MODE_RECENT */ - /* The sensitivity of the Add to Bookmarks item is set in * bookmarks_check_add_sensitivity() */ + /* 'Visit this file' */ + gtk_widget_set_visible (impl->browse_files_popup_menu_visit_file_item, (impl->operation_mode != OPERATION_MODE_BROWSE)); + /* 'Show Hidden Files' */ g_signal_handlers_block_by_func (impl->browse_files_popup_menu_hidden_files_item, G_CALLBACK (show_hidden_toggled_cb), impl); diff --git a/gtk/gtkfilechooserprivate.h b/gtk/gtkfilechooserprivate.h index 81fc3b25d..28691c5cd 100644 --- a/gtk/gtkfilechooserprivate.h +++ b/gtk/gtkfilechooserprivate.h @@ -181,6 +181,7 @@ struct _GtkFileChooserDefault GtkWidget *browse_files_popup_menu_hidden_files_item; GtkWidget *browse_files_popup_menu_size_column_item; GtkWidget *browse_files_popup_menu_copy_file_location_item; + GtkWidget *browse_files_popup_menu_visit_file_item; GtkWidget *browse_new_folder_button; GtkWidget *browse_path_bar_hbox; GtkSizeGroup *browse_path_bar_size_group; -- 2.43.2