Code

Added descriptions to Undo/Redo commands in the menus
authorgustav_b <gustav_b@users.sourceforge.net>
Sun, 9 Jul 2006 11:32:23 +0000 (11:32 +0000)
committergustav_b <gustav_b@users.sourceforge.net>
Sun, 9 Jul 2006 11:32:23 +0000 (11:32 +0000)
12 files changed:
src/document.cpp
src/event-log.cpp
src/event-log.h
src/extension/effect.cpp
src/helper/action.cpp
src/helper/action.h
src/interface.cpp
src/sp-namedview.cpp
src/ui/dialog/undo-history.cpp
src/verbs.cpp
src/verbs.h
src/widgets/button.cpp

index a6b6e4e45ecb5827ac24ec941ae3ce47cc3113d3..69f9128a862e6fc222a494a56f3be51707d4eaa9 100644 (file)
@@ -106,6 +106,7 @@ SPDocument::SPDocument() {
     p->redo = NULL;
 
     p->undoStackObservers.add(p->event_log);
+    p->event_log.setDocument(this);
 
     priv = p;
 
index 40c8364acabdca5de0597dc265a323414172ef33..64a9b19ec9fe067dc1575229a364f44518fb4456 100644 (file)
 #include <glibmm/i18n.h>
 
 #include "desktop.h"
-
 #include "event-log.h"
+#include "inkscape.h"
+#include "util/ucompose.hpp"
 
 namespace Inkscape {
 
 EventLog::EventLog() :
     UndoStackObserver(),
     _connected (false),
+    _document (NULL),
     _event_list_store (Gtk::TreeStore::create(_columns)),
     _event_list_selection (NULL),
     _event_list_view (NULL),
@@ -39,7 +41,7 @@ void
 EventLog::notifyUndoEvent(Event* log) 
 {
     if ( !_notifications_blocked ) {
-      
+    
         // if we're on the first child event...
         if ( _curr_event->parent() &&
              _curr_event == _curr_event->parent()->children().begin() )
@@ -81,7 +83,9 @@ EventLog::notifyUndoEvent(Event* log)
             (*_callback_connections)[CALLB_SELECTION_CHANGE].block(false);
         }
 
+        updateUndoVerbs();
     }
+
 }
 
 void
@@ -137,7 +141,9 @@ EventLog::notifyRedoEvent(Event* log)
             (*_callback_connections)[CALLB_SELECTION_CHANGE].block(false);
         }
 
+        updateUndoVerbs();
     }
+
 }
 
 void 
@@ -219,8 +225,18 @@ EventLog::notifyUndoCommitEvent(Event* log)
         (*_callback_connections)[CALLB_SELECTION_CHANGE].block(false);
     }
 
+    updateUndoVerbs();
 }
 
+
+void
+EventLog::setDocument(SPDocument *document)
+{
+    _document = document;
+    updateUndoVerbs();
+}
+
+
 void 
 EventLog::connectWithDialog(Gtk::TreeView *event_list_view, CallbackMap *callback_connections)
 {
@@ -242,7 +258,76 @@ EventLog::connectWithDialog(Gtk::TreeView *event_list_view, CallbackMap *callbac
     _connected = true;
 }
 
+void
+EventLog::updateUndoVerbs()
+{
+    if(_document) {
+
+        if(_getUndoEvent()) { 
+            Inkscape::Verb::get(SP_VERB_EDIT_UNDO)->sensitive(_document, true);
+
+            Inkscape::Verb::get(SP_VERB_EDIT_UNDO)->name(_document, String::ucompose("%1 %2", 
+                      Glib::ustring(_("_Undo")),
+                      Glib::ustring((*_getUndoEvent())[_columns.description])));
+        } else {
+            Inkscape::Verb::get(SP_VERB_EDIT_UNDO)->name(_document, _("_Undo"));
+            Inkscape::Verb::get(SP_VERB_EDIT_UNDO)->sensitive(_document, false);
+        }
+
+        if(_getRedoEvent()) {
+            Inkscape::Verb::get(SP_VERB_EDIT_REDO)->sensitive(_document, true);
+            Inkscape::Verb::get(SP_VERB_EDIT_REDO)->name(_document, String::ucompose("%1 %2", 
+                      Glib::ustring(_("_Redo")),
+                      Glib::ustring((*_getRedoEvent())[_columns.description])));
+
+        } else {
+            Inkscape::Verb::get(SP_VERB_EDIT_REDO)->name(_document, _("_Redo"));
+            Inkscape::Verb::get(SP_VERB_EDIT_REDO)->sensitive(_document, false);
+        }
+
+    }
+
+}
+
+
+EventLog::const_iterator
+EventLog::_getUndoEvent() const
+{
+    const_iterator undo_event = (const_iterator)NULL;
+    if( _curr_event != _event_list_store->children().begin() )
+        undo_event = _curr_event;
+    return undo_event;
 }
+
+EventLog::const_iterator
+EventLog::_getRedoEvent() const
+{
+    const_iterator redo_event = (const_iterator)NULL;
+
+    if ( _curr_event != _last_event ) {
+
+        if ( !_curr_event->children().empty() )
+            redo_event = _curr_event->children().begin();
+        else  {
+            redo_event = _curr_event;
+            ++redo_event;
+
+            if ( redo_event->parent() &&
+                 redo_event == redo_event->parent()->children().end() ) {
+
+                redo_event = redo_event->parent();
+                ++redo_event;
+
+            }
+        }
+
+    }
+
+    return redo_event;
+}
+
+}
+
 /*
   Local Variables:
   mode:c++
index 148d6329de0fc812963bc8ee90ad608613810437..16ecfd5558c4d77b66627d6ed92ea624e546c033 100644 (file)
@@ -85,6 +85,8 @@ public:
     void setCurrEventParent(iterator event)    { _curr_event_parent = event; }
     void blockNotifications(bool status=true)  { _notifications_blocked = status; }
 
+    void setDocument(SPDocument *document);
+
     /* 
      * Callback types for TreeView changes.
      */
@@ -103,9 +105,16 @@ public:
      */
     void connectWithDialog(Gtk::TreeView *event_list_view, CallbackMap *callback_connections);
 
+    /*
+     * Updates the sensitivity and names of SP_VERB_EDIT_UNDO and SP_VERB_EDIT_REDO to reflect the
+     * current state.
+     */
+    void updateUndoVerbs();
+
 private:
     bool _connected;             //< connected with dialog
+    SPDocument *_document;       //< document that is logged
+
     const EventModelColumns _columns;
 
     /**
@@ -125,6 +134,9 @@ private:
     // Map of connections used to temporary block/unblock callbacks in a TreeView
     CallbackMap *_callback_connections;
 
+    const_iterator _getUndoEvent() const; //< returns the current undoable event or NULL if none
+    const_iterator _getRedoEvent() const; //< returns the current redoable event or NULL if none
+
     // noncopyable, nonassignable
     EventLog(EventLog const &other);
     EventLog& operator=(EventLog const &other);
index 2f884aa1cf0a0126cd95360129392aa916b6f299..71ddf3e247216509297ae421e9d49dfdfba3dc55 100644 (file)
@@ -305,7 +305,7 @@ Effect::EffectVerb::perform (SPAction *action, void * data, void *pdata)
  * is called.
  */
 SPActionEventVector Effect::EffectVerb::vector =
-            {{NULL},Effect::EffectVerb::perform, NULL, NULL, NULL};
+            {{NULL}, Effect::EffectVerb::perform, NULL, NULL, NULL, NULL};
 
 
 } }  /* namespace Inkscape, Extension */
index 9584c5dae22991cd110563b0a682718cbfdcd7fd..1c8c7ec1532a813769ff6319364e1f5c5e10d6b1 100644 (file)
@@ -13,7 +13,6 @@
 
 #include <string.h>
 
-
 #include "helper/action.h"
 
 static void sp_action_class_init (SPActionClass *klass);
@@ -206,6 +205,37 @@ sp_action_set_sensitive (SPAction *action, unsigned int sensitive)
        }
 }
 
+
+/**
+ * Change name for all actions that can be taken with the action.
+ */
+void
+sp_action_set_name (SPAction *action, Glib::ustring name)
+{
+       nr_return_if_fail (action != NULL);
+       nr_return_if_fail (SP_IS_ACTION (action));
+
+        NRActiveObject *aobject;
+        g_free(action->name);
+        action->name = g_strdup(name.c_str());
+        aobject = (NRActiveObject *) action;
+        if (aobject->callbacks) {
+            unsigned int i;
+            for (i = 0; i < aobject->callbacks->length; i++) {
+                NRObjectListener *listener;
+                SPActionEventVector *avector;
+                listener = aobject->callbacks->listeners + i;
+                avector = (SPActionEventVector *) listener->vector;
+                if ((listener->size >= sizeof (SPActionEventVector)) && avector->set_name) {
+                    avector->set_name (action, name, listener->data);
+                }
+            }
+        }
+}
+
+
+
+
 /**
  * Return View associated with the action.
  */
index 1e364643904c9f0f590129d5ff84ffa793fd4e11..4c99e31d859ba372ede843b009efe8f1d214539e 100644 (file)
@@ -25,6 +25,7 @@
 #include "libnr/nr-object.h"
 #include "forward.h"
 
+#include <glibmm/ustring.h>
 //class Inkscape::UI::View::View; 
 
 namespace Inkscape {
@@ -41,6 +42,7 @@ struct SPActionEventVector {
     void (* set_active)(SPAction *action, unsigned active, void *data);       /**< Callback for activation change */
     void (* set_sensitive)(SPAction *action, unsigned sensitive, void *data); /**< Callback for a change in sensitivity */
     void (* set_shortcut)(SPAction *action, unsigned shortcut, void *data);   /**< Callback for setting the shortcut for this function */
+    void (* set_name)(SPAction *action, Glib::ustring, void *data);           /**< Callback for setting the name for this function */
 };
 
 /** All the data that is required to be an action.  This
@@ -74,6 +76,7 @@ SPAction *sp_action_new(Inkscape::UI::View::View *view,
 void sp_action_perform(SPAction *action, void *data);
 void sp_action_set_active(SPAction *action, unsigned active);
 void sp_action_set_sensitive(SPAction *action, unsigned sensitive);
+void sp_action_set_name (SPAction *action, Glib::ustring);
 Inkscape::UI::View::View *sp_action_get_view(SPAction *action);
 
 #endif
index 91a26226fe6a8108521217e74aba69dab53dc309..348e71821acf13b4c6ee2fbf80526a000b460ff7 100644 (file)
@@ -112,13 +112,17 @@ static void sp_ui_drag_data_received(GtkWidget *widget,
 static void sp_ui_menu_item_set_sensitive(SPAction *action,
                                           unsigned int sensitive,
                                           void *data);
+static void sp_ui_menu_item_set_name(SPAction *action, 
+                                     Glib::ustring name,
+                                     void *data);
 
 SPActionEventVector menu_item_event_vector = {
     {NULL},
     NULL,
     NULL, /* set_active */
     sp_ui_menu_item_set_sensitive, /* set_sensitive */
-    NULL  /* set_shortcut */
+    NULL, /* set_shortcut */
+    sp_ui_menu_item_set_name /* set_name */
 };
 
 void
@@ -1317,6 +1321,15 @@ sp_ui_menu_item_set_sensitive(SPAction *action, unsigned int sensitive, void *da
     return gtk_widget_set_sensitive(GTK_WIDGET(data), sensitive);
 }
 
+static void
+sp_ui_menu_item_set_name(SPAction *action, Glib::ustring name, void *data)
+{
+    gtk_label_set_markup_with_mnemonic(
+        GTK_LABEL (gtk_container_get_children(GTK_CONTAINER (GTK_BIN (data)->child))->data), 
+        name.c_str());
+}
+
+
 /*
   Local Variables:
   mode:c++
index 4f9e4e2881aafdb791a77e0f244b7b9908bbef33..f3dea40c76335b2f62b9bf051a9e7a191a6ce487 100644 (file)
@@ -23,6 +23,7 @@
 #include "document.h"
 #include "desktop-events.h"
 #include "desktop-handles.h"
+#include "event-log.h"
 #include "sp-guide.h"
 #include "sp-item-group.h"
 #include "sp-namedview.h"
@@ -674,6 +675,9 @@ void sp_namedview_window_from_document(SPDesktop *desktop)
     if (layer) {
         desktop->setCurrentLayer(layer);
     }
+
+    // FIXME: find a better place to do this
+    sp_desktop_document(desktop)->getEventLog().updateUndoVerbs();
 }
 
 void sp_namedview_document_from_window(SPDesktop *desktop)
index 13f6bff261423f9c26269c2f3a85ba3ee1764720..e1b60f3150f7257b427d9f13efcef66f122c7f75 100644 (file)
@@ -175,7 +175,7 @@ UndoHistory::_onListSelectionChange()
     EventLog::const_iterator selected = _event_list_selection->get_selected();
 
     /* If no event is selected in the view, find the right one and select it. This happens whenever
-     *  a branch we're currently in is collapsed.
+     * a branch we're currently in is collapsed.
      */
     if (!selected) {
 
@@ -239,6 +239,7 @@ UndoHistory::_onListSelectionChange()
                 }
             }
             _event_log->blockNotifications(false);        
+            _event_log->updateUndoVerbs();
 
         } else { // An event after the current one has been selected. Redo to the selected event.
 
@@ -267,6 +268,7 @@ UndoHistory::_onListSelectionChange()
         }
 
         _event_log->setCurrEvent(selected);
+        _event_log->updateUndoVerbs();
     }
 
 }
index 6a595721808d03b8fe80f36871e2935cd6463407..5b740b2158c4149e4bb27ce9eb32481fbd6c93a8 100644 (file)
@@ -654,6 +654,21 @@ Verb::sensitive(SPDocument *in_doc, bool in_sensitive)
     return;
 }
 
+
+void
+Verb::name(SPDocument *in_doc, Glib::ustring in_name)
+{
+    if (_actions != NULL) {
+        for (ActionTable::iterator cur_action = _actions->begin();
+             cur_action != _actions->end();
+             cur_action++) {
+                       if (in_doc == NULL || (cur_action->first != NULL && cur_action->first->doc() == in_doc)) {
+                            sp_action_set_name(cur_action->second, in_name);
+            }
+        }
+    }
+}
+
 /** \brief  A function to remove the action associated with a view.
     \param  view  Which view's actions should be removed.
     \return None
@@ -1686,48 +1701,48 @@ TutorialVerb::perform(SPAction *action, void *data, void *pdata)
  * is called.
  */
 SPActionEventVector FileVerb::vector =
-            {{NULL},FileVerb::perform, NULL, NULL, NULL};
+            {{NULL},FileVerb::perform, NULL, NULL, NULL, NULL};
 /**
  * Action vector to define functions called if a staticly defined edit verb is
  * called.
  */
 SPActionEventVector EditVerb::vector =
-            {{NULL},EditVerb::perform, NULL, NULL, NULL};
+            {{NULL},EditVerb::perform, NULL, NULL, NULL, NULL};
 
 /**
  * Action vector to define functions called if a staticly defined selection
  * verb is called
  */
 SPActionEventVector SelectionVerb::vector =
-            {{NULL},SelectionVerb::perform, NULL, NULL, NULL};
+            {{NULL},SelectionVerb::perform, NULL, NULL, NULL, NULL};
 
 /**
  * Action vector to define functions called if a staticly defined layer
  * verb is called
  */
 SPActionEventVector LayerVerb::vector =
-            {{NULL}, LayerVerb::perform, NULL, NULL, NULL};
+            {{NULL}, LayerVerb::perform, NULL, NULL, NULL, NULL};
 
 /**
  * Action vector to define functions called if a staticly defined object
  * editing verb is called
  */
 SPActionEventVector ObjectVerb::vector =
-            {{NULL},ObjectVerb::perform, NULL, NULL, NULL};
+            {{NULL},ObjectVerb::perform, NULL, NULL, NULL, NULL};
 
 /**
  * Action vector to define functions called if a staticly defined context
  * verb is called
  */
 SPActionEventVector ContextVerb::vector =
-            {{NULL},ContextVerb::perform, NULL, NULL, NULL};
+            {{NULL},ContextVerb::perform, NULL, NULL, NULL, NULL};
 
 /**
  * Action vector to define functions called if a staticly defined zoom verb
  * is called
  */
 SPActionEventVector ZoomVerb::vector =
-            {{NULL},ZoomVerb::perform, NULL, NULL, NULL};
+            {{NULL},ZoomVerb::perform, NULL, NULL, NULL, NULL};
 
 
 /**
@@ -1735,28 +1750,28 @@ SPActionEventVector ZoomVerb::vector =
  * is called
  */
 SPActionEventVector DialogVerb::vector =
-            {{NULL},DialogVerb::perform, NULL, NULL, NULL};
+            {{NULL},DialogVerb::perform, NULL, NULL, NULL, NULL};
 
 /**
  * Action vector to define functions called if a staticly defined help verb
  * is called
  */
 SPActionEventVector HelpVerb::vector =
-            {{NULL},HelpVerb::perform, NULL, NULL, NULL};
+            {{NULL},HelpVerb::perform, NULL, NULL, NULL, NULL};
 
 /**
  * Action vector to define functions called if a staticly defined tutorial verb
  * is called
  */
 SPActionEventVector TutorialVerb::vector =
-            {{NULL},TutorialVerb::perform, NULL, NULL, NULL};
+            {{NULL},TutorialVerb::perform, NULL, NULL, NULL, NULL};
 
 /**
  * Action vector to define functions called if a staticly defined tutorial verb
  * is called
  */
 SPActionEventVector TextVerb::vector =
-            {{NULL},TextVerb::perform, NULL, NULL, NULL};
+            {{NULL},TextVerb::perform, NULL, NULL, NULL, NULL};
 
 
 /* *********** Effect Last ********** */
@@ -1785,7 +1800,7 @@ public:
  * The vector to attach in the last effect verb.
  */
 SPActionEventVector EffectLastVerb::vector =
-            {{NULL},EffectLastVerb::perform, NULL, NULL, NULL};
+            {{NULL},EffectLastVerb::perform, NULL, NULL, NULL, NULL};
 
 /** \brief  Create an action for a \c EffectLastVerb
     \param  view  Which view the action should be created for
@@ -1854,7 +1869,7 @@ public:
  * The vector to attach in the fit canvas verb.
  */
 SPActionEventVector FitCanvasVerb::vector =
-            {{NULL},FitCanvasVerb::perform, NULL, NULL, NULL};
+            {{NULL},FitCanvasVerb::perform, NULL, NULL, NULL, NULL};
 
 /** \brief  Create an action for a \c FitCanvasVerb
     \param  view  Which view the action should be created for
@@ -2312,9 +2327,9 @@ Verb *Verb::_base_verbs[] = {
 
     /* Effect */
     new EffectLastVerb(SP_VERB_EFFECT_LAST, "EffectLast", N_("Previous Effect"),
-                       N_("Repeat the last effect with the same settings"), NULL/*"tutorial_tips"*/),
+                       N_("Repeat the last effect with the same settings"), NULL),
     new EffectLastVerb(SP_VERB_EFFECT_LAST_PREF, "EffectLastPref", N_("Previous Effect Settings..."),
-                       N_("Repeat the last effect with new settings"), NULL/*"tutorial_tips"*/),
+                       N_("Repeat the last effect with new settings"), NULL),
 
     /* Fit Page */
     new FitCanvasVerb(SP_VERB_FIT_CANVAS_TO_SELECTION, "FitCanvasToSelection", N_("Fit Page to Selection"),
index 8474203f63ec3c9d43deca58f282f1fdbde2e00c..fa232280b6b3ce914fa1e1534299fdf77d6db8c6 100644 (file)
@@ -16,6 +16,7 @@
 #include "require-config.h"   /* HAVE_GTK_WINDOW_FULLSCREEN */
 #include "helper/helper-forward.h"
 #include "forward.h"
+#include <glibmm/ustring.h>
 
 /** \brief This anonymous enum is used to provide a list of the Verbs
            which are defined staticly in the verb files.  There may be
@@ -380,6 +381,7 @@ public:
     void delete_view (Inkscape::UI::View::View * view);
 
     void sensitive (SPDocument * in_doc = NULL, bool in_sensitive = true);
+    void name (SPDocument * in_doc = NULL, Glib::ustring in_name = "");
 
 // Yes, multiple public, protected and private sections are bad. We'll clean that up later
 protected:
index 42775213a6de3f3ad506066631589ead1825bdcc..f9e854302424db73802be485664a39a258f6c1b7 100644 (file)
@@ -52,7 +52,8 @@ SPActionEventVector button_event_vector = {
         NULL,
         sp_button_action_set_active,
         sp_button_action_set_sensitive,
-        sp_button_action_set_shortcut
+         sp_button_action_set_shortcut,
+         NULL
 };
 
 GtkType