Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
actions-undo-document.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
14#include <giomm.h>
15#include <glibmm/i18n.h>
16
18#include "actions-helper.h"
19
20#include "document.h"
21#include "document-undo.h"
23
24// ifdef out for headless operation!
25#include "desktop.h"
26#include "inkscape-window.h"
27#include "ui/tools/tool-base.h"
28#include "ui/widget/canvas.h"
29
30void
31undo(SPDocument* document)
32{
34 auto win = app->get_active_window();
35
36 // Undo can be used in headless mode.
37 if (win) {
38 auto desktop = win->get_desktop();
39
40 // No undo while dragging, or if the tool handled this undo.
41 if (desktop->getCanvas()->is_dragging()) {
42 return;
43 }
44 }
45
47}
48
49void
50redo(SPDocument* document)
51{
53 auto win = app->get_active_window();
54
55 // Redo can be used in headless mode.
56 if (win) {
57 auto desktop = win->get_desktop();
58
59 // No redo while dragging, or if the tool handled this redo
60 if (desktop->getCanvas()->is_dragging()) {
61 return;
62 }
63 }
64
66}
67
68void
70{
71 auto group = document->getActionGroup();
72 if (!group)
73 return;
74 auto undo_action = group->lookup_action("undo");
75 auto redo_action = group->lookup_action("redo");
76 auto undo_saction = std::dynamic_pointer_cast<Gio::SimpleAction>(undo_action);
77 auto redo_saction = std::dynamic_pointer_cast<Gio::SimpleAction>(redo_action);
78 // GTK4
79 // auto undo_saction = dynamic_cast<Gio::SimpleAction*>(undo_action);
80 // auto redo_saction = dynamic_cast<Gio::SimpleAction*>(redo_action);
81 if (!undo_saction || !redo_saction) {
82 show_output("UndoActions: can't find undo or redo action!");
83 return;
84 }
85 // Enable/disable menu items.
86 undo_saction->set_enabled(undo);
87 redo_saction->set_enabled(redo);
88}
89
90const Glib::ustring SECTION = NC_("Action Section", "Edit Document");
91
92std::vector<std::vector<Glib::ustring>> raw_data_undo_document =
93{
94 // clang-format off
95 {"doc.undo", N_("Undo"), SECTION, N_("Undo last action")},
96 {"doc.redo", N_("Redo"), SECTION, N_("Do again the last undone action")},
97 // clang-format on
98};
99
100void
102{
103 auto group = document->getActionGroup();
104
105 // clang-format off
106 group->add_action( "undo", sigc::bind(sigc::ptr_fun(&undo), document));
107 group->add_action( "redo", sigc::bind(sigc::ptr_fun(&redo), document));
108 // clang-format on
109
111 if (!app) { // i.e. Inkview
112 return;
113 }
114 app->get_action_extra_data().add_data(raw_data_undo_document);
115}
116
117/*
118 Local Variables:
119 mode:c++
120 c-file-style:"stroustrup"
121 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
122 indent-tabs-mode:nil
123 fill-column:99
124 End:
125*/
126// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
void show_output(Glib::ustring const &data, bool const is_cerr)
void undo(SPDocument *document)
void add_actions_undo_document(SPDocument *document)
const Glib::ustring SECTION
std::vector< std::vector< Glib::ustring > > raw_data_undo_document
void enable_undo_actions(SPDocument *document, bool undo, bool redo)
void redo(SPDocument *document)
Actions for Undo/Redo tied to document.
Inkscape canvas widget.
static InkscapeApplication * instance()
Singleton instance.
static gboolean redo(SPDocument *document)
static gboolean undo(SPDocument *document)
Inkscape::UI::Widget::Canvas * getCanvas() const
Definition desktop.h:190
Typed SVG document implementation.
Definition document.h:101
Glib::RefPtr< Gio::SimpleActionGroup > getActionGroup()
Definition document.h:371
Editable view implementation.
TODO: insert short description here.
Inkscape - An SVG editor.
SPDesktop * desktop