[gthumb] F2 renames the folder if the folder tree is focused



commit ddef62f72f7572ec2fa2c36bda464294439f4acd
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sat Jul 2 20:25:54 2011 +0200

    F2 renames the folder if the folder tree is focused
    
    [bug #448588]

 extensions/file_manager/actions.c                  |   28 ++++++
 extensions/file_manager/actions.h                  |    1 +
 extensions/file_manager/callbacks.c                |   18 +++-
 extensions/file_manager/main.c                     |    7 ++
 extensions/rename_series/Makefile.am               |    2 -
 extensions/rename_series/actions.c                 |   45 ---------
 extensions/rename_series/actions.h                 |   31 ------
 extensions/rename_series/callbacks.c               |  101 +++----------------
 extensions/rename_series/callbacks.h               |    3 +-
 extensions/rename_series/main.c                    |    3 +-
 .../rename_series/rename_series.extension.in.in    |    1 +
 gthumb/gth-main-default-hooks.c                    |    2 +-
 12 files changed, 72 insertions(+), 170 deletions(-)
---
diff --git a/extensions/file_manager/actions.c b/extensions/file_manager/actions.c
index 53cb9fa..1d9aed1 100644
--- a/extensions/file_manager/actions.c
+++ b/extensions/file_manager/actions.c
@@ -427,6 +427,34 @@ gth_browser_activate_action_edit_delete (GtkAction  *action,
 
 
 void
+gth_browser_activate_action_edit_rename (GtkAction  *action,
+					 GthBrowser *browser)
+{
+	GtkWidget *folder_tree;
+	GtkWidget *file_list;
+
+	folder_tree = gth_browser_get_folder_tree (browser);
+	if (gtk_widget_has_focus (folder_tree)) {
+		GthFileData *file_data;
+
+		file_data = gth_folder_tree_get_selected (GTH_FOLDER_TREE (folder_tree));
+		if ((file_data != NULL) && g_file_info_get_attribute_boolean (file_data->info, G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME))
+			gth_folder_tree_start_editing (GTH_FOLDER_TREE (folder_tree), file_data->file);
+
+		_g_object_unref (file_data);
+
+		return;
+	}
+
+	file_list = gth_browser_get_file_list_view (browser);
+	if (gtk_widget_has_focus (file_list)) {
+		gth_hook_invoke ("gth-browser-file-list-rename", browser);
+		return;
+	}
+}
+
+
+void
 gth_browser_activate_action_folder_open_in_file_manager (GtkAction  *action,
 						         GthBrowser *browser)
 {
diff --git a/extensions/file_manager/actions.h b/extensions/file_manager/actions.h
index dea6afa..85f9462 100644
--- a/extensions/file_manager/actions.h
+++ b/extensions/file_manager/actions.h
@@ -34,6 +34,7 @@ DEFINE_ACTION(gth_browser_activate_action_edit_paste)
 DEFINE_ACTION(gth_browser_activate_action_edit_duplicate)
 DEFINE_ACTION(gth_browser_activate_action_edit_trash)
 DEFINE_ACTION(gth_browser_activate_action_edit_delete)
+DEFINE_ACTION(gth_browser_activate_action_edit_rename)
 DEFINE_ACTION(gth_browser_activate_action_folder_open_in_file_manager)
 DEFINE_ACTION(gth_browser_activate_action_folder_create)
 DEFINE_ACTION(gth_browser_activate_action_folder_rename)
diff --git a/extensions/file_manager/callbacks.c b/extensions/file_manager/callbacks.c
index 67ab73d..13c0871 100644
--- a/extensions/file_manager/callbacks.c
+++ b/extensions/file_manager/callbacks.c
@@ -40,6 +40,9 @@ static const char *fixed_ui_info =
 "<ui>"
 "  <menubar name='MenuBar'>"
 "    <menu name='Edit' action='EditMenu'>"
+"      <placeholder name='Folder_Actions'>"
+"        <menuitem action='Edit_Rename'/>"
+"      </placeholder>"
 "      <placeholder name='Folder_Actions_2'>"
 "        <menuitem action='Edit_Trash'/>"
 "        <menuitem action='Edit_Delete'/>"
@@ -181,6 +184,10 @@ static GtkActionEntry action_entries[] = {
 	  N_("_Delete"), NULL,
 	  N_("Delete the selected files"),
 	  G_CALLBACK (gth_browser_activate_action_edit_delete) },
+	{ "Edit_Rename", NULL,
+	  N_("_Rename"), "F2",
+	  N_("Rename the selected files"),
+	  G_CALLBACK (gth_browser_activate_action_edit_rename) },
 	{ "Folder_OpenInFileManager", NULL,
 	  N_("Open with the _File Manager"), "",
 	  NULL,
@@ -776,6 +783,13 @@ fm__gth_browser_folder_tree_drag_data_received_cb (GthBrowser    *browser,
 }
 
 
+void
+fm__gth_browser_folder_tree_selection_changed_cb (GthBrowser *browser)
+{
+	fm__gth_browser_update_sensitivity_cb (browser);
+}
+
+
 static void
 clipboard_targets_received_cb (GtkClipboard *clipboard,
 			       GdkAtom      *atoms,
@@ -864,9 +878,9 @@ fm__gth_browser_update_sensitivity_cb (GthBrowser *browser)
 	set_action_sensitive (data, "File_NewFolder", (folder != NULL) && g_file_info_get_attribute_boolean (folder->info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE));
 	*/
 
-	_gth_browser_update_paste_command_sensitivity (browser, NULL);
-
 	_g_object_unref (folder);
+
+	_gth_browser_update_paste_command_sensitivity (browser, NULL);
 }
 
 
diff --git a/extensions/file_manager/main.c b/extensions/file_manager/main.c
index eed6663..b57cb16 100644
--- a/extensions/file_manager/main.c
+++ b/extensions/file_manager/main.c
@@ -29,6 +29,13 @@
 G_MODULE_EXPORT void
 gthumb_extension_activate (void)
 {
+	/**
+	 * Called when the rename command is invoked on the file list.
+	 *
+	 * @browser (GthBrowser*): the relative window.
+	 **/
+	gth_hook_register ("gth-browser-file-list-rename", 1);
+
 	gth_hook_add_callback ("gth-browser-construct", 10, G_CALLBACK (fm__gth_browser_construct_cb), NULL);
 	gth_hook_add_callback ("gth-browser-load-location-after", 10, G_CALLBACK (fm__gth_browser_load_location_after_cb), NULL);
 	gth_hook_add_callback ("gth-browser-set-current-page", 10, G_CALLBACK (fm__gth_browser_set_current_page_cb), NULL);
diff --git a/extensions/rename_series/Makefile.am b/extensions/rename_series/Makefile.am
index e09ad62..e4ee051 100644
--- a/extensions/rename_series/Makefile.am
+++ b/extensions/rename_series/Makefile.am
@@ -4,8 +4,6 @@ extensiondir = $(pkglibdir)/extensions
 extension_LTLIBRARIES = librename_series.la
 
 librename_series_la_SOURCES = 		\
-	actions.c			\
-	actions.h			\
 	callbacks.c			\
 	callbacks.h			\
 	dlg-rename-series.c		\
diff --git a/extensions/rename_series/callbacks.c b/extensions/rename_series/callbacks.c
index 1c50994..98ddeb4 100644
--- a/extensions/rename_series/callbacks.c
+++ b/extensions/rename_series/callbacks.c
@@ -24,99 +24,30 @@
 #include <glib/gi18n.h>
 #include <glib-object.h>
 #include <gthumb.h>
-#include "actions.h"
-
-
-#define BROWSER_DATA_KEY "rename-series-browser-data"
-
-
-static const char *fixed_ui_info =
-"<ui>"
-"  <menubar name='MenuBar'>"
-"    <menu name='Edit' action='EditMenu'>"
-"      <placeholder name='Folder_Actions'>"
-"        <menuitem action='Edit_Rename'/>"
-"      </placeholder>"
-"    </menu>"
-"  </menubar>"
-"</ui>";
-
-
-static GtkActionEntry action_entries[] = {
-	{ "Edit_Rename", NULL,
-	  N_("_Rename"), "F2",
-	  N_("Rename the selected files"),
-	  G_CALLBACK (gth_browser_activate_action_edit_rename) },
-};
-
-
-typedef struct {
-	GtkActionGroup *action_group;
-	guint           fixed_merge_id;
-} BrowserData;
-
-
-static void
-browser_data_free (BrowserData *data)
-{
-	g_free (data);
-}
-
-
-static void
-set_action_sensitive (BrowserData *data,
-		      const char  *action_name,
-		      gboolean     sensitive)
-{
-	GtkAction *action;
-
-	action = gtk_action_group_get_action (data->action_group, action_name);
-	g_object_set (action, "sensitive", sensitive, NULL);
-}
+#include "dlg-rename-series.h"
 
 
 void
-rs__gth_browser_construct_cb (GthBrowser *browser)
+rs__gth_browser_file_list_rename_cb (GthBrowser *browser)
 {
-	BrowserData *data;
-	GError      *error = NULL;
-
-	g_return_if_fail (GTH_IS_BROWSER (browser));
-
-	data = g_new0 (BrowserData, 1);
-
-	data->action_group = gtk_action_group_new ("Rename Actions");
-	gtk_action_group_set_translation_domain (data->action_group, NULL);
-	gtk_action_group_add_actions (data->action_group,
-				      action_entries,
-				      G_N_ELEMENTS (action_entries),
-				      browser);
-	gtk_ui_manager_insert_action_group (gth_browser_get_ui_manager (browser), data->action_group, 0);
-
-	data->fixed_merge_id = gtk_ui_manager_add_ui_from_string (gth_browser_get_ui_manager (browser), fixed_ui_info, -1, &error);
-	if (data->fixed_merge_id == 0) {
-		g_warning ("building ui failed: %s", error->message);
-		g_error_free (error);
-	}
-
-	g_object_set_data_full (G_OBJECT (browser), BROWSER_DATA_KEY, data, (GDestroyNotify) browser_data_free);
+	GList *items;
+	GList *file_data_list;
+	GList *file_list;
+
+	items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
+	file_data_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
+	file_list = gth_file_data_list_to_file_list (file_data_list);
+	if (file_list != NULL)
+		dlg_rename_series (browser, file_list);
+
+	_g_object_list_unref (file_list);
+	_g_object_list_unref (file_data_list);
+	_gtk_tree_path_list_free (items);
 }
 
 
 void
-rs__gth_browser_update_sensitivity_cb (GthBrowser *browser)
+rs__gth_browser_selection_changed_cb (GthBrowser *browser)
 {
-	BrowserData   *data;
-	GthFileSource *file_source;
-	int            n_selected;
-	gboolean       sensitive;
-
-	data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
-	g_return_if_fail (data != NULL);
-
-	file_source = gth_browser_get_location_source (browser);
-	n_selected = gth_file_selection_get_n_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
 
-	sensitive = (n_selected > 0) && (file_source != NULL);
-	set_action_sensitive (data, "Edit_Rename", sensitive);
 }
diff --git a/extensions/rename_series/callbacks.h b/extensions/rename_series/callbacks.h
index 7598b52..8446fa2 100644
--- a/extensions/rename_series/callbacks.h
+++ b/extensions/rename_series/callbacks.h
@@ -24,7 +24,6 @@
 
 #include <gthumb.h>
 
-void rs__gth_browser_construct_cb          (GthBrowser *browser);
-void rs__gth_browser_update_sensitivity_cb (GthBrowser *browser);
+void rs__gth_browser_file_list_rename_cb  (GthBrowser *browser);
 
 #endif /* CALLBACKS_H */
diff --git a/extensions/rename_series/main.c b/extensions/rename_series/main.c
index d76a938..418a394 100644
--- a/extensions/rename_series/main.c
+++ b/extensions/rename_series/main.c
@@ -29,8 +29,7 @@
 G_MODULE_EXPORT void
 gthumb_extension_activate (void)
 {
-	gth_hook_add_callback ("gth-browser-construct", 10, G_CALLBACK (rs__gth_browser_construct_cb), NULL);
-	gth_hook_add_callback ("gth-browser-update-sensitivity", 10, G_CALLBACK (rs__gth_browser_update_sensitivity_cb), NULL);
+	gth_hook_add_callback ("gth-browser-file-list-rename", 10, G_CALLBACK (rs__gth_browser_file_list_rename_cb), NULL);
 }
 
 
diff --git a/extensions/rename_series/rename_series.extension.in.in b/extensions/rename_series/rename_series.extension.in.in
index 536145a..54d8593 100644
--- a/extensions/rename_series/rename_series.extension.in.in
+++ b/extensions/rename_series/rename_series.extension.in.in
@@ -9,3 +9,4 @@ Category=List-Tool
 [Loader]
 Type=module
 File=%LIBRARY%
+Requires=file_manager
diff --git a/gthumb/gth-main-default-hooks.c b/gthumb/gth-main-default-hooks.c
index 178a8cd..87fa999 100644
--- a/gthumb/gth-main-default-hooks.c
+++ b/gthumb/gth-main-default-hooks.c
@@ -158,7 +158,7 @@ gth_main_register_default_hooks (void)
 	gth_hook_register ("gth-browser-view-file", 2);
 
 	/**
-	 * Called when the selection changes
+	 * Called when the file list selection changes
 	 *
 	 * @browser (GthBrowser*): the relative window.
 	 **/



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