summaryrefslogtreecommitdiffstats
path: root/src/actions/actions-selection.cpp
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2018-11-19 22:49:18 +0000
committerTavmjong Bah <tavmjong@free.fr>2018-11-19 22:49:18 +0000
commit9f666963e7f574c95d26082597e7ee5fbee9780b (patch)
tree901e704d42fbcc2f98b2970bdbc7da25a72e0736 /src/actions/actions-selection.cpp
parentFix --help descriptions of "--actions", "--query-id", " and "--export-id". (diff)
downloadinkscape-9f666963e7f574c95d26082597e7ee5fbee9780b.tar.gz
inkscape-9f666963e7f574c95d26082597e7ee5fbee9780b.zip
Allow any valid Verb to be used in "--actions".
Rename "select" action to "select-via-id". Add "select-via-class", "select-via-element", "select-via-selector", and "select-clear" actions.
Diffstat (limited to 'src/actions/actions-selection.cpp')
-rw-r--r--src/actions/actions-selection.cpp124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/actions/actions-selection.cpp b/src/actions/actions-selection.cpp
new file mode 100644
index 000000000..cafa904cc
--- /dev/null
+++ b/src/actions/actions-selection.cpp
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Gio::Actions for selection tied to the application and without GUI.
+ *
+ * Copyright (C) 2018 Tavmjong Bah
+ *
+ * The contents of this file may be used under the GNU General Public License Version 2 or later.
+ *
+ */
+
+#include <iostream>
+
+#include <giomm.h> // Not <gtkmm.h>! To eventually allow a headless version!
+
+#include "actions-selection.h"
+#include "actions-helper.h"
+#include "inkscape-application.h"
+
+#include "inkscape.h" // Inkscape::Application
+#include "selection.h" // Selection
+
+void
+select_clear(InkscapeApplication* app)
+{
+ SPDocument* document = nullptr;
+ Inkscape::Selection* selection = nullptr;
+ if (!get_document_and_selection(app, &document, &selection)) {
+ return;
+ }
+ selection->clear();
+}
+
+void
+select_via_id(Glib::ustring ids, InkscapeApplication* app)
+{
+ SPDocument* document = nullptr;
+ Inkscape::Selection* selection = nullptr;
+ if (!get_document_and_selection(app, &document, &selection)) {
+ return;
+ }
+
+ auto tokens = Glib::Regex::split_simple("\\s*,\\s*", ids);
+ for (auto id : tokens) {
+ SPObject* object = document->getObjectById(id);
+ if (object) {
+ selection->add(object);
+ } else {
+ std::cerr << "select_via_id: Did not find object with id: " << id << std::endl;
+ }
+ }
+}
+
+void
+select_via_class(Glib::ustring klass, InkscapeApplication* app)
+{
+ SPDocument* document = nullptr;
+ Inkscape::Selection* selection = nullptr;
+ if (!get_document_and_selection(app, &document, &selection)) {
+ return;
+ }
+
+ auto objects = document->getObjectsByClass(klass);
+ selection->add(objects.begin(), objects.end());
+}
+
+void
+select_via_element(Glib::ustring element, InkscapeApplication* app)
+{
+ SPDocument* document = nullptr;
+ Inkscape::Selection* selection = nullptr;
+ if (!get_document_and_selection(app, &document, &selection)) {
+ return;
+ }
+
+ auto objects = document->getObjectsByElement(element);
+ selection->add(objects.begin(), objects.end());
+}
+
+void
+select_via_selector(Glib::ustring selector, InkscapeApplication* app)
+{
+ SPDocument* document = nullptr;
+ Inkscape::Selection* selection = nullptr;
+ if (!get_document_and_selection(app, &document, &selection)) {
+ return;
+ }
+
+ auto objects = document->getObjectsBySelector(selector);
+ selection->add(objects.begin(), objects.end());
+}
+
+void
+select_all(InkscapeApplication* app)
+{
+ SPDocument* document = nullptr;
+ Inkscape::Selection* selection = nullptr;
+ if (!get_document_and_selection(app, &document, &selection)) {
+ return;
+ }
+}
+
+void
+add_actions_selection(InkscapeApplication* app)
+{
+ app->add_action( "select-clear", sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&select_clear), app) );
+ app->add_action_radio_string( "select-via-id", sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&select_via_id), app), "null");
+ app->add_action_radio_string( "select-via-class", sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&select_via_id), app), "null");
+ app->add_action_radio_string( "select-via-element", sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&select_via_element), app), "null");
+ app->add_action_radio_string( "select-via-selector",sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&select_via_selector), app), "null");
+}
+
+
+
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :