1 /*
2 * Inkscape::SelectionDescriber - shows messages describing selection
3 *
4 * Authors:
5 * MenTaLguY <mental@rydia.net>
6 * bulia byak <buliabyak@users.sf.net>
7 *
8 * Copyright (C) 2004 MenTaLguY
9 *
10 * Released under GNU GPL, read the file 'COPYING' for more information
11 */
13 #ifdef HAVE_CONFIG_H
14 # include "config.h"
15 #endif
17 #include <glibmm/i18n.h>
18 #include "xml/quote.h"
19 #include "selection.h"
20 #include "selection-describer.h"
21 #include "desktop.h"
22 #include "sp-textpath.h"
23 #include "sp-offset.h"
24 #include "sp-flowtext.h"
25 #include "sp-use.h"
27 namespace Inkscape {
29 SelectionDescriber::SelectionDescriber(Inkscape::Selection *selection, MessageStack *stack)
30 : _context(stack)
31 {
32 selection->connectChanged(sigc::mem_fun(*this, &SelectionDescriber::_updateMessageFromSelection));
33 _updateMessageFromSelection(selection);
34 }
36 void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *selection) {
37 GSList const *items = selection->itemList();
39 char const *when_selected = _("Click selection to toggle scale/rotation handles");
40 if (!items) { // no items
41 _context.set(Inkscape::NORMAL_MESSAGE, _("No objects selected. Click, Shift+click, or drag around objects to select."));
42 } else {
43 SPItem *item = SP_ITEM(items->data);
44 SPObject *layer = selection->desktop()->layerForObject (SP_OBJECT (item));
45 SPObject *root = selection->desktop()->currentRoot();
46 gchar *layer_phrase;
47 if (layer == root) {
48 layer_phrase = g_strdup(""); // for simplicity
49 } else {
50 char const *name, *fmt;
51 if (layer && layer->label()) {
52 name = layer->label();
53 fmt = _(" in layer <b>%s</b>");
54 } else {
55 name = layer->defaultLabel();
56 fmt = _(" in layer <b><i>%s</i></b>");
57 }
58 char *quoted_name = xml_quote_strdup(name);
59 layer_phrase = g_strdup_printf(fmt, quoted_name);
60 g_free(quoted_name);
61 }
63 if (!items->next) { // one item
64 char *item_desc = sp_item_description(item);
65 if (SP_IS_USE(item) || (SP_IS_OFFSET(item) && SP_OFFSET (item)->sourceHref)) {
66 _context.setF(Inkscape::NORMAL_MESSAGE, "%s%s. %s. %s.",
67 item_desc, layer_phrase,
68 _("Use <b>Shift+D</b> to look up original"), when_selected);
69 } else if (SP_IS_TEXT_TEXTPATH(item)) {
70 _context.setF(Inkscape::NORMAL_MESSAGE, "%s%s. %s. %s.",
71 item_desc, layer_phrase,
72 _("Use <b>Shift+D</b> to look up path"), when_selected);
73 } else if (SP_IS_FLOWTEXT(item) && !SP_FLOWTEXT(item)->has_internal_frame()) {
74 _context.setF(Inkscape::NORMAL_MESSAGE, "%s%s. %s. %s.",
75 item_desc, layer_phrase,
76 _("Use <b>Shift+D</b> to look up frame"), when_selected);
77 } else {
78 _context.setF(Inkscape::NORMAL_MESSAGE, "%s%s. %s.",
79 item_desc, layer_phrase, when_selected);
80 }
81 g_free(item_desc);
82 } else { // multiple items
83 int object_count = g_slist_length((GSList *)items);
84 const gchar *object_count_str = NULL;
85 object_count_str = g_strdup_printf (
86 ngettext("<b>%i</b> object selected",
87 "<b>%i</b> objects selected",
88 object_count),
89 object_count);
91 if (selection->numberOfLayers() == 1) {
92 _context.setF(Inkscape::NORMAL_MESSAGE, _("%s%s. %s."),
93 object_count_str, layer_phrase, when_selected);
94 } else {
95 _context.setF(Inkscape::NORMAL_MESSAGE,
96 ngettext("%s in <b>%i</b> layer. %s.",
97 "%s in <b>%i</b> layers. %s.",
98 selection->numberOfLayers()),
99 object_count_str, selection->numberOfLayers(), when_selected);
100 }
102 if (object_count_str)
103 g_free ((gchar *) object_count_str);
104 }
106 g_free(layer_phrase);
107 }
108 }
110 }
112 /*
113 Local Variables:
114 mode:c++
115 c-file-style:"stroustrup"
116 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
117 indent-tabs-mode:nil
118 fill-column:99
119 End:
120 */
121 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :