Code

Switched pen and pencil toobars to stock GTK+ toolbars
[inkscape.git] / src / event-log.cpp
index 751616d30635c56f85f6de6aa863295dcb81722f..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
  */
@@ -42,6 +42,9 @@ EventLog::notifyUndoEvent(Event* log)
 {
     if ( !_notifications_blocked ) {
     
+        // make sure the supplied event matches the next undoable event
+        g_return_if_fail ( _getUndoEvent() && (*(_getUndoEvent()))[_columns.event] == log );
+
         // if we're on the first child event...
         if ( _curr_event->parent() &&
              _curr_event == _curr_event->parent()->children().begin() )
@@ -77,7 +80,7 @@ EventLog::notifyUndoEvent(Event* log)
             Gtk::TreePath curr_path = _event_list_store->get_path(_curr_event);
             _event_list_view->expand_to_path(curr_path);
             _event_list_selection->select(curr_path);
-            _event_list_view->scroll_to_row(curr_path);  
+            _event_list_view->scroll_to_row(curr_path);
 
             (*_callback_connections)[CALLB_EXPAND].block(false);
             (*_callback_connections)[CALLB_SELECTION_CHANGE].block(false);
@@ -93,6 +96,9 @@ EventLog::notifyRedoEvent(Event* log)
 {
     if ( !_notifications_blocked ) {
 
+        // make sure the supplied event matches the next redoable event
+        g_return_if_fail ( _getRedoEvent() && (*(_getRedoEvent()))[_columns.event] == log );
+
         // if we're on a parent event...
         if ( !_curr_event->children().empty() ) {
 
@@ -135,7 +141,7 @@ EventLog::notifyRedoEvent(Event* log)
 
             _event_list_view->expand_to_path(curr_path);
             _event_list_selection->select(curr_path);
-            _event_list_view->scroll_to_row(curr_path);  
+            _event_list_view->scroll_to_row(curr_path);
 
             (*_callback_connections)[CALLB_EXPAND].block(false);
             (*_callback_connections)[CALLB_SELECTION_CHANGE].block(false);
@@ -149,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;
 
@@ -207,6 +186,7 @@ EventLog::notifyUndoCommitEvent(Event* log)
 
     _curr_event = _last_event = curr_row;
 
+    curr_row[_columns.event] = log;
     curr_row[_columns.type] = event_type;
     curr_row[_columns.description] = log->description;
 
@@ -219,7 +199,7 @@ EventLog::notifyUndoCommitEvent(Event* log)
 
         _event_list_view->expand_to_path(curr_path);
         _event_list_selection->select(curr_path);
-        _event_list_view->scroll_to_row(curr_path);  
+        _event_list_view->scroll_to_row(curr_path);
 
         (*_callback_connections)[CALLB_EXPAND].block(false);
         (*_callback_connections)[CALLB_SELECTION_CHANGE].block(false);
@@ -228,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)
 {
@@ -317,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++