Inkscape
Vector Graphics Editor
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages Concepts
actions-pages.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Gio::Actions for pages, mostly for the toolbar.
4 *
5 * Copyright (C) 2021 Martin Owens
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 <iostream>
12
13#include <giomm.h>
14#include <glibmm/i18n.h>
15
16#include "actions-pages.h"
17#include "desktop.h"
18#include "document-undo.h"
20#include "inkscape-window.h"
21#include "page-manager.h"
22#include "preferences.h"
23
24#include "object/sp-page.h"
25#include "ui/icon-names.h"
26
27void page_new(SPDocument *document)
28{
29 document->getPageManager().selectPage(document->getPageManager().newPage());
30 Inkscape::DocumentUndo::done(document, "New Automatic Page", INKSCAPE_ICON("tool-pages"));
31}
32
34{
35 if (auto desktop = window->get_desktop()) {
36 if (auto document = desktop->getDocument()) {
37 page_new(document);
38 document->getPageManager().centerToSelectedPage(desktop);
39 }
40 }
41}
42
43void page_delete(SPDocument *document)
44{
45 // Delete page's content if move_objects is checked.
46 document->getPageManager().deletePage(document->getPageManager().move_objects());
47 Inkscape::DocumentUndo::done(document, "Delete Page", INKSCAPE_ICON("tool-pages"));
48}
49
51{
52 if (auto desktop = window->get_desktop()) {
53 if (auto document = desktop->getDocument()) {
54 page_delete(document);
55 document->getPageManager().centerToSelectedPage(desktop);
56 }
57 }
58}
59
61{
62 auto &page_manager = document->getPageManager();
63 if (auto page = page_manager.getSelected()) {
64 if (page->setPageIndex(page->getPageIndex() - 1, page_manager.move_objects())) {
65 Inkscape::DocumentUndo::done(document, "Shift Page Backwards", INKSCAPE_ICON("tool-pages"));
66 }
67 }
68}
69
70void page_forward(SPDocument *document)
71{
72 auto &page_manager = document->getPageManager();
73 if (auto page = page_manager.getSelected()) {
74 if (page->setPageIndex(page->getPageIndex() + 1, page_manager.move_objects())) {
75 Inkscape::DocumentUndo::done(document, "Shift Page Forewards", INKSCAPE_ICON("tool-pages"));
76 }
77 }
78}
79
81{
82 if (auto action = doc->getActionGroup()->lookup_action("page-move-objects")) {
83 bool active = false;
84 action->get_state(active);
85 active = !active; // toggle
86 action->change_state(active);
87
88 auto prefs = Inkscape::Preferences::get();
89 prefs->setBool("/tools/pages/move_objects", active);
90 } else {
91 g_warning("Can't find page-move-objects action group!");
92 }
93}
94
95const Glib::ustring SECTION = NC_("Action Section", "Page");
96
97std::vector<std::vector<Glib::ustring>> doc_page_actions =
98{
99 // clang-format off
100 {"doc.page-new", N_("New Page"), SECTION, N_("Create a new page") },
101 {"doc.page-delete", N_("Delete Page"), SECTION, N_("Delete the selected page") },
102 {"doc.page-move-objects", N_("Move Objects with Page"), SECTION, N_("Move overlapping objects as the page is moved") },
103 {"doc.page-move-backward", N_("Move Before Previous"), SECTION, N_("Move page backwards in the page order") },
104 {"doc.page-move-forward", N_("Move After Next"), SECTION, N_("Move page forwards in the page order") },
105 // clang-format on
106};
107
109{
111
112 auto group = doc->getActionGroup();
113 group->add_action("page-new", sigc::bind(sigc::ptr_fun(&page_new), doc));
114 group->add_action("page-delete", sigc::bind(sigc::ptr_fun(&page_delete), doc));
115 group->add_action("page-move-backward", sigc::bind(sigc::ptr_fun(&page_backward), doc));
116 group->add_action("page-move-forward", sigc::bind(sigc::ptr_fun(&page_forward), doc));
117 group->add_action_bool("page-move-objects", sigc::bind(sigc::ptr_fun(&set_move_objects), doc),
118 prefs->getBool("/tools/pages/move_objects", true));
119
120 // Note: This will only work for the first ux to load, possible problem.
122 if (!app) { // i.e. Inkview
123 return;
124 }
125 app->get_action_extra_data().add_data(doc_page_actions);
126}
127
128std::vector<std::vector<Glib::ustring>> win_page_actions =
129{
130 // clang-format off
131 {"win.page-new", N_("New Page"), SECTION, N_("Create a new page and center view on it")},
132 {"win.page-delete", N_("Delete Page"), SECTION, N_("Delete the selected page and center view on next page")},
133 // clang-format on
134};
135
137{
138 win->add_action("page-new", sigc::bind(sigc::ptr_fun(&page_new_and_center), win));
139 win->add_action("page-delete", sigc::bind(sigc::ptr_fun(&page_delete_and_center), win));
140
142 app->get_action_extra_data().add_data(win_page_actions);
143}
144
145/*
146 Local Variables:
147 mode:c++
148 c-file-style:"stroustrup"
149 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
150 indent-tabs-mode:nil
151 fill-column:99
152 End:
153*/
154// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
void page_delete(SPDocument *document)
void set_move_objects(SPDocument *doc)
const Glib::ustring SECTION
void page_new_and_center(InkscapeWindow *window)
void page_backward(SPDocument *document)
void add_actions_page_tools(InkscapeWindow *win)
void add_actions_pages(SPDocument *doc)
void page_forward(SPDocument *document)
std::vector< std::vector< Glib::ustring > > win_page_actions
void page_new(SPDocument *document)
std::vector< std::vector< Glib::ustring > > doc_page_actions
void page_delete_and_center(InkscapeWindow *window)
uint64_t page
Definition canvas.cpp:171
static InkscapeApplication * instance()
Singleton instance.
SPDesktop * get_desktop()
static void done(SPDocument *document, Glib::ustring const &event_description, Glib::ustring const &undo_icon, unsigned int object_modified_tag=0)
SPPage * newPage()
Add a new page of the default size, this will be either the size of the viewBox if no pages exist,...
bool selectPage(SPPage *page)
Set the given page as the selected page.
void deletePage(SPPage *page, bool contents=false)
Delete the given page.
static bool move_objects()
Preference storage class.
Definition preferences.h:66
bool getBool(Glib::ustring const &pref_path, bool def=false)
Retrieve a Boolean value.
static Preferences * get()
Access the singleton Preferences object.
SPDocument * getDocument() const
Definition desktop.h:189
Typed SVG document implementation.
Definition document.h:102
Glib::RefPtr< Gio::SimpleActionGroup > getActionGroup()
Definition document.h:371
Inkscape::PageManager & getPageManager()
Definition document.h:163
Editable view implementation.
TODO: insert short description here.
Macro for icon names used in Inkscape.
Inkscape - An SVG editor.
Singleton class to access the preferences file in a convenient way.
SPPage – a page object.
SPDesktop * desktop