Code

Fix self-snapping when dragging the transformation center of a selection containing...
[inkscape.git] / src / document-undo.cpp
index 0f0a606a1253237954f69e3ddd462150c3ec4c90..e63fe8a529c552e19f12a82419d4ef6a1635f8f1 100644 (file)
@@ -58,6 +58,8 @@
 #if HAVE_STDLIB_H
 #endif
 
+#include <string>
+#include <cstring>
 #include "xml/repr.h"
 #include "document-private.h"
 #include "inkscape.h"
@@ -123,11 +125,10 @@ sp_document_done (SPDocument *doc, const unsigned int event_type, Glib::ustring
         sp_document_maybe_done (doc, NULL, event_type, event_description);
 }
 
-void
-sp_document_reset_key (Inkscape::Application *inkscape, SPDesktop *desktop, GtkObject *base)
+void sp_document_reset_key( Inkscape::Application * /*inkscape*/, SPDesktop * /*desktop*/, GtkObject *base )
 {
-       SPDocument *doc = (SPDocument *) base;
-       doc->actionkey = NULL;
+    SPDocument *doc = reinterpret_cast<SPDocument *>(base);
+    doc->actionkey.clear();
 }
 
 namespace {
@@ -146,8 +147,8 @@ public:
     CommitEvent(SPDocument *doc, const gchar *key, const unsigned int type)
     : InteractionEvent(share_static_string("commit"))
     {
-        _addProperty(share_static_string("timestamp"), timestamp()); 
-        gchar *serial = g_strdup_printf("%ul", doc->serial());
+        _addProperty(share_static_string("timestamp"), timestamp());
+        gchar *serial = g_strdup_printf("%lu", doc->serial());
         _addProperty(share_static_string("document"), serial);
         g_free(serial);
         Verb *verb = Verb::get(type);
@@ -169,6 +170,9 @@ sp_document_maybe_done (SPDocument *doc, const gchar *key, const unsigned int ev
        g_assert (doc != NULL);
        g_assert (doc->priv != NULL);
        g_assert (doc->priv->sensitive);
+        if ( key && !*key ) {
+            g_warning("Blank undo key specified.");
+        }
 
         Inkscape::Debug::EventTracker<CommitEvent> tracker(doc, key, event_type);
 
@@ -186,7 +190,7 @@ sp_document_maybe_done (SPDocument *doc, const gchar *key, const unsigned int ev
                return;
        }
 
-       if (key && doc->actionkey && !strcmp (key, doc->actionkey) && doc->priv->undo) {
+       if (key && !doc->actionkey.empty() && (doc->actionkey == key) && doc->priv->undo) {
                 ((Inkscape::Event *)doc->priv->undo->data)->event =
                     sp_repr_coalesce_log (((Inkscape::Event *)doc->priv->undo->data)->event, log);
        } else {
@@ -196,12 +200,14 @@ sp_document_maybe_done (SPDocument *doc, const gchar *key, const unsigned int ev
                doc->priv->undoStackObservers.notifyUndoCommitEvent(event);
        }
 
-       doc->actionkey = key;
+        if ( key ) {
+            doc->actionkey = key;
+        } else {
+            doc->actionkey.clear();
+        }
 
        doc->virgin = FALSE;
-       if (!doc->rroot->attribute("sodipodi:modified")) {
-               doc->rroot->setAttribute("sodipodi:modified", "true");
-       }
+        doc->setModifiedSinceSave();
 
        sp_repr_begin_transaction (doc->rdoc);
 
@@ -226,9 +232,7 @@ sp_document_cancel (SPDocument *doc)
        sp_repr_begin_transaction (doc->rdoc);
 }
 
-namespace {
-
-void finish_incomplete_transaction(SPDocument &doc) {
+static void finish_incomplete_transaction(SPDocument &doc) {
        SPDocumentPrivate &priv=*doc.priv;
        Inkscape::XML::Event *log=sp_repr_commit_undoable(doc.rdoc);
        if (log || priv.partial) {
@@ -242,8 +246,6 @@ void finish_incomplete_transaction(SPDocument &doc) {
        }
 }
 
-}
-
 gboolean
 sp_document_undo (SPDocument *doc)
 {
@@ -261,7 +263,7 @@ sp_document_undo (SPDocument *doc)
        doc->priv->sensitive = FALSE;
         doc->priv->seeking = true;
 
-       doc->actionkey = NULL;
+       doc->actionkey.clear();
 
        finish_incomplete_transaction(*doc);
 
@@ -271,7 +273,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->setModifiedSinceSave();
                 doc->priv->undoStackObservers.notifyUndoEvent(log);
 
                ret = TRUE;
@@ -307,7 +309,7 @@ sp_document_redo (SPDocument *doc)
        doc->priv->sensitive = FALSE;
         doc->priv->seeking = true;
 
-       doc->actionkey = NULL;
+       doc->actionkey.clear();
 
        finish_incomplete_transaction(*doc);
 
@@ -317,7 +319,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->setModifiedSinceSave();
                doc->priv->undoStackObservers.notifyRedoEvent(log);
 
                ret = TRUE;