Code

Notify UndoStackObservers on commited incomplete transactions and sp_document_{undo...
authorgustav_b <gustav_b@users.sourceforge.net>
Thu, 29 Mar 2007 23:02:20 +0000 (23:02 +0000)
committergustav_b <gustav_b@users.sourceforge.net>
Thu, 29 Mar 2007 23:02:20 +0000 (23:02 +0000)
see #1684042.

src/composite-undo-stack-observer.cpp
src/composite-undo-stack-observer.h
src/console-output-undo-observer.cpp
src/console-output-undo-observer.h
src/document-undo.cpp
src/event-log.cpp
src/event-log.h
src/undo-stack-observer.h

index 85d7aed13242d58f4706c892a18c7ec6e1562aee..03e4796bd4526be23a3448d42f471d3dd8de3a88 100644 (file)
@@ -79,6 +79,30 @@ CompositeUndoStackObserver::notifyUndoCommitEvent(Event* log)
        this->_unlock();
 }
 
+void
+CompositeUndoStackObserver::notifyClearUndoEvent()
+{
+       this->_lock();
+       for(UndoObserverRecordList::iterator i = this->_active.begin(); i != _active.end(); ++i) {
+               if (!i->to_remove) {
+                       i->issueClearUndo();
+               }
+       }
+       this->_unlock();
+}
+
+void
+CompositeUndoStackObserver::notifyClearRedoEvent()
+{
+       this->_lock();
+       for(UndoObserverRecordList::iterator i = this->_active.begin(); i != _active.end(); ++i) {
+               if (!i->to_remove) {
+                       i->issueClearRedo();
+               }
+       }
+       this->_unlock();
+}
+
 bool
 CompositeUndoStackObserver::_remove_one(UndoObserverRecordList& list, UndoStackObserver& o)
 {
index 7e45ccae4f01e24087184f040118fd8d85cd9945..e24561ace61ca5467887c77fea9b2f2227ea4258 100644 (file)
@@ -85,6 +85,26 @@ public:
                        this->_observer.notifyUndoCommitEvent(log);
                }
 
+               /**
+                * Issue a clear undo event to the UndoStackObserver
+                * that is associated with this
+                * UndoStackObserverRecord.
+                */
+               void issueClearUndo()
+               {
+                       this->_observer.notifyClearUndoEvent();
+               }
+            
+               /**
+                * Issue a clear redo event to the UndoStackObserver
+                * that is associated with this
+                * UndoStackObserverRecord.
+                */
+               void issueClearRedo()
+               {
+                       this->_observer.notifyClearRedoEvent();
+               }
+
        private:
                UndoStackObserver& _observer;
        };
@@ -134,6 +154,9 @@ public:
         */
        void notifyUndoCommitEvent(Event* log);
 
+       virtual void notifyClearUndoEvent();
+       virtual void notifyClearRedoEvent();
+
 private:
        // Remove an observer from a given list
        bool _remove_one(UndoObserverRecordList& list, UndoStackObserver& rec);
index 7035e89feb1fb7450b2cabc7915ecaa2eb9d30fd..98e6c69a66206b98beb0e1205b050bc47e54de92 100644 (file)
@@ -34,6 +34,18 @@ ConsoleOutputUndoObserver::notifyUndoCommitEvent(Event* log)
     //g_message("notifyUndoCommitEvent (sp_document_maybe_done) called; log=%p\n", log->event);
 }
 
+void
+ConsoleOutputUndoObserver::notifyClearUndoEvent()
+{
+    //g_message("notifyClearUndoEvent (sp_document_clear_undo) called);
+}
+
+void
+ConsoleOutputUndoObserver::notifyClearRedoEvent()
+{
+    //g_message("notifyClearRedoEvent (sp_document_clear_redo) called);
+}
+
 }
 
 /*
index 32149c15dc012b13b83d5d68e2897938826a11ee..b6fec7f326b634f7ccca712b34f2afb775241043 100644 (file)
@@ -25,6 +25,8 @@ public:
     void notifyUndoEvent(Event* log);
     void notifyRedoEvent(Event* log);
     void notifyUndoCommitEvent(Event* log);
+    void notifyClearUndoEvent();
+    void notifyClearRedoEvent();
 
 };
 }
index 47d56ca662bb0f0d088d758f4a1fff1d529dd85f..f37b53f89c5d89c228d78dd5b9eb67c61aa3aeff 100644 (file)
@@ -201,7 +201,9 @@ void finish_incomplete_transaction(SPDocument &doc) {
                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, new Inkscape::Event(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;
        }
 }
@@ -303,6 +305,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;
 
@@ -318,6 +323,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;
 
index d6bc99bea8a34e195cb2c0331413bc0136d5c355..4ee65f3f8417ae9b18c7c295d58b03b4b7b5b04d 100644 (file)
@@ -2,7 +2,7 @@
  * Author:
  *   Gustav Broberg <broberg@kth.se>
  *
- * Copyright (c) 2006 Authors
+ * Copyright (c) 2006, 2007 Authors
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
@@ -155,34 +155,7 @@ EventLog::notifyRedoEvent(Event* log)
 void 
 EventLog::notifyUndoCommitEvent(Event* log)
 {
-    // If we're not at the last event in list then erase the previously undone events 
-    if ( _last_event != _curr_event ) {
-
-        _last_event = _curr_event;
-
-        if ( !_last_event->children().empty() ) {
-            _last_event = _last_event->children().begin();
-        } else {
-            ++_last_event;
-        }
-
-        while ( _last_event != _event_list_store->children().end() ) {
-
-            if (_last_event->parent()) {
-                while ( _last_event != _last_event->parent()->children().end() ) {
-                    _last_event = _event_list_store->erase(_last_event);
-                }
-                _last_event = _last_event->parent();
-
-                (*_last_event)[_columns.child_count] = _last_event->children().size() + 1;
-
-                ++_last_event;
-            } else {
-                _last_event = _event_list_store->erase(_last_event);
-            }
-
-        }
-    }
+    _clearRedo();
 
     const unsigned int event_type = log->type;
 
@@ -235,6 +208,20 @@ EventLog::notifyUndoCommitEvent(Event* log)
     updateUndoVerbs();
 }
 
+void
+EventLog::notifyClearUndoEvent()
+{
+    _clearUndo();    
+    updateUndoVerbs();
+}
+
+void
+EventLog::notifyClearRedoEvent()
+{
+    _clearRedo();
+    updateUndoVerbs();
+}
+
 void 
 EventLog::connectWithDialog(Gtk::TreeView *event_list_view, CallbackMap *callback_connections)
 {
@@ -324,8 +311,48 @@ EventLog::_getRedoEvent() const
     return redo_event;
 }
 
+void
+EventLog::_clearUndo()
+{
+    // TODO: Implement when needed
+}
+
+void
+EventLog::_clearRedo()
+{
+    if ( _last_event != _curr_event ) {
+
+        _last_event = _curr_event;
+
+        if ( !_last_event->children().empty() ) {
+            _last_event = _last_event->children().begin();
+        } else {
+            ++_last_event;
+        }
+
+        while ( _last_event != _event_list_store->children().end() ) {
+
+            if (_last_event->parent()) {
+                while ( _last_event != _last_event->parent()->children().end() ) {
+                    _last_event = _event_list_store->erase(_last_event);
+                }
+                _last_event = _last_event->parent();
+
+                (*_last_event)[_columns.child_count] = _last_event->children().size() + 1;
+
+                ++_last_event;
+            } else {
+                _last_event = _event_list_store->erase(_last_event);
+            }
+
+        }
+
+    }
 }
 
+} // namespace Inkscape
+
+
 /*
   Local Variables:
   mode:c++
index 02cfa4b9a2560ecd5d245b970e78be8570932e73..a618f0467e0a1b7e84fce9dba1c08231b0649075 100644 (file)
@@ -16,7 +16,7 @@
  * Author:
  *   Gustav Broberg <broberg@kth.se>
  *
- * Copyright (c) 2006 Authors
+ * Copyright (c) 2006, 2007 Authors
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
@@ -72,6 +72,8 @@ public:
     void notifyUndoEvent(Event *log);
     void notifyRedoEvent(Event *log);
     void notifyUndoCommitEvent(Event *log);
+    void notifyClearUndoEvent();
+    void notifyClearRedoEvent();
 
     /**
      * Accessor functions
@@ -116,10 +118,6 @@ private:
 
     const EventModelColumns _columns;
 
-    /**
-     * Helper functions for initialization
-     */
-
     Glib::RefPtr<Gtk::TreeStore> _event_list_store; 
     Glib::RefPtr<Gtk::TreeSelection> _event_list_selection;
     Gtk::TreeView *_event_list_view;
@@ -133,9 +131,16 @@ private:
     // Map of connections used to temporary block/unblock callbacks in a TreeView
     CallbackMap *_callback_connections;
 
+    /**
+     * Helper functions
+     */
+
     const_iterator _getUndoEvent() const; //< returns the current undoable event or NULL if none
     const_iterator _getRedoEvent() const; //< returns the current redoable event or NULL if none
 
+    void _clearUndo();  //< erase all previously commited events
+    void _clearRedo();  //< erase all previously undone events
+
     // noncopyable, nonassignable
     EventLog(EventLog const &other);
     EventLog& operator=(EventLog const &other);
index dbda2b9809e04f867224b3efaa16c5fe6415af53..5bf405f7f290f210d3695c2e1d0d155b2ac80ea4 100644 (file)
@@ -59,6 +59,17 @@ public:
         * \param log Pointer to an Event describing the committed events.
         */
        virtual void notifyUndoCommitEvent(Event* log) = 0;
+
+       /**
+        * Triggered when the undo log is cleared.
+        */
+       virtual void notifyClearUndoEvent() = 0;
+
+       /**
+        * Triggered when the redo log is cleared.
+        */
+       virtual void notifyClearRedoEvent() = 0;
+
 };
 
 }