Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / verbs.cpp
index 5c35c1e51900c9919d3c31bdc427021392e16af0..a218e85dbf7d5359083ebcbbf56e717898bf93ca 100644 (file)
@@ -1,4 +1,3 @@
-#define __SP_VERBS_C__
 /**
  * \file verbs.cpp
  *
@@ -17,6 +16,7 @@
  *   David Turner <novalis@gnu.org>
  *   bulia byak <buliabyak@users.sf.net>
  *   Jon A. Cruz <jon@joncruz.org>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
  * Copyright (C) (date unspecified) Authors
@@ -63,6 +63,7 @@
 #include "selection-chemistry.h"
 #include "seltrans.h"
 #include "shape-editor.h"
+#include "shortcuts.h"
 #include "sp-flowtext.h"
 #include "sp-guide.h"
 #include "splivarot.h"
@@ -81,6 +82,8 @@
 #include "ui/icon-names.h"
 #include "ui/tool/node-tool.h"
 
+using Inkscape::DocumentUndo;
+
 //#ifdef WITH_INKBOARD
 //#include "jabber_whiteboard/session-manager.h"
 //#endif
@@ -334,7 +337,15 @@ Verb::VerbIDTable Verb::_verb_ids;
     in the \c _verbs hashtable which is indexed by the \c code.
 */
 Verb::Verb(gchar const *id, gchar const *name, gchar const *tip, gchar const *image) :
-    _actions(NULL), _id(id), _name(name), _tip(tip), _image(image)
+    _actions(0),
+    _id(id),
+    _name(name),
+    _tip(tip),
+    _full_tip(0),
+    _shortcut(0),
+    _image(image),
+    _code(0),
+    _default_sensitive(false)
 {
     static int count = SP_VERB_LAST;
 
@@ -342,8 +353,6 @@ Verb::Verb(gchar const *id, gchar const *name, gchar const *tip, gchar const *im
     _code = count;
     _verbs.insert(VerbTable::value_type(count, this));
     _verb_ids.insert(VerbIDTable::value_type(_id, this));
-
-    return;
 }
 
 /** \brief  Destroy a verb.
@@ -358,7 +367,10 @@ Verb::~Verb(void)
         delete _actions;
     }
 
-    return;
+    if (_full_tip) {
+        g_free(_full_tip);
+        _full_tip = 0;
+    }
 }
 
 /** \brief  Verbs are no good without actions.  This is a place holder
@@ -628,10 +640,30 @@ Verb::sensitive(SPDocument *in_doc, bool in_sensitive)
 }
 
 /** \brief Accessor to get the tooltip for verb as localised string */
-gchar const *
-Verb::get_tip (void)
+gchar const *Verb::get_tip(void)
 {
-       return _(_tip);
+    gchar const *result = 0;
+    if (_tip) {
+        unsigned int shortcut = sp_shortcut_get_primary(this);
+        if ( (shortcut != _shortcut) || !_full_tip) {
+            if (_full_tip) {
+                g_free(_full_tip);
+                _full_tip = 0;
+            }
+            _shortcut = shortcut;
+            gchar* shortcutString = sp_shortcut_get_label(shortcut);
+            if (shortcutString) {
+                _full_tip = g_strdup_printf("%s (%s)", _(_tip), shortcutString);
+                g_free(shortcutString);
+                shortcutString = 0;
+            } else {
+                _full_tip = g_strdup(_(_tip));
+            }
+        }
+        result = _full_tip;
+    }
+
+    return result;
 }
 
 void
@@ -1098,8 +1130,8 @@ LayerVerb::perform(SPAction *action, void *data, void */*pdata*/)
             SPObject *next=Inkscape::next_layer(dt->currentRoot(), dt->currentLayer());
             if (next) {
                 dt->setCurrentLayer(next);
-                SPDocumentUndo::done(sp_desktop_document(dt), SP_VERB_LAYER_NEXT,
-                                 _("Switch to next layer"));
+                DocumentUndo::done(sp_desktop_document(dt), SP_VERB_LAYER_NEXT,
+                                   _("Switch to next layer"));
                 dt->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Switched to next layer."));
             } else {
                 dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Cannot go past last layer."));
@@ -1110,8 +1142,8 @@ LayerVerb::perform(SPAction *action, void *data, void */*pdata*/)
             SPObject *prev=Inkscape::previous_layer(dt->currentRoot(), dt->currentLayer());
             if (prev) {
                 dt->setCurrentLayer(prev);
-                SPDocumentUndo::done(sp_desktop_document(dt), SP_VERB_LAYER_PREV,
-                                 _("Switch to previous layer"));
+                DocumentUndo::done(sp_desktop_document(dt), SP_VERB_LAYER_PREV,
+                                   _("Switch to previous layer"));
                 dt->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Switched to previous layer."));
             } else {
                 dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Cannot go before first layer."));
@@ -1138,7 +1170,7 @@ LayerVerb::perform(SPAction *action, void *data, void */*pdata*/)
             SPItem *layer=SP_ITEM(dt->currentLayer());
             g_return_if_fail(layer != NULL);
 
-            SPObject *old_pos=SP_OBJECT_NEXT(layer);
+            SPObject *old_pos = layer->getNext();
 
             switch (verb) {
                 case SP_VERB_LAYER_TO_TOP:
@@ -1155,7 +1187,7 @@ LayerVerb::perform(SPAction *action, void *data, void */*pdata*/)
                     break;
             }
 
-            if ( SP_OBJECT_NEXT(layer) != old_pos ) {
+            if ( layer->getNext() != old_pos ) {
                 char const *message = NULL;
                 Glib::ustring description = "";
                 switch (verb) {
@@ -1176,7 +1208,7 @@ LayerVerb::perform(SPAction *action, void *data, void */*pdata*/)
                         description = _("Lower layer");
                         break;
                 };
-                SPDocumentUndo::done(sp_desktop_document(dt), verb, description);
+                DocumentUndo::done(sp_desktop_document(dt), verb, description);
                 if (message) {
                     dt->messageStack()->flash(Inkscape::NORMAL_MESSAGE, message);
                     g_free((void *) message);
@@ -1208,7 +1240,7 @@ LayerVerb::perform(SPAction *action, void *data, void */*pdata*/)
 #else
                 // Copies everything, regardless of locks, visibility, sublayers.
                 //XML Tree being directly used here while it shouldn't be.
-                               Inkscape::XML::Node *selected = dt->currentLayer()->getRepr();
+                Inkscape::XML::Node *selected = dt->currentLayer()->getRepr();
                 Inkscape::XML::Node *parent = sp_repr_parent(selected);
                 Inkscape::XML::Node *dup = selected->duplicate(parent->document());
                 parent->addChild(dup, selected);
@@ -1222,8 +1254,8 @@ LayerVerb::perform(SPAction *action, void *data, void */*pdata*/)
                     dt->setCurrentLayer(new_layer);
                 }
 #endif
-                SPDocumentUndo::done(sp_desktop_document(dt), SP_VERB_LAYER_DUPLICATE,
-                                 _("Duplicate layer"));
+                DocumentUndo::done(sp_desktop_document(dt), SP_VERB_LAYER_DUPLICATE,
+                                   _("Duplicate layer"));
 
                 // TRANSLATORS: this means "The layer has been duplicated."
                 dt->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Duplicated layer."));
@@ -1254,8 +1286,8 @@ LayerVerb::perform(SPAction *action, void *data, void */*pdata*/)
                     dt->setCurrentLayer(survivor);
                 }
 
-                SPDocumentUndo::done(sp_desktop_document(dt), SP_VERB_LAYER_DELETE,
-                                 _("Delete layer"));
+                DocumentUndo::done(sp_desktop_document(dt), SP_VERB_LAYER_DELETE,
+                                   _("Delete layer"));
 
                 // TRANSLATORS: this means "The layer has been deleted."
                 dt->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Deleted layer."));
@@ -1269,7 +1301,7 @@ LayerVerb::perform(SPAction *action, void *data, void */*pdata*/)
                 dt->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("No current layer."));
             } else {
                 dt->toggleLayerSolo( dt->currentLayer() );
-                SPDocumentUndo::maybe_done(sp_desktop_document(dt), "layer:solo", SP_VERB_LAYER_SOLO, _("Toggle layer solo"));
+                DocumentUndo::maybeDone(sp_desktop_document(dt), "layer:solo", SP_VERB_LAYER_SOLO, _("Toggle layer solo"));
             }
             break;
         }
@@ -1329,13 +1361,13 @@ ObjectVerb::perform( SPAction *action, void *data, void */*pdata*/ )
             break;
         case SP_VERB_OBJECT_FLIP_HORIZONTAL:
             sp_selection_scale_relative(sel, center, Geom::Scale(-1.0, 1.0));
-            SPDocumentUndo::done(sp_desktop_document(dt), SP_VERB_OBJECT_FLIP_HORIZONTAL,
-                             _("Flip horizontally"));
+            DocumentUndo::done(sp_desktop_document(dt), SP_VERB_OBJECT_FLIP_HORIZONTAL,
+                               _("Flip horizontally"));
             break;
         case SP_VERB_OBJECT_FLIP_VERTICAL:
             sp_selection_scale_relative(sel, center, Geom::Scale(1.0, -1.0));
-            SPDocumentUndo::done(sp_desktop_document(dt), SP_VERB_OBJECT_FLIP_VERTICAL,
-                             _("Flip vertically"));
+            DocumentUndo::done(sp_desktop_document(dt), SP_VERB_OBJECT_FLIP_VERTICAL,
+                               _("Flip vertically"));
             break;
         case SP_VERB_OBJECT_SET_MASK:
             sp_selection_set_mask(dt, false, false);
@@ -1683,9 +1715,9 @@ ZoomVerb::perform(SPAction *action, void *data, void */*pdata*/)
         case SP_VERB_VIEW_MODE_OUTLINE:
             dt->setDisplayModeOutline();
             break;
-        case SP_VERB_VIEW_MODE_PRINT_COLORS_PREVIEW:
-            dt->setDisplayModePrintColorsPreview();
-            break;
+//        case SP_VERB_VIEW_MODE_PRINT_COLORS_PREVIEW:
+//            dt->setDisplayModePrintColorsPreview();
+//            break;
         case SP_VERB_VIEW_MODE_TOGGLE:
             dt->displayModeToggle();
             break;
@@ -2163,19 +2195,19 @@ LockAndHideVerb::perform(SPAction *action, void *data, void */*pdata*/)
     switch (reinterpret_cast<std::size_t>(data)) {
         case SP_VERB_UNLOCK_ALL:
             unlock_all(dt);
-            SPDocumentUndo::done(doc, SP_VERB_UNLOCK_ALL, _("Unlock all objects in the current layer"));
+            DocumentUndo::done(doc, SP_VERB_UNLOCK_ALL, _("Unlock all objects in the current layer"));
             break;
         case SP_VERB_UNLOCK_ALL_IN_ALL_LAYERS:
             unlock_all_in_all_layers(dt);
-            SPDocumentUndo::done(doc, SP_VERB_UNLOCK_ALL_IN_ALL_LAYERS, _("Unlock all objects in all layers"));
+            DocumentUndo::done(doc, SP_VERB_UNLOCK_ALL_IN_ALL_LAYERS, _("Unlock all objects in all layers"));
             break;
         case SP_VERB_UNHIDE_ALL:
             unhide_all(dt);
-            SPDocumentUndo::done(doc, SP_VERB_UNHIDE_ALL, _("Unhide all objects in the current layer"));
+            DocumentUndo::done(doc, SP_VERB_UNHIDE_ALL, _("Unhide all objects in the current layer"));
             break;
         case SP_VERB_UNHIDE_ALL_IN_ALL_LAYERS:
             unhide_all_in_all_layers(dt);
-            SPDocumentUndo::done(doc, SP_VERB_UNHIDE_ALL_IN_ALL_LAYERS, _("Unhide all objects in all layers"));
+            DocumentUndo::done(doc, SP_VERB_UNHIDE_ALL_IN_ALL_LAYERS, _("Unhide all objects in all layers"));
             break;
         default:
             return;
@@ -2297,8 +2329,8 @@ Verb *Verb::_base_verbs[] = {
                  N_("Deselect any selected objects or nodes"), INKSCAPE_ICON_EDIT_SELECT_NONE),
     new EditVerb(SP_VERB_EDIT_GUIDES_AROUND_PAGE, "EditGuidesAroundPage", N_("_Guides Around Page"),
                  N_("Create four guides aligned with the page borders"), NULL),
-    new EditVerb(SP_VERB_EDIT_NEXT_PATHEFFECT_PARAMETER, "EditNextPathEffectParameter", N_("Next Path Effect Parameter"),
-                 N_("Show next Path Effect parameter for editing"), INKSCAPE_ICON_PATH_EFFECT_PARAMETER_NEXT),
+    new EditVerb(SP_VERB_EDIT_NEXT_PATHEFFECT_PARAMETER, "EditNextPathEffectParameter", N_("Next path effect parameter"),
+                 N_("Show next editable path effect parameter"), INKSCAPE_ICON_PATH_EFFECT_PARAMETER_NEXT),
 
     /* Selection */
     new SelectionVerb(SP_VERB_SELECTION_TO_FRONT, "SelectionToFront", N_("Raise to _Top"),
@@ -2542,7 +2574,7 @@ Verb *Verb::_base_verbs[] = {
     new ZoomVerb(SP_VERB_TOGGLE_SCROLLBARS, "ToggleScrollbars", N_("Scroll_bars"), N_("Show or hide the canvas scrollbars"), NULL),
     new ZoomVerb(SP_VERB_TOGGLE_GRID, "ToggleGrid", N_("_Grid"), N_("Show or hide the grid"), INKSCAPE_ICON_SHOW_GRID),
     new ZoomVerb(SP_VERB_TOGGLE_GUIDES, "ToggleGuides", N_("G_uides"), N_("Show or hide guides (drag from a ruler to create a guide)"), INKSCAPE_ICON_SHOW_GUIDES),
-    new ZoomVerb(SP_VERB_TOGGLE_SNAPPING, "ToggleSnapGlobal", N_("Snap"), N_("Toggle snapping on or off"), INKSCAPE_ICON_SNAP),
+    new ZoomVerb(SP_VERB_TOGGLE_SNAPPING, "ToggleSnapGlobal", N_("Snap"), N_("Enable snapping"), INKSCAPE_ICON_SNAP),
     new ZoomVerb(SP_VERB_ZOOM_NEXT, "ZoomNext", N_("Nex_t Zoom"), N_("Next zoom (from the history of zooms)"),
                  INKSCAPE_ICON_ZOOM_NEXT),
     new ZoomVerb(SP_VERB_ZOOM_PREV, "ZoomPrev", N_("Pre_vious Zoom"), N_("Previous zoom (from the history of zooms)"),
@@ -2570,8 +2602,8 @@ Verb *Verb::_base_verbs[] = {
                  N_("Switch to normal display without filters"), NULL),
     new ZoomVerb(SP_VERB_VIEW_MODE_OUTLINE, "ViewModeOutline", N_("_Outline"),
                  N_("Switch to outline (wireframe) display mode"), NULL),
-    new ZoomVerb(SP_VERB_VIEW_MODE_PRINT_COLORS_PREVIEW, "ViewModePrintColorsPreview", N_("_Print Colors Preview"),
-                 N_("Switch to print colors preview mode"), NULL),
+//    new ZoomVerb(SP_VERB_VIEW_MODE_PRINT_COLORS_PREVIEW, "ViewModePrintColorsPreview", N_("_Print Colors Preview"),
+//                 N_("Switch to print colors preview mode"), NULL),
     new ZoomVerb(SP_VERB_VIEW_MODE_TOGGLE, "ViewModeToggle", N_("_Toggle"),
                  N_("Toggle between normal and outline display modes"), NULL),
 
@@ -2597,7 +2629,7 @@ Verb *Verb::_base_verbs[] = {
     new DialogVerb(SP_VERB_DIALOG_METADATA, "DialogMetadata", N_("Document _Metadata..."),
                    N_("Edit document metadata (to be saved with the document)"), INKSCAPE_ICON_DOCUMENT_METADATA ),
     new DialogVerb(SP_VERB_DIALOG_FILL_STROKE, "DialogFillStroke", N_("_Fill and Stroke..."),
-                   N_("Edit objects' colors, gradients, stroke width, arrowheads, dash patterns..."), INKSCAPE_ICON_DIALOG_FILL_AND_STROKE),
+                   N_("Edit objects' colors, gradients, arrowheads, and other fill and stroke properties..."), INKSCAPE_ICON_DIALOG_FILL_AND_STROKE),
     new DialogVerb(SP_VERB_DIALOG_GLYPHS, "DialogGlyphs", N_("Glyphs..."),
                    N_("Select characters from a glyphs palette"), GTK_STOCK_SELECT_FONT),
     // TRANSLATORS: "Swatches" means: color samples
@@ -2739,4 +2771,4 @@ Verb::list (void) {
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :