Scroll the History panel to keep the border between 'done' and 'undone' in the centre...
[synfig.git] / synfig-studio / trunk / src / gtkmm / dock_history.cpp
index 9e9a5ba..4887895 100644 (file)
@@ -6,7 +6,7 @@
 **
 **     \legal
 **     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
-**     Copyright (c) 2007 Chris Moore
+**     Copyright (c) 2007, 2008 Chris Moore
 **
 **     This package is free software; you can redistribute it and/or
 **     modify it under the terms of the GNU General Public License as
@@ -207,7 +207,7 @@ Dock_History::create_action_tree()
                column->set_resizable();
                column->set_clickable();
 
-               column->set_sort_column_id(COLUMNID_JUMP);
+               column->set_sort_column(COLUMNID_JUMP);
 
                action_tree->append_column(*column);
                //column->clicked();
@@ -289,14 +289,48 @@ Dock_History::update_undo_redo()
 }
 
 void
+Dock_History::on_undo_tree_changed()
+{
+       Gtk::TreeModel::Children children(selected_instance->history_tree_store()->children());
+
+       if (!children.size())
+               return;
+
+       studio::HistoryTreeStore::Model model;
+
+       Gtk::TreeModel::Children::iterator iter, prev = children.end();
+       for (iter = children.begin(); iter != children.end(); prev = iter++)
+               if ((*iter)[model.is_redo])
+               {
+                       if (prev == children.end())
+                               action_tree->get_selection()->unselect_all();
+                       else
+                       {
+                               action_tree->scroll_to_row(Gtk::TreePath(prev), 0.5);
+                               action_tree->get_selection()->select(prev);
+                       }
+                       return;
+               }
+
+       action_tree->scroll_to_row(Gtk::TreePath(prev), 0.5);
+       action_tree->get_selection()->select(prev);
+}
+
+void
 Dock_History::set_selected_instance_(etl::handle<studio::Instance> instance)
 {
        if(studio::App::shutdown_in_progress)
                return;
 
+       if (on_undo_tree_changed_connection)
+               on_undo_tree_changed_connection.disconnect();
+
        selected_instance=instance;
        if(instance)
        {
+               on_undo_tree_changed_connection = selected_instance->history_tree_store()->signal_undo_tree_changed().connect(
+                       sigc::mem_fun(*this,&Dock_History::on_undo_tree_changed));
+
                action_tree->set_model(instance->history_tree_store());
                action_tree->show();
                update_undo_redo();