Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
actions-window.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Gio::Actions for window handling tied to the application and with GUI.
4 *
5 * Copyright (C) 2020 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-window.h"
12
13#include <giomm.h> // Not <gtkmm.h>! To eventually allow a headless version!
14#include <glibmm/i18n.h>
15
16#include "actions-helper.h"
17#include "desktop.h"
18#include "document.h"
20#include "inkscape-window.h"
22
23// Actions for window handling (should be integrated with file dialog).
24
25// Open a window for current document
27{
28 auto document = app->get_active_document();
29 if (document) {
30 auto desktop = app->get_active_desktop();
32 // We have a tab with an untouched template document, use this tab.
33 app->document_swap(desktop, document);
34 } else {
35 app->desktopOpen(document);
36 }
37 } else {
38 show_output("window_open(): failed to find document!");
39 }
40}
41
43{
44 if (auto window = app->get_active_window()) {
45 if (auto desktop = window->get_desktop()) {
46 auto const [w, h] = desktop->getWindowSize();
47 show_output(Glib::ustring("w:") + Inkscape::ustring::format_classic(w), false);
48 show_output(Glib::ustring("h:") + Inkscape::ustring::format_classic(h), false);
49 }
50 } else {
51 show_output("this action needs active window, probably you need to add --active-window / -q");
52 }
53}
54
55void
56window_set_geometry(const Glib::VariantBase& value, InkscapeApplication *app)
57{
58 Glib::Variant<Glib::ustring> s = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring> >(value);
59
60 std::vector<Glib::ustring> tokens = Glib::Regex::split_simple(",", s.get());
61 if (tokens.size() != 4) {
62 show_output("action:set geometry: requires 'x, y, width, height'");
63 return;
64 }
65 if (auto window = app->get_active_window()) {
66 if (auto desktop = window->get_desktop()) {
67 if (desktop->is_maximized()) {
68 desktop->getInkscapeWindow()->unmaximize();
69 }
70 int w = std::stoi(tokens[2]);
71 int h = std::stoi(tokens[3]);
72 desktop->setWindowSize({w, h});
73 }
74 } else {
75 show_output("this action needs active window, probably you need to add --active-window / -q");
76 }
77}
78
79void
84
85std::vector<std::vector<Glib::ustring>> hint_data_window =
86{
87 // clang-format off
88 {"app.window-set-geometry", N_("Enter comma-separated string for x, y, width, height") }
89 // clang-format on
90};
91
92const Glib::ustring SECTION = NC_("Action Section", "Window");
93
94std::vector<std::vector<Glib::ustring>> raw_data_window =
95{
96 // clang-format off
97 {"app.window-open", N_("Window Open"), SECTION, N_("Open a window for the active document; GUI only") },
98 {"app.window-close", N_("Window Close"), SECTION, N_("Close the active window, does not check for data loss") },
99 {"app.window-query-geometry", N_("Window Query Geometry"), SECTION, N_("Query the active window's location and size") },
100 {"app.window-set-geometry", N_("Window Set Geometry"), SECTION, N_("Set the active window's location and size (x, y, width, height)") },
101 {"app.window-crash", N_("Force Crash"), SECTION, N_("Force Inkscape to crash, useful for testing.") },
102 // clang-format on
103};
104
105void
107{
108 auto *gapp = app->gio_app();
109 Glib::VariantType String(Glib::VARIANT_TYPE_STRING);
110 // clang-format off
111 gapp->add_action( "window-open", sigc::bind(sigc::ptr_fun(&window_open), app));
112 gapp->add_action( "window-close", sigc::bind(sigc::ptr_fun(&window_close), app));
113 gapp->add_action( "window-query-geometry", sigc::bind(sigc::ptr_fun(&window_query_geometry), app));
114 gapp->add_action_with_parameter( "window-set-geometry", String, sigc::bind(sigc::ptr_fun(&window_set_geometry), app));
115 gapp->add_action("window-crash", [=](){
116 abort();
117 });
118 // clang-format on
119
122}
123
124
125/*
126 Local Variables:
127 mode:c++
128 c-file-style:"stroustrup"
129 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
130 indent-tabs-mode:nil
131 fill-column:99
132 End:
133*/
134// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
void show_output(Glib::ustring const &data, bool const is_cerr)
void window_query_geometry(InkscapeApplication *app)
std::vector< std::vector< Glib::ustring > > hint_data_window
const Glib::ustring SECTION
void window_open(InkscapeApplication *app)
void add_actions_window(InkscapeApplication *app)
void window_set_geometry(const Glib::VariantBase &value, InkscapeApplication *app)
void window_close(InkscapeApplication *app)
std::vector< std::vector< Glib::ustring > > raw_data_window
void add_data(std::vector< std::vector< Glib::ustring > > const &raw_data)
void add_data(std::vector< std::vector< Glib::ustring > > &raw_data)
InkActionExtraData & get_action_extra_data()
InkscapeWindow * get_active_window()
bool document_swap(SPDesktop *desktop, SPDocument *document)
Swap out one document for another in a tab.
Gio::Application * gio_app()
The Gio application instance, never NULL.
SPDesktop * get_active_desktop()
SPDocument * get_active_document()
SPDesktop * desktopOpen(SPDocument *document)
InkActionHintData & get_action_hint_data()
SPDocument * getDocument() const
Definition desktop.h:189
InkscapeWindow const * getInkscapeWindow() const
Definition desktop.cpp:975
void setWindowSize(Geom::IntPoint const &size)
Definition desktop.cpp:965
Geom::IntPoint getWindowSize() const
Definition desktop.cpp:960
bool is_maximized() const
Definition desktop.cpp:924
bool getVirgin()
Definition document.h:135
const double w
Definition conic-4.cpp:19
Editable view implementation.
Inkscape - An SVG editor.
Glib::ustring format_classic(T const &... args)
SPDesktop * desktop