summaryrefslogtreecommitdiffstats
path: root/src/actions/actions-undo-document.cpp
blob: 12e5b7e462421b76d67a0a5b8aec04da7c17b00b (plain)
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
// 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 <giomm.h>
#include <glibmm/i18n.h>

#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<std::vector<Glib::ustring>> 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<SPDocument*>(sigc::ptr_fun(&undo), document));
    group->add_action( "redo",                            sigc::bind<SPDocument*>(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<std::vector<Glib::ustring>> 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 :