diff options
Diffstat (limited to 'libnautilus')
-rw-r--r-- | libnautilus/.cvsignore | 10 | ||||
-rw-r--r-- | libnautilus/Makefile.am | 40 | ||||
-rw-r--r-- | libnautilus/nautilus-distributed-undo.idl | 40 | ||||
-rw-r--r-- | libnautilus/nautilus-undo-manager-component.idl | 18 | ||||
-rw-r--r-- | libnautilus/nautilus-undo-manager-private.h | 2 | ||||
-rw-r--r-- | libnautilus/nautilus-undo-manager.c | 431 | ||||
-rw-r--r-- | libnautilus/nautilus-undo-manager.h | 59 | ||||
-rw-r--r-- | libnautilus/nautilus-undo-transaction.h | 4 | ||||
-rw-r--r-- | libnautilus/nautilus-undo.idl | 40 | ||||
-rw-r--r-- | libnautilus/nautilus-undoable.c | 5 | ||||
-rw-r--r-- | libnautilus/nautilus-undoable.h | 7 | ||||
-rw-r--r-- | libnautilus/nautilus-view-component.idl | 6 |
12 files changed, 303 insertions, 359 deletions
diff --git a/libnautilus/.cvsignore b/libnautilus/.cvsignore index ac14f1dac..989bd8abd 100644 --- a/libnautilus/.cvsignore +++ b/libnautilus/.cvsignore @@ -7,13 +7,13 @@ libnautilus.la nautilus-common.c nautilus-skels.c nautilus-stubs.c -nautilus-undo-manager-component-common.c -nautilus-undo-manager-component-skels.c -nautilus-undo-manager-component-stubs.c -nautilus-undo-manager-component.h +nautilus-undo-common.c +nautilus-undo-skels.c +nautilus-undo-stubs.c +nautilus-undo.h nautilus-view-component-common.c nautilus-view-component-skels.c nautilus-view-component-stubs.c nautilus-view-component.h -nautilus_undo_manager_component_idl_stamp +nautilus_undo_idl_stamp nautilus_view_component_idl_stamp diff --git a/libnautilus/Makefile.am b/libnautilus/Makefile.am index 10554b423..dbbac331e 100644 --- a/libnautilus/Makefile.am +++ b/libnautilus/Makefile.am @@ -21,23 +21,22 @@ libnautilus_la_LDFLAGS=\ $(XML_LIBS) \ $(LIBPNG) -nautilus_undo_manager_component_idl_sources = \ - nautilus-undo-manager-component-stubs.c \ - nautilus-undo-manager-component-skels.c \ - nautilus-undo-manager-component-common.c \ - nautilus-undo-manager-component.h - nautilus_view_component_idl_sources = \ nautilus-view-component-stubs.c \ nautilus-view-component-skels.c \ nautilus-view-component.h \ nautilus-view-component-common.c -BUILT_SOURCES = \ - $(nautilus_undo_manager_component_idl_sources) \ - $(nautilus_view_component_idl_sources) \ - $(NULL) +nautilus_undo_idl_sources = \ + nautilus-undo-stubs.c \ + nautilus-undo-skels.c \ + nautilus-undo.h \ + nautilus-undo-common.c +BUILT_SOURCES = \ + $(nautilus_view_component_idl_sources) \ + $(nautilus_undo_idl_sources) + libnautilusincludedir=$(includedir)/libnautilus libnautilusinclude_HEADERS= \ @@ -57,8 +56,8 @@ libnautilusinclude_HEADERS= \ libnautilus_la_SOURCES= \ nautilus-undo-manager-private.h \ nautilus-view-frame-private.h \ - $(nautilus_undo_manager_component_idl_sources) \ $(nautilus_view_component_idl_sources) \ + $(nautilus_undo_idl_sources) \ nautilus-clipboard.c \ nautilus-content-view-frame.c \ nautilus-meta-view-frame.c \ @@ -69,16 +68,21 @@ libnautilus_la_SOURCES= \ nautilus-undoable.c \ $(NULL) -$(nautilus_undo_manager_component_idl_sources): nautilus_undo_manager_component_idl_stamp -nautilus_undo_manager_component_idl_stamp: nautilus-undo-manager-component.idl - orbit-idl -I${datadir}/idl `gnome-config --cflags idl` $(srcdir)/nautilus-undo-manager-component.idl - touch nautilus_undo_manager_component_idl_stamp - $(nautilus_view_component_idl_sources): nautilus_view_component_idl_stamp nautilus_view_component_idl_stamp: nautilus-view-component.idl orbit-idl -I${datadir}/idl `gnome-config --cflags idl` $(srcdir)/nautilus-view-component.idl touch nautilus_view_component_idl_stamp -CLEANFILES=nautilus_view_component_idl_stamp nautilus_undo_manager_component_idl_stamp +$(nautilus_undo_idl_sources): nautilus_undo_idl_stamp +nautilus_undo_idl_stamp: nautilus-undo.idl + orbit-idl -I${datadir}/idl `gnome-config --cflags idl` $(srcdir)/nautilus-undo.idl + touch nautilus_undo_idl_stamp + +CLEANFILES = \ + nautilus_view_component_idl_stamp \ + nautilus_undo_idl_stamp + +EXTRA_DIST = \ + nautilus-view-component.idl \ + nautilus-undo.idl -EXTRA_DIST = nautilus-undo-manager-component.idl nautilus-view-component.idl diff --git a/libnautilus/nautilus-distributed-undo.idl b/libnautilus/nautilus-distributed-undo.idl new file mode 100644 index 000000000..cd63e190b --- /dev/null +++ b/libnautilus/nautilus-distributed-undo.idl @@ -0,0 +1,40 @@ +/* -*- Mode: IDL; tab-width: 8; indent-tabs-mode: 8; c-basic-offset: 8 -*- */ + +#ifndef NAUTUILUS_UNDO_IDL_INCLUDED +#define NAUTUILUS_UNDO_MANAGER_IDL_INCLUDED + +#include <gnome-factory.idl> +#include <Bonobo.idl> + +module Nautilus { + + module Undo { + + // Forward declarations + interface Manager; + interface Transaction; + + // Contains elements that describe a transaction + struct TransactionMenuInfo { + string name; + string description; + }; + + // An undo transaction + interface Transaction : ::Bonobo::Unknown { + readonly attribute TransactionMenuInfo undo_description; + readonly attribute TransactionMenuInfo redo_description; + readonly attribute string base_description; + + void undo (in Transaction transaction); + }; + + // The main interface that handles undo transactions + interface Manager : ::Bonobo::Unknown { + void append (in Transaction transaction); + void forget (in Transaction transaction); + }; + }; +}; + +#endif /* NAUTUILUS_UNDO_IDL_INCLUDED */ diff --git a/libnautilus/nautilus-undo-manager-component.idl b/libnautilus/nautilus-undo-manager-component.idl deleted file mode 100644 index 9913a452d..000000000 --- a/libnautilus/nautilus-undo-manager-component.idl +++ /dev/null @@ -1,18 +0,0 @@ -/* -*- Mode: IDL; tab-width: 8; indent-tabs-mode: 8; c-basic-offset: 8 -*- */ - - -#ifndef _NAUTUILUS_UNDO_MANAGER_IDL_INCLUDED_ -#define _NAUTUILUS_UNDO_MANAGER_IDL_INCLUDED_ - -#include <gnome-factory.idl> -#include <Bonobo.idl> - -module Nautilus { - - interface UndoManager : ::Bonobo::Unknown { - boolean begin_transaction (in string name); - boolean end_transaction (); - }; -}; - -#endif /* _NAUTUILUS_UNDO_MANAGER_IDL_INCLUDED_ */
\ No newline at end of file diff --git a/libnautilus/nautilus-undo-manager-private.h b/libnautilus/nautilus-undo-manager-private.h index b825fe9c1..09dea2cfc 100644 --- a/libnautilus/nautilus-undo-manager-private.h +++ b/libnautilus/nautilus-undo-manager-private.h @@ -31,10 +31,8 @@ #include "nautilus-undo-transaction.h" /* Private data */ -NautilusUndoManager *global_undo_manager; struct NautilusUndoManagerDetails { - NautilusUndoTransaction *transaction; /* Current active and unique transaction */ GList *undo_list; GList *redo_list; gboolean transaction_in_progress; diff --git a/libnautilus/nautilus-undo-manager.c b/libnautilus/nautilus-undo-manager.c index 1faf53994..97b1c0948 100644 --- a/libnautilus/nautilus-undo-manager.c +++ b/libnautilus/nautilus-undo-manager.c @@ -25,6 +25,7 @@ #include <config.h> #include <gtk/gtksignal.h> #include <gtk/gtkmain.h> +#include <glib.h> #include <string.h> #include <bonobo/bonobo-main.h> #include <bonobo/bonobo-control.h> @@ -45,11 +46,11 @@ static guint signals[LAST_SIGNAL]; typedef struct { - POA_Nautilus_UndoManager servant; + POA_Nautilus_Undo_Manager servant; gpointer bonobo_object; NautilusUndoManager *gtk_object; -} impl_POA_Nautilus_UndoManager; +} impl_POA_Nautilus_Undo_Manager; /* GtkObject */ @@ -62,33 +63,33 @@ static GList *prune_undo_manager_list (GList *list, gint items); /* CORBA/Bonobo */ -static CORBA_boolean impl_Nautilus_UndoManager__begin_transaction (impl_POA_Nautilus_UndoManager *servant, - const CORBA_char *name, - CORBA_Environment *ev); -static void impl_Nautilus_UndoManager__end_transaction (impl_POA_Nautilus_UndoManager *servant, - CORBA_Environment *ev); +static void impl_Nautilus_Undo_Manager__append (impl_POA_Nautilus_Undo_Manager *servant, + const CORBA_char *name, + CORBA_Environment *ev); +static void impl_Nautilus_Undo_Manager__forget (impl_POA_Nautilus_Undo_Manager *servant, + CORBA_Environment *ev); NAUTILUS_DEFINE_CLASS_BOILERPLATE(NautilusUndoManager, nautilus_undo_manager, BONOBO_OBJECT_TYPE) -POA_Nautilus_UndoManager__epv libnautilus_extensions_Nautilus_UndoManager_epv = +POA_Nautilus_Undo_Manager__epv libnautilus_Nautilus_Undo_Manager_epv = { NULL, /* _private */ - (gpointer) &impl_Nautilus_UndoManager__begin_transaction, - (gpointer) &impl_Nautilus_UndoManager__end_transaction, + (gpointer) &impl_Nautilus_Undo_Manager__append, + (gpointer) &impl_Nautilus_Undo_Manager__forget, }; static PortableServer_ServantBase__epv base_epv = { NULL, NULL, NULL }; -static POA_Nautilus_UndoManager__vepv impl_Nautilus_UndoManager_vepv = +static POA_Nautilus_Undo_Manager__vepv impl_Nautilus_Undo_Manager_vepv = { &base_epv, NULL, - &libnautilus_extensions_Nautilus_UndoManager_epv + &libnautilus_Nautilus_Undo_Manager_epv }; static void -impl_Nautilus_UndoManager__destroy(BonoboObject *obj, impl_POA_Nautilus_UndoManager *servant) +impl_Nautilus_Undo_Manager__destroy(BonoboObject *obj, impl_POA_Nautilus_Undo_Manager *servant) { PortableServer_ObjectId *objid; CORBA_Environment ev; @@ -107,17 +108,17 @@ impl_Nautilus_UndoManager__destroy(BonoboObject *obj, impl_POA_Nautilus_UndoMana CORBA_exception_free(&ev); } -static Nautilus_UndoManager -impl_Nautilus_UndoManager__create(NautilusUndoManager *manager, CORBA_Environment * ev) +static Nautilus_Undo_Manager +impl_Nautilus_Undo_Manager__create(NautilusUndoManager *manager, CORBA_Environment * ev) { - Nautilus_UndoManager retval; - impl_POA_Nautilus_UndoManager *servant; + Nautilus_Undo_Manager retval; + impl_POA_Nautilus_Undo_Manager *servant; void (*servant_init_func) (PortableServer_Servant servant, CORBA_Environment *ev); NautilusUndoManagerClass *undo_class = NAUTILUS_UNDO_MANAGER_CLASS (GTK_OBJECT(manager)->klass); servant_init_func = undo_class->servant_init_func; - servant = g_new0 (impl_POA_Nautilus_UndoManager, 1); + servant = g_new0 (impl_POA_Nautilus_Undo_Manager, 1); servant->servant.vepv = undo_class->vepv; if (!servant->servant.vepv->Bonobo_Unknown_epv) servant->servant.vepv->Bonobo_Unknown_epv = bonobo_object_get_epv (); @@ -127,24 +128,22 @@ impl_Nautilus_UndoManager__create(NautilusUndoManager *manager, CORBA_Environmen retval = bonobo_object_activate_servant (BONOBO_OBJECT (manager), servant); - gtk_signal_connect (GTK_OBJECT (manager), "destroy", GTK_SIGNAL_FUNC (impl_Nautilus_UndoManager__destroy), servant); + gtk_signal_connect (GTK_OBJECT (manager), "destroy", GTK_SIGNAL_FUNC (impl_Nautilus_Undo_Manager__destroy), servant); return retval; } -static CORBA_boolean -impl_Nautilus_UndoManager__begin_transaction (impl_POA_Nautilus_UndoManager *servant, +static void +impl_Nautilus_Undo_Manager__append (impl_POA_Nautilus_Undo_Manager *servant, const CORBA_char *name, CORBA_Environment *ev) { - return nautilus_undo_manager_begin_transaction (name); } static void -impl_Nautilus_UndoManager__end_transaction (impl_POA_Nautilus_UndoManager *servant, +impl_Nautilus_Undo_Manager__forget (impl_POA_Nautilus_Undo_Manager *servant, CORBA_Environment *ev) { - nautilus_undo_manager_end_transaction (); } @@ -169,9 +168,6 @@ nautilus_undo_manager_initialize (NautilusUndoManager *manager) manager->details = g_new0 (NautilusUndoManagerDetails, 1); - /* Init transaction to none */ - manager->details->transaction = NULL; - /* Create empty lists */ manager->details->undo_list = NULL; manager->details->redo_list = NULL; @@ -185,7 +181,7 @@ nautilus_undo_manager_initialize (NautilusUndoManager *manager) /* No transaction is in progress */ manager->details->transaction_in_progress = FALSE; - bonobo_object_construct (BONOBO_OBJECT (manager), impl_Nautilus_UndoManager__create (manager, &ev)); + bonobo_object_construct (BONOBO_OBJECT (manager), impl_Nautilus_Undo_Manager__create (manager, &ev)); CORBA_exception_free(&ev); } @@ -201,9 +197,9 @@ nautilus_undo_manager_initialize_class (NautilusUndoManagerClass *klass) object_class->destroy = destroy; - klass->servant_init_func = POA_Nautilus_UndoManager__init; - klass->servant_destroy_func = POA_Nautilus_UndoManager__fini; - klass->vepv = &impl_Nautilus_UndoManager_vepv; + klass->servant_init_func = POA_Nautilus_Undo_Manager__init; + klass->servant_destroy_func = POA_Nautilus_Undo_Manager__fini; + klass->vepv = &impl_Nautilus_Undo_Manager_vepv; /* Setup signals */ signals[UNDO_TRANSACTION_OCCURED] @@ -218,236 +214,149 @@ nautilus_undo_manager_initialize_class (NautilusUndoManagerClass *klass) gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); } -/* nautilus_undo_manager_transaction_in_progress */ -gboolean -nautilus_undo_manager_transaction_in_progress (void) -{ - return global_undo_manager->details->transaction_in_progress; -} - - -/* nautilus_undo_manager_get_current_transaction - * Return current undo transaction - */ -NautilusUndoTransaction * -nautilus_undo_manager_get_current_transaction (void) -{ - return global_undo_manager->details->transaction; -} - /* nautilus_undo_manager_begin_transaction */ -gboolean -nautilus_undo_manager_begin_transaction (const gchar *name) +NautilusUndoTransactionInProgress * +nautilus_undo_manager_begin_transaction (GtkObject *object, const gchar *name) { + NautilusUndoManager *manager; + NautilusUndoTransactionInProgress *tip; + + /* Locate undo manager */ + manager = gtk_object_get_data (object, NAUTILUS_UNDO_MANAGER_NAME); + g_return_val_if_fail (manager != NULL, NULL); + /* We aren't handling nested transactions currently */ - if (global_undo_manager->details->transaction_in_progress) { + if (manager->details->transaction_in_progress) { g_warning("NautilusUndoManager does not handle nested transactions. End previous transaction first."); - return FALSE; + return NULL; } + /* Create NautilusUndoTransactionInProgress */ + tip = g_new (NautilusUndoTransactionInProgress, 1); + g_assert(tip); + + tip->manager = manager; + /* Create new transaction */ - global_undo_manager->details->transaction = nautilus_undo_transaction_new(name); + tip->transaction = nautilus_undo_transaction_new(name); - global_undo_manager->details->transaction_in_progress = TRUE; + tip->manager->details->transaction_in_progress = TRUE; - return TRUE; + return tip; } /* nautilus_undo_manager_end_transaction */ -gboolean -nautilus_undo_manager_end_transaction (void) +void +nautilus_undo_manager_end_transaction (NautilusUndoTransactionInProgress *tip) { /* Verify a transaction is in progress */ - if (!global_undo_manager->details->transaction_in_progress) { + if (!tip->manager->details->transaction_in_progress) { g_warning("NautilusUndoManager has no current transaction. Begin a transaction first."); - return FALSE; + return; } - global_undo_manager->details->transaction_in_progress = FALSE; + tip->manager->details->transaction_in_progress = FALSE; /* Commit current transaction to undo list */ - nautilus_undo_manager_add_undo_transaction (global_undo_manager->details->transaction); + nautilus_undo_manager_add_transaction (tip->manager, tip->transaction); /* Fire off signal informing that an undo transaction has occurred */ - gtk_signal_emit (GTK_OBJECT (global_undo_manager), signals[UNDO_TRANSACTION_OCCURED]); - - return TRUE; + gtk_signal_emit (GTK_OBJECT (tip->manager), signals[UNDO_TRANSACTION_OCCURED]); } /* nautilus_undo_manager_undo_last_transaction */ -gboolean -nautilus_undo_manager_undo_last_transaction (void) +void +nautilus_undo_manager_undo (NautilusUndoManager *manager) { GList *list; NautilusUndoTransaction *undo_transaction; /* Verify we have a transaction to be undone */ - if (global_undo_manager->details->undo_list == NULL) { + if (manager->details->undo_list == NULL) { g_warning("NautilusUndoManager has no transaction to be undone."); - return FALSE; + return; } /* Pop last transaction off undo list */ - list = g_list_last(global_undo_manager->details->undo_list); + list = g_list_last(manager->details->undo_list); g_assert(list); undo_transaction = list->data; - global_undo_manager->details->undo_list = g_list_remove(global_undo_manager->details->undo_list, list->data); + manager->details->undo_list = g_list_remove(manager->details->undo_list, list->data); /* Undo transaction */ nautilus_undo_transaction_undo(undo_transaction); /* Place transaction into redo list */ - if (global_undo_manager->details->enable_redo) { - nautilus_undo_manager_add_redo_transaction (undo_transaction); + if (manager->details->enable_redo) { + /* nautilus_undo_manager_add_redo_transaction (undo_transaction); */ } else { /* Purge transaction */ nautilus_undo_transaction_destroy(undo_transaction); } /* Fire off signal informing that an undo transaction has occurred */ - gtk_signal_emit (GTK_OBJECT (global_undo_manager), signals[UNDO_TRANSACTION_OCCURED]); - - return TRUE; + gtk_signal_emit (GTK_OBJECT (manager), signals[UNDO_TRANSACTION_OCCURED]); } /* nautilus_undo_manager_redo_last_undone_transaction */ -gboolean -nautilus_undo_manager_redo_last_undone_transaction (void) +void +nautilus_undo_manager_redo (NautilusUndoManager *manager) { GList *list; NautilusUndoTransaction *redo_transaction; /* Are we allowing redo operations? */ - if (global_undo_manager->details->enable_redo) { + if (manager->details->enable_redo) { g_warning("NautilusUndoManager is not configure to allow redo operations."); - return FALSE; + return; } /* Verify we have a transaction to be redone */ - if (global_undo_manager->details->redo_list == NULL) { + if (manager->details->redo_list == NULL) { g_warning("NautilusUndoManager has no transaction to be redone."); - return FALSE; + return; } /* Pop last transaction off redo list */ - list = g_list_last(global_undo_manager->details->redo_list); + list = g_list_last(manager->details->redo_list); g_assert(list); redo_transaction = list->data; nautilus_undo_transaction_undo(redo_transaction); /* Place transaction into undo list */ - nautilus_undo_manager_add_undo_transaction (redo_transaction); - - return TRUE; + nautilus_undo_manager_add_transaction (manager, redo_transaction); } -/* nautilus_undo_manager_add_undoable_to_transaction */ -gboolean -nautilus_undo_manager_add_undoable_to_transaction (NautilusUndoable *undoable) -{ - gboolean result; - - /* Verify a transaction is in progress */ - if (!global_undo_manager->details->transaction_in_progress) { - g_warning("NautilusUndoManager has no current transaction. Begin a transaction first."); - return FALSE; - } - - g_assert(global_undo_manager->details->transaction != NULL); - - result = nautilus_undo_transaction_add_undoable(global_undo_manager->details->transaction, undoable); - - return result; -} - - -/* nautilus_undo_manager_remove_transaction */ -gboolean -nautilus_undo_manager_remove_transaction (NautilusUndoTransaction *transaction) -{ - /* Verify a transaction is not in progress */ - if (global_undo_manager->details->transaction_in_progress) { - g_warning("NautilusUndoManager cannot remove a transaction while one is in progress."); - return FALSE; - } - - g_return_val_if_fail(transaction != NULL, FALSE); - - /* Remove transaction from undo list */ - global_undo_manager->details->undo_list = g_list_remove(global_undo_manager->details->undo_list, - transaction); - - /* Remove transaction from redo list */ - global_undo_manager->details->redo_list = g_list_remove(global_undo_manager->details->redo_list, - transaction); - - /* Fire off signal informing that an undo transaction has occurred */ - gtk_signal_emit (GTK_OBJECT (global_undo_manager), signals[UNDO_TRANSACTION_OCCURED]); - - return TRUE; -} - - /* nautilus_undo_manager_add_undo_transaction */ -gboolean -nautilus_undo_manager_add_undo_transaction (NautilusUndoTransaction *transaction) +void +nautilus_undo_manager_add_transaction (NautilusUndoManager *manager, NautilusUndoTransaction *transaction) { int length; /* Verify a transaction is not in progress */ - if (global_undo_manager->details->transaction_in_progress) { + if (manager->details->transaction_in_progress) { g_warning("NautilusUndoManager cannot add a transaction while one is in progress."); - return FALSE; + return; } - g_return_val_if_fail(transaction != NULL, FALSE); + g_return_if_fail (transaction != NULL); /* Check and see if we are over our queue limit */ - length = g_list_length(global_undo_manager->details->undo_list); + length = g_list_length (manager->details->undo_list); - if (length >= global_undo_manager->details->queue_depth) { - global_undo_manager->details->undo_list = prune_undo_manager_list ( - global_undo_manager->details->undo_list, - (length - global_undo_manager->details->queue_depth) + 1); + if (length >= manager->details->queue_depth) { + manager->details->undo_list = prune_undo_manager_list ( + manager->details->undo_list, + (length - manager->details->queue_depth) + 1); } /* Add transaction to undo list */ - global_undo_manager->details->undo_list = g_list_append(global_undo_manager->details->undo_list, - transaction); + manager->details->undo_list = g_list_append(manager->details->undo_list, transaction); /* Fire off signal informing that an undo transaction has occurred */ - gtk_signal_emit (GTK_OBJECT (global_undo_manager), signals[UNDO_TRANSACTION_OCCURED]); - - return TRUE; -} - -/* nautilus_undo_manager_add_redo_transaction */ -gboolean -nautilus_undo_manager_add_redo_transaction (NautilusUndoTransaction *transaction) -{ - g_return_val_if_fail(transaction != NULL, FALSE); - - /* Verify a transaction is not in progress */ - if (global_undo_manager->details->transaction_in_progress) { - g_warning("NautilusUndoManager cannot add a transaction while one is in progress."); - return FALSE; - } - - /* Make sure we allow redo */ - if (!global_undo_manager->details->enable_redo) { - return FALSE; - } - - /* Add transaction to undo list */ - global_undo_manager->details->undo_list = g_list_append(global_undo_manager->details->undo_list, - transaction); - - /* Fire off signal informing that an redo transaction has occurred */ - gtk_signal_emit (GTK_OBJECT (global_undo_manager), signals[UNDO_TRANSACTION_OCCURED]); - - return TRUE; + gtk_signal_emit (GTK_OBJECT (manager), signals[UNDO_TRANSACTION_OCCURED]); } @@ -456,27 +365,32 @@ nautilus_undo_manager_add_redo_transaction (NautilusUndoTransaction *transaction * Remove any transaction with object as target from * the undo and redo queues */ - + gboolean nautilus_undo_manager_unregister_object (GtkObject *object) { + NautilusUndoManager *manager; NautilusUndoTransaction *transaction; gboolean success; GList *list; int index, length; success = FALSE; - + + /* Locate undo manager */ + manager = gtk_object_get_data (object, NAUTILUS_UNDO_MANAGER_NAME); + g_return_val_if_fail (manager != NULL, success); + /* Check undo list */ - length = g_list_length(global_undo_manager->details->undo_list); + length = g_list_length (manager->details->undo_list); for (index = 0; index < length; index++) { - list = g_list_nth(global_undo_manager->details->undo_list, index); + list = g_list_nth (manager->details->undo_list, index); if (list) { transaction = list->data; - if (nautilus_undo_transaction_contains_object(transaction, object)) { - global_undo_manager->details->undo_list = - g_list_remove(global_undo_manager->details->undo_list, transaction); - nautilus_undo_transaction_destroy(transaction); + if (nautilus_undo_transaction_contains_object (transaction, object)) { + manager->details->undo_list = + g_list_remove (manager->details->undo_list, transaction); + nautilus_undo_transaction_destroy (transaction); index--; success = TRUE; } @@ -484,14 +398,14 @@ nautilus_undo_manager_unregister_object (GtkObject *object) } /* Check redo list */ - length = g_list_length(global_undo_manager->details->redo_list); + length = g_list_length (manager->details->redo_list); for (index = 0; index < length; index++) { - list = g_list_nth(global_undo_manager->details->redo_list, index); + list = g_list_nth (manager->details->redo_list, index); if (list) { transaction = list->data; if (nautilus_undo_transaction_contains_object(transaction, object)) { - global_undo_manager->details->redo_list = - g_list_remove(global_undo_manager->details->redo_list, transaction); + manager->details->redo_list = + g_list_remove (manager->details->redo_list, transaction); nautilus_undo_transaction_destroy(transaction); index--; success = TRUE; @@ -501,7 +415,7 @@ nautilus_undo_manager_unregister_object (GtkObject *object) if (success) { /* Fire off signal informing that a transaction has occurred */ - gtk_signal_emit (GTK_OBJECT (global_undo_manager), signals[UNDO_TRANSACTION_OCCURED]); + gtk_signal_emit (GTK_OBJECT (manager), signals[UNDO_TRANSACTION_OCCURED]); } return success; @@ -509,10 +423,10 @@ nautilus_undo_manager_unregister_object (GtkObject *object) /* nautilus_undo_manager_can_undo */ gboolean -nautilus_undo_manager_can_undo (void) +nautilus_undo_manager_can_undo (NautilusUndoManager *manager) { - if (global_undo_manager != NULL) { - return (g_list_length(global_undo_manager->details->undo_list) > 0); + if (manager != NULL) { + return (g_list_length (manager->details->undo_list) > 0); } else { return FALSE; } @@ -520,11 +434,11 @@ nautilus_undo_manager_can_undo (void) /* nautilus_undo_manager_can_redo */ gboolean -nautilus_undo_manager_can_redo (void) +nautilus_undo_manager_can_redo (NautilusUndoManager *manager) { - if (global_undo_manager->details->enable_redo) { - if (global_undo_manager != NULL) { - return (g_list_length(global_undo_manager->details->redo_list) > 0); + if (manager->details->enable_redo) { + if (manager != NULL) { + return (g_list_length (manager->details->redo_list) > 0); } else { return FALSE; } @@ -540,23 +454,22 @@ nautilus_undo_manager_can_redo (void) * current undo transaction. */ -static gint -get_current_transaction_name(GList *list, gchar *name, gint max_length) +static const gchar * +get_current_transaction_name (GList *list) { NautilusUndoTransaction *transaction; const gchar *transaction_name; - gint name_length; - + /* Check for NULL list */ if (list == NULL) { g_warning("Unable to get current transaction name due to NULL undo list."); - return -1; + return NULL; } /* Check for empty list */ if (g_list_length(list) <= 0) { g_warning("No transaction to get current undo transaction name from."); - return -1; + return NULL; } /* Get last transaction from list */ @@ -564,30 +477,17 @@ get_current_transaction_name(GList *list, gchar *name, gint max_length) transaction = list->data; if (transaction == NULL) { g_warning("Unable to get current transaction name due to NULL transaction in list."); - return -1; + return NULL; } /* Check for valid transaction name */ transaction_name = nautilus_undo_transaction_get_name(transaction); if ( transaction_name == NULL) { g_warning("Current transaction name is NULL."); - return -1; + return NULL; } - /* Return length of transaction name if name argument is NULL */ - if (name == NULL) { - return strlen(transaction_name); - } - - /* Copy over requested amount into return name argument */ - name_length = strlen(transaction_name); - if (name_length > max_length) { - strncpy(name, transaction_name, max_length); - return max_length; - } else { - strncpy(name, transaction_name, name_length); - return name_length; - } + return transaction_name; } @@ -598,10 +498,10 @@ get_current_transaction_name(GList *list, gchar *name, gint max_length) * current undo transaction. */ -gint -nautilus_undo_manager_get_current_undo_transaction_name (gchar *name, gint max_length) +const gchar * +nautilus_undo_manager_get_current_undo_transaction_name (NautilusUndoManager *manager) { - return get_current_transaction_name(global_undo_manager->details->undo_list, name, max_length); + return get_current_transaction_name (manager->details->undo_list); } /* nautilus_undo_manager_get_current_undo_transaction_name @@ -611,120 +511,97 @@ nautilus_undo_manager_get_current_undo_transaction_name (gchar *name, gint max_l * current undo transaction. */ -gint -nautilus_undo_manager_get_current_redo_transaction_name (gchar *name, gint max_length) +const gchar * +nautilus_undo_manager_get_current_redo_transaction_name (NautilusUndoManager *manager) { - return get_current_transaction_name(global_undo_manager->details->redo_list, name, max_length); + return get_current_transaction_name (manager->details->redo_list); } /* destroy */ static void destroy (GtkObject *object) { + NautilusUndoManager *manager; + g_return_if_fail (NAUTILUS_IS_UNDO_MANAGER (object)); + manager = NAUTILUS_UNDO_MANAGER (object); + /* Clear lists */ - global_undo_manager->details->undo_list = free_undo_manager_list_data(global_undo_manager->details->undo_list); - global_undo_manager->details->redo_list = free_undo_manager_list_data(global_undo_manager->details->redo_list); + manager->details->undo_list = free_undo_manager_list_data (manager->details->undo_list); + manager->details->redo_list = free_undo_manager_list_data (manager->details->redo_list); NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object)); } -/* Initialize Nautilus global undo manager */ -gboolean -nautilus_undo_manager_initialize_global_manager (void) -{ - if (global_undo_manager != NULL) { - g_warning("A global undo manager has already been created."); - return FALSE; - } - - global_undo_manager = nautilus_undo_manager_new(); - - return TRUE; -} - - -/* Return global undo manager */ -NautilusUndoManager * -nautilus_undo_manager_get_undo_manager (void) -{ - g_return_val_if_fail(global_undo_manager != NULL, NULL); - return global_undo_manager; -} - - /* nautilus_undo_manager_enable_redo * * Enable or disable redo functionality */ -gboolean -nautilus_undo_manager_enable_redo (gboolean value) + +void +nautilus_undo_manager_enable_redo (NautilusUndoManager *manager, gboolean value) { - g_return_val_if_fail(global_undo_manager != NULL, FALSE); + g_return_if_fail (manager != NULL); - global_undo_manager->details->enable_redo = value; + manager->details->enable_redo = value; /* Flush and free redo queue */ - g_list_free(global_undo_manager->details->redo_list); - - return TRUE; + g_list_free (manager->details->redo_list); } /* nautilus_undo_manager_enable_redo * * Enable or disable redo functionality */ -gboolean -nautilus_undo_manager_set_queue_depth (gint depth) +void +nautilus_undo_manager_set_queue_depth (NautilusUndoManager *manager, gint depth) { int length; /* Don't allow negative or zero queue depth */ if (depth <= 0) { g_warning ("NautilusUndoManager doesn not allow negative or zero length queue."); - return FALSE; + return; } - global_undo_manager->details->queue_depth = depth; + manager->details->queue_depth = depth; /* Prune lists */ - length = g_list_length (global_undo_manager->details->undo_list); + length = g_list_length (manager->details->undo_list); if (length > depth) { - global_undo_manager->details->undo_list = prune_undo_manager_list (global_undo_manager->details->undo_list, + manager->details->undo_list = prune_undo_manager_list (manager->details->undo_list, length - depth); } - length = g_list_length (global_undo_manager->details->redo_list); + length = g_list_length (manager->details->redo_list); if (length > depth) { - global_undo_manager->details->undo_list = prune_undo_manager_list (global_undo_manager->details->redo_list, - length - depth); + manager->details->undo_list = prune_undo_manager_list (manager->details->redo_list, + length - depth); } /* Fire off signal informing that an undo transaction has occurred */ - gtk_signal_emit (GTK_OBJECT (global_undo_manager), signals[UNDO_TRANSACTION_OCCURED]); - - return TRUE; + gtk_signal_emit (GTK_OBJECT (manager), signals[UNDO_TRANSACTION_OCCURED]); } /* free_undo_manager_list_data * * Clear undo data from list */ - + static GList * free_undo_manager_list_data (GList *list) { int length, index; NautilusUndoTransaction *transaction; - - length = g_list_length(list); + + length = g_list_length (list); for (index = 0; index < length; index++) { - list = g_list_last(list); + list = g_list_last (list); if (list) { transaction = list->data; - list = g_list_remove(list, transaction); - nautilus_undo_transaction_destroy(transaction); + list = g_list_remove (list, transaction); + nautilus_undo_transaction_destroy (transaction); } } @@ -736,7 +613,7 @@ free_undo_manager_list_data (GList *list) * * Prune n items from start of list */ - + static GList * prune_undo_manager_list (GList *list, gint items) { @@ -744,11 +621,11 @@ prune_undo_manager_list (GList *list, gint items) NautilusUndoTransaction *transaction; for (index = 0; index < items; index++) { - list = g_list_first(list); + list = g_list_first (list); if (list) { transaction = list->data; - list = g_list_remove(list, transaction); - nautilus_undo_transaction_destroy(transaction); + list = g_list_remove (list, transaction); + nautilus_undo_transaction_destroy (transaction); } } diff --git a/libnautilus/nautilus-undo-manager.h b/libnautilus/nautilus-undo-manager.h index aef846797..272f0bd00 100644 --- a/libnautilus/nautilus-undo-manager.h +++ b/libnautilus/nautilus-undo-manager.h @@ -26,9 +26,10 @@ #define NAUTILUS_UNDO_MANAGER_H #include <bonobo/bonobo-object.h> -#include <libnautilus/nautilus-undo-manager-component.h> #include <bonobo/bonobo-persist.h> + #include "nautilus-undo-transaction.h" +#include "nautilus-undo.h" #define NAUTILUS_TYPE_UNDO_MANAGER \ (nautilus_undo_manager_get_type ()) @@ -43,6 +44,7 @@ typedef struct NautilusUndoManagerClass NautilusUndoManagerClass; typedef struct NautilusUndoManagerDetails NautilusUndoManagerDetails; +typedef struct NautilusUndoTransactionInProgress NautilusUndoTransactionInProgress; struct NautilusUndoManager { BonoboPersist parent; @@ -50,41 +52,44 @@ struct NautilusUndoManager { }; struct NautilusUndoManagerClass { - BonoboPersistClass parent_class; - + BonoboPersistClass parent_class; void (* undo_transaction_occurred) (GtkObject *object, gpointer data); - gpointer servant_init_func, servant_destroy_func, vepv; }; +struct NautilusUndoTransactionInProgress { + NautilusUndoManager *manager; + NautilusUndoTransaction *transaction; + +}; + +#define NAUTILUS_UNDO_MANAGER_NAME "NautilusUndoManager" /* GtkObject */ -GtkType nautilus_undo_manager_get_type (void); -NautilusUndoManager *nautilus_undo_manager_new (void); +GtkType nautilus_undo_manager_get_type (void); +NautilusUndoManager *nautilus_undo_manager_new (void); /* Prototypes */ -gboolean nautilus_undo_manager_initialize_global_manager (void); -gboolean nautilus_undo_manager_add_undoable_to_transaction (NautilusUndoable *undoable); -gboolean nautilus_undo_manager_begin_transaction (const gchar *name); -gboolean nautilus_undo_manager_end_transaction (void); -gboolean nautilus_undo_manager_undo_last_transaction (void); -gboolean nautilus_undo_manager_redo_last_undone_transaction (void); -NautilusUndoTransaction *nautilus_undo_manager_get_current_transaction (void); -gboolean nautilus_undo_manager_transaction_in_progress (void); -gboolean nautilus_undo_manager_add_undo_transaction (NautilusUndoTransaction - *transaction); -gboolean nautilus_undo_manager_add_redo_transaction (NautilusUndoTransaction - *transaction); -gboolean nautilus_undo_manager_remove_transaction (NautilusUndoTransaction - *transaction); +NautilusUndoTransactionInProgress *nautilus_undo_manager_begin_transaction (GtkObject *object, const gchar *name); +void nautilus_undo_manager_end_transaction (NautilusUndoTransactionInProgress *transaction); + +void nautilus_undo_manager_undo (NautilusUndoManager *manager); +void nautilus_undo_manager_redo (NautilusUndoManager *manager); + +void nautilus_undo_manager_add_transaction (NautilusUndoManager *manager, + NautilusUndoTransaction *transaction); + +gboolean nautilus_undo_manager_can_undo (NautilusUndoManager *manager); +gboolean nautilus_undo_manager_can_redo (NautilusUndoManager *manager); + +const gchar *nautilus_undo_manager_get_current_undo_transaction_name (NautilusUndoManager *manager); +const gchar *nautilus_undo_manager_get_current_redo_transaction_name (NautilusUndoManager *manager); + +void nautilus_undo_manager_enable_redo (NautilusUndoManager *manager, gboolean value); +void nautilus_undo_manager_set_queue_depth (NautilusUndoManager *manager, gint depth); + + gboolean nautilus_undo_manager_unregister_object (GtkObject *object); -gboolean nautilus_undo_manager_can_undo (void); -gboolean nautilus_undo_manager_can_redo (void); -gint nautilus_undo_manager_get_current_undo_transaction_name (gchar *name, gint max_length); -gint nautilus_undo_manager_get_current_redo_transaction_name (gchar *name, gint max_length); -NautilusUndoManager *nautilus_undo_manager_get_undo_manager (void); -gboolean nautilus_undo_manager_enable_redo (gboolean value); -gboolean nautilus_undo_manager_set_queue_depth (gint depth); #endif diff --git a/libnautilus/nautilus-undo-transaction.h b/libnautilus/nautilus-undo-transaction.h index 6da767e4c..82026c0fb 100644 --- a/libnautilus/nautilus-undo-transaction.h +++ b/libnautilus/nautilus-undo-transaction.h @@ -26,17 +26,13 @@ #define NAUTILUS_UNDO_TRANSACTION_H #include <glib.h> - #include "nautilus-undoable.h" -typedef struct NautilusUndoTransaction NautilusUndoTransaction; - struct NautilusUndoTransaction { gchar *name; GList *transaction_list; }; - NautilusUndoTransaction *nautilus_undo_transaction_new (const gchar *name); void nautilus_undo_transaction_destroy (NautilusUndoTransaction *transaction); gboolean nautilus_undo_transaction_add_undoable (NautilusUndoTransaction *transaction, diff --git a/libnautilus/nautilus-undo.idl b/libnautilus/nautilus-undo.idl new file mode 100644 index 000000000..cd63e190b --- /dev/null +++ b/libnautilus/nautilus-undo.idl @@ -0,0 +1,40 @@ +/* -*- Mode: IDL; tab-width: 8; indent-tabs-mode: 8; c-basic-offset: 8 -*- */ + +#ifndef NAUTUILUS_UNDO_IDL_INCLUDED +#define NAUTUILUS_UNDO_MANAGER_IDL_INCLUDED + +#include <gnome-factory.idl> +#include <Bonobo.idl> + +module Nautilus { + + module Undo { + + // Forward declarations + interface Manager; + interface Transaction; + + // Contains elements that describe a transaction + struct TransactionMenuInfo { + string name; + string description; + }; + + // An undo transaction + interface Transaction : ::Bonobo::Unknown { + readonly attribute TransactionMenuInfo undo_description; + readonly attribute TransactionMenuInfo redo_description; + readonly attribute string base_description; + + void undo (in Transaction transaction); + }; + + // The main interface that handles undo transactions + interface Manager : ::Bonobo::Unknown { + void append (in Transaction transaction); + void forget (in Transaction transaction); + }; + }; +}; + +#endif /* NAUTUILUS_UNDO_IDL_INCLUDED */ diff --git a/libnautilus/nautilus-undoable.c b/libnautilus/nautilus-undoable.c index 56d3a680c..807940e83 100644 --- a/libnautilus/nautilus-undoable.c +++ b/libnautilus/nautilus-undoable.c @@ -122,7 +122,8 @@ destroy (GtkObject *object) /* nautilus_undoable_save_undo_snapshot */ void -nautilus_undoable_save_undo_snapshot (GtkObject *target, GtkSignalFunc save_func, GtkSignalFunc restore_func) +nautilus_undoable_save_undo_snapshot (NautilusUndoTransaction *transaction, GtkObject *target, + GtkSignalFunc save_func, GtkSignalFunc restore_func) { gboolean result; NautilusUndoable *undoable; @@ -138,7 +139,7 @@ nautilus_undoable_save_undo_snapshot (GtkObject *target, GtkSignalFunc save_func gtk_signal_connect_while_alive (GTK_OBJECT (undoable), "restore_from_undo_snapshot", restore_func, target, target); /* Add undoable to current transaction */ - result = nautilus_undo_manager_add_undoable_to_transaction (undoable); + result = nautilus_undo_transaction_add_undoable (transaction, undoable); /* Fire SAVE_UNDO_SNAPSHOT signal */ gtk_signal_emit (GTK_OBJECT (undoable), diff --git a/libnautilus/nautilus-undoable.h b/libnautilus/nautilus-undoable.h index a6c1805c9..9d56b5190 100644 --- a/libnautilus/nautilus-undoable.h +++ b/libnautilus/nautilus-undoable.h @@ -40,9 +40,10 @@ #define NAUTILUS_IS_UNDOABLE_CLASS(klass) \ (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_UNDOABLE)) -typedef struct NautilusUndoable NautilusUndoable; typedef struct NautilusUndoableClass NautilusUndoableClass; typedef struct NautilusUndoManager NautilusUndoManager; +typedef struct NautilusUndoable NautilusUndoable; +typedef struct NautilusUndoTransaction NautilusUndoTransaction; struct NautilusUndoable { GtkObject parent; @@ -62,8 +63,8 @@ struct NautilusUndoableClass { GtkType nautilus_undoable_get_type (void); GtkObject *nautilus_undoable_new (void); -void nautilus_undoable_save_undo_snapshot (GtkObject *target, GtkSignalFunc save_func, - GtkSignalFunc restore_func); +void nautilus_undoable_save_undo_snapshot (NautilusUndoTransaction *transaction, GtkObject *target, + GtkSignalFunc save_func, GtkSignalFunc restore_func); void nautilus_undoable_restore_from_undo_snapshot (NautilusUndoable *undoable); #endif diff --git a/libnautilus/nautilus-view-component.idl b/libnautilus/nautilus-view-component.idl index 24f2ce8a8..ddabf376c 100644 --- a/libnautilus/nautilus-view-component.idl +++ b/libnautilus/nautilus-view-component.idl @@ -10,14 +10,14 @@ #pragma inhibit push #endif -#include "nautilus-undo-manager-component.idl" +#include "nautilus-undo.idl" #if !defined(__BONOBO_COMPILATION) && defined(__ORBIT_IDL__) #pragma inhibit pop #endif %{ -#pragma include_defs "libnautilus/nautilus-undo-manager-component.h" +#pragma include_defs "libnautilus/nautilus-undo.h" %} module Nautilus { @@ -120,7 +120,7 @@ module Nautilus { interface Application : ::Bonobo::GenericFactory, ::Bonobo::Unknown { readonly attribute ViewWindowList view_windows; - readonly attribute UndoManager undo_manager; + readonly attribute Undo::Manager undo_manager; ViewWindow new_view_window (); }; }; |