[nautilus/undo-manager: 98/98] undo-manager: simplify and comment the code somewhat



commit ed690d6805db60c51653e3dd5d3f5887bbe184d3
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Dec 7 13:05:45 2010 +0100

    undo-manager: simplify and comment the code somewhat
    
    - add DEBUG messages for stack operations
    - remove useless properties
    - move some code around to make the reading flow more logical

 libnautilus-private/nautilus-undostack-manager.c |  632 ++++++++++------------
 libnautilus-private/nautilus-undostack-types.h   |    1 -
 2 files changed, 277 insertions(+), 356 deletions(-)
---
diff --git a/libnautilus-private/nautilus-undostack-manager.c b/libnautilus-private/nautilus-undostack-manager.c
index 76cc025..1b8da1c 100644
--- a/libnautilus-private/nautilus-undostack-manager.c
+++ b/libnautilus-private/nautilus-undostack-manager.c
@@ -41,235 +41,162 @@
 #include <gdk/gdk.h>
 #include <eel/eel-glib-extensions.h>
 
+#define DEBUG_FLAG NAUTILUS_DEBUG_UNDO
+#include "nautilus-debug.h"
+
 /* Default depth of the undo/redo stack. */
 #define DEFAULT_UNDO_DEPTH 32
 
 #define NAUTILUS_UNDO_STACK_MANAGER_GET_PRIVATE(o)	\
 	 (G_TYPE_INSTANCE_GET_PRIVATE ((o), NAUTILUS_TYPE_UNDO_STACK_MANAGER, NautilusUndoStackManagerPrivate))
 
-enum
-{
-	PROP_UNDO_LEVELS = 1,
-	PROP_CONFIRM_DELETE,
-	NUM_PROPERTIES,
-};
-
-static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
-
 G_DEFINE_TYPE (NautilusUndoStackManager, nautilus_undo_stack_manager, G_TYPE_OBJECT)
 
 static NautilusUndoStackManager *singleton = NULL;
 
+/* must be called with the mutex locked */
 static NautilusUndoStackActionData *
 get_next_redo_action (NautilusUndoStackManagerPrivate *priv)
 {
-	NautilusUndoStackActionData *action;
+	UndoData *retval = NULL;
 
 	if (g_queue_is_empty (priv->stack)) {
-		return NULL;
+		DEBUG ("Queue is empty, no redo actions to return");
+		goto out;
 	}
 
 	if (priv->index == 0) {
-		/* ... no redo actions */
-		return NULL;
+		DEBUG ("Queue has only undoable actions, no redo actions to return");
+		goto out;
 	}
 
-	action = (NautilusUndoStackActionData *) g_queue_peek_nth (priv->stack, priv->index - 1);
+	DEBUG ("Getting redo action for index %d", priv->index);
+	retval = g_queue_peek_nth (priv->stack, priv->index - 1);
 
-	if (action->locked) {
-		return NULL;
-	} else {
-		return action;
+	if (retval && retval->locked) {
+		DEBUG ("Action is locked, no redo actions to return");
+		retval = NULL;
 	}
+
+ out:
+	DEBUG ("Returning %p as next redo action", retval);
+	return retval;
 }
 
+/* must be called with the mutex locked */
 static NautilusUndoStackActionData *
 get_next_undo_action (NautilusUndoStackManagerPrivate *priv)
 {
-	NautilusUndoStackActionData *action;
+	UndoData *retval = NULL;
 	guint stack_size;
 
 	if (g_queue_is_empty (priv->stack)) {
-		return NULL;
+		DEBUG ("Queue is empty, no undo actions to return");
+		goto out;
 	}
 
 	stack_size = g_queue_get_length (priv->stack);
 
 	if (priv->index == stack_size) {
-		return NULL;
+		DEBUG ("Queue has only of undone actions, no undo actions to return");
+		goto out;
 	}
 
-	action = (NautilusUndoStackActionData *) g_queue_peek_nth (priv->stack, priv->index);
-
-	if (action->locked) {
-		return NULL;
-	} else {
-		return action;
-	}
-}
-
-static void
-refresh_strings (UndoData *action)
-{
-	gchar **descriptions;
-	gchar **labels;
-
-	descriptions = (gchar **) g_malloc0 (3 * sizeof (gchar *));
-	descriptions[2] = NULL;
-
-	labels = (gchar **) g_malloc0 (3 * sizeof (gchar *));
-	labels[2] = NULL;
-
-	action->strings_func (action, action->count,
-			      labels, descriptions);
-
-	action->undo_label = labels[0];
-	action->redo_label = labels[1];
-
-	action->undo_description = descriptions[0];
-	action->redo_description = descriptions[1];
-
-	g_free (descriptions);
-	g_free (labels);
-}
+	DEBUG ("Getting undo action for index %d", priv->index);
+	retval = g_queue_peek_nth (priv->stack, priv->index);
 
-static const gchar *
-get_redo_label (UndoData *action)
-{
-	if (action->redo_label == NULL) {
-		refresh_strings (action);
+	if (retval->locked) {
+		DEBUG ("Action is locked, no undo actions to return");
+		retval = NULL;
 	}
 
-	return action->redo_label;
-}
-
-static const gchar *
-get_undo_label (UndoData *action)
-{
-	if (action->undo_label == NULL) {
-		refresh_strings (action);
-	}
-
-	return action->undo_label;
-}
-
-static const char *
-get_undo_description (UndoData *action)
-{
-	if (action->undo_description == NULL) {
-		refresh_strings (action);
-	}
-
-	return action->undo_description;
-}
-
-static const char *
-get_redo_description (UndoData *action)
-{
-	if (action->redo_description == NULL) {
-		refresh_strings (action);
-	}
-
-	return action->redo_description;
+ out:
+	DEBUG ("Returning %p as next undo action", retval);
+	return retval;
 }
 
+/* must be called with the mutex locked */
 static void
-do_menu_update (NautilusUndoStackManager * manager)
+clear_redo_actions (NautilusUndoStackManagerPrivate *priv)
 {
-	NautilusUndoStackActionData *action;
-	NautilusUndoStackManagerPrivate *priv;
-	NautilusUndoStackMenuData *data;
+	DEBUG ("Clearing redo actions, index is %d", priv->index);
 
-	g_return_if_fail (manager != NULL);
-
-	priv = manager->priv;
-	data = g_slice_new0 (NautilusUndoStackMenuData);
-
-	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);
-	}
+	while (priv->index > 0) {
+		UndoData *head;
 
-	g_mutex_unlock (priv->mutex);
+		head = g_queue_pop_head (priv->stack);
+		nautilus_undo_stack_action_data_free (head);
 
-	/* Update menus */
-	g_signal_emit_by_name (manager, "request-menu-update", data);
+		DEBUG ("Removed action, index was %d", priv->index);
 
-	/* Free the signal data */
-	/* Note: we do not own labels and descriptions, they are part of the action. */
-	g_slice_free (NautilusUndoStackMenuData, data);
-}
-
-static void
-clear_redo_actions (NautilusUndoStackManagerPrivate *priv)
-{
-	while (priv->index > 0) {
-		NautilusUndoStackActionData *head;
-		head = (NautilusUndoStackActionData *)g_queue_pop_head (priv->stack);
-		nautilus_undo_stack_action_data_free (head);
 		priv->index--;
 	}
 }
 
+/* must be called with the mutex locked */
 static gboolean
 can_undo (NautilusUndoStackManagerPrivate *priv)
 {
 	return (get_next_undo_action (priv) != NULL);
 }
 
+/* must be called with the mutex locked */
 static gboolean
 can_redo (NautilusUndoStackManagerPrivate *priv)
 {
 	return (get_next_redo_action (priv) != NULL);
 }
 
+/* must be called with the mutex locked */
 static NautilusUndoStackActionData *
 stack_scroll_right (NautilusUndoStackManagerPrivate *priv)
 {
-	NautilusUndoStackActionData *data;
+	UndoData *data;
 
-	if (!can_undo (priv))
+	if (!can_undo (priv)) {
+		DEBUG ("Scrolling stack right, but no undo actions");
 		return NULL;
+	}
+
+	data = g_queue_peek_nth (priv->stack, priv->index);
 
-	data = (NautilusUndoStackActionData *) g_queue_peek_nth (priv->stack, priv->index);
 	if (priv->index < g_queue_get_length (priv->stack)) {
 		priv->index++;
+		DEBUG ("Scrolling stack right, increasing index to %d", priv->index);
 	}
 
 	return data;
 }
 
+/* must be called with the mutex locked */
 static NautilusUndoStackActionData *
 stack_scroll_left (NautilusUndoStackManagerPrivate *priv)
 {
 	NautilusUndoStackActionData *data;
 
-	if (!can_redo (priv))
+	if (!can_redo (priv)) {
+		DEBUG ("Scrolling stack left, but no redo actions");
 		return NULL;
+	}
 
 	priv->index--;
-	data = (NautilusUndoStackActionData *) g_queue_peek_nth (priv->stack, priv->index);
+	data = g_queue_peek_nth (priv->stack, priv->index);
+
+	DEBUG ("Scrolling stack left, decreasing index to %d", priv->index);
 
 	return data;
 }
 
+/* must be called with the mutex locked */
 static void
-stack_clear_n_oldest (GQueue * stack, guint n)
+stack_clear_n_oldest (GQueue *stack,
+		      guint n)
 {
 	NautilusUndoStackActionData *action;
 	guint i;
 
+	DEBUG ("Clearing %u oldest actions from the undo stack", n);
+
 	for (i = 0; i < n; i++) {
 		action = (NautilusUndoStackActionData *) g_queue_pop_tail (stack);
 		if (action->locked) {
@@ -280,55 +207,121 @@ stack_clear_n_oldest (GQueue * stack, guint n)
 	}
 }
 
+/* must be called with the mutex locked */
 static void
-do_undo_redo (NautilusUndoStackManager *self,
-	      gboolean undo,
-	      NautilusUndoStackFinishCallback callback,
-	      gpointer user_data)
+stack_ensure_size (NautilusUndoStackManager *self)
 {
 	NautilusUndoStackManagerPrivate *priv = self->priv;
-	UndoData *action;
+	guint length;
 
-	/* Update the menus invalidating undo/redo while an operation is already underway */
-	g_mutex_lock (priv->mutex);
+	length = g_queue_get_length (priv->stack);
 
-	if (undo) {
-		action = stack_scroll_right (priv);
-	} else {
-		action = stack_scroll_left (priv);
+	if (length > priv->undo_levels) {
+		if (priv->index > (priv->undo_levels + 1)) {
+			/* If the index will fall off the stack
+			 * move it back to the maximum position */
+			priv->index = priv->undo_levels + 1;
+		}
+		stack_clear_n_oldest (priv->stack, length - (priv->undo_levels));
 	}
+}
 
-	/* Action will be NULL if redo is not possible */
-	if (action != NULL) {
-		action->locked = TRUE;  /* Remember to unlock when finished */
-	}
+/* must be called with the mutex locked */
+static void
+stack_push_action (NautilusUndoStackManager *self,
+		   NautilusUndoStackActionData *action)
+{
+	NautilusUndoStackManagerPrivate *priv = self->priv;
+
+	/* clear all the redo items, as we're pushing a new undoable action */
+	clear_redo_actions (priv);
+
+	g_queue_push_head (priv->stack, action);
+
+	/* cleanup items in excess, if any */
+	stack_ensure_size (self);
+}
+
+static void
+nautilus_undo_stack_manager_init (NautilusUndoStackManager * self)
+{
+	NautilusUndoStackManagerPrivate *priv;
+
+	priv = NAUTILUS_UNDO_STACK_MANAGER_GET_PRIVATE (self);
+
+	self->priv = priv;
+
+	/* Initialize private fields */
+	priv->stack = g_queue_new ();
+	priv->mutex = g_mutex_new ();
+	priv->index = 0;
+	priv->undo_redo_flag = FALSE;
 
+	/* initialize the undo stack depth */
+	priv->undo_levels = DEFAULT_UNDO_DEPTH;
+
+	g_mutex_lock (priv->mutex);
+	stack_ensure_size (self);
 	g_mutex_unlock (priv->mutex);
+}
 
-	do_menu_update (self);
+static void
+nautilus_undo_stack_manager_finalize (GObject * object)
+{
+	NautilusUndoStackManager *self = NAUTILUS_UNDO_STACK_MANAGER (object);
+	NautilusUndoStackManagerPrivate *priv = self->priv;
 
-	if (action != NULL) {
-		priv->undo_redo_flag = TRUE;
+	g_mutex_lock (priv->mutex);
+	
+	g_queue_foreach (priv->stack, (GFunc) nautilus_undo_stack_action_data_free, NULL);
+	g_queue_free (priv->stack);
 
-		if (undo) {
-			action->undo_func (action);
-		} else {
-			action->redo_func (action);
-		}
-	}
+	g_mutex_unlock (priv->mutex);
+	g_mutex_free (priv->mutex);
 
-	if (callback != NULL) {
-		callback (user_data);
+	G_OBJECT_CLASS (nautilus_undo_stack_manager_parent_class)->finalize (object);
+}
+
+static GObject *
+nautilus_undo_stack_manager_constructor (GType type,
+					 guint n_construct_params,
+					 GObjectConstructParam *construct_params)
+{
+	GObject *retval;
+
+	if (singleton != NULL) {
+		return g_object_ref (singleton);
 	}
-	
+
+	retval = G_OBJECT_CLASS (nautilus_undo_stack_manager_parent_class)->constructor
+		(type, n_construct_params, construct_params);
+
+	singleton = NAUTILUS_UNDO_STACK_MANAGER (retval);
+	g_object_add_weak_pointer (retval, (gpointer) &singleton);
+
+	return retval;
+}
+
+static void
+nautilus_undo_stack_manager_class_init (NautilusUndoStackManagerClass *klass)
+{
+	GObjectClass *oclass;
+
+	oclass = G_OBJECT_CLASS (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);
+
+	g_type_class_add_private (klass, sizeof (NautilusUndoStackManagerPrivate));
 }
 
-/**
- * nautilus_undo_stack_manager_trash_has_emptied:
- * @manager:
- *
- * Callback after emptying the trash
- */
 void
 nautilus_undo_stack_manager_trash_has_emptied (NautilusUndoStackManager *manager)
 {
@@ -366,12 +359,6 @@ nautilus_undo_stack_manager_trash_has_emptied (NautilusUndoStackManager *manager
 	g_mutex_unlock (priv->mutex);
 }
 
-/**
- * nautilus_undo_stack_manager_request_menu_update:
- * @manager:
- *
- * Returns the modification time for the given file (used for undo trash)
- */
 guint64
 nautilus_undo_stack_manager_get_file_modification_time (GFile * file)
 {
@@ -392,219 +379,156 @@ nautilus_undo_stack_manager_get_file_modification_time (GFile * file)
 }
 
 static void
-stack_fix_size (NautilusUndoStackManagerPrivate *priv)
+refresh_strings (UndoData *action)
 {
-	guint length;
+	gchar **descriptions;
+	gchar **labels;
 
-	length = g_queue_get_length (priv->stack);
+	descriptions = (gchar **) g_malloc0 (3 * sizeof (gchar *));
+	descriptions[2] = NULL;
 
-	if (length > priv->undo_levels) {
-		if (priv->index > (priv->undo_levels + 1)) {
-			/* If the index will fall off the stack
-			 * move it back to the maximum position */
-			priv->index = priv->undo_levels + 1;
-		}
-		stack_clear_n_oldest (priv->stack, length - (priv->undo_levels));
-	}
-}
+	labels = (gchar **) g_malloc0 (3 * sizeof (gchar *));
+	labels[2] = NULL;
 
-static void
-stack_push_action (NautilusUndoStackManagerPrivate *priv,
-		   NautilusUndoStackActionData *action)
-{
-	guint length;
+	action->strings_func (action, action->count,
+			      labels, descriptions);
 
-	clear_redo_actions (priv);
+	action->undo_label = labels[0];
+	action->redo_label = labels[1];
 
-	g_queue_push_head (priv->stack, (gpointer) action);
-	length = g_queue_get_length (priv->stack);
+	action->undo_description = descriptions[0];
+	action->redo_description = descriptions[1];
 
-	if (length > priv->undo_levels) {
-		stack_fix_size (priv);
-	}
+	g_free (descriptions);
+	g_free (labels);
 }
 
-static void
-nautilus_undo_stack_manager_init (NautilusUndoStackManager * self)
+static const gchar *
+get_redo_label (UndoData *action)
 {
-	NautilusUndoStackManagerPrivate *priv;
+	if (action->redo_label == NULL) {
+		refresh_strings (action);
+	}
 
-	priv = NAUTILUS_UNDO_STACK_MANAGER_GET_PRIVATE (self);
+	return action->redo_label;
+}
 
-	self->priv = priv;
+static const gchar *
+get_undo_label (UndoData *action)
+{
+	if (action->undo_label == NULL) {
+		refresh_strings (action);
+	}
 
-	/* Initialize private fields */
-	priv->stack = g_queue_new ();
-	priv->mutex = g_mutex_new ();
-	priv->index = 0;
-	priv->undo_redo_flag = FALSE;
-	priv->confirm_delete = FALSE;
+	return action->undo_label;
 }
 
-static void
-nautilus_undo_stack_manager_finalize (GObject * object)
+static const char *
+get_undo_description (UndoData *action)
 {
-	NautilusUndoStackManager *self = NAUTILUS_UNDO_STACK_MANAGER (object);
-	NautilusUndoStackManagerPrivate *priv = self->priv;
+	if (action->undo_description == NULL) {
+		refresh_strings (action);
+	}
 
-	g_mutex_lock (priv->mutex);
-	
-	g_queue_foreach (priv->stack, (GFunc) nautilus_undo_stack_action_data_free, NULL);
-	g_queue_free (priv->stack);
+	return action->undo_description;
+}
 
-	g_mutex_unlock (priv->mutex);
-	g_mutex_free (priv->mutex);
+static const char *
+get_redo_description (UndoData *action)
+{
+	if (action->redo_description == NULL) {
+		refresh_strings (action);
+	}
 
-	G_OBJECT_CLASS (nautilus_undo_stack_manager_parent_class)->finalize (object);
+	return action->redo_description;
 }
 
 static void
-nautilus_undo_stack_manager_set_property (GObject *object,
-					  guint prop_id,
-					  const GValue *value,
-					  GParamSpec * pspec)
+do_menu_update (NautilusUndoStackManager * manager)
 {
-	NautilusUndoStackManager *manager;
+	NautilusUndoStackActionData *action;
 	NautilusUndoStackManagerPrivate *priv;
-	guint new_undo_levels;
+	NautilusUndoStackMenuData *data;
 
-	g_return_if_fail (NAUTILUS_IS_UNDO_STACK_MANAGER (object));
+	g_return_if_fail (manager != NULL);
 
-	manager = NAUTILUS_UNDO_STACK_MANAGER (object);
 	priv = manager->priv;
+	data = g_slice_new0 (NautilusUndoStackMenuData);
 
-	switch (prop_id) {
-	case PROP_UNDO_LEVELS:
-		new_undo_levels = g_value_get_uint (value);
-		if (new_undo_levels > 0 && (priv->undo_levels != new_undo_levels)) {
-			priv->undo_levels = new_undo_levels;
-			g_mutex_lock (priv->mutex);
-			stack_fix_size (priv);
-			g_mutex_unlock (priv->mutex);
-			do_menu_update (manager);
-		}
-		break;
-	case PROP_CONFIRM_DELETE:
-		priv->confirm_delete = g_value_get_boolean (value);
-		break;
-	default:
-		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-		break;
-	}
-}
-
-static void
-nautilus_undo_stack_manager_get_property (GObject *object,
-					  guint prop_id,
-					  GValue *value,
-					  GParamSpec *pspec)
-{
-	NautilusUndoStackManager *manager;
-	NautilusUndoStackManagerPrivate *priv;
+	DEBUG ("Updating menus");
 
-	g_return_if_fail (NAUTILUS_IS_UNDO_STACK_MANAGER (object));
+	g_mutex_lock (priv->mutex);
 
-	manager = NAUTILUS_UNDO_STACK_MANAGER (object);
-	priv = manager->priv;
+	action = get_next_undo_action (priv);
 
-	switch (prop_id) {
-	case PROP_UNDO_LEVELS:
-		g_value_set_uint (value, priv->undo_levels);
-		break;
-	default:
-		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-		break;
+	if (action != NULL) {
+		data->undo_label = get_undo_label (action);
+		data->undo_description = get_undo_description (action);
 	}
-}
 
-static GObject *
-nautilus_undo_stack_manager_constructor (GType type,
-					 guint n_construct_params,
-					 GObjectConstructParam *construct_params)
-{
-	GObject *retval;
+	action = get_next_redo_action (priv);
 
-	if (singleton != NULL) {
-		return g_object_ref (singleton);
+	if (action != NULL) {
+		data->redo_label = get_redo_label (action);
+		data->redo_description = get_redo_description (action);
 	}
 
-	retval = G_OBJECT_CLASS (nautilus_undo_stack_manager_parent_class)->constructor
-		(type, n_construct_params, construct_params);
+	g_mutex_unlock (priv->mutex);
 
-	singleton = NAUTILUS_UNDO_STACK_MANAGER (retval);
-	g_object_add_weak_pointer (retval, (gpointer) &singleton);
+	/* Update menus */
+	g_signal_emit_by_name (manager, "request-menu-update", data);
 
-	return retval;
+	/* 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
-nautilus_undo_stack_manager_class_init (NautilusUndoStackManagerClass *klass)
+do_undo_redo (NautilusUndoStackManager *self,
+	      gboolean undo,
+	      NautilusUndoStackFinishCallback callback,
+	      gpointer user_data)
 {
-	GObjectClass *oclass;
+	NautilusUndoStackManagerPrivate *priv = self->priv;
+	UndoData *action;
 
-	oclass = G_OBJECT_CLASS (klass);
+	/* Update the menus invalidating undo/redo while an operation is already underway */
+	g_mutex_lock (priv->mutex);
 
-	oclass->constructor = nautilus_undo_stack_manager_constructor;
-	oclass->finalize = nautilus_undo_stack_manager_finalize;
-	oclass->set_property = nautilus_undo_stack_manager_set_property;
-	oclass->get_property = nautilus_undo_stack_manager_get_property;
-
-
-	/* Create properties */
-	properties[PROP_UNDO_LEVELS] =
-		g_param_spec_uint ("undo-levels",
-				   "undo levels",
-				   "Number of undo levels to be stored",
-				   1, UINT_MAX, DEFAULT_UNDO_DEPTH,
-				   G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
-	properties[PROP_CONFIRM_DELETE] =
-		g_param_spec_boolean ("confirm-delete",
-				      "confirm delete",
-				      "Always confirm file deletion",
-				      FALSE,
-				      G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
-
-	g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
+	if (undo) {
+		action = stack_scroll_right (priv);
+	} else {
+		action = stack_scroll_left (priv);
+	}
 
-	/* 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);
+	/* Action will be NULL if redo is not possible */
+	if (action != NULL) {
+		action->locked = TRUE;  /* Remember to unlock when finished */
+	}
 
-	g_type_class_add_private (klass, sizeof (NautilusUndoStackManagerPrivate));
-}
+	g_mutex_unlock (priv->mutex);
 
-/**
- * nautilus_undo_stack_manager_get:
- *
- * Gets the undo manager singleton.
- *
- * Returns: The #NautilusUndoStackManager singleton.
- */
-NautilusUndoStackManager *
-nautilus_undo_stack_manager_get (void)
-{
-	NautilusUndoStackManager *manager;
+	do_menu_update (self);
 
-	manager = g_object_new (NAUTILUS_TYPE_UNDO_STACK_MANAGER,
-				"undo-levels", DEFAULT_UNDO_DEPTH,
-				NULL);
+	if (action != NULL) {
+		priv->undo_redo_flag = TRUE;
 
-	return manager;
-}
+		if (undo) {
+			action->undo_func (action);
+		} else {
+			action->redo_func (action);
+		}
+	}
 
-/**
- * nautilus_undo_stack_manager_request_menu_update:
- * @manager:
- *
- *
- */
-void
-nautilus_undo_stack_manager_request_menu_update (NautilusUndoStackManager *manager)
-{
-	do_menu_update (manager);
+	if (callback != NULL) {
+		callback (user_data);
+	}
 }
 
 void
@@ -623,41 +547,28 @@ nautilus_undo_stack_manager_undo (NautilusUndoStackManager        *manager,
 	do_undo_redo (manager, TRUE, callback, user_data);
 }
 
-/**
- * nautilus_undo_stack_manager_add_action:
- * @manager:
- * @action:
- *
- * Pushes an undo action onto the top of the stack.
- */
 void
-nautilus_undo_stack_manager_add_action (NautilusUndoStackManager    *manager,
+nautilus_undo_stack_manager_add_action (NautilusUndoStackManager    *self,
                                         NautilusUndoStackActionData *action)
 {
 	NautilusUndoStackManagerPrivate *priv;
 
-	priv = manager->priv;
+	priv = self->priv;
 
 	if (!(action && action->is_valid)) {
 		nautilus_undo_stack_action_data_free (action);
 		return;
 	}
 
-	action->manager = manager;
+	action->manager = self;
 
 	g_mutex_lock (priv->mutex);
-	stack_push_action (priv, action);
+	stack_push_action (self, action);
 	g_mutex_unlock (priv->mutex);
 
-	do_menu_update (manager);
+	do_menu_update (self);
 }
 
-/**
- * nautilus_undo_stack_manager_is_undo_redo:
- * @manager:
- *
- * Returns: %TRUE if undoing or redoing. TODO: Why does this clear the flag?
- */
 gboolean
 nautilus_undo_stack_manager_is_undo_redo (NautilusUndoStackManager *manager)
 {
@@ -672,3 +583,14 @@ nautilus_undo_stack_manager_is_undo_redo (NautilusUndoStackManager *manager)
 
 	return FALSE;
 }
+
+NautilusUndoStackManager *
+nautilus_undo_stack_manager_get (void)
+{
+	NautilusUndoStackManager *manager;
+
+	manager = g_object_new (NAUTILUS_TYPE_UNDO_STACK_MANAGER,
+				NULL);
+
+	return manager;
+}
diff --git a/libnautilus-private/nautilus-undostack-types.h b/libnautilus-private/nautilus-undostack-types.h
index a6bb9a2..b104967 100644
--- a/libnautilus-private/nautilus-undostack-types.h
+++ b/libnautilus-private/nautilus-undostack-types.h
@@ -132,7 +132,6 @@ struct _NautilusUndoStackManagerPrivate
 	guint undo_levels;
 	guint index;
 	guint undo_redo_flag : 1;
-	guint confirm_delete : 1;
 };
 
 #endif /* __NAUTILUS_UNDOSTACK_TYPES_H__ */



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