From e173aaf34472892de413d42ef20b7fd00aafd45b Mon Sep 17 00:00:00 2001 From: gustav_b Date: Sun, 9 Jul 2006 11:32:23 +0000 Subject: [PATCH] Added descriptions to Undo/Redo commands in the menus --- src/document.cpp | 1 + src/event-log.cpp | 89 +++++++++++++++++++++++++++++++++- src/event-log.h | 14 +++++- src/extension/effect.cpp | 2 +- src/helper/action.cpp | 32 +++++++++++- src/helper/action.h | 3 ++ src/interface.cpp | 15 +++++- src/sp-namedview.cpp | 4 ++ src/ui/dialog/undo-history.cpp | 4 +- src/verbs.cpp | 45 +++++++++++------ src/verbs.h | 2 + src/widgets/button.cpp | 3 +- 12 files changed, 191 insertions(+), 23 deletions(-) diff --git a/src/document.cpp b/src/document.cpp index a6b6e4e45..69f9128a8 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -106,6 +106,7 @@ SPDocument::SPDocument() { p->redo = NULL; p->undoStackObservers.add(p->event_log); + p->event_log.setDocument(this); priv = p; diff --git a/src/event-log.cpp b/src/event-log.cpp index 40c8364ac..64a9b19ec 100644 --- a/src/event-log.cpp +++ b/src/event-log.cpp @@ -10,14 +10,16 @@ #include #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++ diff --git a/src/event-log.h b/src/event-log.h index 148d6329d..16ecfd555 100644 --- a/src/event-log.h +++ b/src/event-log.h @@ -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); diff --git a/src/extension/effect.cpp b/src/extension/effect.cpp index 2f884aa1c..71ddf3e24 100644 --- a/src/extension/effect.cpp +++ b/src/extension/effect.cpp @@ -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 */ diff --git a/src/helper/action.cpp b/src/helper/action.cpp index 9584c5dae..1c8c7ec15 100644 --- a/src/helper/action.cpp +++ b/src/helper/action.cpp @@ -13,7 +13,6 @@ #include - #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. */ diff --git a/src/helper/action.h b/src/helper/action.h index 1e3646439..4c99e31d8 100644 --- a/src/helper/action.h +++ b/src/helper/action.h @@ -25,6 +25,7 @@ #include "libnr/nr-object.h" #include "forward.h" +#include //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 diff --git a/src/interface.cpp b/src/interface.cpp index 91a26226f..348e71821 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -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++ diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 4f9e4e288..f3dea40c7 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -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) diff --git a/src/ui/dialog/undo-history.cpp b/src/ui/dialog/undo-history.cpp index 13f6bff26..e1b60f315 100644 --- a/src/ui/dialog/undo-history.cpp +++ b/src/ui/dialog/undo-history.cpp @@ -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(); } } diff --git a/src/verbs.cpp b/src/verbs.cpp index 6a5957218..5b740b215 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -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"), diff --git a/src/verbs.h b/src/verbs.h index 8474203f6..fa232280b 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -16,6 +16,7 @@ #include "require-config.h" /* HAVE_GTK_WINDOW_FULLSCREEN */ #include "helper/helper-forward.h" #include "forward.h" +#include /** \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: diff --git a/src/widgets/button.cpp b/src/widgets/button.cpp index 42775213a..f9e854302 100644 --- a/src/widgets/button.cpp +++ b/src/widgets/button.cpp @@ -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 -- 2.30.2