file chooser: Allow opening folders in the file manager

This has been suggested in
https://bugzilla.gnome.org/show_bug.cgi?id=325150#c2
This commit is contained in:
Matthias Clasen 2015-02-11 23:34:04 -05:00
parent 6886f479fe
commit b876e036b2

View File

@ -77,6 +77,8 @@
#include "gtkorientable.h" #include "gtkorientable.h"
#include "gtkwindowgroup.h" #include "gtkwindowgroup.h"
#include "gtkintl.h" #include "gtkintl.h"
#include "gtkshow.h"
#include "gtkmain.h"
#include <cairo-gobject.h> #include <cairo-gobject.h>
#include <errno.h> #include <errno.h>
@ -218,6 +220,7 @@ struct _GtkFileChooserWidgetPrivate {
GtkWidget *browse_files_popup_menu_size_column_item; GtkWidget *browse_files_popup_menu_size_column_item;
GtkWidget *browse_files_popup_menu_copy_file_location_item; GtkWidget *browse_files_popup_menu_copy_file_location_item;
GtkWidget *browse_files_popup_menu_visit_file_item; GtkWidget *browse_files_popup_menu_visit_file_item;
GtkWidget *browse_files_popup_menu_open_folder_item;
GtkWidget *browse_files_popup_menu_sort_directories_item; GtkWidget *browse_files_popup_menu_sort_directories_item;
GtkWidget *browse_new_folder_button; GtkWidget *browse_new_folder_button;
GtkWidget *browse_path_bar_hbox; GtkWidget *browse_path_bar_hbox;
@ -1426,6 +1429,30 @@ visit_file_cb (GtkMenuItem *item,
g_slist_free (files); g_slist_free (files);
} }
/* Callback used when the "Open this folder" menu item is activated */
static void
open_folder_cb (GtkMenuItem *item,
GtkFileChooserWidget *impl)
{
GSList *files;
files = search_get_selected_files (impl);
/* Sigh, just use the first one */
if (files)
{
GFile *file = files->data;
gchar *uri;
uri = g_file_get_uri (file);
gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (impl)), uri, gtk_get_current_event_time (), NULL);
g_free (uri);
}
g_slist_foreach (files, (GFunc) g_object_unref, NULL);
g_slist_free (files);
}
/* callback used when the "Show Hidden Files" menu item is toggled */ /* callback used when the "Show Hidden Files" menu item is toggled */
static void static void
show_hidden_toggled_cb (GtkCheckMenuItem *item, show_hidden_toggled_cb (GtkCheckMenuItem *item,
@ -1659,6 +1686,9 @@ check_file_list_menu_sensitivity (GtkFileChooserWidget *impl)
gtk_widget_set_sensitive (priv->browse_files_popup_menu_add_shortcut_item, active && all_folders); gtk_widget_set_sensitive (priv->browse_files_popup_menu_add_shortcut_item, active && all_folders);
if (priv->browse_files_popup_menu_visit_file_item) if (priv->browse_files_popup_menu_visit_file_item)
gtk_widget_set_sensitive (priv->browse_files_popup_menu_visit_file_item, active); gtk_widget_set_sensitive (priv->browse_files_popup_menu_visit_file_item, active);
if (priv->browse_files_popup_menu_open_folder_item)
gtk_widget_set_visible (priv->browse_files_popup_menu_open_folder_item, (num_selected == 1) && all_folders);
} }
static GtkWidget * static GtkWidget *
@ -1711,6 +1741,9 @@ file_list_build_popup_menu (GtkFileChooserWidget *impl)
priv->browse_files_popup_menu_visit_file_item = file_list_add_menu_item (impl, _("_Visit File"), priv->browse_files_popup_menu_visit_file_item = file_list_add_menu_item (impl, _("_Visit File"),
G_CALLBACK (visit_file_cb)); G_CALLBACK (visit_file_cb));
priv->browse_files_popup_menu_open_folder_item = file_list_add_menu_item (impl, _("_Open With File Manager"),
G_CALLBACK (open_folder_cb));
priv->browse_files_popup_menu_copy_file_location_item = file_list_add_menu_item (impl, _("_Copy Location"), priv->browse_files_popup_menu_copy_file_location_item = file_list_add_menu_item (impl, _("_Copy Location"),
G_CALLBACK (copy_file_location_cb)); G_CALLBACK (copy_file_location_cb));