X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fevent-log.cpp;h=4ee65f3f8417ae9b18c7c295d58b03b4b7b5b04d;hb=c6172c4f6cb97ec651af9a89ea5b55e6cbc24ebd;hp=40c8364acabdca5de0597dc265a323414172ef33;hpb=c57da20fee24a6e5b368730153d72eabe26425b2;p=inkscape.git diff --git a/src/event-log.cpp b/src/event-log.cpp index 40c8364ac..4ee65f3f8 100644 --- a/src/event-log.cpp +++ b/src/event-log.cpp @@ -2,7 +2,7 @@ * Author: * Gustav Broberg * - * Copyright (c) 2006 Authors + * Copyright (c) 2006, 2007 Authors * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -10,14 +10,16 @@ #include #include "desktop.h" - #include "event-log.h" +#include "inkscape.h" +#include "util/ucompose.hpp" namespace Inkscape { -EventLog::EventLog() : +EventLog::EventLog(SPDocument* document) : UndoStackObserver(), _connected (false), + _document (document), _event_list_store (Gtk::TreeStore::create(_columns)), _event_list_selection (NULL), _event_list_view (NULL), @@ -39,7 +41,10 @@ void 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() ) @@ -75,13 +80,15 @@ 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); } + updateUndoVerbs(); } + } void @@ -89,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() ) { @@ -131,46 +141,21 @@ 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); } + updateUndoVerbs(); } + } 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; @@ -201,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; @@ -213,12 +199,27 @@ 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); } + updateUndoVerbs(); +} + +void +EventLog::notifyClearUndoEvent() +{ + _clearUndo(); + updateUndoVerbs(); +} + +void +EventLog::notifyClearRedoEvent() +{ + _clearRedo(); + updateUndoVerbs(); } void @@ -242,7 +243,116 @@ EventLog::connectWithDialog(Gtk::TreeView *event_list_view, CallbackMap *callbac _connected = true; } +void +EventLog::updateUndoVerbs() +{ + if(_document) { + + if(_getUndoEvent()) { + Inkscape::Verb::get(SP_VERB_EDIT_UNDO)->sensitive(_document, true); + + Inkscape::Verb::get(SP_VERB_EDIT_UNDO)->name(_document, String::ucompose("%1: %2", + Glib::ustring(_("_Undo")), + Glib::ustring((*_getUndoEvent())[_columns.description]))); + } else { + Inkscape::Verb::get(SP_VERB_EDIT_UNDO)->name(_document, _("_Undo")); + Inkscape::Verb::get(SP_VERB_EDIT_UNDO)->sensitive(_document, false); + } + + if(_getRedoEvent()) { + Inkscape::Verb::get(SP_VERB_EDIT_REDO)->sensitive(_document, true); + Inkscape::Verb::get(SP_VERB_EDIT_REDO)->name(_document, String::ucompose("%1: %2", + Glib::ustring(_("_Redo")), + Glib::ustring((*_getRedoEvent())[_columns.description]))); + + } else { + Inkscape::Verb::get(SP_VERB_EDIT_REDO)->name(_document, _("_Redo")); + Inkscape::Verb::get(SP_VERB_EDIT_REDO)->sensitive(_document, false); + } + + } + +} + + +EventLog::const_iterator +EventLog::_getUndoEvent() const +{ + const_iterator undo_event = (const_iterator)NULL; + if( _curr_event != _event_list_store->children().begin() ) + undo_event = _curr_event; + return undo_event; +} + +EventLog::const_iterator +EventLog::_getRedoEvent() const +{ + const_iterator redo_event = (const_iterator)NULL; + + if ( _curr_event != _last_event ) { + + if ( !_curr_event->children().empty() ) + redo_event = _curr_event->children().begin(); + else { + redo_event = _curr_event; + ++redo_event; + + if ( redo_event->parent() && + redo_event == redo_event->parent()->children().end() ) { + + redo_event = redo_event->parent(); + ++redo_event; + + } + } + + } + + 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++