Code

Connector tool: make connectors avoid the convex hull of shapes.
[inkscape.git] / src / selection-describer.cpp
index a5515f3ab929a45b613a5e3ecb1613434f2702ff..27dd8413a25a7f22b5e4abd43a0705a580f1d7e7 100644 (file)
@@ -5,7 +5,7 @@
  *   MenTaLguY <mental@rydia.net>
  *   bulia byak <buliabyak@users.sf.net>
  *
- * Copyright (C) 2004 MenTaLguY
+ * Copyright (C) 2004-2006 Authors
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
@@ -24,6 +24,7 @@
 #include "sp-flowtext.h"
 #include "sp-use.h"
 #include "sp-rect.h"
+#include "box3d.h"
 #include "sp-ellipse.h"
 #include "sp-star.h"
 #include "sp-anchor.h"
@@ -38,7 +39,10 @@ const gchar *
 type2term(GType type)
 {
     if (type == SP_TYPE_ANCHOR)
-        { return _("Link"); }
+        //TRANSLATORS: only translate "string" in "context|string".
+        // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
+       // "Link" means internet link (anchor)
+        { return Q_("web|Link"); }
     if (type == SP_TYPE_CIRCLE)
         { return _("Circle"); }
     if (type == SP_TYPE_ELLIPSE)
@@ -59,10 +63,15 @@ type2term(GType type)
         { return _("Polyline"); }
     if (type == SP_TYPE_RECT)
         { return _("Rectangle"); }
+    if (type == SP_TYPE_BOX3D)
+        { return _("3D Box"); }
     if (type == SP_TYPE_TEXT)
         { return _("Text"); }
     if (type == SP_TYPE_USE)
-        { return _("Clone"); }
+        // TRANSLATORS: only translate "string" in "context|string".
+        // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
+        // "Clone" is a noun, type of object
+        { return Q_("object|Clone"); }
     if (type == SP_TYPE_ARC)
         { return _("Ellipse"); }
     if (type == SP_TYPE_OFFSET)
@@ -91,7 +100,25 @@ namespace Inkscape {
 SelectionDescriber::SelectionDescriber(Inkscape::Selection *selection, MessageStack *stack)
 : _context(stack)
 {
-    selection->connectChanged(sigc::mem_fun(*this, &SelectionDescriber::_updateMessageFromSelection));
+    _selection_changed_connection = new sigc::connection (
+             selection->connectChanged(
+                 sigc::mem_fun(*this, &SelectionDescriber::_updateMessageFromSelection)));
+    _selection_modified_connection = new sigc::connection (
+             selection->connectModified(
+                 sigc::mem_fun(*this, &SelectionDescriber::_selectionModified)));
+    _updateMessageFromSelection(selection);
+}
+
+SelectionDescriber::~SelectionDescriber()
+{
+    _selection_changed_connection->disconnect();
+    _selection_modified_connection->disconnect();
+    delete _selection_changed_connection;
+    delete _selection_modified_connection;
+}
+
+void SelectionDescriber::_selectionModified(Inkscape::Selection *selection, guint /*flags*/)
+{
     _updateMessageFromSelection(selection);
 }
 
@@ -105,40 +132,71 @@ void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *select
         SPItem *item = SP_ITEM(items->data);
         SPObject *layer = selection->desktop()->layerForObject (SP_OBJECT (item));
         SPObject *root = selection->desktop()->currentRoot();
-        gchar *layer_phrase;
+
+        // Layer name
+        gchar *layer_name;
         if (layer == root) {
-            layer_phrase = g_strdup("");  // for simplicity
+            layer_name = g_strdup(_("root"));
         } else {
-            char const *name, *fmt;
+            char const *layer_label;
+            bool is_label = false;
             if (layer && layer->label()) {
-                name = layer->label();
-                fmt = _(" in layer <b>%s</b>");
+                layer_label = layer->label();
+                is_label = true;
+            } else {
+                layer_label = layer->defaultLabel();
+            }
+            char *quoted_layer_label = xml_quote_strdup(layer_label);
+            if (is_label) {
+                layer_name = g_strdup_printf(_("layer <b>%s</b>"), quoted_layer_label);
             } else {
-                name = layer->defaultLabel();
-                fmt = _(" in layer <b><i>%s</i></b>");
+                layer_name = g_strdup_printf(_("layer <b><i>%s</i></b>"), quoted_layer_label);
             }
-            char *quoted_name = xml_quote_strdup(name);
-            layer_phrase = g_strdup_printf(fmt, quoted_name);
-            g_free(quoted_name);
+            g_free(quoted_layer_label);
         }
 
+        // Parent name
+        SPObject *parent = SP_OBJECT_PARENT (item);
+        gchar *parent_label = SP_OBJECT_ID(parent);
+        char *quoted_parent_label = xml_quote_strdup(parent_label);
+        gchar *parent_name = g_strdup_printf(_("<i>%s</i>"), quoted_parent_label);
+        g_free(quoted_parent_label);
+
+        gchar *in_phrase;
+        guint num_layers = selection->numberOfLayers();
+        guint num_parents = selection->numberOfParents();
+        if (num_layers == 1) {
+            if (num_parents == 1) {
+                if (layer == parent)
+                    in_phrase = g_strdup_printf(_(" in %s"), layer_name);
+                else 
+                    in_phrase = g_strdup_printf(_(" in group %s (%s)"), parent_name, layer_name);
+            } else {
+                    in_phrase = g_strdup_printf(ngettext(" in <b>%i</b> parents (%s)", " in <b>%i</b> parents (%s)", num_parents), num_parents, layer_name);
+            }
+        } else {
+            in_phrase = g_strdup_printf(ngettext(" in <b>%i</b> layers", " in <b>%i</b> layers", num_layers), num_layers);
+        }
+        g_free (layer_name);
+        g_free (parent_name);
+
         if (!items->next) { // one item
             char *item_desc = sp_item_description(item);
             if (SP_IS_USE(item) || (SP_IS_OFFSET(item) && SP_OFFSET (item)->sourceHref)) {
                 _context.setF(Inkscape::NORMAL_MESSAGE, "%s%s. %s. %s.",
-                              item_desc, layer_phrase,
+                              item_desc, in_phrase,
                               _("Use <b>Shift+D</b> to look up original"), when_selected);
             } else if (SP_IS_TEXT_TEXTPATH(item)) {
                 _context.setF(Inkscape::NORMAL_MESSAGE, "%s%s. %s. %s.",
-                              item_desc, layer_phrase,
+                              item_desc, in_phrase,
                               _("Use <b>Shift+D</b> to look up path"), when_selected);
             } else if (SP_IS_FLOWTEXT(item) && !SP_FLOWTEXT(item)->has_internal_frame()) {
                 _context.setF(Inkscape::NORMAL_MESSAGE, "%s%s. %s. %s.",
-                              item_desc, layer_phrase,
+                              item_desc, in_phrase,
                               _("Use <b>Shift+D</b> to look up frame"), when_selected);
             } else {
                 _context.setF(Inkscape::NORMAL_MESSAGE, "%s%s. %s.",
-                              item_desc, layer_phrase, when_selected);
+                              item_desc, in_phrase, when_selected);
             }
             g_free(item_desc);
         } else { // multiple items
@@ -150,47 +208,38 @@ void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *select
             if (n_terms == 0) {
                 objects_str = g_strdup_printf (
                     // this is only used with 2 or more objects
-                    ngettext("", "<b>%i</b> objects selected", object_count), 
+                    ngettext("<b>%i</b> object selected", "<b>%i</b> objects selected", object_count), 
                     object_count);
             } else if (n_terms == 1) {
                 objects_str = g_strdup_printf (
                     // this is only used with 2 or more objects
-                    ngettext("", "<b>%i</b> objects of type <b>%s</b>", object_count),
+                    ngettext("<b>%i</b> object of type <b>%s</b>", "<b>%i</b> objects of type <b>%s</b>", object_count),
                     object_count, (gchar *) terms->data);
             } else if (n_terms == 2) {
                 objects_str = g_strdup_printf (
                     // this is only used with 2 or more objects
-                    ngettext("", "<b>%i</b> objects of types <b>%s</b>, <b>%s</b>", object_count), 
+                    ngettext("<b>%i</b> object of types <b>%s</b>, <b>%s</b>", "<b>%i</b> objects of types <b>%s</b>, <b>%s</b>", object_count), 
                     object_count, (gchar *) terms->data, (gchar *) terms->next->data);
             } else if (n_terms == 3) {
                 objects_str = g_strdup_printf (
                     // this is only used with 2 or more objects
-                    ngettext("", "<b>%i</b> objects of types <b>%s</b>, <b>%s</b>, <b>%s</b>", object_count), 
+                    ngettext("<b>%i</b> object of types <b>%s</b>, <b>%s</b>, <b>%s</b>", "<b>%i</b> objects of types <b>%s</b>, <b>%s</b>, <b>%s</b>", object_count), 
                     object_count, (gchar *) terms->data, (gchar *) terms->next->data, (gchar *) terms->next->next->data);
             } else {
                 objects_str = g_strdup_printf (
                     // this is only used with 2 or more objects
-                    ngettext("", "<b>%i</b> objects of <b>%i</b> types", object_count), 
+                    ngettext("<b>%i</b> object of <b>%i</b> types", "<b>%i</b> objects of <b>%i</b> types", object_count), 
                     object_count, n_terms);
             }
             g_slist_free (terms);
 
-            if (selection->numberOfLayers() == 1) {
-                _context.setF(Inkscape::NORMAL_MESSAGE, _("%s%s. %s."),
-                              objects_str, layer_phrase, when_selected);
-            } else {
-                _context.setF(Inkscape::NORMAL_MESSAGE,
-                              ngettext("%s in <b>%i</b> layer. %s.",
-                                       "%s in <b>%i</b> layers. %s.",
-                                       selection->numberOfLayers()),
-                              objects_str, selection->numberOfLayers(), when_selected);
-            }
+            _context.setF(Inkscape::NORMAL_MESSAGE, _("%s%s. %s."), objects_str, in_phrase, when_selected);
 
             if (objects_str)
                 g_free ((gchar *) objects_str);
         }
 
-        g_free(layer_phrase);
+        g_free(in_phrase);
     }
 }