[gthumb] selections: added a command to open the original folder



commit ffdbabbdf509af120648558fbea764752b9ceb74
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Mon Apr 9 20:52:54 2012 +0200

    selections: added a command to open the original folder

 extensions/selections/actions.c   |   24 ++++++++++++++++
 extensions/selections/actions.h   |    1 +
 extensions/selections/callbacks.c |   54 +++++++++++++++++++++++++++++++++++++
 extensions/selections/callbacks.h |   11 +++++---
 extensions/selections/main.c      |    1 +
 5 files changed, 87 insertions(+), 4 deletions(-)
---
diff --git a/extensions/selections/actions.c b/extensions/selections/actions.c
index 8dbd9a1..036f365 100644
--- a/extensions/selections/actions.c
+++ b/extensions/selections/actions.c
@@ -137,3 +137,27 @@ gth_browser_activate_action_remove_from_selection (GthBrowser *browser,
 	g_free (uri);
 }
 
+
+void
+gth_browser_activate_action_selection_go_to_container (GthBrowser *browser,
+						       int         n_selection)
+{
+	GList *items;
+	GList *file_list = NULL;
+
+	items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
+	file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
+
+	if (file_list != NULL) {
+		GthFileData *first_file = file_list->data;
+		GFile       *parent;
+
+		parent = g_file_get_parent (first_file->file);
+		gth_browser_go_to (browser, parent, first_file->file);
+
+		g_object_unref (parent);
+	}
+
+	_g_object_list_unref (file_list);
+	_gtk_tree_path_list_free (items);
+}
diff --git a/extensions/selections/actions.h b/extensions/selections/actions.h
index 7c31c7e..bf641b6 100644
--- a/extensions/selections/actions.h
+++ b/extensions/selections/actions.h
@@ -37,5 +37,6 @@ DEFINE_ACTION(gth_browser_activate_action_go_selection_3)
 DEFINE_ACTION(gth_browser_activate_action_add_to_selection_1)
 DEFINE_ACTION(gth_browser_activate_action_add_to_selection_2)
 DEFINE_ACTION(gth_browser_activate_action_add_to_selection_3)
+DEFINE_ACTION(gth_browser_activate_action_selection_go_to_container)
 
 #endif /* ACTIONS_H */
diff --git a/extensions/selections/callbacks.c b/extensions/selections/callbacks.c
index 2b3a5e0..7a67c52 100644
--- a/extensions/selections/callbacks.c
+++ b/extensions/selections/callbacks.c
@@ -58,9 +58,30 @@ static const char *fixed_ui_info =
 "</ui>";
 
 
+static const char *vfs_ui_info =
+"<ui>"
+"  <popup name='FileListPopup'>"
+"    <placeholder name='Open_Actions'>"
+"      <menuitem action='Go_FileContainer'/>"
+"    </placeholder>"
+"  </popup>"
+"  <popup name='FilePopup'>"
+"    <placeholder name='Open_Actions'>"
+"      <menuitem action='Go_FileContainer'/>"
+"    </placeholder>"
+"  </popup>"
+"</ui>";
+
+
 static GthActionEntryExt selections_action_entries[] = {
 	{ "Edit_AddToSelection", GTK_STOCK_ADD, N_("Add to _Selection") },
 
+        { "Go_FileContainer", GTK_STOCK_JUMP_TO,
+          N_("Open _Folder"), "<alt>End",
+          N_("Go to the folder that contains the selected file"),
+       	  GTH_ACTION_FLAG_NONE,
+          G_CALLBACK (gth_browser_activate_action_selection_go_to_container) },
+
 	{ "Edit_AddToSelection_1", "selection1",
 	  N_("Selection 1"), NULL,
 	  NULL,
@@ -99,6 +120,7 @@ static guint selections_action_entries_size = G_N_ELEMENTS (selections_action_en
 typedef struct {
 	GthBrowser     *browser;
 	GtkActionGroup *actions;
+	guint           vfs_merge_id;
 } BrowserData;
 
 
@@ -174,6 +196,38 @@ selections__gth_browser_file_list_key_press_cb (GthBrowser  *browser,
 
 
 void
+selections__gth_browser_load_location_after_cb (GthBrowser   *browser,
+						GthFileData  *location_data,
+						const GError *error)
+{
+	BrowserData *data;
+
+	if ((location_data == NULL) || (error != NULL))
+		return;
+
+	data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
+
+	if (GTH_IS_FILE_SOURCE_SELECTIONS (gth_browser_get_location_source (browser))) {
+		if (data->vfs_merge_id == 0) {
+			GError *error = NULL;
+
+			data->vfs_merge_id = gtk_ui_manager_add_ui_from_string (gth_browser_get_ui_manager (browser), vfs_ui_info, -1, &error);
+			if (data->vfs_merge_id == 0) {
+				g_message ("building menus failed: %s", error->message);
+				g_error_free (error);
+			}
+		}
+	}
+	else {
+		if (data->vfs_merge_id != 0) {
+			gtk_ui_manager_remove_ui (gth_browser_get_ui_manager (browser), data->vfs_merge_id);
+			data->vfs_merge_id = 0;
+		}
+	}
+}
+
+
+void
 selections__gth_browser_update_extra_widget_cb (GthBrowser *browser)
 {
 	GthFileData *location_data;
diff --git a/extensions/selections/callbacks.h b/extensions/selections/callbacks.h
index 18139d6..0bff3bb 100644
--- a/extensions/selections/callbacks.h
+++ b/extensions/selections/callbacks.h
@@ -24,9 +24,12 @@
 
 #include <gthumb.h>
 
-void      selections__gth_browser_construct_cb           (GthBrowser  *browser);
-gpointer  selections__gth_browser_file_list_key_press_cb (GthBrowser  *browser,
-							  GdkEventKey *event);
-void      selections__gth_browser_update_extra_widget_cb (GthBrowser  *browser);
+void      selections__gth_browser_construct_cb           (GthBrowser   *browser);
+gpointer  selections__gth_browser_file_list_key_press_cb (GthBrowser   *browser,
+							  GdkEventKey  *event);
+void      selections__gth_browser_load_location_after_cb (GthBrowser   *browser,
+							  GthFileData  *location_data,
+							  const GError *error);
+void      selections__gth_browser_update_extra_widget_cb (GthBrowser   *browser);
 
 #endif /* CALLBACKS_H */
diff --git a/extensions/selections/main.c b/extensions/selections/main.c
index ef87285..2dcfaeb 100644
--- a/extensions/selections/main.c
+++ b/extensions/selections/main.c
@@ -33,6 +33,7 @@ gthumb_extension_activate (void)
 	gth_main_register_file_source (GTH_TYPE_FILE_SOURCE_SELECTIONS);
 	gth_hook_add_callback ("gth-browser-construct", 10, G_CALLBACK (selections__gth_browser_construct_cb), NULL);
 	gth_hook_add_callback ("gth-browser-file-list-key-press", 10, G_CALLBACK (selections__gth_browser_file_list_key_press_cb), NULL);
+	gth_hook_add_callback ("gth-browser-load-location-after", 10, G_CALLBACK (selections__gth_browser_load_location_after_cb), NULL);
 	gth_hook_add_callback ("gth-browser-update-extra-widget", 20, G_CALLBACK (selections__gth_browser_update_extra_widget_cb), NULL);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]