[nautilus/undo-manager] undostack-manager: change the signal emitted for menu update



commit 8bfba4739f7fc20fa1ddd70a78b2885b038eb6d9
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Dec 7 16:53:01 2010 +0100

    undostack-manager: change the signal emitted for menu update
    
    The signal-based approach doesn't cope too well with FMDirectoryView
    accumulating callbacks for menu updates; change it to an explicit
    _get_menu_data() function and a 'undo-changed' signal.

 libnautilus-private/nautilus-undostack-actions.c |    8 +-
 libnautilus-private/nautilus-undostack-manager.c |  112 +++++++++++-----------
 libnautilus-private/nautilus-undostack-manager.h |    3 +
 3 files changed, 65 insertions(+), 58 deletions(-)
---
diff --git a/libnautilus-private/nautilus-undostack-actions.c b/libnautilus-private/nautilus-undostack-actions.c
index 55db010..0872227 100644
--- a/libnautilus-private/nautilus-undostack-actions.c
+++ b/libnautilus-private/nautilus-undostack-actions.c
@@ -173,9 +173,8 @@ static void
 undo_redo_done_transfer_callback (GHashTable * debuting_uris,
                                   gpointer data)
 {
-	NautilusUndoStackActionData *action;
-
-	action = (NautilusUndoStackActionData *) data;
+	NautilusUndoStackActionData *action = data;
+	NautilusUndoStackManager *manager = action->manager;
 
 	/* If the action needed to be freed but was locked, free now */
 	if (action->freed) {
@@ -185,7 +184,7 @@ undo_redo_done_transfer_callback (GHashTable * debuting_uris,
 	}
 
 	/* Update menus */
-	nautilus_undo_stack_manager_request_menu_update (action->manager);
+	g_signal_emit_by_name (manager, "undo-changed", 0);
 }
 
 static void
@@ -994,6 +993,7 @@ create_from_type (NautilusUndoStackActionType type)
 	return retval;
 }
 
+/* functions to manipulate the action data */
 NautilusUndoStackActionData *
 nautilus_undo_stack_action_data_new (NautilusUndoStackActionType type,
                                      gint                        items_count)
diff --git a/libnautilus-private/nautilus-undostack-manager.c b/libnautilus-private/nautilus-undostack-manager.c
index 1b8da1c..090c8d4 100644
--- a/libnautilus-private/nautilus-undostack-manager.c
+++ b/libnautilus-private/nautilus-undostack-manager.c
@@ -50,6 +50,13 @@
 #define NAUTILUS_UNDO_STACK_MANAGER_GET_PRIVATE(o)	\
 	 (G_TYPE_INSTANCE_GET_PRIVATE ((o), NAUTILUS_TYPE_UNDO_STACK_MANAGER, NautilusUndoStackManagerPrivate))
 
+enum {
+	SIGNAL_UNDO_CHANGED,
+	NUM_SIGNALS,
+};
+
+static guint signals[NUM_SIGNALS] = { 0, };
+
 G_DEFINE_TYPE (NautilusUndoStackManager, nautilus_undo_stack_manager, G_TYPE_OBJECT)
 
 static NautilusUndoStackManager *singleton = NULL;
@@ -312,12 +319,13 @@ nautilus_undo_stack_manager_class_init (NautilusUndoStackManagerClass *klass)
 	oclass->constructor = nautilus_undo_stack_manager_constructor;
 	oclass->finalize = nautilus_undo_stack_manager_finalize;
 
-	/* The UI menu needs to update its status */
-	g_signal_new ("request-menu-update",
-			G_TYPE_FROM_CLASS (klass),
-			G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
-			0, NULL, NULL,
-			g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);
+	signals[SIGNAL_UNDO_CHANGED] =
+		g_signal_new ("undo-changed",
+			      G_TYPE_FROM_CLASS (klass),
+			      G_SIGNAL_RUN_LAST,
+			      0, NULL, NULL,
+			      g_cclosure_marshal_VOID__VOID,
+			      G_TYPE_NONE, 0);
 
 	g_type_class_add_private (klass, sizeof (NautilusUndoStackManagerPrivate));
 }
@@ -444,52 +452,6 @@ get_redo_description (UndoData *action)
 }
 
 static void
-do_menu_update (NautilusUndoStackManager * manager)
-{
-	NautilusUndoStackActionData *action;
-	NautilusUndoStackManagerPrivate *priv;
-	NautilusUndoStackMenuData *data;
-
-	g_return_if_fail (manager != NULL);
-
-	priv = manager->priv;
-	data = g_slice_new0 (NautilusUndoStackMenuData);
-
-	DEBUG ("Updating menus");
-
-	g_mutex_lock (priv->mutex);
-
-	action = get_next_undo_action (priv);
-
-	if (action != NULL) {
-		data->undo_label = get_undo_label (action);
-		data->undo_description = get_undo_description (action);
-	}
-
-	action = get_next_redo_action (priv);
-
-	if (action != NULL) {
-		data->redo_label = get_redo_label (action);
-		data->redo_description = get_redo_description (action);
-	}
-
-	g_mutex_unlock (priv->mutex);
-
-	/* Update menus */
-	g_signal_emit_by_name (manager, "request-menu-update", data);
-
-	/* Free the signal data */
-	/* Note: we do not own labels and descriptions, they are part of the action. */
-	g_slice_free (NautilusUndoStackMenuData, data);
-}
-
-void
-nautilus_undo_stack_manager_request_menu_update (NautilusUndoStackManager *manager)
-{
-	do_menu_update (manager);
-}
-
-static void
 do_undo_redo (NautilusUndoStackManager *self,
 	      gboolean undo,
 	      NautilusUndoStackFinishCallback callback,
@@ -514,7 +476,7 @@ do_undo_redo (NautilusUndoStackManager *self,
 
 	g_mutex_unlock (priv->mutex);
 
-	do_menu_update (self);
+	g_signal_emit (self, signals[SIGNAL_UNDO_CHANGED], 0);
 
 	if (action != NULL) {
 		priv->undo_redo_flag = TRUE;
@@ -555,7 +517,10 @@ nautilus_undo_stack_manager_add_action (NautilusUndoStackManager    *self,
 
 	priv = self->priv;
 
+	DEBUG ("Adding action %p, type %d", action, action->type);
+
 	if (!(action && action->is_valid)) {
+		DEBUG ("Action %p is not valid, ignoring", action);
 		nautilus_undo_stack_action_data_free (action);
 		return;
 	}
@@ -566,7 +531,7 @@ nautilus_undo_stack_manager_add_action (NautilusUndoStackManager    *self,
 	stack_push_action (self, action);
 	g_mutex_unlock (priv->mutex);
 
-	do_menu_update (self);
+	g_signal_emit (self, signals[SIGNAL_UNDO_CHANGED], 0);
 }
 
 gboolean
@@ -594,3 +559,42 @@ nautilus_undo_stack_manager_get (void)
 
 	return manager;
 }
+
+NautilusUndoStackMenuData *
+nautilus_undo_stack_manager_get_menu_data (NautilusUndoStackManager *self)
+{
+	NautilusUndoStackActionData *action;
+	NautilusUndoStackManagerPrivate *priv;
+	NautilusUndoStackMenuData *data;
+
+	priv = self->priv;
+	data = g_slice_new0 (NautilusUndoStackMenuData);
+
+	DEBUG ("Getting menu data");
+
+	g_mutex_lock (priv->mutex);
+
+	action = get_next_undo_action (priv);
+
+	if (action != NULL) {
+		data->undo_label = get_undo_label (action);
+		data->undo_description = get_undo_description (action);
+	}
+
+	action = get_next_redo_action (priv);
+
+	if (action != NULL) {
+		data->redo_label = get_redo_label (action);
+		data->redo_description = get_redo_description (action);
+	}
+
+	g_mutex_unlock (priv->mutex);
+
+	return data;
+}
+
+void
+nautilus_undo_stack_menu_data_free (NautilusUndoStackMenuData *data)
+{
+	g_slice_free (NautilusUndoStackMenuData, data);
+}
diff --git a/libnautilus-private/nautilus-undostack-manager.h b/libnautilus-private/nautilus-undostack-manager.h
index 3384b09..b9347a6 100644
--- a/libnautilus-private/nautilus-undostack-manager.h
+++ b/libnautilus-private/nautilus-undostack-manager.h
@@ -80,4 +80,7 @@ void nautilus_undo_stack_manager_trash_has_emptied (NautilusUndoStackManager *ma
 void nautilus_undo_stack_manager_request_menu_update (NautilusUndoStackManager        *manager);
 guint64 nautilus_undo_stack_manager_get_file_modification_time (GFile *file);
 
+NautilusUndoStackMenuData * nautilus_undo_stack_manager_get_menu_data (NautilusUndoStackManager *self);
+void nautilus_undo_stack_menu_data_free (NautilusUndoStackMenuData *data);
+
 #endif /* __NAUTILUS_UNDO_STACK_MANAGER_H__ */



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