1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
// SPDX-License-Identifier: GPL-2.0-or-later
/** \file
*
* Actions related to View mode
*
* Authors:
* Sushant A A <sushant.co19@gmail.com>
* Tavmjong Bah
*
* Copyright (C) 2021, 2022 Authors
*
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#include <giomm.h>
#include <glibmm/i18n.h>
#include "actions-view-mode.h"
#include "inkscape-application.h"
#include "inkscape-window.h"
#include "object/sp-namedview.h"
#include "ui/monitor.h" // Monitor aspect ratio
#include "ui/widget/canvas.h"
#include "widgets/desktop-widget.h"
// Helper function to set state.
void
canvas_set_state(InkscapeWindow *win, Glib::ustring action_name, bool state)
{
// Get Action
auto action = win->lookup_action(action_name);
if (!action) {
std::cerr << "canvas_set_state: " << action_name << " action missing!" << std::endl;
return;
}
auto saction = Glib::RefPtr<Gio::SimpleAction>::cast_dynamic(action);
if (!saction) {
std::cerr << "canvas_set_state: " << action_name << " not SimpleAction!" << std::endl;
return;
}
// Set State
saction->change_state(state);
}
// Helper function to toggle state.
bool
canvas_toggle_state(InkscapeWindow *win, Glib::ustring action_name)
{
// Get Action
auto action = win->lookup_action(action_name);
if (!action) {
std::cerr << "canvas_toggle_state: " << action_name << " action missing!" << std::endl;
return false;
}
auto saction = Glib::RefPtr<Gio::SimpleAction>::cast_dynamic(action);
if (!saction) {
std::cerr << "canvas_toggle_state: " << action_name << " not SimpleAction!" << std::endl;
return false;
}
// Toggle State
bool state = false;
saction->get_state(state);
state = !state;
saction->change_state(state);
return state;
}
void
canvas_show_grid_toggle(InkscapeWindow *win)
{
// Toggle State
canvas_toggle_state(win, "canvas-show-grid");
// Do Action
SPDesktop* dt = win->get_desktop();
dt->toggleGrids();
}
void
canvas_commands_bar_toggle(InkscapeWindow *win)
{
// Toggle State
canvas_toggle_state(win, "canvas-commands-bar");
// Do Action
SPDesktop* dt = win->get_desktop();
dt->toggleToolbar("commands");
}
void
canvas_snap_controls_bar_toggle(InkscapeWindow *win)
{
// Toggle State
canvas_toggle_state(win, "canvas-snap-controls-bar");
// Do Action
SPDesktop* dt = win->get_desktop();
dt->toggleToolbar("snaptoolbox");
}
void
canvas_tool_control_bar_toggle(InkscapeWindow *win)
{
// Toggle State
canvas_toggle_state(win, "canvas-tool-control-bar");
// Do Action
SPDesktop* dt = win->get_desktop();
dt->toggleToolbar("toppanel");
}
void
canvas_toolbox_toggle(InkscapeWindow *win)
{
// Toggle State
canvas_toggle_state(win, "canvas-toolbox");
// Do Action
SPDesktop* dt = win->get_desktop();
dt->toggleToolbar("toolbox");
}
void
canvas_rulers_toggle(InkscapeWindow *win)
{
// Toggle State
canvas_toggle_state(win, "canvas-rulers");
// Do Action
SPDesktop* dt = win->get_desktop();
dt->toggleToolbar("rulers");
}
void
canvas_scroll_bars(InkscapeWindow *win)
{
// Toggle State
canvas_toggle_state(win, "canvas-scroll-bars");
// Do Action
SPDesktop* dt = win->get_desktop();
dt->toggleToolbar("scrollbars");
}
void
canvas_palette_toggle(InkscapeWindow *win)
{
// Toggle State
canvas_toggle_state(win, "canvas-palette");
// Do Action
SPDesktop* dt = win->get_desktop();
dt->toggleToolbar("panels");
}
void
canvas_statusbar_toggle(InkscapeWindow *win)
{
// Toggle State
canvas_toggle_state(win, "canvas-statusbar");
// Do Action
SPDesktop* dt = win->get_desktop();
dt->toggleToolbar("statusbar");
}
void
canvas_interface_mode(InkscapeWindow *win)
{
// Toggle State
bool state = canvas_toggle_state(win, "canvas-interface-mode");
// Save to preferences
auto prefs = Inkscape::Preferences::get();
Glib::ustring pref_root = "/window/";
auto desktop = win->get_desktop();
if (desktop && desktop->is_focusMode()) {
pref_root = "/focus/";
} else if (desktop && desktop->is_fullscreen()) {
pref_root = "/fullscreen/";
}
prefs->setBool(pref_root + "interface_mode", state);
// Update Interface
auto desktop_widget = win->get_desktop_widget();
desktop_widget->layoutWidgets();
}
void
view_fullscreen(InkscapeWindow *win)
{
SPDesktop* dt = win->get_desktop();
dt->fullscreen();
}
void
view_full_screen_focus(InkscapeWindow *win)
{
SPDesktop* dt = win->get_desktop();
dt->fullscreen();
dt->focusMode(!dt->is_fullscreen());
}
void
view_focus_toggle(InkscapeWindow *win)
{
SPDesktop* dt = win->get_desktop();
dt->focusMode(!dt->is_focusMode());
}
void
canvas_command_palette(InkscapeWindow *win)
{
SPDesktop* dt = win->get_desktop();
dt->toggleCommandPalette();
}
/*
* Sets state of actions (and thus toggle buttons).
* Needed when changing window mode (fullscreen, normal, focus).
*/
void
view_set_gui(InkscapeWindow* win)
{
auto prefs = Inkscape::Preferences::get();
SPDesktop* desktop = win->get_desktop();
if (!desktop) {
std::cerr << "canvas_set_gui: no desktop!" << std::endl;
return;
}
Glib::ustring pref_root = "/window/";
if (desktop && desktop->is_focusMode()) {
pref_root = "/focus/";
} else if (desktop && desktop->is_fullscreen()) {
pref_root = "/fullscreen/";
}
// clang-format off
// Current States of Actions
bool commands_state = prefs->getBool(pref_root + "commands/state", true);
bool snaptoolbox_state = prefs->getBool(pref_root + "snaptoolbox/state", true);
bool toppanel_state = prefs->getBool(pref_root + "toppanel/state", true);
bool toolbox_state = prefs->getBool(pref_root + "toolbox/state", true);
bool palette_state = prefs->getBool(pref_root + "panels/state", true);
bool statusbar_state = prefs->getBool(pref_root + "statusbar/state", true);
bool scrollbars_state = prefs->getBool(pref_root + "scrollbars/state", true);
bool rulers_state = prefs->getBool(pref_root + "rulers/state", true);
bool interface_mode = prefs->getInt(pref_root + "interface_mode", false);
canvas_set_state(win, "canvas-commands-bar", commands_state);
canvas_set_state(win, "canvas-snap-controls-bar", snaptoolbox_state);
canvas_set_state(win, "canvas-tool-control-bar", toppanel_state);
canvas_set_state(win, "canvas-toolbox", toolbox_state);
canvas_set_state(win, "canvas-rulers", rulers_state);
canvas_set_state(win, "canvas-scroll-bars", scrollbars_state);
canvas_set_state(win, "canvas-palette", palette_state);
canvas_set_state(win, "canvas-statusbar", statusbar_state);
// clang-format on
}
std::vector<std::vector<Glib::ustring>> raw_data_view_mode =
{
// clang-format off
{"win.canvas-show-grid", N_("Page Grid"), "Canvas Display", N_("Show or hide the page grid")},
{"win.canvas-commands-bar", N_("Commands Bar"), "Canvas Display", N_("Show or hide the Commands bar (under the menu)")},
{"win.canvas-snap-controls-bar", N_("Snap Controls Bar"), "Canvas Display", N_("Show or hide the snapping controls")},
{"win.canvas-tool-control-bar", N_("Tool Controls Bar"), "Canvas Display", N_("Show or hide the Tool Controls bar")},
{"win.canvas-toolbox", N_("Toolbox"), "Canvas Display", N_("Show or hide the main toolbox (on the left)")},
{"win.canvas-rulers", N_("Rulers"), "Canvas Display", N_("Show or hide the canvas rulers")},
{"win.canvas-scroll-bars", N_("Scroll bars"), "Canvas Display", N_("Show or hide the canvas scrollbars")},
{"win.canvas-palette", N_("Palette"), "Canvas Display", N_("Show or hide the color palette")},
{"win.canvas-statusbar", N_("Statusbar"), "Canvas Display", N_("Show or hide the statusbar (at the bottom of the window)")},
{"win.canvas-command-palette", N_("Command Palette"), "Canvas Display", N_("Show or hide the on-canvas command palette")},
{"win.view-fullscreen", N_("Fullscreen"), "Canvas Display", N_("Stretch this document window to full screen")},
{"win.view-full-screen-focus", N_("Fullscreen & Focus Mode"), "Canvas Display", N_("Stretch this document window to full screen")},
{"win.view-focus-toggle", N_("Focus Mode"), "Canvas Display", N_("Remove excess toolbars to focus on drawing")},
{"win.canvas-interface-mode", N_("Interface Mode"), "Canvas Display", N_("Toggle wide or narrow screen setup")},
// clang-format on
};
void
add_actions_view_mode(InkscapeWindow* win)
{
auto prefs = Inkscape::Preferences::get();
SPDesktop* desktop = win->get_desktop();
if (!desktop) {
std::cerr << "add_actions_view_mode: no desktop!" << std::endl;
}
Glib::ustring pref_root = "/window/";
if (desktop && desktop->is_focusMode()) {
pref_root = "/focus/";
} else if (desktop && desktop->is_fullscreen()) {
pref_root = "/fullscreen/";
}
// Initial States of Actions
// If interface_mode unset, use screen aspect ratio.
Gdk::Rectangle monitor_geometry = Inkscape::UI::get_monitor_geometry_primary();
double const width = monitor_geometry.get_width();
double const height = monitor_geometry.get_height();
bool widescreen = (height > 0 && width/height > 1.65);
widescreen = prefs->getInt(pref_root + "task/taskset", widescreen ? 2 : 0) == 2; // legacy
// clang-format off
bool commands_toggle = prefs->getBool(pref_root + "commands/state", true);
bool snaptoolbox_toggle = prefs->getBool(pref_root + "snaptoolbox/state", true);
bool toppanel_toggle = prefs->getBool(pref_root + "toppanel/state", true);
bool toolbox_toggle = prefs->getBool(pref_root + "toolbox/state", true);
bool rulers_toggle = prefs->getBool(pref_root + "rulers/state", true);
bool scrollbars_toggle = prefs->getBool(pref_root + "scrollbars/state", true);
bool palette_toggle = prefs->getBool(pref_root + "panels/state", true);
bool statusbar_toggle = prefs->getBool(pref_root + "statusbar/state", true);
bool interface_mode = prefs->getBool(pref_root + "interface_mode", widescreen);
win->add_action_bool( "canvas-show-grid", sigc::bind<InkscapeWindow*>(sigc::ptr_fun(&canvas_show_grid_toggle), win));
win->add_action_bool( "canvas-commands-bar", sigc::bind<InkscapeWindow*>(sigc::ptr_fun(&canvas_commands_bar_toggle), win), commands_toggle);
win->add_action_bool( "canvas-snap-controls-bar", sigc::bind<InkscapeWindow*>(sigc::ptr_fun(&canvas_snap_controls_bar_toggle), win), snaptoolbox_toggle);
win->add_action_bool( "canvas-tool-control-bar", sigc::bind<InkscapeWindow*>(sigc::ptr_fun(&canvas_tool_control_bar_toggle), win), toppanel_toggle);
win->add_action_bool( "canvas-toolbox", sigc::bind<InkscapeWindow*>(sigc::ptr_fun(&canvas_toolbox_toggle), win), toolbox_toggle);
win->add_action_bool( "canvas-rulers", sigc::bind<InkscapeWindow*>(sigc::ptr_fun(&canvas_rulers_toggle), win), rulers_toggle);
win->add_action_bool( "canvas-scroll-bars", sigc::bind<InkscapeWindow*>(sigc::ptr_fun(&canvas_scroll_bars), win), scrollbars_toggle);
win->add_action_bool( "canvas-palette", sigc::bind<InkscapeWindow*>(sigc::ptr_fun(&canvas_palette_toggle), win), palette_toggle);
win->add_action_bool( "canvas-statusbar", sigc::bind<InkscapeWindow*>(sigc::ptr_fun(&canvas_statusbar_toggle), win), statusbar_toggle);
win->add_action_bool ( "canvas-interface-mode", sigc::bind<InkscapeWindow*>(sigc::ptr_fun(&canvas_interface_mode), win), interface_mode);
win->add_action( "view-fullscreen", sigc::bind<InkscapeWindow*>(sigc::ptr_fun(&view_fullscreen), win));
win->add_action( "view-full-screen-focus", sigc::bind<InkscapeWindow*>(sigc::ptr_fun(&view_full_screen_focus), win));
win->add_action( "view-focus-toggle", sigc::bind<InkscapeWindow*>(sigc::ptr_fun(&view_focus_toggle), win));
win->add_action( "canvas-command-palette", sigc::bind<InkscapeWindow*>(sigc::ptr_fun(&canvas_command_palette), win));
// clang-format on
auto app = InkscapeApplication::instance();
if (!app) {
std::cerr << "add_actions_view_mode: no app!" << std::endl;
return;
}
app->get_action_extra_data().add_data(raw_data_view_mode);
}
/*
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:fileencoding=utf-8:textwidth=99:
|