From 8443720ce6429b9beec839e60b8a808595f4ba72 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 2 Apr 2013 23:01:45 +0200 Subject: Cleaned up a bit. Uses some C++11 features. (bzr r11608.1.72) --- src/selection-describer.cpp | 88 +++++++++++++++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 22 deletions(-) (limited to 'src/selection-describer.cpp') diff --git a/src/selection-describer.cpp b/src/selection-describer.cpp index 391db8950..1639a2b95 100644 --- a/src/selection-describer.cpp +++ b/src/selection-describer.cpp @@ -37,46 +37,89 @@ #include "sp-polyline.h" #include "sp-spiral.h" -static const gchar * -type2term(GType type) -{ - if (type == SP_TYPE_ANCHOR) +//static const gchar * +//type2term(GType type) +//{ +// if (type == SP_TYPE_ANCHOR) +// //TRANSLATORS: "Link" means internet link (anchor) +// { return C_("Web", "Link"); } +// if (type == SP_TYPE_CIRCLE) +// { return _("Circle"); } +// if (type == SP_TYPE_ELLIPSE) +// { return _("Ellipse"); } +// if (type == SP_TYPE_FLOWTEXT) +// { return _("Flowed text"); } +// if (type == SP_TYPE_GROUP) +// { return _("Group"); } +// if (type == SP_TYPE_IMAGE) +// { return _("Image"); } +// if (type == SP_TYPE_LINE) +// { return _("Line"); } +// if (type == SP_TYPE_PATH) +// { return _("Path"); } +// if (type == SP_TYPE_POLYGON) +// { return _("Polygon"); } +// if (type == SP_TYPE_POLYLINE) +// { return _("Polyline"); } +// if (type == SP_TYPE_RECT) +// { return _("Rectangle"); } +// if (type == SP_TYPE_BOX3D) +// { return _("3D Box"); } +// if (type == SP_TYPE_TEXT) +// { return C_("Object", "Text"); } +// if (type == SP_TYPE_USE) +// // TRANSLATORS: "Clone" is a noun, type of object +// { return C_("Object", "Clone"); } +// if (type == SP_TYPE_ARC) +// { return _("Ellipse"); } +// if (type == SP_TYPE_OFFSET) +// { return _("Offset path"); } +// if (type == SP_TYPE_SPIRAL) +// { return _("Spiral"); } +// if (type == SP_TYPE_STAR) +// { return _("Star"); } +// return NULL; +//} + +// CPPIFY: this is ugly. +static const char* object2term(SPObject* object) { + if (SP_IS_ANCHOR(object)) //TRANSLATORS: "Link" means internet link (anchor) { return C_("Web", "Link"); } - if (type == SP_TYPE_CIRCLE) + if (SP_IS_CIRCLE(object)) { return _("Circle"); } - if (type == SP_TYPE_ELLIPSE) + if (SP_IS_ELLIPSE(object)) { return _("Ellipse"); } - if (type == SP_TYPE_FLOWTEXT) + if (SP_IS_FLOWTEXT(object)) { return _("Flowed text"); } - if (type == SP_TYPE_GROUP) + if (SP_IS_GROUP(object)) { return _("Group"); } - if (type == SP_TYPE_IMAGE) + if (SP_IS_IMAGE(object)) { return _("Image"); } - if (type == SP_TYPE_LINE) + if (SP_IS_LINE(object)) { return _("Line"); } - if (type == SP_TYPE_PATH) + if (SP_IS_PATH(object)) { return _("Path"); } - if (type == SP_TYPE_POLYGON) + if (SP_IS_POLYGON(object)) { return _("Polygon"); } - if (type == SP_TYPE_POLYLINE) + if (SP_IS_POLYLINE(object)) { return _("Polyline"); } - if (type == SP_TYPE_RECT) + if (SP_IS_RECT(object)) { return _("Rectangle"); } - if (type == SP_TYPE_BOX3D) + if (SP_IS_BOX3D(object)) { return _("3D Box"); } - if (type == SP_TYPE_TEXT) + if (SP_IS_TEXT(object)) { return C_("Object", "Text"); } - if (type == SP_TYPE_USE) + if (SP_IS_USE(object)) // TRANSLATORS: "Clone" is a noun, type of object { return C_("Object", "Clone"); } - if (type == SP_TYPE_ARC) + if (SP_IS_ARC(object)) { return _("Ellipse"); } - if (type == SP_TYPE_OFFSET) + if (SP_IS_OFFSET(object)) { return _("Offset path"); } - if (type == SP_TYPE_SPIRAL) + if (SP_IS_SPIRAL(object)) { return _("Spiral"); } - if (type == SP_TYPE_STAR) + if (SP_IS_STAR(object)) { return _("Star"); } return NULL; } @@ -85,7 +128,8 @@ static GSList *collect_terms (GSList *items) { GSList *r = NULL; for (GSList *i = items; i != NULL; i = i->next) { - const gchar *term = type2term (G_OBJECT_TYPE(i->data)); + //const gchar *term = type2term (G_OBJECT_TYPE(i->data)); + const char* term = object2term(SP_OBJECT(i->data)); if (term != NULL && g_slist_find (r, term) == NULL) r = g_slist_prepend (r, (void *) term); } -- cgit v1.2.3 From 8073924aacdda310fb7492750f78d5389b3186af Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Fri, 5 Apr 2013 22:45:01 +0200 Subject: Merged Item. (bzr r11608.1.81) --- src/selection-describer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/selection-describer.cpp') diff --git a/src/selection-describer.cpp b/src/selection-describer.cpp index 1639a2b95..b9e1ed510 100644 --- a/src/selection-describer.cpp +++ b/src/selection-describer.cpp @@ -236,7 +236,7 @@ void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *select g_free (parent_name); if (!items->next) { // one item - char *item_desc = item->description(); + char *item_desc = item->getDetailedDescription(); if (SP_IS_USE(item) && SP_IS_SYMBOL(item->firstChild())) { _context.setF(Inkscape::NORMAL_MESSAGE, "%s%s. %s. %s.", item_desc, in_phrase, -- cgit v1.2.3 From eb3598e7e27619c759ef33bb9ec4ffb8898523de Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Fri, 20 Sep 2013 00:45:16 -0400 Subject: Refactor status-bar text for multiple items, was very broken Fixed bugs: - https://launchpad.net/bugs/1199192 (bzr r12550) --- src/selection-describer.cpp | 108 ++++++++------------------------------------ 1 file changed, 20 insertions(+), 88 deletions(-) (limited to 'src/selection-describer.cpp') diff --git a/src/selection-describer.cpp b/src/selection-describer.cpp index 4c2229667..fc6cb7f91 100644 --- a/src/selection-describer.cpp +++ b/src/selection-describer.cpp @@ -38,64 +38,22 @@ #include "sp-polyline.h" #include "sp-spiral.h" -// CPPIFY: this is ugly. -static const gchar * -type2term(SPItem *item) +// Returns a list of terms for the items to be used in the statusbar +const char* collect_terms (GSList *items) { -// GType type = G_OBJECT_TYPE( item ); -// if (type == SP_TYPE_ANCHOR) -// //TRANSLATORS: "Link" means internet link (anchor) -// { return C_("Web", "Link"); } -// if (type == SP_TYPE_CIRCLE) -// { return _("Circle"); } -// if (type == SP_TYPE_ELLIPSE) -// { return _("Ellipse"); } -// if (type == SP_TYPE_FLOWTEXT) -// { return _("Flowed text"); } -// if (type == SP_TYPE_GROUP) -// { return _("Group"); } -// if (type == SP_TYPE_IMAGE) -// { return _("Image"); } -// if (type == SP_TYPE_LINE) -// { return _("Line"); } -// if (type == SP_TYPE_PATH) -// { return _("Path"); } -// if (type == SP_TYPE_POLYGON) -// { return _("Polygon"); } -// if (type == SP_TYPE_POLYLINE) -// { return _("Polyline"); } -// if (type == SP_TYPE_RECT) -// { return _("Rectangle"); } -// if (type == SP_TYPE_BOX3D) -// { return _("3D Box"); } -// if (type == SP_TYPE_TEXT) -// { return C_("Object", "Text"); } -// if (type == SP_TYPE_USE) -// if (SP_IS_SYMBOL(item->firstChild())) -// { return C_("Object", "Symbol"); } -// // TRANSLATORS: "Clone" is a noun, type of object -// { return C_("Object", "Clone"); } -// if (type == SP_TYPE_ARC) -// { return _("Ellipse"); } -// if (type == SP_TYPE_OFFSET) -// { return _("Offset path"); } -// if (type == SP_TYPE_SPIRAL) -// { return _("Spiral"); } -// if (type == SP_TYPE_STAR) -// { return _("Star"); } -// return NULL; - return "Selektion-Describer ---"; -} - -static GSList *collect_terms (GSList *items) -{ - GSList *r = NULL; - for (GSList *i = items; i != NULL; i = i->next) { - const gchar *term = type2term ( SP_ITEM(i->data) ); - if (term != NULL && g_slist_find (r, term) == NULL) - r = g_slist_prepend (r, (void *) term); + GSList *check = NULL; + std::stringstream ss; + bool first = true; + + for (GSList *i = (GSList *)items; i != NULL; i = i->next) { + const char *term = SP_ITEM(i->data)->display_name(); + if (term != NULL && g_slist_find (check, term) == NULL) { + check = g_slist_prepend (check, (void *) term); + ss << (first ? "" : ", ") << "" << term << ""; + first = false; + } } - return r; + return ss.str().c_str(); } // Returns the number of filtered items in the list @@ -201,7 +159,8 @@ void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *select g_free (parent_name); if (!items->next) { // one item - char *item_desc = item->description(); + char *item_desc = item->getDetailedDescription(); + if (SP_IS_USE(item) && SP_IS_SYMBOL(item->firstChild())) { _context.setF(Inkscape::NORMAL_MESSAGE, "%s%s. %s. %s.", item_desc, in_phrase, @@ -229,38 +188,11 @@ void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *select g_free(item_desc); } else { // multiple items int object_count = g_slist_length((GSList *)items); + const char *terms = collect_terms ((GSList *)items); - gchar *objects_str = NULL; - GSList *terms = collect_terms ((GSList *)items); - int n_terms = g_slist_length(terms); - if (n_terms == 0) { - objects_str = g_strdup_printf ( - // this is only used with 2 or more objects - ngettext("%i object selected", "%i 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("%i object of type %s", "%i objects of type %s", 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("%i object of types %s, %s", "%i objects of types %s, %s", 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("%i object of types %s, %s, %s", "%i objects of types %s, %s, %s", 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("%i object of %i types", "%i objects of %i types", object_count), - object_count, n_terms); - } - g_slist_free (terms); - + gchar *objects_str = + g_strdup_printf( "%i objects selected of types %s", + object_count, terms ); // indicate all, some, or none filtered gchar *filt_str = NULL; -- cgit v1.2.3