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/document-undo.h | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/document-undo.h (limited to 'src/document-undo.h') diff --git a/src/document-undo.h b/src/document-undo.h new file mode 100644 index 0000000..937fa8b --- /dev/null +++ b/src/document-undo.h @@ -0,0 +1,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 // 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 : -- cgit v1.2.3