Code

Partial fix for bug #1824387 [Still asks to save after complete undo]
authorcilix42 <cilix42@users.sourceforge.net>
Tue, 13 Nov 2007 14:27:44 +0000 (14:27 +0000)
committercilix42 <cilix42@users.sourceforge.net>
Tue, 13 Nov 2007 14:27:44 +0000 (14:27 +0000)
src/event-log.cpp
src/event-log.h
src/file.cpp

index 4ee65f3f8417ae9b18c7c295d58b03b4b7b5b04d..4c2ef9c7add8a2a2d9a7c4d9dda76f6a071d0f29 100644 (file)
@@ -13,6 +13,9 @@
 #include "event-log.h"
 #include "inkscape.h"
 #include "util/ucompose.hpp"
+#include "document.h"
+#include "xml/repr.h"
+#include "sp-object.h"
 
 namespace Inkscape {
 
@@ -29,7 +32,7 @@ EventLog::EventLog(SPDocument* document) :
 {
     // add initial pseudo event
     Gtk::TreeRow curr_row = *(_event_list_store->append());
-    _curr_event = _last_event = curr_row;
+    _curr_event = _last_saved = _last_event = curr_row;
     
     curr_row[_columns.description] = _("[Unchanged]");
     curr_row[_columns.type] = SP_VERB_FILE_NEW;
@@ -72,6 +75,8 @@ EventLog::notifyUndoEvent(Event* log)
             }
        }
 
+        checkForVirginity();
+
         // update the view
         if (_connected) {
             (*_callback_connections)[CALLB_SELECTION_CHANGE].block();
@@ -132,6 +137,8 @@ EventLog::notifyRedoEvent(Event* log)
             }
         }
 
+        checkForVirginity();
+
         // update the view
         if (_connected) {
             Gtk::TreePath curr_path = _event_list_store->get_path(_curr_event);
@@ -190,6 +197,8 @@ EventLog::notifyUndoCommitEvent(Event* log)
     curr_row[_columns.type] = event_type;
     curr_row[_columns.description] = log->description;
 
+    checkForVirginity();
+
     // update the view
     if (_connected) {
         Gtk::TreePath curr_path = _event_list_store->get_path(_curr_event);
@@ -350,6 +359,19 @@ EventLog::_clearRedo()
     }
 }
 
+/* mark document as untouched if we reach a state where the document was previously saved */
+void
+EventLog::checkForVirginity() {
+    g_return_if_fail (_document);
+    if (_curr_event == _last_saved) {
+        Inkscape::XML::Node *repr = sp_document_repr_root(_document);
+        bool saved = sp_document_get_undo_sensitive(_document);
+        sp_document_set_undo_sensitive(_document, false);
+        repr->setAttribute("sodipodi:modified", NULL);
+        sp_document_set_undo_sensitive(_document, saved);
+    }
+}
+
 } // namespace Inkscape
 
 
index 33faa57f6595ef1c9a0c3337293490751b10b500..9fcd01e1c7a2b9c45e4d688a3dcd99e9bd237e70 100644 (file)
@@ -87,6 +87,7 @@ public:
     void setCurrEvent(iterator event)          { _curr_event = event; }
     void setCurrEventParent(iterator event)    { _curr_event_parent = event; }
     void blockNotifications(bool status=true)  { _notifications_blocked = status; }
+    void rememberFileSave()                    { _last_saved = _curr_event; }
 
     /* 
      * Callback types for TreeView changes.
@@ -126,6 +127,8 @@ private:
     iterator _last_event;        //< end position in _event_list_store
     iterator _curr_event_parent; //< parent to current event, if any
 
+    iterator _last_saved;        //< position where last document save occurred
+
     bool _notifications_blocked; //< if notifications should be handled
 
     // Map of connections used to temporary block/unblock callbacks in a TreeView
@@ -141,6 +144,8 @@ private:
     void _clearUndo();  //< erase all previously commited events
     void _clearRedo();  //< erase all previously undone events
 
+    void checkForVirginity(); //< marks the document as untouched if undo/redo reaches a previously saved state
+
     // noncopyable, nonassignable
     EventLog(EventLog const &other);
     EventLog& operator=(EventLog const &other);
index 346f17891626e50522d3534da97c834293c0c9a5..748a288e5aacff5e0ac919727fba0b2d0c52ddaa 100644 (file)
@@ -538,6 +538,7 @@ file_save(Gtk::Window &parentWindow, SPDocument *doc, const Glib::ustring &uri,
         return sp_file_save_dialog(parentWindow, doc);
     }
 
+    SP_ACTIVE_DESKTOP->event_log->rememberFileSave();
     SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Document saved."));
     return true;
 }