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-undo-document.cpp | 115 ++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/actions/actions-undo-document.cpp (limited to 'src/actions/actions-undo-document.cpp') diff --git a/src/actions/actions-undo-document.cpp b/src/actions/actions-undo-document.cpp new file mode 100644 index 0000000..12e5b7e --- /dev/null +++ b/src/actions/actions-undo-document.cpp @@ -0,0 +1,115 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** \file + * + * Actions for Undo/Redo tied to document. + * + * Authors: + * Tavmjong Bah + * + * Copyright (C) 2021 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include +#include + +#include "actions-undo-document.h" + +#include "document.h" +#include "document-undo.h" +#include "inkscape-application.h" + +// ifdef out for headless operation! +#include "desktop.h" +#include "inkscape-window.h" +#include "ui/widget/canvas.h" + +void +undo(SPDocument* document) +{ + auto app = InkscapeApplication::instance(); + auto win = app->get_active_window(); + if (win) { + // Could be in headless mode. + auto desktop = win->get_desktop(); + // No undo while dragging, too dangerous. + if (desktop->getCanvas()->is_dragging()) { + return; + } + } + + Inkscape::DocumentUndo::undo(document); +} + +void +redo(SPDocument* document) +{ + auto app = InkscapeApplication::instance(); + auto win = app->get_active_window(); + if (win) { + // Could be in headless mode. + auto desktop = win->get_desktop(); + // No redo while dragging, too dangerous. + if (desktop->getCanvas()->is_dragging()) { + return; + } + } + + Inkscape::DocumentUndo::redo(document); +} + + +std::vector> raw_data_undo_document = +{ + // clang-format off + {"doc.undo", N_("Undo"), "Edit Document", N_("Undo last action")}, + {"doc.redo", N_("Redo"), "Edit Document", N_("Do again the last undone action")}, + // clang-format on +}; + +void +add_actions_undo_document(SPDocument* document) +{ + auto group = document->getActionGroup(); + + // clang-format off + group->add_action( "undo", sigc::bind(sigc::ptr_fun(&undo), document)); + group->add_action( "redo", sigc::bind(sigc::ptr_fun(&redo), document)); + // clang-format on + + auto app = InkscapeApplication::instance(); + if (!app) { + std::cerr << "add_actions_undo: no app!" << std::endl; + return; + } + app->get_action_extra_data().add_data(raw_data_undo_document); +} + +std::vector> raw_data_undo_app = +{ + // clang-format off + {"app.undo", N_("Undo"), "Edit Document", N_("Undo last action")}, + {"app.redo", N_("Redo"), "Edit Document", N_("Do again the last undone action")}, + // clang-format on +}; + +void +add_actions_undo_app(InkscapeApplication* app) +{ + auto gapp = app->gio_app(); + gapp->add_action( "undo", [=]{ undo(app->get_active_window()->get_desktop()->getDocument()); }); + gapp->add_action( "redo", [=]{ redo(app->get_active_window()->get_desktop()->getDocument()); }); + app->get_action_extra_data().add_data(raw_data_undo_app); +} + +/* + 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