diff options
author | Darin Adler <darin@src.gnome.org> | 2000-06-07 02:47:10 +0000 |
---|---|---|
committer | Darin Adler <darin@src.gnome.org> | 2000-06-07 02:47:10 +0000 |
commit | 62ae037752dc780c7def921c36df45dc2cfb66f0 (patch) | |
tree | c4e2c923f38b282120f3ab717c1787e403adf7f5 /libnautilus-private/nautilus-undo-manager.c | |
parent | aac364ac6b2ab7205a694b13d95d2d21f4e8335d (diff) | |
download | nautilus-62ae037752dc780c7def921c36df45dc2cfb66f0.tar.gz |
The main change here is revamping the undo manager.
To get a complete check-out you might have to delete
the file named libnautilus/nautilus-undo.h that used
to be a generated file and is now checked-in.
* components/help/help-method.c: (vfs_module_transform):
Removed a bogus extraneous FIXME.
* libnautilus-extensions/Makefile.am:
Moved the undo manager into libnautilus-extensions
since it's not needed by Nautilus components.
* libnautilus-extensions/nautilus-entry.c:
* libnautilus-extensions/nautilus-icon-text-item.c:
* libnautilus/nautilus-view.c:
* src/nautilus-application.c:
* src/nautilus-bookmarks-window.c: (create_bookmarks_window):
* src/nautilus-view-frame.c:
* src/nautilus-window-private.h:
* src/nautilus-window.c:
Updated includes and a few small function name changes.
* libnautilus-extensions/nautilus-gtk-extensions.h:
* libnautilus-extensions/nautilus-gtk-extensions.c:
(alive_disconnecter),
(nautilus_gtk_signal_connect_full_while_alive):
Added a new function that combines the features of
gtk_signal_connect_full with gtk_signal_connect_while_alive.
* libnautilus/nautilus-undo-context.h: [removed]
* libnautilus/nautilus-undo-context.c: [removed]
* libnautilus-extensions/nautilus-undo-context.h:
* libnautilus-extensions/nautilus-undo-context.c:
(impl_Nautilus_Undo_Context__destroy),
(impl_Nautilus_Undo_Context__create),
(impl_Nautilus_Undo_Context__get_undo_manager),
(nautilus_undo_context_new), (destroy),
(nautilus_undo_context_initialize_class):
Rewrote this class to simplify it (after moving it here).
* libnautilus/nautilus-undo-manager.h: [removed]
* libnautilus/nautilus-undo-manager.c: [removed]
* libnautilus/nautilus-undo-manager-private.h: [removed]
* libnautilus-extensions/nautilus-undo-manager.h:
* libnautilus-extensions/nautilus-undo-manager.c:
(impl_Nautilus_Undo_Manager__destroy),
(impl_Nautilus_Undo_Manager__create),
(impl_Nautilus_Undo_Manager__append),
(impl_Nautilus_Undo_Manager__forget),
(nautilus_undo_manager_initialize),
(nautilus_undo_manager_initialize_class),
(nautilus_undo_manager_undo),
(nautilus_undo_manager_add_transaction),
(nautilus_undo_manager_forget_transaction),
(nautilus_undo_manager_set_queue_depth),
(nautilus_undo_manager_attach),
(nautilus_undo_manager_add_interface), (update_undo_menu_item),
(undo_menu_handler_connection_free),
(undo_menu_handler_connection_free_cover),
(nautilus_undo_manager_set_up_bonobo_ui_handler_undo_item):
Rewrote this class to simplify it. Got rid of many old
interfaces and added some new ones.
* libnautilus/.cvsignore:
* libnautilus/Makefile.am:
Renamed the old nautilus-undo.idl to
nautilus-distributed-undo.idl. The IDL is only about the internal
part of the undo framework. Clients use calls that are in
nautilus-undo.h. The part that's public needs the prettier name.
* libnautilus/nautilus-undo.idl: [removed]
* libnautilus/nautilus-distributed-undo.idl:
Updated the names of menu-item-related things to better match the
standard terminology.
* libnautilus/nautilus-undo-private.h:
Added this new header for things needed by the undo manager that
are in libnautilus. Maybe we can eliminate this later.
* libnautilus/nautilus-undo-transaction.h:
* libnautilus/nautilus-undo-transaction.c:
(impl_Nautilus_Undo_Transaction__destroy),
(impl_Nautilus_Undo_Transaction__create),
(impl_Nautilus_Undo_Transaction__get_undo_menu_item),
(impl_Nautilus_Undo_Transaction__get_redo_menu_item),
(impl_Nautilus_Undo_Transaction__get_operation_name),
(impl_Nautilus_Undo_Transaction__undo),
(nautilus_undo_transaction_new),
(nautilus_undo_transaction_initialize),
(remove_transaction_from_object),
(nautilus_undo_transaction_destroy),
(nautilus_undo_transaction_initialize_class),
(nautilus_undo_transaction_add_atom),
(nautilus_undo_transaction_undo),
(nautilus_undo_transaction_add_to_undo_manager), (remove_atoms),
(remove_atoms_cover),
(nautilus_undo_transaction_unregister_object), (undo_atom_free),
(undo_atom_undo_and_free), (undo_atom_free_cover),
(undo_atom_undo_and_free_cover), (undo_atom_list_free),
(undo_atom_list_undo_and_free):
Rewrote and simplified this class and got rid of all uses of
NautilusUndoable.
* libnautilus/nautilus-undoable.h: [removed]
* libnautilus/nautilus-undoable.c: [removed]
* libnautilus/nautilus-undo.h:
* libnautilus/nautilus-undo.c: (nautilus_undo_register),
(nautilus_undo_register_full), (nautilus_undo_unregister),
(nautilus_undo), (nautilus_undo_get_undo_manager),
(undo_manager_ref), (undo_manager_unref),
(undo_manager_unref_cover), (nautilus_undo_attach_undo_manager),
(nautilus_undo_share_undo_manager), (set_up_bonobo_control),
(nautilus_undo_set_up_bonobo_control):
Added this new file with the public interface of the undo code and
most of the basic implementation. Most of this was previously in
nautilus-undoable.c.
* nautilus-widgets/nautilus-preferences.c:
(preferences_hash_node_free), (preferences_hash_node_add_callback),
(preferences_hash_node_remove_callback),
(preferences_hash_node_check_changes_func),
(preferences_callback_node_alloc),
(preferences_callback_node_free),
(preferences_callback_node_free_func),
(preferences_callback_node_invoke_func),
(preferences_gconf_callback):
Fixed a repeated spelling error in this file.
* src/nautilus-application.c: (nautilus_app_init):
* src/nautilus-view-frame.c: (nautilus_view_frame_load_client):
* src/nautilus-window-menus.c: (edit_menu_undo_callback),
(nautilus_window_initialize_menus):
* src/nautilus-window.c: (nautilus_window_constructed):
Changed to use public parts of the undo API instead of the old
stuff that used private secret stuff. Many places use nice new
convenient calls that do a lot of the work for you.
Diffstat (limited to 'libnautilus-private/nautilus-undo-manager.c')
-rw-r--r-- | libnautilus-private/nautilus-undo-manager.c | 423 |
1 files changed, 162 insertions, 261 deletions
diff --git a/libnautilus-private/nautilus-undo-manager.c b/libnautilus-private/nautilus-undo-manager.c index 15af401ff..28946d900 100644 --- a/libnautilus-private/nautilus-undo-manager.c +++ b/libnautilus-private/nautilus-undo-manager.c @@ -25,25 +25,22 @@ #include <config.h> #include "nautilus-undo-manager.h" +#include <libnautilus-extensions/nautilus-gtk-macros.h> +#include <libnautilus-extensions/nautilus-gtk-extensions.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> - -#include "nautilus-undo-manager-private.h" - -#include <libnautilus-extensions/nautilus-gnome-extensions.h> -#include <libnautilus-extensions/nautilus-gtk-extensions.h> -#include <libnautilus-extensions/nautilus-gtk-macros.h> - - -/* Gloabl instance of undo manager */ -Nautilus_Undo_Manager global_undo_manager; +#include <libnautilus/nautilus-undo-private.h> +#include "nautilus-undo-context.h" + +struct NautilusUndoManagerDetails { + GList *undo_list; + GList *redo_list; + gboolean enable_redo; + gint queue_depth; +}; enum { - UNDO_TRANSACTION_OCCURRED, + CHANGED, LAST_SIGNAL }; static guint signals[LAST_SIGNAL]; @@ -53,40 +50,45 @@ typedef struct { NautilusUndoManager *bonobo_object; } impl_POA_Nautilus_Undo_Manager; +typedef struct { + BonoboUIHandler *handler; + char *path; + char *no_undo_menu_item_label; + char *no_undo_menu_item_hint; +} UndoMenuHandlerConnection; + /* GtkObject */ -static void nautilus_undo_manager_initialize_class (NautilusUndoManagerClass *class); -static void nautilus_undo_manager_initialize (NautilusUndoManager *item); -static void destroy (GtkObject *object); -static void free_undo_manager_list (GList *list); -static GList *prune_undo_manager_list (GList *list, - int items); +static void nautilus_undo_manager_initialize_class (NautilusUndoManagerClass *class); +static void nautilus_undo_manager_initialize (NautilusUndoManager *item); +static void destroy (GtkObject *object); +static void free_undo_manager_list (GList *list); +static GList *prune_undo_manager_list (GList *list, + int items); /* CORBA/Bonobo */ -static void impl_Nautilus_Undo_Manager__append (PortableServer_Servant servant, - const Nautilus_Undo_Transaction transaction, - CORBA_Environment *ev); -static void impl_Nautilus_Undo_Manager__forget (PortableServer_Servant servant, - const Nautilus_Undo_Transaction transaction, - CORBA_Environment *ev); -static void impl_Nautilus_Undo_Manager__undo (PortableServer_Servant servant, - CORBA_Environment *ev); -static void nautilus_undo_manager_add_transaction (NautilusUndoManager *manager, - Nautilus_Undo_Transaction transaction); -static void nautilus_undo_manager_forget_transaction (NautilusUndoManager *manager, - Nautilus_Undo_Transaction transaction); -static void nautilus_undo_manager_undo (NautilusUndoManager *manager); +static void impl_Nautilus_Undo_Manager__append (PortableServer_Servant servant, + Nautilus_Undo_Transaction transaction, + CORBA_Environment *ev); +static void impl_Nautilus_Undo_Manager__forget (PortableServer_Servant servant, + Nautilus_Undo_Transaction transaction, + CORBA_Environment *ev); +static void impl_Nautilus_Undo_Manager__undo (PortableServer_Servant servant, + CORBA_Environment *ev); +static void nautilus_undo_manager_add_transaction (NautilusUndoManager *manager, + Nautilus_Undo_Transaction transaction); +static void nautilus_undo_manager_forget_transaction (NautilusUndoManager *manager, + Nautilus_Undo_Transaction transaction); NAUTILUS_DEFINE_CLASS_BOILERPLATE(NautilusUndoManager, nautilus_undo_manager, BONOBO_OBJECT_TYPE) -POA_Nautilus_Undo_Manager__epv libnautilus_Nautilus_Undo_Manager_epv = +static POA_Nautilus_Undo_Manager__epv libnautilus_Nautilus_Undo_Manager_epv = { - NULL, /* _private */ + NULL, &impl_Nautilus_Undo_Manager__append, &impl_Nautilus_Undo_Manager__forget, &impl_Nautilus_Undo_Manager__undo, }; - static PortableServer_ServantBase__epv base_epv; -static POA_Nautilus_Undo_Manager__vepv impl_Nautilus_Undo_Manager_vepv = +static POA_Nautilus_Undo_Manager__vepv vepv = { &base_epv, NULL, @@ -94,53 +96,48 @@ static POA_Nautilus_Undo_Manager__vepv impl_Nautilus_Undo_Manager_vepv = }; static void -impl_Nautilus_Undo_Manager__destroy (BonoboObject *obj, impl_POA_Nautilus_Undo_Manager *servant) +impl_Nautilus_Undo_Manager__destroy (BonoboObject *object, + impl_POA_Nautilus_Undo_Manager *servant) { - PortableServer_ObjectId *objid; + PortableServer_ObjectId *object_id; CORBA_Environment ev; - void (*servant_destroy_func) (PortableServer_Servant servant, CORBA_Environment *ev); CORBA_exception_init (&ev); - servant_destroy_func = NAUTILUS_UNDO_MANAGER_CLASS (GTK_OBJECT (servant->bonobo_object)->klass)->servant_destroy_func; - objid = PortableServer_POA_servant_to_id (bonobo_poa (), servant, &ev); - PortableServer_POA_deactivate_object (bonobo_poa (), objid, &ev); - CORBA_free (objid); - obj->servant = NULL; + object_id = PortableServer_POA_servant_to_id (bonobo_poa (), servant, &ev); + PortableServer_POA_deactivate_object (bonobo_poa (), object_id, &ev); + CORBA_free (object_id); + object->servant = NULL; - servant_destroy_func ((PortableServer_Servant) servant, &ev); + POA_Nautilus_Undo_Manager__fini (servant, &ev); g_free (servant); + CORBA_exception_free (&ev); } static Nautilus_Undo_Manager -impl_Nautilus_Undo_Manager__create (NautilusUndoManager *manager, CORBA_Environment * ev) +impl_Nautilus_Undo_Manager__create (NautilusUndoManager *bonobo_object, + CORBA_Environment *ev) { - 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_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 (); - servant_init_func ((PortableServer_Servant) servant, ev); - - servant->bonobo_object = manager; - retval = bonobo_object_activate_servant (BONOBO_OBJECT (manager), servant); + vepv.Bonobo_Unknown_epv = bonobo_object_get_epv (); + servant->servant.vepv = &vepv; + POA_Nautilus_Undo_Manager__init ((PortableServer_Servant) servant, ev); - gtk_signal_connect (GTK_OBJECT (manager), "destroy", GTK_SIGNAL_FUNC (impl_Nautilus_Undo_Manager__destroy), servant); + gtk_signal_connect (GTK_OBJECT (bonobo_object), "destroy", + GTK_SIGNAL_FUNC (impl_Nautilus_Undo_Manager__destroy), + servant); - return retval; + servant->bonobo_object = bonobo_object; + return bonobo_object_activate_servant (BONOBO_OBJECT (bonobo_object), servant); } static void impl_Nautilus_Undo_Manager__append (PortableServer_Servant servant, - const Nautilus_Undo_Transaction undo_transaction, + Nautilus_Undo_Transaction undo_transaction, CORBA_Environment *ev) { NautilusUndoManager *manager; @@ -153,7 +150,7 @@ impl_Nautilus_Undo_Manager__append (PortableServer_Servant servant, static void impl_Nautilus_Undo_Manager__forget (PortableServer_Servant servant, - const Nautilus_Undo_Transaction transaction, + Nautilus_Undo_Transaction transaction, CORBA_Environment *ev) { NautilusUndoManager *manager; @@ -182,8 +179,7 @@ nautilus_undo_manager_new (void) return gtk_type_new (nautilus_undo_manager_get_type ()); } -/* Object initialization function for the NautilusUndoManager */ -static void +static void nautilus_undo_manager_initialize (NautilusUndoManager *manager) { CORBA_Environment ev; @@ -192,23 +188,16 @@ nautilus_undo_manager_initialize (NautilusUndoManager *manager) manager->details = g_new0 (NautilusUndoManagerDetails, 1); - /* Create empty lists */ - manager->details->undo_list = NULL; - manager->details->redo_list = NULL; - - /* Default to no redo functionality */ - manager->details->enable_redo = FALSE; - /* Set queue depth to a single level */ manager->details->queue_depth = 1; - bonobo_object_construct (BONOBO_OBJECT (manager), impl_Nautilus_Undo_Manager__create (manager, &ev)); + bonobo_object_construct (BONOBO_OBJECT (manager), + impl_Nautilus_Undo_Manager__create (manager, &ev)); CORBA_exception_free (&ev); } -/* Class initialization function for the NautilusUndoManager. */ static void nautilus_undo_manager_initialize_class (NautilusUndoManagerClass *klass) { @@ -218,24 +207,19 @@ nautilus_undo_manager_initialize_class (NautilusUndoManagerClass *klass) object_class->destroy = destroy; - 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_OCCURRED] - = gtk_signal_new ("undo_transaction_occurred", + signals[CHANGED] + = gtk_signal_new ("changed", GTK_RUN_LAST, object_class->type, GTK_SIGNAL_OFFSET (NautilusUndoManagerClass, - undo_transaction_occurred), + changed), gtk_marshal_NONE__NONE, GTK_TYPE_NONE, 0); gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); } -static void +void nautilus_undo_manager_undo (NautilusUndoManager *manager) { GList *last_in_list; @@ -246,7 +230,6 @@ nautilus_undo_manager_undo (NautilusUndoManager *manager) /* Verify we have a transaction to be undone */ if (manager->details->undo_list == NULL) { - g_warning ("NautilusUndoManager has no transaction to be undone."); return; } @@ -269,8 +252,7 @@ nautilus_undo_manager_undo (NautilusUndoManager *manager) } /* Fire off signal informing that an undo transaction has occurred */ - gtk_signal_emit (GTK_OBJECT (manager), - signals[UNDO_TRANSACTION_OCCURRED]); + gtk_signal_emit (GTK_OBJECT (manager), signals[CHANGED]); CORBA_exception_free (&ev); } @@ -342,8 +324,7 @@ nautilus_undo_manager_add_transaction (NautilusUndoManager *manager, manager->details->undo_list = g_list_append (manager->details->undo_list, duplicate_transaction); /* Fire off signal informing that an undo transaction has occurred */ - gtk_signal_emit (GTK_OBJECT (manager), - signals[UNDO_TRANSACTION_OCCURRED]); + gtk_signal_emit (GTK_OBJECT (manager), signals[CHANGED]); CORBA_exception_free (&ev); } @@ -392,39 +373,13 @@ nautilus_undo_manager_forget_transaction (NautilusUndoManager *manager, if (success) { /* Fire off signal informing that a transaction has occurred */ - gtk_signal_emit (GTK_OBJECT (manager), - signals[UNDO_TRANSACTION_OCCURRED]); + gtk_signal_emit (GTK_OBJECT (manager), signals[CHANGED]); } CORBA_exception_free (&ev); } - -Nautilus_Undo_Transaction -nautilus_undo_manager_get_current_undo_transaction (NautilusUndoManager *manager) -{ - GList *last_in_list; - CORBA_Object undo_transaction; - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - /* Verify we have a transaction to be undone */ - if (manager->details->undo_list == NULL) { - g_warning ("NautilusUndoManager has no undo transaction in the queue."); - return NULL; - } - - /* Pop last transaction off undo list */ - last_in_list = g_list_last (manager->details->undo_list); - g_assert (last_in_list != NULL); - undo_transaction = last_in_list->data; - - return undo_transaction; - - CORBA_exception_free (&ev); -} - +#if 0 gboolean nautilus_undo_manager_can_undo (NautilusUndoManager *manager) @@ -441,6 +396,8 @@ nautilus_undo_manager_can_redo (NautilusUndoManager *manager) && manager->details->redo_list != NULL; } +#endif + static void destroy (GtkObject *object) { @@ -455,6 +412,8 @@ destroy (GtkObject *object) NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object)); } +#if 0 + /* nautilus_undo_manager_enable_redo * * Enable or disable redo functionality @@ -495,10 +454,11 @@ nautilus_undo_manager_set_queue_depth (NautilusUndoManager *manager, int depth) } /* Fire off signal informing that an undo transaction has occurred */ - gtk_signal_emit (GTK_OBJECT (manager), - signals[UNDO_TRANSACTION_OCCURRED]); + gtk_signal_emit (GTK_OBJECT (manager), signals[CHANGED]); } +#endif + /* free_undo_manager_list * * Clear undo data from list @@ -546,174 +506,115 @@ prune_undo_manager_list (GList *list, int items) return list; } -Nautilus_Undo_Manager -nautilus_get_undo_manager (GtkObject *start_object) -{ - Nautilus_Undo_Manager manager; - GtkWidget *parent; - GtkWindow *transient_parent; - - if (start_object == NULL) { - return NULL; - } - - g_return_val_if_fail (GTK_IS_OBJECT (start_object), NULL); - - /* Check for an undo manager right here. */ - manager = gtk_object_get_data (start_object, "Nautilus undo"); - if (manager != NULL) { - return manager; - } - - /* Check for undo manager up the parent chain. */ - if (GTK_IS_WIDGET (start_object)) { - parent = GTK_WIDGET (start_object)->parent; - if (parent != NULL) { - manager = nautilus_get_undo_manager (GTK_OBJECT (parent)); - if (manager != NULL) { - return manager; - } - } - - /* Check for undo manager in our window's parent. */ - if (GTK_IS_WINDOW (start_object)) { - transient_parent = GTK_WINDOW (start_object)->transient_parent; - if (transient_parent != NULL) { - manager = nautilus_get_undo_manager (GTK_OBJECT (transient_parent)); - if (manager != NULL) { - return manager; - } - } - } - } - - /* In the case of a canvas item, try the canvas. */ - if (GNOME_IS_CANVAS_ITEM (start_object)) { - manager = nautilus_get_undo_manager (GTK_OBJECT (GNOME_CANVAS_ITEM (start_object)->canvas)); - if (manager != NULL) { - return manager; - } - } - - /* Found nothing. I can live with that. */ - return NULL; -} - -static void -undo_manager_unref (gpointer manager) -{ - CORBA_Environment ev; - - CORBA_exception_init (&ev); - Nautilus_Undo_Manager_unref (manager, &ev); - CORBA_Object_release (manager, &ev); - CORBA_exception_free (&ev); -} - void -nautilus_attach_undo_manager (GtkObject *object, - Nautilus_Undo_Manager manager) +nautilus_undo_manager_attach (NautilusUndoManager *manager, GtkObject *target) { - CORBA_Environment ev; - Nautilus_Undo_Manager stored_manager; - - g_return_if_fail (GTK_IS_OBJECT (object)); - - if (manager == NULL) { - gtk_object_remove_data (object, "Nautilus undo"); - return; - } - - CORBA_exception_init (&ev); - Nautilus_Undo_Manager_ref (manager, &ev); - stored_manager = CORBA_Object_duplicate (manager, &ev); - CORBA_exception_free (&ev); + g_return_if_fail (NAUTILUS_IS_UNDO_MANAGER (manager)); + g_return_if_fail (GTK_IS_OBJECT (target)); - gtk_object_set_data_full - (object, "Nautilus undo", - stored_manager, undo_manager_unref); + nautilus_undo_attach_undo_manager + (target, + bonobo_object_corba_objref (BONOBO_OBJECT (manager))); } -/* This is useful because nautilus_get_undo_manager will be - * private one day. - */ void -nautilus_share_undo_manager (GtkObject *destination_object, - GtkObject *source_object) +nautilus_undo_manager_add_interface (NautilusUndoManager *manager, BonoboObject *object) { - Nautilus_Undo_Manager manager; - CORBA_Environment ev; + NautilusUndoContext *context; - manager = nautilus_get_undo_manager (source_object); - nautilus_attach_undo_manager - (destination_object, manager); + g_return_if_fail (NAUTILUS_IS_UNDO_MANAGER (manager)); + g_return_if_fail (BONOBO_IS_OBJECT (object)); - CORBA_exception_init (&ev); - CORBA_Object_release (manager, &ev); - CORBA_exception_free (&ev); + context = nautilus_undo_context_new (bonobo_object_corba_objref (BONOBO_OBJECT (manager))); + bonobo_object_add_interface (object, BONOBO_OBJECT (context)); } -/* Locates an undo manager for this bonobo control. - * The undo manager is supplied by an interface on - * the control frame. The put that undo manager on - * the Bonobo control's widget. - */ static void -set_up_bonobo_control (BonoboControl *control) +update_undo_menu_item (NautilusUndoManager *manager, + UndoMenuHandlerConnection *connection) { - Nautilus_Undo_Manager manager; - Bonobo_ControlFrame control_frame; CORBA_Environment ev; - Nautilus_Undo_Context undo_context; - GtkWidget *widget; - - g_assert (BONOBO_IS_CONTROL (control)); - - manager = CORBA_OBJECT_NIL; + Nautilus_Undo_MenuItem *menu_item; + g_assert (NAUTILUS_IS_UNDO_MANAGER (manager)); + g_assert (connection != NULL); + g_assert (BONOBO_IS_UI_HANDLER (connection->handler)); + g_assert (connection->path != NULL); + g_assert (connection->no_undo_menu_item_label != NULL); + g_assert (connection->no_undo_menu_item_hint != NULL); + CORBA_exception_init (&ev); - /* Find the undo manager. */ - control_frame = bonobo_control_get_control_frame (control); - if (!CORBA_Object_is_nil (control_frame, &ev)) { - undo_context = Bonobo_Control_query_interface - (control_frame, "IDL:Nautilus/Undo/Context:1.0", &ev); - if (!CORBA_Object_is_nil (undo_context, &ev)) { - manager = Nautilus_Undo_Context__get_undo_manager (undo_context, &ev); - } - CORBA_Object_release (undo_context, &ev); + if (manager->details->undo_list == NULL) { + menu_item = NULL; + } else { + menu_item = Nautilus_Undo_Transaction__get_undo_menu_item + (g_list_last (manager->details->undo_list)->data, &ev); } - CORBA_Object_release (control_frame, &ev); - - /* Attach the undo manager to the widget, or detach the old one. */ - widget = bonobo_control_get_widget (control); - nautilus_attach_undo_manager (GTK_OBJECT (widget), manager); - CORBA_Object_release (manager, &ev); - + + bonobo_ui_handler_menu_set_sensitivity + (connection->handler, connection->path, + menu_item != NULL); + bonobo_ui_handler_menu_set_label + (connection->handler, connection->path, + menu_item == NULL + ? connection->no_undo_menu_item_label + : menu_item->label); + bonobo_ui_handler_menu_set_hint + (connection->handler, connection->path, + menu_item == NULL + ? connection->no_undo_menu_item_hint + : menu_item->hint); + + CORBA_free (menu_item); + CORBA_exception_free (&ev); } -void -nautilus_undo_set_up_bonobo_control (BonoboControl *control) +static void +undo_menu_handler_connection_free (UndoMenuHandlerConnection *connection) { - g_return_if_fail (BONOBO_IS_CONTROL (control)); - - set_up_bonobo_control (control); - gtk_signal_connect (GTK_OBJECT (control), "set_frame", - GTK_SIGNAL_FUNC (set_up_bonobo_control), NULL); + g_assert (connection != NULL); + g_assert (BONOBO_IS_UI_HANDLER (connection->handler)); + g_assert (connection->path != NULL); + g_assert (connection->no_undo_menu_item_label != NULL); + g_assert (connection->no_undo_menu_item_hint != NULL); + + g_free (connection->path); + g_free (connection->no_undo_menu_item_label); + g_free (connection->no_undo_menu_item_hint); + g_free (connection); } - -void -nautilus_undo_manager_stash_global_undo (Nautilus_Undo_Manager undo_manager) +static void +undo_menu_handler_connection_free_cover (gpointer data) { - global_undo_manager = undo_manager; + undo_menu_handler_connection_free (data); } -Nautilus_Undo_Manager -nautilus_undo_manager_get_global_undo (void) +void +nautilus_undo_manager_set_up_bonobo_ui_handler_undo_item (NautilusUndoManager *manager, + BonoboUIHandler *handler, + const char *path, + const char *no_undo_menu_item_label, + const char *no_undo_menu_item_hint) { - return global_undo_manager; + UndoMenuHandlerConnection *connection; + + connection = g_new (UndoMenuHandlerConnection, 1); + connection->handler = handler; + connection->path = g_strdup (path); + connection->no_undo_menu_item_label = g_strdup (no_undo_menu_item_label); + connection->no_undo_menu_item_hint = g_strdup (no_undo_menu_item_hint); + + /* Set initial state of menu item. */ + update_undo_menu_item (manager, connection); + + /* Update it again whenever the changed signal is emitted. */ + nautilus_gtk_signal_connect_full_while_alive + (GTK_OBJECT (manager), "changed", + GTK_SIGNAL_FUNC (update_undo_menu_item), NULL, + connection, undo_menu_handler_connection_free_cover, + FALSE, FALSE, + GTK_OBJECT (handler)); } - - |