Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
actions-base.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Gio::Actions tied to the application and independent of GUI.
4 *
5 * Copyright (C) 2018 Tavmjong Bah
6 *
7 * The contents of this file may be used under the GNU General Public License Version 2 or later.
8 *
9 */
10
11#include "actions-base.h"
12
13#include <iostream>
14
15#include <giomm.h> // Not <gtkmm.h>! To eventually allow a headless version!
16#include <glibmm/i18n.h>
17
18#include "actions-helper.h"
19
21
22#include "document.h" // SPDocument
23#include "document-update.h"
24#include "file.h" // dpi convert method
25#include "inkscape-version-info.h"// Inkscape version
26#include "inkscape.h" // Inkscape::Application
27#include "preferences.h"
28#include "page-manager.h"
29#include "path-prefix.h" // Extension directory
30#include "selection.h" // Selection
31
34#include "io/resource.h"
35#include "object/sp-root.h" // query_all()
36
37void
42
43void
47
48void
52
53void
57
58void
63
64void
66{
67 show_output(Glib::build_filename(get_inkscape_datadir(), "inkscape"), false);
68}
69
70void
75
76// Helper function for query_x(), query_y(), query_width(), and query_height().
77void
78query_dimension(InkscapeApplication* app, bool extent, Geom::Dim2 const axis)
79{
80 SPDocument* document = nullptr;
81 Inkscape::Selection* selection = nullptr;
82 if (!get_document_and_selection(app, &document, &selection)) {
83 return;
84 }
85
86 if (selection->isEmpty()) {
87 selection->add(document->getRoot());
88 }
89
90 bool first = true;
91 auto items = selection->items();
92 Glib::ustring out = "";
93 for (auto item : items) {
94 if (!first) {
95 out += ",";
96 }
97 first = false;
99 if (area) {
100 if (extent) {
101 out += Inkscape::ustring::format_classic(area->dimensions()[axis]);
102 } else {
103 out += Inkscape::ustring::format_classic(area->min()[axis]);
104 }
105 } else {
106 out += "0";
107 }
108 }
109 show_output(out, false);
110}
111
112void
114{
115 query_dimension(app, false, Geom::X);
116}
117
118void
120{
121 query_dimension(app, false, Geom::Y);
122}
123
124void
129
130void
135
136// Helper for query_all()
137void
139{
140 auto item = cast<SPItem>(o);
141 if (item && item->getId()) {
143 Glib::ustring out = "";
144 if (area) {
145 // clang-format off
146 out += Glib::ustring(item->getId()) + ",";
147 out += Inkscape::ustring::format_classic(area->min()[Geom::X]) + ",";
148 out += Inkscape::ustring::format_classic(area->min()[Geom::Y]) + ",";
149 out += Inkscape::ustring::format_classic(area->dimensions()[Geom::X]) + ",";
150 out += Inkscape::ustring::format_classic(area->dimensions()[Geom::Y]);
151 // clang-format on
152 }
153 show_output(out, false);
154 for (auto& child: o->children) {
156 }
157 }
158}
159
160void
162{
163 SPDocument* doc = app->get_active_document();
164 if (!doc) {
165 show_output("query_all: no document!");
166 return;
167 }
168
169 SPObject *o = doc->getRoot();
170 if (o) {
172 }
173}
174
175void
177{
178 if (SPDocument* doc = app->get_active_document()) {
179 auto &pm = doc->getPageManager();
181 return;
182 }
183 show_output("query-pages: no document!");
184}
185
186void
188{
189 INKSCAPE.set_pages(std::to_string(page));
190}
191
192void
193convert_dpi_method(Glib::ustring method)
194{
195 if (method == "none") {
197 } else if (method == "scale-viewbox") {
199 } else if (method == "scale-document") {
201 } else {
202 show_output("dpi_convert_method: invalid option");
203 }
204}
205
206void
211
212const Glib::ustring SECTION_BASE = NC_("Action Section", "Base");
213const Glib::ustring SECTION_IMPORT = NC_("Action Section", "Import");
214const Glib::ustring SECTION_QUERY = NC_("Action Section", "Query");
215
216std::vector<std::vector<Glib::ustring>> raw_data_base =
217{
218 // clang-format off
219 {"app.inkscape-version", N_("Inkscape Version"), SECTION_BASE, N_("Print Inkscape version and exit") },
220 {"app.active-window-start", N_("Active Window: Start Call"), SECTION_BASE, N_("Start execution in active window") },
221 {"app.active-window-end", N_("Active Window: End Call"), SECTION_BASE, N_("End execution in active window") },
222 {"app.save-preferences", N_("Save preferences"), SECTION_BASE, N_("Make sure the preferences are saved") },
223 {"app.debug-info", N_("Debug Info"), SECTION_BASE, N_("Print debugging information and exit") },
224 {"app.system-data-directory", N_("System Directory"), SECTION_BASE, N_("Print system data directory and exit") },
225 {"app.user-data-directory", N_("User Directory"), SECTION_BASE, N_("Print user data directory and exit") },
226 {"app.action-list", N_("List Actions"), SECTION_BASE, N_("Print a list of actions and exit") },
227 {"app.list-input-types", N_("List Input File Extensions"), SECTION_BASE, N_("Print a list of input file extensions and exit") },
228 {"app.quit", N_("Quit"), SECTION_BASE, N_("Quit Inkscape, check for data loss") },
229 {"app.quit-immediate", N_("Quit Immediately"), SECTION_BASE, N_("Immediately quit Inkscape, no check for data loss") },
230
231 {"app.open-page", N_("Import Page Number"), SECTION_IMPORT, N_("Select PDF page number to import") },
232 {"app.convert-dpi-method", N_("Import DPI Method"), SECTION_IMPORT, N_("Set DPI conversion method for legacy Inkscape files")},
233 {"app.no-convert-baseline", N_("No Import Baseline Conversion"), SECTION_IMPORT, N_("Do not convert text baselines in legacy Inkscape files") },
234
235 {"app.query-x", N_("Query X"), SECTION_QUERY, N_("Query 'x' value(s) of selected objects") },
236 {"app.query-y", N_("Query Y"), SECTION_QUERY, N_("Query 'y' value(s) of selected objects") },
237 {"app.query-width", N_("Query Width"), SECTION_QUERY, N_("Query 'width' value(s) of object(s)") },
238 {"app.query-height", N_("Query Height"), SECTION_QUERY, N_("Query 'height' value(s) of object(s)") },
239 {"app.query-all", N_("Query All"), SECTION_QUERY, N_("Query 'x', 'y', 'width', and 'height'") },
240 {"app.query-pages", N_("Query Pages"), SECTION_QUERY, N_("Query number of pages in the document") }
241 // clang-format on
242};
243
244void
246{
247 auto *gapp = app->gio_app();
248 // Note: "radio" actions are just an easy way to set type without using templating.
249 // clang-format off
250 gapp->add_action( "inkscape-version", sigc::ptr_fun(&print_inkscape_version) );
251 gapp->add_action( "active-window-start", sigc::ptr_fun(&active_window_start) );
252 gapp->add_action( "active-window-end", sigc::ptr_fun(&active_window_end) );
253 gapp->add_action( "save-preferences", sigc::ptr_fun(&save_preferences) );
254 gapp->add_action( "debug-info", sigc::ptr_fun(&print_debug_info) );
255 gapp->add_action( "system-data-directory", sigc::ptr_fun(&print_system_data_directory) );
256 gapp->add_action( "user-data-directory", sigc::ptr_fun(&print_user_data_directory) );
257 gapp->add_action( "action-list", sigc::mem_fun(*app, &InkscapeApplication::print_action_list) );
258 gapp->add_action( "list-input-types", sigc::mem_fun(*app, &InkscapeApplication::print_input_type_list) );
259 gapp->add_action( "quit", sigc::mem_fun(*app, &InkscapeApplication::on_quit) );
260 gapp->add_action( "quit-immediate", sigc::mem_fun(*app, &InkscapeApplication::on_quit_immediate) );
261
262 gapp->add_action_radio_integer( "open-page", sigc::ptr_fun(&pdf_page), 0);
263 gapp->add_action_radio_string( "convert-dpi-method", sigc::ptr_fun(&convert_dpi_method), "none");
264 gapp->add_action( "no-convert-baseline", sigc::ptr_fun(&no_convert_baseline) );
265
266
267 gapp->add_action( "query-x", sigc::bind(sigc::ptr_fun(&query_x), app) );
268 gapp->add_action( "query-y", sigc::bind(sigc::ptr_fun(&query_y), app) );
269 gapp->add_action( "query-width", sigc::bind(sigc::ptr_fun(&query_width), app) );
270 gapp->add_action( "query-height", sigc::bind(sigc::ptr_fun(&query_height), app) );
271 gapp->add_action( "query-all", sigc::bind(sigc::ptr_fun(&query_all), app) );
272 gapp->add_action( "query-pages", sigc::bind(sigc::ptr_fun(&query_pages), app) );
273 // clang-format on
274
275 // Revision string is going to be added to the actions interface so it can be queried for existance by GApplication
276 gapp->add_action(Inkscape::inkscape_revision(), [=]() { g_warning("Don't call this action"); });
277
279}
280
281/*
282 Local Variables:
283 mode:c++
284 c-file-style:"stroustrup"
285 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
286 indent-tabs-mode:nil
287 fill-column:99
288 End:
289*/
290// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
void pdf_page(int page)
void query_height(InkscapeApplication *app)
void query_x(InkscapeApplication *app)
const Glib::ustring SECTION_BASE
void query_y(InkscapeApplication *app)
std::vector< std::vector< Glib::ustring > > raw_data_base
void query_width(InkscapeApplication *app)
void active_window_start()
void query_pages(InkscapeApplication *app)
void active_window_end()
void print_user_data_directory()
void print_system_data_directory()
void no_convert_baseline()
const Glib::ustring SECTION_IMPORT
void save_preferences()
void query_all_recurse(SPObject *o)
const Glib::ustring SECTION_QUERY
void print_debug_info()
void print_inkscape_version()
void query_all(InkscapeApplication *app)
void add_actions_base(InkscapeApplication *app)
void convert_dpi_method(Glib::ustring method)
void query_dimension(InkscapeApplication *app, bool extent, Geom::Dim2 const axis)
void show_output(Glib::ustring const &data, bool const is_cerr)
void active_window_start_helper()
void active_window_end_helper()
bool get_document_and_selection(InkscapeApplication *app, SPDocument **document, Inkscape::Selection **selection)
uint64_t page
Definition canvas.cpp:171
Axis-aligned rectangle that can be empty.
Definition rect.h:203
void add_data(std::vector< std::vector< Glib::ustring > > const &raw_data)
InkActionExtraData & get_action_extra_data()
Gio::Application * gio_app()
The Gio application instance, never NULL.
SPDocument * get_active_document()
void print_input_type_list() const
Prints file type extensions (without leading dot) of input formats.
SPItemRange items()
Returns a range of selected SPItems.
Definition object-set.h:230
bool isEmpty()
Returns true if no items are selected.
static Preferences * get()
Access the singleton Preferences object.
void save()
Save all preferences to the hard disk.
The set of selected SPObjects for a given document and layer model.
Definition selection.h:80
void add(XML::Node *repr)
Add an XML node's SPObject to the set of selected objects.
Definition selection.h:107
Typed SVG document implementation.
Definition document.h:101
SPRoot * getRoot()
Returns our SPRoot.
Definition document.h:200
Geom::OptRect documentVisualBounds() const
Get item's visual bbox in document coordinate system.
Definition sp-item.cpp:1026
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Definition sp-object.h:160
char const * getId() const
Returns the objects current ID string.
ChildrenList children
Definition sp-object.h:907
int sp_file_convert_dpi_method_commandline
@ FILE_DPI_VIEWBOX_SCALED
@ FILE_DPI_UNCHANGED
@ FILE_DPI_DOCUMENT_SCALED
bool sp_no_convert_text_baseline_spacing
Definition document.cpp:100
Dim2
2D axis enumeration (X or Y).
Definition coord.h:48
@ Y
Definition coord.h:48
@ X
Definition coord.h:48
SPItem * item
Consolidates version info for Inkscape, its various dependencies and the OS we're running on.
std::string profile_path()
Definition resource.cpp:415
Glib::ustring format_classic(T const &... args)
std::string inkscape_revision()
Return Inkscape repository revision string.
std::string debug_info()
Return full debug info.
std::string inkscape_version()
Return Inkscape version string.
char const * get_inkscape_datadir()
Determine the location of the Inkscape data directory (typically the share/ folder from where Inkscap...
TODO: insert short description here.
Singleton class to access the preferences file in a convenient way.
Ocnode * child[8]
Definition quantize.cpp:33
Inkscape::IO::Resource - simple resource API.
GList * items
SPRoot: SVG <svg> implementation.