summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/actions/CMakeLists.txt2
-rw-r--r--src/actions/actions-base.cpp43
-rw-r--r--src/actions/actions-helper.cpp48
-rw-r--r--src/actions/actions-helper.h34
-rw-r--r--src/actions/actions-selection.cpp124
-rw-r--r--src/actions/actions-selection.h29
-rw-r--r--src/actions/selection.cpp137
-rw-r--r--src/actions/selection.h29
-rw-r--r--src/inkscape-application.cpp11
10 files changed, 416 insertions, 45 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e2ccea569..9117122df 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -285,6 +285,10 @@ set(main_SRC
inkscape-application.cpp
actions/actions-base.h
actions/actions-base.cpp
+ actions/actions-helper.h
+ actions/actions-helper.cpp
+ actions/actions-selection.h
+ actions/actions-selection.cpp
)
set(view_SRC
inkview-main.cpp
diff --git a/src/actions/CMakeLists.txt b/src/actions/CMakeLists.txt
index e16dbc505..d5b833922 100644
--- a/src/actions/CMakeLists.txt
+++ b/src/actions/CMakeLists.txt
@@ -2,9 +2,11 @@
set(actions_SRC
# actions-base.cpp
+ # actions-selection.cpp
# HEADERS
# actions-base.h
+ # actions-selection.h
)
add_inkscape_source("${actions_SRC}")
diff --git a/src/actions/actions-base.cpp b/src/actions/actions-base.cpp
index a3ff363a7..9ce38da4b 100644
--- a/src/actions/actions-base.cpp
+++ b/src/actions/actions-base.cpp
@@ -13,6 +13,7 @@
#include <giomm.h> // Not <gtkmm.h>! To eventually allow a headless version!
#include "actions-base.h"
+#include "actions-helper.h"
#include "inkscape-application.h"
@@ -48,46 +49,6 @@ print_verb_list()
Inkscape::Verb::list(); // verbs.h
}
-// Helper function: returns true if both document and selection found.
-bool
-get_document_and_selection(InkscapeApplication* app, SPDocument** document, Inkscape::Selection** selection)
-{
- *document = app->get_active_document();
- if (!(*document)) {
- std::cerr << "get_document_and_selection: No document!" << std::endl;
- return false;
- }
-
- Inkscape::ActionContext context = INKSCAPE.action_context_for_document(*document);
- *selection = context.getSelection();
- if (!*selection) {
- std::cerr << "get_document_and_selection: No selection!" << std::endl;
- return false;
- }
-
- return true;
-}
-
-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: did not find object with id: " << id << std::endl;
- }
- }
-}
-
// Helper function for query_x(), query_y(), query_width(), and query_height().
void
query_dimension(InkscapeApplication* app, bool extent, Geom::Dim2 const axis)
@@ -253,10 +214,8 @@ add_actions_base(InkscapeApplication* app)
app->add_action( "no-convert-baseline", sigc::ptr_fun(&no_convert_baseline) );
app->add_action( "vacuum-defs", sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&vacuum_defs), app) );
- app->add_action_radio_string( "select", sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&select_via_id), app), "null");
app->add_action_radio_string( "verb", sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&verbs), app), "null");
- app->add_action_radio_string( "query-id", sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&select_via_id), app), "null"); // For backwards compatibility.
app->add_action( "query-x", sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&query_x), app) );
app->add_action( "query-y", sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&query_y), app) );
app->add_action( "query-width", sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&query_width), app) );
diff --git a/src/actions/actions-helper.cpp b/src/actions/actions-helper.cpp
new file mode 100644
index 000000000..e72a15dad
--- /dev/null
+++ b/src/actions/actions-helper.cpp
@@ -0,0 +1,48 @@
+// 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 "actions-helper.h"
+
+#include "inkscape-application.h"
+#include "inkscape.h"
+#include "selection.h"
+
+// Helper function: returns true if both document and selection found. Maybe this should
+// work on current view. Or better, application could return the selection of the current view.
+bool
+get_document_and_selection(InkscapeApplication* app, SPDocument** document, Inkscape::Selection** selection)
+{
+ *document = app->get_active_document();
+ if (!(*document)) {
+ std::cerr << "get_document_and_selection: No document!" << std::endl;
+ return false;
+ }
+
+ // To do: get selection from active view (which could be from desktop or not).
+ Inkscape::ActionContext context = INKSCAPE.action_context_for_document(*document);
+ *selection = context.getSelection();
+ if (!*selection) {
+ std::cerr << "get_document_and_selection: No selection!" << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+/*
+ 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 :
diff --git a/src/actions/actions-helper.h b/src/actions/actions-helper.h
new file mode 100644
index 000000000..da65e10ac
--- /dev/null
+++ b/src/actions/actions-helper.h
@@ -0,0 +1,34 @@
+// 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.
+ *
+ */
+
+#ifndef INK_ACTIONS_HELPER_H
+#define INK_ACTIONS_HELPER_H
+
+class InkscapeApplication;
+class SPDocument;
+namespace Inkscape {
+ class Selection;
+}
+
+bool get_document_and_selection(InkscapeApplication* app, SPDocument** document, Inkscape::Selection** selection);
+
+
+#endif // INK_ACTIONS_HELPER_H
+
+/*
+ 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 :
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 :
diff --git a/src/actions/actions-selection.h b/src/actions/actions-selection.h
new file mode 100644
index 000000000..1d5a31127
--- /dev/null
+++ b/src/actions/actions-selection.h
@@ -0,0 +1,29 @@
+// 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.
+ *
+ */
+
+#ifndef INK_ACTIONS_SELECTION_H
+#define INK_ACTIONS_SELECTION_H
+
+class InkscapeApplication;
+
+void add_actions_selection(InkscapeApplication* app);
+
+#endif // INK_ACTIONS_SELECTION_H
+
+/*
+ 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 :
diff --git a/src/actions/selection.cpp b/src/actions/selection.cpp
new file mode 100644
index 000000000..05634c33a
--- /dev/null
+++ b/src/actions/selection.cpp
@@ -0,0 +1,137 @@
+// 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 "selection.h"
+
+// Helper function: returns true if both document and selection found. Maybe this should
+// work on current view. Or better, application could return the selection of the current view.
+bool
+get_document_and_selection(InkscapeApplication* app, SPDocument** document, Inkscape::Selection** selection)
+{
+ *document = app->get_active_document();
+ if (!(*document)) {
+ std::cerr << "get_document_and_selection: No document!" << std::endl;
+ return false;
+ }
+
+ // To do: get selection from active view (which could be from desktop or not).
+ Inkscape::ActionContext context = INKSCAPE.action_context_for_document(*document);
+ *selection = context.getSelection();
+ if (!*selection) {
+ std::cerr << "get_document_and_selection: No selection!" << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+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->getObjectByClass(klass);
+ selection->add(objects.start(), 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->getObjectByElement(element);
+ selection->add(objects.start(), 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->getObjectBySelector(selector);
+ selection->add(objects.start(), objects.end());
+}
+
+void
+select_all(Inkscape* 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(&selecton_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 :
diff --git a/src/actions/selection.h b/src/actions/selection.h
new file mode 100644
index 000000000..1d5a31127
--- /dev/null
+++ b/src/actions/selection.h
@@ -0,0 +1,29 @@
+// 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.
+ *
+ */
+
+#ifndef INK_ACTIONS_SELECTION_H
+#define INK_ACTIONS_SELECTION_H
+
+class InkscapeApplication;
+
+void add_actions_selection(InkscapeApplication* app);
+
+#endif // INK_ACTIONS_SELECTION_H
+
+/*
+ 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 :
diff --git a/src/inkscape-application.cpp b/src/inkscape-application.cpp
index 93133a214..e99f7071c 100644
--- a/src/inkscape-application.cpp
+++ b/src/inkscape-application.cpp
@@ -20,7 +20,9 @@
#include "file.h" // File open and window creation.
#include "io/file.h" // File open (command line).
#include "desktop.h" // Access to window
-#include "actions/actions-base.h" // Actions
+
+#include "actions/actions-base.h" // Actions
+#include "actions/actions-selection.h" // Actions
#ifdef WITH_DBUS
# include "extension/dbus/dbus-init.h"
@@ -59,6 +61,7 @@ InkscapeApplication::InkscapeApplication()
// ======================== Actions =========================
add_actions_base(this); // actions that are GUI independent
+ add_actions_selection(this); // actions for object selection
// ====================== Command Line ======================
@@ -363,7 +366,6 @@ InkscapeApplication::on_handle_local_options(const Glib::RefPtr<Glib::VariantDic
// Split action list
std::vector<Glib::ustring> tokens = Glib::Regex::split_simple("\\s*;\\s*", actions);
for (auto token : tokens) {
- std::cout << token << std::endl;
std::vector<Glib::ustring> tokens2 = Glib::Regex::split_simple("\\s*:\\s*", token);
std::string action;
std::string value;
@@ -399,8 +401,11 @@ InkscapeApplication::on_handle_local_options(const Glib::RefPtr<Glib::VariantDic
_command_line_actions.push_back( std::make_pair( action, Glib::VariantBase() ) );
}
} else {
+ // Assume a verb
std::cerr << "InkscapeApplication::on_handle_local_options: '"
<< action << "' is not a valid action!" << std::endl;
+ _command_line_actions.push_back(
+ std::make_pair("verb", Glib::Variant<Glib::ustring>::create(action)));
}
}
}
@@ -435,7 +440,7 @@ InkscapeApplication::on_handle_local_options(const Glib::RefPtr<Glib::VariantDic
options->lookup_value("query-id", query_id);
if (!query_id.empty()) {
_command_line_actions.push_back(
- std::make_pair("query-id", Glib::Variant<Glib::ustring>::create(query_id)));
+ std::make_pair("select-via-id", Glib::Variant<Glib::ustring>::create(query_id)));
}
}