Code

Implement singleton behaviour for undo history dialog. Make sure event
authorgustav_b <gustav_b@users.sourceforge.net>
Fri, 6 Oct 2006 22:13:54 +0000 (22:13 +0000)
committergustav_b <gustav_b@users.sourceforge.net>
Fri, 6 Oct 2006 22:13:54 +0000 (22:13 +0000)
log gets created on SPDesktop::change_document.

src/desktop.cpp
src/event-log.cpp
src/ui/dialog/undo-history.cpp
src/ui/dialog/undo-history.h

index 722aa81e9b61e2bf71324e04ee297eab224bd610..47dbe1bec648890668f91ef24c244876f1a8305e 100644 (file)
@@ -288,10 +288,6 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas)
     /* setup LayerManager */
     //   (Setting up after the connections are all in place, as it may use some of them)
     layer_manager = new Inkscape::LayerManager( this );
-
-    /* setup EventLog */
-    event_log = new Inkscape::EventLog(document);
-    document->addUndoObserver(*event_log);
 }
 
 
@@ -1105,6 +1101,10 @@ SPDesktop::setDocument (SPDocument *doc)
     _layer_hierarchy->connectChanged(sigc::bind(sigc::ptr_fun(_layer_hierarchy_changed), this));
     _layer_hierarchy->setTop(SP_DOCUMENT_ROOT(doc));
 
+    /* setup EventLog */
+    event_log = new Inkscape::EventLog(doc);
+    doc->addUndoObserver(*event_log);
+
     _commit_connection.disconnect();
     _commit_connection = doc->connectCommit(sigc::mem_fun(*this, &SPDesktop::updateNow));
 
index 751616d30635c56f85f6de6aa863295dcb81722f..08fb45f9b79422a0bd1c0248def448f790e33a44 100644 (file)
@@ -77,7 +77,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);
@@ -135,7 +135,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);
@@ -219,7 +219,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);
index 5cfba60f60dfd6a3e4fbd0315f847927be8695e7..98f8cc0cc961edeb119b0d029a94aa8c2783b194 100644 (file)
@@ -84,17 +84,52 @@ CellRendererInt::render_vfunc(const Glib::RefPtr<Gdk::Drawable>& window,
                               const Gdk::Rectangle& expose_area,
                               Gtk::CellRendererState flags)
 {
-   if( _filter(_property_number) ) {
+    if( _filter(_property_number) ) {
         std::ostringstream s;
         s << _property_number << std::flush;
         property_text() = s.str();
         Gtk::CellRendererText::render_vfunc(window, widget, background_area, 
                                             cell_area, expose_area, flags);
-   }
+    }
 }
 
 const CellRendererInt::Filter& CellRendererInt::no_filter = CellRendererInt::NoFilter();
 
+static UndoHistory *_instance = 0;
+
+/* local desktop event handlers */
+static void on_document_replaced(SPDesktop* desktop, SPDocument*);
+static void on_activate_desktop(Inkscape::Application*, SPDesktop* desktop, void*);
+static void on_deactivate_desktop(Inkscape::Application*, SPDesktop* desktop, void*);
+
+UndoHistory*
+UndoHistory::create()
+{
+    if (_instance) return _instance;
+    _instance = new UndoHistory;
+    return _instance;
+}
+
+void
+UndoHistory::setDesktop(SPDesktop* desktop)
+{
+    if (!desktop || !SP_ACTIVE_DOCUMENT) return;
+
+    _document = SP_ACTIVE_DOCUMENT;
+
+    _event_log = desktop->event_log;
+
+    _callback_connections[EventLog::CALLB_SELECTION_CHANGE].block();
+
+    _event_list_store = _event_log->getEventListStore();
+    _event_list_view.set_model(_event_list_store);
+    _event_list_selection = _event_list_view.get_selection();
+
+    _event_log->connectWithDialog(&_event_list_view, &_callback_connections);
+    _event_list_view.scroll_to_row(_event_list_store->get_path(_event_list_selection->get_selected()));
+
+    _callback_connections[EventLog::CALLB_SELECTION_CHANGE].block(false);
+}
 
 UndoHistory::UndoHistory()
     : Dialog ("dialogs.undo-history", SP_VERB_DIALOG_UNDO_HISTORY),
@@ -146,7 +181,12 @@ UndoHistory::UndoHistory()
 
     _scrolled_window.add(_event_list_view);
 
-    // connect callbacks
+    // connect desktop event callbacks
+    _document_replaced_connection = _desktop->connectDocumentReplaced(sigc::ptr_fun(on_document_replaced));
+    g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK(on_activate_desktop), 0);
+    g_signal_connect(G_OBJECT(INKSCAPE), "deactivate_desktop", G_CALLBACK(on_deactivate_desktop), 0);
+
+    // connect EventLog callbacks
     _callback_connections[EventLog::CALLB_SELECTION_CHANGE] =
         _event_list_selection->signal_changed().connect(sigc::mem_fun(*this, &Inkscape::UI::Dialog::UndoHistory::_onListSelectionChange));
 
@@ -156,13 +196,13 @@ UndoHistory::UndoHistory()
     _callback_connections[EventLog::CALLB_COLLAPSE] =
         _event_list_view.signal_row_collapsed().connect(sigc::mem_fun(*this, &Inkscape::UI::Dialog::UndoHistory::_onCollapseEvent));
 
-    // connect with the event log
+    // connect with the EventLog
     _event_log->connectWithDialog(&_event_list_view, &_callback_connections);
 
-    _event_list_view.scroll_to_row(_event_list_store->get_path(_event_list_selection->get_selected()));
-
     show_all_children();
 
+    // scroll to the selected row
+    _event_list_view.set_cursor(_event_list_store->get_path(_event_log->getCurrEvent()));
 }
 
 UndoHistory::~UndoHistory()
@@ -309,6 +349,33 @@ UndoHistory::_onCollapseEvent(const Gtk::TreeModel::iterator &iter, const Gtk::T
 
 const CellRendererInt::Filter& UndoHistory::greater_than_1 = UndoHistory::GreaterThan(1);
 
+static void 
+on_activate_desktop(Inkscape::Application*, SPDesktop* desktop, void*)
+{
+    if (!_instance) return;
+
+    _instance->_document_replaced_connection = 
+        SP_ACTIVE_DESKTOP->connectDocumentReplaced(sigc::ptr_fun(on_document_replaced));
+
+    _instance->setDesktop(desktop);
+}
+
+static void 
+on_deactivate_desktop(Inkscape::Application*, SPDesktop* desktop, void*)
+{
+    if (!_instance) return;
+
+    _instance->_document_replaced_connection.disconnect();
+}
+
+static void 
+on_document_replaced(SPDesktop* desktop, SPDocument*)
+{
+    if (!_instance) return;
+
+    _instance->setDesktop(desktop);
+}
+
 } // namespace Dialog
 } // namespace UI
 } // namespace Inkscape
index 2857fb88a5e4c160f65ead579a4c427f2c197d41..7b900fde5c1d67e41aef6e36773bf1d46be6e608 100644 (file)
@@ -120,7 +120,10 @@ class UndoHistory : public Dialog {
 public:
     virtual ~UndoHistory();
 
-    static UndoHistory *create() { return new UndoHistory(); }
+    static UndoHistory *create();
+    void setDesktop(SPDesktop* desktop);
+
+    sigc::connection _document_replaced_connection;
 
 protected:
 
@@ -158,7 +161,6 @@ private:
     static const CellRendererInt::Filter& greater_than_1;
 };
 
-
 } // namespace Dialog
 } // namespace UI
 } // namespace Inkscape