summaryrefslogtreecommitdiffstats
path: root/src/document-undo.h
blob: 937fa8bd0644055f948129407efafb6078905b28 (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
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
 * TODO: insert short description here
 *//*
 * Authors: see git history
 *
 * Copyright (C) 2018 Authors
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */
#ifndef SEEN_SP_DOCUMENT_UNDO_H
#define SEEN_SP_DOCUMENT_UNDO_H

#include <glib.h>   // gboolean, gchar

namespace Glib {
    class ustring;
}

class SPDocument;

namespace Inkscape {

class DocumentUndo
{
public:

    /**
     * Set undo sensitivity.
     *
     * Don't use this to temporarily turn sensitivity off, use ScopedInsensitive instead.
    */
    static void setUndoSensitive(SPDocument *doc, bool sensitive);

    static bool getUndoSensitive(SPDocument const *document);

    static void clearUndo(SPDocument *document);

    static void clearRedo(SPDocument *document);

    /* undo_icon is only used in History dialog. */
    static void done(SPDocument *document, Glib::ustring const &event_description, Glib::ustring const &undo_icon);

    static void maybeDone(SPDocument *document, const gchar *keyconst, Glib::ustring const &event_description, Glib::ustring const &undo_icon);

private:
    static void finish_incomplete_transaction(SPDocument &document);

    static void perform_document_update(SPDocument &document);

public:
    static void resetKey(SPDocument *document);

    static void cancel(SPDocument *document);

    static gboolean undo(SPDocument *document);

    static gboolean redo(SPDocument *document);

    /**
     * RAII-style mechanism for creating a temporary undo-insensitive context.
     *
     * \verbatim
        {
            DocumentUndo::ScopedInsensitive tmp(document);
            ... do stuff ...
            // "tmp" goes out of scope here and automatically restores undo-sensitivity
        } \endverbatim
     */
    class ScopedInsensitive {
        SPDocument * m_doc;
        bool m_saved;

      public:
        ScopedInsensitive(SPDocument *doc)
            : m_doc(doc)
        {
            m_saved = getUndoSensitive(doc);
            setUndoSensitive(doc, false);
        }
        ~ScopedInsensitive() { setUndoSensitive(m_doc, m_saved); }
    };
};

} // namespace Inkscape

#endif // SEEN_SP_DOCUMENT_UNDO_H

/*
  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:fileencoding=utf-8:textwidth=99 :