Code

abstract use of sodipodi:modified
[inkscape.git] / src / document-undo.cpp
index 53c272566af1e33faa0ae0d272eb3a4c070f8eb3..2acd740f2022b5e45216d38b1443fc71bf349818 100644 (file)
 #include "debug/timestamp.h"
 #include "event.h"
 
+bool SPDocument::isModified() const {
+    return rroot ? rroot->attribute("sodipodi:modified") != NULL : false;
+}
+void SPDocument::setModified(bool modified) {
+    if (rroot) {
+        rroot->setAttribute("sodipodi:modified", "true");
+    }
+}
+
 
 /*
  * Undo & redo
@@ -124,10 +133,10 @@ sp_document_done (SPDocument *doc, const unsigned int event_type, Glib::ustring
 }
 
 void
-sp_document_reset_key (Inkscape::Application */*inkscape*/, SPDesktop *desktop, GtkObject *base)
+sp_document_reset_key (Inkscape::Application */*inkscape*/, SPDesktop */*desktop*/, GtkObject *base)
 {
-       SPDocument *doc = (SPDocument *) base;
-       doc->actionkey = NULL;
+    SPDocument *doc = (SPDocument *) base;
+    doc->actionkey = NULL;
 }
 
 namespace {
@@ -146,7 +155,7 @@ public:
     CommitEvent(SPDocument *doc, const gchar *key, const unsigned int type)
     : InteractionEvent(share_static_string("commit"))
     {
-        _addProperty(share_static_string("timestamp"), timestamp()); 
+        _addProperty(share_static_string("timestamp"), timestamp());
         gchar *serial = g_strdup_printf("%lu", doc->serial());
         _addProperty(share_static_string("document"), serial);
         g_free(serial);
@@ -199,9 +208,7 @@ sp_document_maybe_done (SPDocument *doc, const gchar *key, const unsigned int ev
        doc->actionkey = key;
 
        doc->virgin = FALSE;
-       if (!doc->rroot->attribute("sodipodi:modified")) {
-               doc->rroot->setAttribute("sodipodi:modified", "true");
-       }
+        doc->setModified();
 
        sp_repr_begin_transaction (doc->rdoc);
 
@@ -267,7 +274,7 @@ sp_document_undo (SPDocument *doc)
                sp_repr_undo_log (log->event);
                doc->priv->redo = g_slist_prepend (doc->priv->redo, log);
 
-               doc->rroot->setAttribute("sodipodi:modified", "true");
+                doc->setModified();
                 doc->priv->undoStackObservers.notifyUndoEvent(log);
 
                ret = TRUE;
@@ -313,7 +320,7 @@ sp_document_redo (SPDocument *doc)
                sp_repr_replay_log (log->event);
                doc->priv->undo = g_slist_prepend (doc->priv->undo, log);
 
-               doc->rroot->setAttribute("sodipodi:modified", "true");
+                doc->setModified();
                doc->priv->undoStackObservers.notifyRedoEvent(log);
 
                ret = TRUE;