From: gustav_b Date: Fri, 6 Oct 2006 22:13:54 +0000 (+0000) Subject: Implement singleton behaviour for undo history dialog. Make sure event X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=068e269d6d0391bdf69963f651be776f3fcb4dd5;p=inkscape.git Implement singleton behaviour for undo history dialog. Make sure event log gets created on SPDesktop::change_document. --- diff --git a/src/desktop.cpp b/src/desktop.cpp index 722aa81e9..47dbe1bec 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -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)); diff --git a/src/event-log.cpp b/src/event-log.cpp index 751616d30..08fb45f9b 100644 --- a/src/event-log.cpp +++ b/src/event-log.cpp @@ -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); diff --git a/src/ui/dialog/undo-history.cpp b/src/ui/dialog/undo-history.cpp index 5cfba60f6..98f8cc0cc 100644 --- a/src/ui/dialog/undo-history.cpp +++ b/src/ui/dialog/undo-history.cpp @@ -84,17 +84,52 @@ CellRendererInt::render_vfunc(const Glib::RefPtr& 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 diff --git a/src/ui/dialog/undo-history.h b/src/ui/dialog/undo-history.h index 2857fb88a..7b900fde5 100644 --- a/src/ui/dialog/undo-history.h +++ b/src/ui/dialog/undo-history.h @@ -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