From cca66b9ec4e494c1d919bff0f71a820d8afab1fa Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:24:48 +0200 Subject: Adding upstream version 1.2.2. Signed-off-by: Daniel Baumann --- src/actions/actions-pages.cpp | 113 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/actions/actions-pages.cpp (limited to 'src/actions/actions-pages.cpp') diff --git a/src/actions/actions-pages.cpp b/src/actions/actions-pages.cpp new file mode 100644 index 0000000..50bd820 --- /dev/null +++ b/src/actions/actions-pages.cpp @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Gio::Actions for pages, mostly for the toolbar. + * + * Copyright (C) 2021 Martin Owens + * + * The contents of this file may be used under the GNU General Public License Version 2 or later. + * + */ + +#include + +#include +#include + +#include "actions-pages.h" +#include "inkscape-application.h" +#include "document-undo.h" + +#include "page-manager.h" +#include "object/sp-page.h" +#include "ui/icon-names.h" + +void page_new(SPDocument *document) +{ + document->getPageManager().selectPage(document->getPageManager().newPage()); + Inkscape::DocumentUndo::done(document, "New Automatic Page", INKSCAPE_ICON("tool-pages")); +} + +void page_delete(SPDocument *document) +{ + // Delete page's content if move_objects is checked. + document->getPageManager().deletePage(document->getPageManager().move_objects()); + Inkscape::DocumentUndo::done(document, "Delete Page", INKSCAPE_ICON("tool-pages")); +} + +void page_backward(SPDocument *document) +{ + auto &page_manager = document->getPageManager(); + if (auto page = page_manager.getSelected()) { + if (page->setPageIndex(page->getPageIndex() - 1, page_manager.move_objects())) { + Inkscape::DocumentUndo::done(document, "Shift Page Backwards", INKSCAPE_ICON("tool-pages")); + } + } +} + +void page_forward(SPDocument *document) +{ + auto &page_manager = document->getPageManager(); + if (auto page = page_manager.getSelected()) { + if (page->setPageIndex(page->getPageIndex() + 1, page_manager.move_objects())) { + Inkscape::DocumentUndo::done(document, "Shift Page Forewards", INKSCAPE_ICON("tool-pages")); + } + } +} + +void set_move_objects(SPDocument *doc) +{ + if (auto action = doc->getActionGroup()->lookup_action("page-move-objects")) { + bool active = false; + action->get_state(active); + active = !active; // toggle + action->change_state(active); + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setBool("/tools/pages/move_objects", active); + } else { + g_warning("Can't find page-move-objects action group!"); + } +} + +std::vector> raw_data_actions = +{ + // clang-format off + {"doc.page-new", N_("New Page"), "Page", N_("Create a new page") }, + {"doc.page-delete", N_("Delete Page"), "Page", N_("Delete the selected page") }, + {"doc.page-move-objects", N_("Move Objects with Page"), "Page", N_("Move overlapping objects as the page is moved.") }, + {"doc.page-move-backward", N_("Move Before Previous"), "Page", N_("Move page backwards in the page order") }, + {"doc.page-move-forward", N_("Move After Next"), "Page", N_("Move page forwards in the page order") }, + // clang-format on +}; + +void add_actions_pages(SPDocument* doc) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + + auto group = doc->getActionGroup(); + group->add_action("page-new", sigc::bind(sigc::ptr_fun(&page_new), doc)); + group->add_action("page-delete", sigc::bind(sigc::ptr_fun(&page_delete), doc)); + group->add_action("page-move-backward", sigc::bind(sigc::ptr_fun(&page_backward), doc)); + group->add_action("page-move-forward", sigc::bind(sigc::ptr_fun(&page_forward), doc)); + group->add_action_bool("page-move-objects", sigc::bind(sigc::ptr_fun(&set_move_objects), doc), + prefs->getBool("/tools/pages/move_objects", true)); + + // Note: This will only work for the first ux to load, possible problem. + auto app = InkscapeApplication::instance(); + if (!app) { + std::cerr << "add_actions_pages: no app!" << std::endl; + return; + } + app->get_action_extra_data().add_data(raw_data_actions); +} + +/* + 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 : -- cgit v1.2.3