[nautilus/undo-manager] directory-view: update to the new menu code from undo-manager
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/undo-manager] directory-view: update to the new menu code from undo-manager
- Date: Tue, 7 Dec 2010 15:56:51 +0000 (UTC)
commit 64171b2f052941bc76e65cc482a718969e70aa30
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Tue Dec 7 16:54:24 2010 +0100
directory-view: update to the new menu code from undo-manager
src/file-manager/fm-directory-view.c | 217 ++++++++++++++--------------------
1 files changed, 89 insertions(+), 128 deletions(-)
---
diff --git a/src/file-manager/fm-directory-view.c b/src/file-manager/fm-directory-view.c
index fe67709..e6dd36e 100644
--- a/src/file-manager/fm-directory-view.c
+++ b/src/file-manager/fm-directory-view.c
@@ -250,13 +250,6 @@ struct FMDirectoryViewDetails
gboolean allow_moves;
GdkPoint context_menu_position;
-
- gboolean undo_active;
- gboolean redo_active;
- gchar* undo_action_description;
- gchar* undo_action_label;
- gchar* redo_action_description;
- gchar* redo_action_label;
};
typedef struct {
@@ -387,18 +380,6 @@ static inline void fm_directory_view_widget_to_file_operation_position (FMDirect
static void fm_directory_view_widget_to_file_operation_position_xy (FMDirectoryView *view,
int *x, int *y);
-/* undo-related actions */
-static void undo_redo_menu_update_callback (NautilusUndoStackManager *manager,
- gpointer arg1,
- gpointer data);
-static void undo_update_menu (FMDirectoryView *view);
-static void real_action_undo (FMDirectoryView *view);
-static void real_action_redo (FMDirectoryView *view);
-static void action_undo_callback (GtkAction *action,
- gpointer callback_data);
-static void action_redo_callback (GtkAction *action,
- gpointer callback_data);
-
EEL_CLASS_BOILERPLATE (FMDirectoryView, fm_directory_view, GTK_TYPE_SCROLLED_WINDOW)
EEL_IMPLEMENT_MUST_OVERRIDE_SIGNAL (fm_directory_view, add_file)
@@ -1877,77 +1858,13 @@ file_list_from_location_list (const GList *uri_list)
static void
-undo_redo_menu_update_callback (NautilusUndoStackManager* manager, gpointer arg, gpointer data)
+undo_manager_changed_cb (NautilusUndoStackManager* manager,
+ FMDirectoryView *view)
{
- FMDirectoryView *view;
- NautilusUndoStackMenuData *menudata;
-
- view = FM_DIRECTORY_VIEW (data);
-
- menudata = (NautilusUndoStackMenuData*) arg;
-
- g_free (view->details->undo_action_label);
- g_free (view->details->undo_action_description);
- g_free (view->details->redo_action_label);
- g_free (view->details->redo_action_description);
-
- view->details->undo_active = menudata->undo_label ? TRUE : FALSE;
- view->details->redo_active = menudata->redo_label ? TRUE : FALSE;
-
- view->details->undo_action_label = g_strdup (menudata->undo_label);
- view->details->undo_action_description = g_strdup (menudata->undo_description);
- view->details->redo_action_label = g_strdup (menudata->redo_label);
- view->details->redo_action_description = g_strdup (menudata->redo_description);
-
schedule_update_menus (view);
}
static void
-undo_update_menu (FMDirectoryView *view)
-{
- GtkAction *action;
- gchar *label;
- gchar *tooltip;
- gboolean available;
-
- /* Update undo entry */
- action = gtk_action_group_get_action (view->details->dir_action_group,
- FM_ACTION_UNDO);
- available = view->details->undo_active;
- if (available) {
- label = view->details->undo_action_label;
- tooltip = view->details->undo_action_description;
- } else {
- /* Reset to default info */
- label = _("Undo");
- tooltip = _("Undo the last action");
- }
- g_object_set (action,
- "label", label,
- "tooltip", tooltip,
- NULL);
- gtk_action_set_sensitive (action, available);
-
- /* Update redo entry */
- action = gtk_action_group_get_action (view->details->dir_action_group,
- FM_ACTION_REDO);
- available = view->details->redo_active;
- if (available) {
- label = view->details->redo_action_label;
- tooltip = view->details->redo_action_description;
- } else {
- /* Reset to default info */
- label = _("Redo");
- tooltip = _("Redo the last undone action");
- }
- g_object_set (action,
- "label", label,
- "tooltip", tooltip,
- NULL);
- gtk_action_set_sensitive (action, available);
-}
-
-static void
fm_directory_view_set_selection_locations (NautilusView *nautilus_view,
GList *selection_locations)
{
@@ -2030,6 +1947,7 @@ fm_directory_view_init (FMDirectoryView *view)
NautilusDirectory *scripts_directory;
NautilusDirectory *templates_directory;
char *templates_uri;
+ NautilusUndoStackManager* manager;
view->details = g_new0 (FMDirectoryViewDetails, 1);
@@ -2103,20 +2021,9 @@ fm_directory_view_init (FMDirectoryView *view)
"changed::" NAUTILUS_PREFERENCES_LOCKDOWN_COMMAND_LINE,
G_CALLBACK (schedule_update_menus), view);
- /* Update undo actions stuff and connect signals from the undostack manager */
- view->details->undo_active = FALSE;
- view->details->redo_active = FALSE;
- view->details->undo_action_description = NULL;
- view->details->undo_action_label = NULL;
- view->details->redo_action_description = NULL;
- view->details->redo_action_label = NULL;
-
- NautilusUndoStackManager* manager = nautilus_undo_stack_manager_get ();
-
- g_signal_connect_object (G_OBJECT(manager), "request-menu-update",
- G_CALLBACK(undo_redo_menu_update_callback), view, 0);
-
- nautilus_undo_stack_manager_request_menu_update (nautilus_undo_stack_manager_get());
+ manager = nautilus_undo_stack_manager_get ();
+ g_signal_connect_object (manager, "undo-changed",
+ G_CALLBACK (undo_manager_changed_cb), view, 0);
}
static void
@@ -3253,20 +3160,6 @@ schedule_changes (FMDirectoryView *view)
}
static void
-action_undo_callback (GtkAction *action,
- gpointer callback_data)
-{
- real_action_undo (FM_DIRECTORY_VIEW (callback_data));
-}
-
-static void
-action_redo_callback (GtkAction *action,
- gpointer callback_data)
-{
- real_action_redo (FM_DIRECTORY_VIEW (callback_data));
-}
-
-static void
files_added_callback (NautilusDirectory *directory,
GList *files,
gpointer callback_data)
@@ -6238,6 +6131,64 @@ invoke_external_bulk_rename_utility (FMDirectoryView *view,
}
static void
+update_undo_actions (FMDirectoryView *view,
+ gboolean invalidate)
+{
+ NautilusUndoStackManager *manager;
+ NautilusUndoStackMenuData *menu_data;
+ GtkAction *action;
+ const gchar *label, *tooltip;
+ gboolean available;
+ gboolean undo_active, redo_active;
+
+ manager = nautilus_undo_stack_manager_get ();
+ menu_data = nautilus_undo_stack_manager_get_menu_data (manager);
+
+ undo_active = menu_data->undo_label != NULL && !invalidate;
+ redo_active = menu_data->redo_label != NULL && !invalidate;
+
+ /* Update undo entry */
+ action = gtk_action_group_get_action (view->details->dir_action_group,
+ FM_ACTION_UNDO);
+ available = undo_active;
+ if (available) {
+ label = menu_data->undo_label;
+ tooltip = menu_data->undo_description;
+ } else {
+ /* Reset to default info */
+ label = _("Undo");
+ tooltip = _("Undo the last action");
+ }
+
+ g_object_set (action,
+ "label", label,
+ "tooltip", tooltip,
+ NULL);
+ gtk_action_set_sensitive (action, available);
+
+ /* Update redo entry */
+ action = gtk_action_group_get_action (view->details->dir_action_group,
+ FM_ACTION_REDO);
+ available = redo_active;
+ if (available) {
+ label = menu_data->redo_label;
+ tooltip = menu_data->redo_description;
+ } else {
+ /* Reset to default info */
+ label = _("Redo");
+ tooltip = _("Redo the last undone action");
+ }
+
+ g_object_set (action,
+ "label", label,
+ "tooltip", tooltip,
+ NULL);
+ gtk_action_set_sensitive (action, available);
+
+ nautilus_undo_stack_menu_data_free (menu_data);
+}
+
+static void
real_action_undo (FMDirectoryView *view)
{
NautilusUndoStackManager *manager;
@@ -6245,9 +6196,7 @@ real_action_undo (FMDirectoryView *view)
manager = nautilus_undo_stack_manager_get ();
/* Disable menus because they are in an untrustworthy status */
- view->details->undo_active = FALSE;
- view->details->redo_active = FALSE;
- fm_directory_view_update_menus (view);
+ update_undo_actions (view, TRUE);
nautilus_undo_stack_manager_undo (manager, NULL, NULL);
}
@@ -6260,14 +6209,26 @@ real_action_redo (FMDirectoryView *view)
manager = nautilus_undo_stack_manager_get ();
/* Disable menus because they are in an untrustworthy status */
- view->details->undo_active = FALSE;
- view->details->redo_active = FALSE;
- fm_directory_view_update_menus (view);
+ update_undo_actions (view, TRUE);
nautilus_undo_stack_manager_redo (manager, NULL, NULL);
}
static void
+action_undo_callback (GtkAction *action,
+ gpointer callback_data)
+{
+ real_action_undo (FM_DIRECTORY_VIEW (callback_data));
+}
+
+static void
+action_redo_callback (GtkAction *action,
+ gpointer callback_data)
+{
+ real_action_redo (FM_DIRECTORY_VIEW (callback_data));
+}
+
+static void
real_action_rename (FMDirectoryView *view,
gboolean select_all)
{
@@ -7314,14 +7275,14 @@ static const GtkActionEntry directory_view_entries[] = {
/* label, accelerator */ N_("_Restore"), NULL,
NULL,
G_CALLBACK (action_restore_from_trash_callback) },
- /* name, stock id */ { FM_ACTION_UNDO, GTK_STOCK_UNDO,
- /* label, accelerator */ N_("_Undo"), "<control>Z",
- /* tooltip */ N_("Undo the last action"),
- G_CALLBACK (action_undo_callback) },
- /* name, stock id */ { FM_ACTION_REDO, GTK_STOCK_REDO,
- /* label, accelerator */ N_("_Redo"), "<control>Y",
- /* tooltip */ N_("Redo the last undone action"),
- G_CALLBACK (action_redo_callback) },
+ /* name, stock id */ { FM_ACTION_UNDO, GTK_STOCK_UNDO,
+ /* label, accelerator */ N_("_Undo"), "<control>Z",
+ /* tooltip */ N_("Undo the last action"),
+ G_CALLBACK (action_undo_callback) },
+ /* name, stock id */ { FM_ACTION_REDO, GTK_STOCK_REDO,
+ /* label, accelerator */ N_("_Redo"), "<control>Y",
+ /* tooltip */ N_("Redo the last undone action"),
+ G_CALLBACK (action_redo_callback) },
/*
* multiview-TODO: decide whether "Reset to Defaults" should
* be window-wide, and not just view-wide.
@@ -8990,7 +8951,7 @@ real_update_menus (FMDirectoryView *view)
real_update_menus_volumes (view, selection, selection_count);
- undo_update_menu (view);
+ update_undo_actions (view, FALSE);
nautilus_file_list_free (selection);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]