X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fdocument-undo.cpp;h=ae1c82e71f4e4d2e02b4ab2e6e480599ac26096f;hb=57eb32794c2df43d60ee8f0a9aa8576567358ce6;hp=226183bda8185752d2a8b6cd62427908ee238084;hpb=c87d0307348fcfdc65b6b4ab6999a3cb0de2431f;p=inkscape.git diff --git a/src/document-undo.cpp b/src/document-undo.cpp index 226183bda..ae1c82e71 100644 --- a/src/document-undo.cpp +++ b/src/document-undo.cpp @@ -7,6 +7,7 @@ * Lauris Kaplinski * MenTaLguY * + * Copyright (C) 2007 MenTaLguY * Copyright (C) 1999-2003 authors * Copyright (C) 2001-2002 Ximian, Inc. * @@ -57,11 +58,14 @@ #if HAVE_STDLIB_H #endif +#include +#include #include "xml/repr.h" #include "document-private.h" #include "inkscape.h" #include "debug/event-tracker.h" #include "debug/simple-event.h" +#include "debug/timestamp.h" #include "event.h" @@ -76,7 +80,7 @@ * should be done like this: *\verbatim bool saved = sp_document_get_undo_sensitive(document); - sp_document_set_undo_sensitive(document, FALSE); + sp_document_set_undo_sensitive(document, false); ... do stuff ... sp_document_set_undo_sensitive(document, saved); \endverbatim */ @@ -86,7 +90,7 @@ sp_document_set_undo_sensitive (SPDocument *doc, bool sensitive) g_assert (doc != NULL); g_assert (doc->priv != NULL); - if ( !(sensitive) == !(doc->priv->sensitive) ) + if ( sensitive == doc->priv->sensitive ) return; if (sensitive) { @@ -98,9 +102,16 @@ sp_document_set_undo_sensitive (SPDocument *doc, bool sensitive) ); } - doc->priv->sensitive = !!sensitive; + doc->priv->sensitive = sensitive; } +/*TODO: Throughout the inkscape code tree set/get_undo_sensitive are used for + * as is shown above. Perhaps it makes sense to create new functions, + * undo_ignore, and undo_recall to replace the start and end parts of the above. + * The main complexity with this is that they have to nest, so you have to store + * the saved bools in a stack. Perhaps this is why the above solution is better. + */ + bool sp_document_get_undo_sensitive(SPDocument const *document) { g_assert(document != NULL); g_assert(document->priv != NULL); @@ -115,10 +126,42 @@ 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 { + +using Inkscape::Debug::Event; +using Inkscape::Debug::SimpleEvent; +using Inkscape::Util::share_static_string; +using Inkscape::Debug::timestamp; +using Inkscape::Verb; + +typedef SimpleEvent InteractionEvent; + +class CommitEvent : public InteractionEvent { +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("%lu", doc->serial()); + _addProperty(share_static_string("document"), serial); + g_free(serial); + Verb *verb = Verb::get(type); + if (verb) { + _addProperty(share_static_string("context"), verb->get_id()); + } + if (key) { + _addProperty(share_static_string("merge-key"), key); + } + } +}; + } void @@ -129,6 +172,8 @@ sp_document_maybe_done (SPDocument *doc, const gchar *key, const unsigned int ev g_assert (doc->priv != NULL); g_assert (doc->priv->sensitive); + Inkscape::Debug::EventTracker tracker(doc, key, event_type); + doc->collectOrphans(); sp_document_ensure_up_to_date (doc); @@ -144,9 +189,8 @@ sp_document_maybe_done (SPDocument *doc, const gchar *key, const unsigned int ev } if (key && doc->actionkey && !strcmp (key, doc->actionkey) && doc->priv->undo) { - doc->priv->undo->data = - new Inkscape::Event(sp_repr_coalesce_log (((Inkscape::Event *) - doc->priv->undo->data)->event, log)); + ((Inkscape::Event *)doc->priv->undo->data)->event = + sp_repr_coalesce_log (((Inkscape::Event *)doc->priv->undo->data)->event, log); } else { Inkscape::Event *event = new Inkscape::Event(log, event_type, event_description); doc->priv->undo = g_slist_prepend (doc->priv->undo, event); @@ -157,9 +201,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->setModifiedSinceSave(); sp_repr_begin_transaction (doc->rdoc); @@ -184,29 +226,27 @@ 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) { g_warning ("Incomplete undo transaction:"); priv.partial = sp_repr_coalesce_log(priv.partial, log); sp_repr_debug_print_log(priv.partial); - priv.undo = g_slist_prepend(priv.undo, priv.partial); + Inkscape::Event *event = new Inkscape::Event(priv.partial); + priv.undo = g_slist_prepend(priv.undo, event); + priv.undoStackObservers.notifyUndoCommitEvent(event); priv.partial = NULL; } } -} - -bool +gboolean sp_document_undo (SPDocument *doc) { using Inkscape::Debug::EventTracker; using Inkscape::Debug::SimpleEvent; - bool ret; + gboolean ret; EventTracker > tracker("undo"); @@ -215,6 +255,7 @@ sp_document_undo (SPDocument *doc) g_assert (doc->priv->sensitive); doc->priv->sensitive = FALSE; + doc->priv->seeking = true; doc->actionkey = NULL; @@ -226,7 +267,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; @@ -237,6 +278,7 @@ sp_document_undo (SPDocument *doc) sp_repr_begin_transaction (doc->rdoc); doc->priv->sensitive = TRUE; + doc->priv->seeking = false; if (ret) inkscape_external_change(); @@ -244,13 +286,13 @@ sp_document_undo (SPDocument *doc) return ret; } -bool +gboolean sp_document_redo (SPDocument *doc) { using Inkscape::Debug::EventTracker; using Inkscape::Debug::SimpleEvent; - bool ret; + gboolean ret; EventTracker > tracker("redo"); @@ -259,6 +301,7 @@ sp_document_redo (SPDocument *doc) g_assert (doc->priv->sensitive); doc->priv->sensitive = FALSE; + doc->priv->seeking = true; doc->actionkey = NULL; @@ -270,7 +313,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; @@ -281,6 +324,7 @@ sp_document_redo (SPDocument *doc) sp_repr_begin_transaction (doc->rdoc); doc->priv->sensitive = TRUE; + doc->priv->seeking = false; if (ret) inkscape_external_change(); @@ -291,6 +335,9 @@ sp_document_redo (SPDocument *doc) void sp_document_clear_undo (SPDocument *doc) { + if (doc->priv->undo) + doc->priv->undoStackObservers.notifyClearUndoEvent(); + while (doc->priv->undo) { GSList *current; @@ -306,6 +353,9 @@ sp_document_clear_undo (SPDocument *doc) void sp_document_clear_redo (SPDocument *doc) { + if (doc->priv->redo) + doc->priv->undoStackObservers.notifyClearRedoEvent(); + while (doc->priv->redo) { GSList *current;