summaryrefslogtreecommitdiffstats
path: root/src/document-undo.h
diff options
context:
space:
mode:
authorThomas Holder <thomas@thomas-holder.de>2018-12-14 10:05:39 +0000
committerThomas Holder <thomas@thomas-holder.de>2018-12-14 10:05:39 +0000
commit91112f9d55017b82caa02a3c4673a8420a361801 (patch)
tree6f72e874054ed63bfbab5a2b9e1f34b56d842c53 /src/document-undo.h
parentextract_uri: fix, test, document (diff)
downloadinkscape-91112f9d55017b82caa02a3c4673a8420a361801.tar.gz
inkscape-91112f9d55017b82caa02a3c4673a8420a361801.zip
DocumentUndo::ScopedInsensitive
Diffstat (limited to 'src/document-undo.h')
-rw-r--r--src/document-undo.h37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/document-undo.h b/src/document-undo.h
index 1651bcfba..5ed9db8f6 100644
--- a/src/document-undo.h
+++ b/src/document-undo.h
@@ -14,11 +14,7 @@ namespace Glib {
class ustring;
}
-typedef struct _GObject GObject;
-
-class SPDesktop;
class SPDocument;
-struct InkscapeApplication;
namespace Inkscape {
@@ -29,14 +25,7 @@ public:
/**
* Set undo sensitivity.
*
- * \note
- * Since undo sensitivity needs to be nested, setting undo sensitivity
- * should be done like this:
- *\verbatim
- bool saved = DocumentUndo::getUndoSensitive(document);
- DocumentUndo::setUndoSensitive(document, false);
- ... do stuff ...
- DocumentUndo::setUndoSensitive(document, saved); \endverbatim
+ * Don't use this to temporarily turn sensitivity off, use ScopedInsensitive instead.
*/
static void setUndoSensitive(SPDocument *doc, bool sensitive);
@@ -57,6 +46,30 @@ public:
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