summaryrefslogtreecommitdiffstats
path: root/src/selection-chemistry.cpp
diff options
context:
space:
mode:
authorJohn Smith <john.smith7545@yahoo.com>2012-07-25 02:42:34 +0000
committerJohn Smith <john.smith7545@yahoo.com>2012-07-25 02:42:34 +0000
commitd71d34161792bd83064081bda825ef9579825b78 (patch)
tree03d50df0b06563d4f479330b6a53da9c7f55a81a /src/selection-chemistry.cpp
parentFix for 1028425 : Gradient Stop Alpha value not correct in Fill/Stroke dialog (diff)
downloadinkscape-d71d34161792bd83064081bda825ef9579825b78.tar.gz
inkscape-d71d34161792bd83064081bda825ef9579825b78.zip
Fix for 722625 : Select Same by Object Type
(bzr r11573)
Diffstat (limited to 'src/selection-chemistry.cpp')
-rw-r--r--src/selection-chemistry.cpp105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp
index d70435df6..041bc4b2d 100644
--- a/src/selection-chemistry.cpp
+++ b/src/selection-chemistry.cpp
@@ -48,6 +48,12 @@ SPCycleType SP_CYCLING = SP_CYCLE_FOCUS;
#include "sp-flowtext.h"
#include "sp-flowregion.h"
#include "sp-image.h"
+#include "sp-rect.h"
+#include "sp-ellipse.h"
+#include "sp-star.h"
+#include "sp-spiral.h"
+#include "sp-polyline.h"
+#include "sp-line.h"
#include "text-editing.h"
#include "text-context.h"
#include "connector-context.h"
@@ -172,6 +178,11 @@ void SelectionHelper::selectSameStrokeStyle(SPDesktop *dt)
sp_select_same_stroke_style(dt);
}
+void SelectionHelper::selectSameObjectType(SPDesktop *dt)
+{
+ sp_select_same_object_type(dt);
+}
+
void SelectionHelper::invert(SPDesktop *dt)
{
if (tools_isactive(dt, TOOLS_NODES)) {
@@ -1699,6 +1710,45 @@ void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolea
/*
+ * Selects all the visible items with the same object type as the items in the current selection
+ *
+ * Params:
+ * desktop - set the selection on this desktop
+ */
+void sp_select_same_object_type(SPDesktop *desktop)
+{
+ if (!desktop) {
+ return;
+ }
+
+
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ bool onlyvisible = prefs->getBool("/options/kbselection/onlyvisible", true);
+ bool onlysensitive = prefs->getBool("/options/kbselection/onlysensitive", true);
+ bool ingroups = TRUE;
+
+ GSList *all_list = get_all_items(NULL, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, NULL);
+ GSList *matches = all_list;
+
+ Inkscape::Selection *selection = sp_desktop_selection (desktop);
+
+ for (GSList const* sel_iter = selection->itemList(); sel_iter; sel_iter = sel_iter->next) {
+ SPItem *sel = SP_ITEM(sel_iter->data);
+ matches = sp_get_same_object_type(sel, matches);
+ }
+
+ selection->clear();
+ selection->setList(matches);
+
+ if (matches) {
+ g_slist_free(matches);
+ }
+ if (all_list) {
+ g_slist_free(all_list);
+ }
+}
+
+/*
* Selects all the visible items with the same stroke style as the items in the current selection
*
* Params:
@@ -1795,6 +1845,61 @@ GSList *sp_get_same_fill_or_stroke_color(SPItem *sel, GSList *src, SPSelectStrok
return matches;
}
+bool item_type_match (SPItem *i, SPItem *j)
+{
+ if ( SP_IS_RECT(i)) {
+ return ( SP_IS_RECT(j) );
+
+ } else if (SP_IS_GENERICELLIPSE(i) || SP_IS_ELLIPSE(i) || SP_IS_ARC(i) || SP_IS_CIRCLE(i)) {
+ return (SP_IS_GENERICELLIPSE(j) || SP_IS_ELLIPSE(j) || SP_IS_ARC(j) || SP_IS_CIRCLE(j));
+
+ } else if (SP_IS_STAR(i) || SP_IS_POLYGON(i)) {
+ return (SP_IS_STAR(j) || SP_IS_POLYGON(j)) ;
+
+ } else if (SP_IS_SPIRAL(i)) {
+ return (SP_IS_SPIRAL(j));
+
+ } else if (SP_IS_PATH(i) || SP_IS_LINE(i) || SP_IS_POLYLINE(i)) {
+ return (SP_IS_PATH(j) || SP_IS_LINE(j) || SP_IS_POLYLINE(j));
+
+ } else if (SP_IS_TEXT(i) || SP_IS_FLOWTEXT(i) || SP_IS_TSPAN(i) || SP_IS_TREF(i) || SP_IS_STRING(i)) {
+ return (SP_IS_TEXT(j) || SP_IS_FLOWTEXT(j) || SP_IS_TSPAN(j) || SP_IS_TREF(j) || SP_IS_STRING(j));
+
+ } else if (SP_IS_USE(i)) {
+ return (SP_IS_USE(j)) ;
+
+ } else if (SP_IS_IMAGE(i)) {
+ return (SP_IS_IMAGE(j));
+
+ } else if (SP_IS_OFFSET(i) && SP_OFFSET(i)->sourceHref) { // Linked offset
+ return (SP_IS_OFFSET(j) && SP_OFFSET(j)->sourceHref);
+
+ } else if (SP_IS_OFFSET(i) && !SP_OFFSET(i)->sourceHref) { // Dynamic offset
+ return (SP_IS_OFFSET(j) && !SP_OFFSET(j)->sourceHref);
+
+ }
+
+ return false;
+}
+
+/*
+ * Find all items in src list that have the same object type as sel by type
+ * Return the list of matching items
+ */
+GSList *sp_get_same_object_type(SPItem *sel, GSList *src)
+{
+ GSList *matches = NULL;
+
+ for (GSList *i = src; i != NULL; i = i->next) {
+ SPItem *item = SP_ITEM(i->data);
+ if (item_type_match (sel, item)) {
+ matches = g_slist_prepend (matches, item);
+ }
+ }
+
+ return matches;
+}
+
/*
* Find all items in src list that have the same stroke style as sel by type
* Return the list of matching items