Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
inkscape-application.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * The main Inkscape application.
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#ifndef INKSCAPE_APPLICATION_H
11#define INKSCAPE_APPLICATION_H
12
13#include <map>
14#include <span>
15#include <string>
16#include <utility>
17#include <vector>
18#include <glibmm/refptr.h>
19#include <glibmm/ustring.h>
20#include <gtkmm/application.h>
21
25#include "io/file-export-cmd.h" // File export (non-verb)
27#include "util/smart_ptr_keys.h"
28
29namespace Gio {
30class File;
31} // namespace Gio
32
33using action_vector_t = std::vector<std::pair<std::string, Glib::VariantBase>>;
34
35class InkscapeWindow;
36class SPDocument;
37class SPDesktop;
38
39namespace Inkscape {
40class Selection;
41namespace UI::Dialog {
42class StartScreen;
43}
44} // namespace Inkscape
45
47{
48public:
51
55
57 Gtk::Application *gtk_app() { return dynamic_cast<Gtk::Application *>(_gio_application.get()); }
59 Gio::Application *gio_app() { return _gio_application.get(); }
60
61 SPDesktop *createDesktop(SPDocument *document, bool replace);
62 void create_window(Glib::RefPtr<Gio::File> const &file = {});
63 bool destroyDesktop(SPDesktop *desktop, bool keep_alive = false);
65 bool destroy_all();
66 void print_action_list();
67 void print_input_type_list() const;
68
70 int on_handle_local_options(const Glib::RefPtr<Glib::VariantDict> &options);
71 void on_new();
72 void on_quit(); // Check for data loss.
73 void on_quit_immediate(); // Don't check for data loss.
74
75 // Gio::Actions need to know what document, selection, desktop to work on.
76 // In headless mode, these are set for each file processed.
77 // With GUI, these are set everytime the cursor enters an InkscapeWindow.
79 void set_active_document(SPDocument* document) { _active_document = document; };
80
83 {_active_selection = selection;};
84
85 // A desktop should track selection and canvas to document transform matrix. This is partially
86 // redundant with the selection functions above.
87 // Canvas to document transform matrix should be stored in the canvas, itself.
90
91 // The currently focused window (nominally corresponding to _active_document).
92 // A window must have a document but a document may have zero, one, or more windows.
93 // This will replace _active_desktop.
96
97 /****** Document ******/
98 /* These should not require a GUI! */
99 SPDocument *document_add(std::unique_ptr<SPDocument> document);
100
101 SPDocument *document_new(std::string const &template_filename = {});
102 std::pair<SPDocument *, bool /*cancelled*/> document_open(Glib::RefPtr<Gio::File> const &file);
103 SPDocument *document_open(std::span<char const> buffer);
104 bool document_swap(SPDesktop *desktop, SPDocument *document);
105 bool document_revert(SPDocument* document);
106 void document_close(SPDocument* document);
107
108 /* These require a GUI! */
110
111 std::vector<SPDocument *> get_documents();
112
113 /******* Window *******/
115 void windowClose(InkscapeWindow *window);
116
117 /******* Desktop *******/
118 SPDesktop *desktopOpen(SPDocument *document);
120 void desktopCloseActive();
121
122 /****** Actions *******/
126 std::map<std::string, Glib::ustring>& get_menu_label_to_tooltip_map() { return _menu_label_to_tooltip_map; };
127
128 /******* Debug ********/
129 void dump();
130
131 int get_number_of_windows() const;
132
133protected:
134 Glib::RefPtr<Gio::Application> _gio_application;
135
136 bool _with_gui = true;
137 bool _batch_process = false; // Temp
138 bool _use_shell = false;
139 bool _use_pipe = false;
140 bool _auto_export = false;
141 int _pdf_poppler = false;
145 Glib::ustring _pages;
146
147 // Documents are owned by the application which is responsible for opening/saving/exporting.
148 // Not supported by Apple Clang yet:
149 // std::unordered_map<std::unique_ptr<SPDocument>,
150 // std::vector<std::unique_ptr<InkscapeWindow>>,
151 // TransparentPtrHash<SPDocument>,
152 // TransparentPtrEqual<SPDocument>> _documents;
153 std::map<std::unique_ptr<SPDocument>,
154 std::vector<std::unique_ptr<SPDesktop>>,
156
157 std::vector<std::unique_ptr<InkscapeWindow>> _windows;
158
159 // We keep track of these things so we don't need a window to find them (for headless operation).
164
166
167 // Actions from the command line or file.
168 // Must read in on_handle_local_options() but parse in on_startup(). This is done as we must
169 // have a valid app before initializing extensions which must be done before parsing.
172
173 // Extra data associated with actions (Label, Section, Tooltip/Help).
177 // Needed due to the inabilitiy to get the corresponding Gio::Action from a Gtk::MenuItem.
178 // std::string is used as key type because Glib::ustring has slow comparison and equality
179 // operators.
180 std::map<std::string, Glib::ustring> _menu_label_to_tooltip_map;
181 void on_startup();
182 void on_activate();
183 void on_open(const Gio::Application::type_vec_files &files, const Glib::ustring &hint);
184 void process_document(SPDocument* document, std::string output_path);
185 void parse_actions(const Glib::ustring& input, action_vector_t& action_vector);
186
187 void redirect_output();
188 void shell(bool active_window = false);
189
190 void _start_main_option_section(const Glib::ustring& section_name = "");
191
192private:
194 std::vector<Glib::RefPtr<Gio::SimpleAction>> _effect_actions;
195};
196
197#endif // INKSCAPE_APPLICATION_H
198
199/*
200 Local Variables:
201 mode:c++
202 c-file-style:"stroustrup"
203 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
204 indent-tabs-mode:nil
205 fill-column:99
206 End:
207*/
208// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Authors: Sushant A A sushant.co19@gmail.com
std::vector< std::pair< std::string, Glib::VariantBase > > action_vector_t
Authors: Sushant A A sushant.co19@gmail.com
void on_open(const Gio::Application::type_vec_files &files, const Glib::ustring &hint)
void set_active_desktop(SPDesktop *desktop)
InkActionExtraData & get_action_extra_data()
InkActionEffectData & get_action_effect_data()
void document_fix(SPDesktop *desktop)
Fix up a document if necessary (Only fixes that require GUI).
InkActionEffectData _action_effect_data
std::vector< Glib::RefPtr< Gio::SimpleAction > > _effect_actions
void set_active_window(InkscapeWindow *window)
std::map< std::string, Glib::ustring > _menu_label_to_tooltip_map
void process_document(SPDocument *document, std::string output_path)
Common processing for documents.
InkscapeWindow * get_active_window()
void dump()
Debug function.
bool destroyDesktop(SPDesktop *desktop, bool keep_alive=false)
Destroy a window and close the document it contains.
bool document_swap(SPDesktop *desktop, SPDocument *document)
Swap out one document for another in a tab.
InkFileExportCmd _file_export
std::pair< SPDocument *, bool > document_open(Glib::RefPtr< Gio::File > const &file)
void set_active_selection(Inkscape::Selection *selection)
void _start_main_option_section(const Glib::ustring &section_name="")
Gio::Application * gio_app()
The Gio application instance, never NULL.
void shell(bool active_window=false)
bool document_revert(SPDocument *document)
Revert document: open saved document and swap it for each window.
SPDesktop * get_active_desktop()
void set_active_document(SPDocument *document)
Glib::RefPtr< Gio::Application > _gio_application
Glib::ustring _command_line_actions_input
std::map< std::unique_ptr< SPDocument >, std::vector< std::unique_ptr< SPDesktop > >, TransparentPtrLess< SPDocument > > _documents
void windowClose(InkscapeWindow *window)
SPDocument * get_active_document()
SPDesktop * desktopOpen(SPDocument *document)
SPDocument * document_new(std::string const &template_filename={})
InkActionExtraData _action_extra_data
void parse_actions(const Glib::ustring &input, action_vector_t &action_vector)
static InkscapeApplication * instance()
Singleton instance.
int on_handle_local_options(const Glib::RefPtr< Glib::VariantDict > &options)
Gtk::Application * gtk_app()
The Gtk application instance, or NULL if running headless without display.
void print_input_type_list() const
Prints file type extensions (without leading dot) of input formats.
InkFileExportCmd * file_export()
std::map< std::string, Glib::ustring > & get_menu_label_to_tooltip_map()
InkscapeApplication()
Exclusively for the creation of the singleton instance inside main().
Inkscape::Selection * _active_selection
void detachDesktopToNewWindow(SPDesktop *desktop)
InkActionHintData & get_action_hint_data()
void create_window(Glib::RefPtr< Gio::File > const &file={})
Create a window given a Gio::File.
SPDocument * document_add(std::unique_ptr< SPDocument > document)
std::vector< std::unique_ptr< InkscapeWindow > > _windows
Inkscape::Selection * get_active_selection()
void document_close(SPDocument *document)
Close a document, remove from app.
std::vector< SPDocument * > get_documents()
Get a list of open documents (from document map).
SPDesktop * createDesktop(SPDocument *document, bool replace)
Create a desktop given a document.
InkActionHintData _action_hint_data
int get_number_of_windows() const
Return number of open Inkscape Windows (irrespective of number of documents)
action_vector_t _command_line_actions
void desktopClose(SPDesktop *desktop)
InkscapeWindow * _active_window
The set of selected SPObjects for a given document and layer model.
Definition selection.h:80
To do: update description of desktop.
Definition desktop.h:149
Typed SVG document implementation.
Definition document.h:101
PDF Parsing utility functions and classes.
FontStrategy
Definition enums.h:17
std::vector< std::pair< std::string, Glib::VariantBase > > action_vector_t
Helper class to stream background task notifications as a series of messages.
Enable smart pointers to be used as map keys.
SPDesktop * desktop