[gthumb: 20/23] selections: added context menu commands to add files to a selection



commit e6d6bf0b4512642c0696108987ce9fb1cbfbba72
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Mar 4 17:18:22 2012 +0100

    selections: added context menu commands to add files to a selection

 extensions/selections/actions.c   |   49 +++++++++++++++++++++++++
 extensions/selections/actions.h   |    6 +++
 extensions/selections/callbacks.c |   73 ++++++++++++++++++++++---------------
 3 files changed, 98 insertions(+), 30 deletions(-)
---
diff --git a/extensions/selections/actions.c b/extensions/selections/actions.c
index d79d73d..40227f5 100644
--- a/extensions/selections/actions.c
+++ b/extensions/selections/actions.c
@@ -22,6 +22,7 @@
 
 #include <config.h>
 #include <gthumb.h>
+#include "gth-selections-manager.h"
 
 
 static void
@@ -62,3 +63,51 @@ gth_browser_activate_action_go_selection_3 (GtkAction  *action,
 {
 	gth_browser_activate_action_show_selection (browser, 3);
 }
+
+
+void
+gth_browser_activate_action_add_to_selection (GthBrowser *browser,
+					      int         n_selection)
+{
+	char  *uri;
+	GFile *folder;
+	GList *items;
+	GList *file_list = NULL;
+	GList *files;
+
+	uri = g_strdup_printf ("selection:///%d", n_selection);
+	folder = g_file_new_for_uri (uri);
+	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);
+	files = gth_file_data_list_to_file_list (file_list);
+	gth_selections_manager_add_files (folder, files, -1);
+
+	_g_object_list_unref (files);
+	_g_object_list_unref (file_list);
+	_gtk_tree_path_list_free (items);
+	g_object_unref (folder);
+	g_free (uri);
+}
+
+
+void
+gth_browser_activate_action_add_to_selection_1 (GtkAction  *action,
+						GthBrowser *browser)
+{
+	gth_browser_activate_action_add_to_selection (browser, 1);
+}
+
+void
+gth_browser_activate_action_add_to_selection_2 (GtkAction  *action,
+						GthBrowser *browser)
+{
+	gth_browser_activate_action_add_to_selection (browser, 2);
+}
+
+
+void
+gth_browser_activate_action_add_to_selection_3 (GtkAction  *action,
+						GthBrowser *browser)
+{
+	gth_browser_activate_action_add_to_selection (browser, 3);
+}
diff --git a/extensions/selections/actions.h b/extensions/selections/actions.h
index 7de5e18..9d2ef59 100644
--- a/extensions/selections/actions.h
+++ b/extensions/selections/actions.h
@@ -26,8 +26,14 @@
 
 #define DEFINE_ACTION(x) void x (GtkAction *action, gpointer data);
 
+void gth_browser_activate_action_add_to_selection (GthBrowser *browser,
+						   int         n_selection);
+
 DEFINE_ACTION(gth_browser_activate_action_go_selection_1)
 DEFINE_ACTION(gth_browser_activate_action_go_selection_2)
 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)
 
 #endif /* ACTIONS_H */
diff --git a/extensions/selections/callbacks.c b/extensions/selections/callbacks.c
index f69df21..82c77de 100644
--- a/extensions/selections/callbacks.c
+++ b/extensions/selections/callbacks.c
@@ -34,24 +34,62 @@
 
 static const char *fixed_ui_info =
 "<ui>"
+"  <popup name='FileListPopup'>"
+"    <placeholder name='Folder_Actions2'>"
+"      <menu action='Edit_AddToSelection'>"
+"        <menuitem action='Edit_AddToSelection_1'/>"
+"        <menuitem action='Edit_AddToSelection_2'/>"
+"        <menuitem action='Edit_AddToSelection_3'/>"
+"      </menu>"
+"    </placeholder>"
+"  </popup>"
+"  <popup name='FilePopup'>"
+"    <placeholder name='Folder_Actions2'>"
+"      <menu action='Edit_AddToSelection'>"
+"        <menuitem action='Edit_AddToSelection_1'/>"
+"        <menuitem action='Edit_AddToSelection_2'/>"
+"        <menuitem action='Edit_AddToSelection_3'/>"
+"      </menu>"
+"    </placeholder>"
+"  </popup>"
 "  <accelerator action=\"Go_Selection_1\" />"
 "  <accelerator action=\"Go_Selection_2\" />"
 "  <accelerator action=\"Go_Selection_3\" />"
 "</ui>";
 
 
-static GtkActionEntry selections_action_entries[] = {
+static GthActionEntryExt selections_action_entries[] = {
+	{ "Edit_AddToSelection", GTK_STOCK_ADD, N_("Add to _Selection") },
+
+	{ "Edit_AddToSelection_1", "selection1",
+	  N_("Selection 1"), NULL,
+	  NULL,
+	  GTH_ACTION_FLAG_ALWAYS_SHOW_IMAGE,
+	  G_CALLBACK (gth_browser_activate_action_add_to_selection_1) },
+	{ "Edit_AddToSelection_2", "selection2",
+	  N_("Selection 2"), NULL,
+	  NULL,
+	  GTH_ACTION_FLAG_ALWAYS_SHOW_IMAGE,
+	  G_CALLBACK (gth_browser_activate_action_add_to_selection_2) },
+	{ "Edit_AddToSelection_3", "selection3",
+	  N_("Selection 3"), NULL,
+	  NULL,
+	  GTH_ACTION_FLAG_ALWAYS_SHOW_IMAGE,
+	  G_CALLBACK (gth_browser_activate_action_add_to_selection_3) },
 	{ "Go_Selection_1", NULL,
 	  NULL, "<control>1",
 	  NULL,
+	  GTH_ACTION_FLAG_NONE,
 	  G_CALLBACK (gth_browser_activate_action_go_selection_1) },
 	{ "Go_Selection_2", NULL,
 	  NULL, "<control>2",
 	  NULL,
+	  GTH_ACTION_FLAG_NONE,
 	  G_CALLBACK (gth_browser_activate_action_go_selection_2) },
 	{ "Go_Selection_3", NULL,
 	  NULL, "<control>3",
 	  NULL,
+	  GTH_ACTION_FLAG_NONE,
 	  G_CALLBACK (gth_browser_activate_action_go_selection_3) }
 
 };
@@ -86,10 +124,10 @@ selections__gth_browser_construct_cb (GthBrowser *browser)
 
 	data->actions = gtk_action_group_new ("Selections Actions");
 	gtk_action_group_set_translation_domain (data->actions, NULL);
-	gtk_action_group_add_actions (data->actions,
-				      selections_action_entries,
-				      selections_action_entries_size,
-				      browser);
+	_gtk_action_group_add_actions_with_flags (data->actions,
+						  selections_action_entries,
+						  selections_action_entries_size,
+						  browser);
 	gtk_ui_manager_insert_action_group (gth_browser_get_ui_manager (browser), data->actions, 0);
 
 	if (! gtk_ui_manager_add_ui_from_string (gth_browser_get_ui_manager (browser), fixed_ui_info, -1, &error)) {
@@ -99,31 +137,6 @@ selections__gth_browser_construct_cb (GthBrowser *browser)
 }
 
 
-static void
-gth_browser_activate_action_add_to_selection (GthBrowser *browser,
-					      int         n_selection)
-{
-	char  *uri;
-	GFile *folder;
-	GList *items;
-	GList *file_list = NULL;
-	GList *files;
-
-	uri = g_strdup_printf ("selection:///%d", n_selection);
-	folder = g_file_new_for_uri (uri);
-	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);
-	files = gth_file_data_list_to_file_list (file_list);
-	gth_selections_manager_add_files (folder, files, -1);
-
-	_g_object_list_unref (files);
-	_g_object_list_unref (file_list);
-	_gtk_tree_path_list_free (items);
-	g_object_unref (folder);
-	g_free (uri);
-}
-
-
 gpointer
 selections__gth_browser_file_list_key_press_cb (GthBrowser  *browser,
 						GdkEventKey *event)



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