From 9eb4a1dc89898024bbd0721fdbf59f4151c71a4c Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Thu, 11 Aug 2005 19:27:00 +0000 Subject: [PATCH] r616: The UndoStackItem::redo() is dropped and replaced by UndoStackItem::undo(). The latter must reverse its state so that the next invocation does a redo. --- cinelerra/mainundo.C | 26 ++++++++------------------ cinelerra/mwindowedit.C | 26 ++++++++------------------ cinelerra/undostackitem.C | 4 ---- cinelerra/undostackitem.h | 11 ++++++----- 4 files changed, 22 insertions(+), 45 deletions(-) diff --git a/cinelerra/mainundo.C b/cinelerra/mainundo.C index 42ac6b35..dc504dd3 100644 --- a/cinelerra/mainundo.C +++ b/cinelerra/mainundo.C @@ -20,13 +20,12 @@ class MainUndoStackItem : public UndoStackItem { public: - MainUndoStackItem(MainUndo* main_undo, char* description, + MainUndoStackItem(MainUndo* undo, char* description, uint32_t load_flags); virtual ~MainUndoStackItem(); void set_data_before(char *data); virtual void undo(); - virtual void redo(); virtual int get_size(); private: @@ -118,22 +117,20 @@ void MainUndo::update_undo_after() int MainUndo::undo() { - if(undo_stack.last) - { - UndoStackItem* current_entry = undo_stack.last; + UndoStackItem* current_entry = undo_stack.last; + if(current_entry) + { // move item to redo_stack undo_stack.remove_pointer(current_entry); + current_entry->undo(); redo_stack.append(current_entry); - - if(current_entry->description && mwindow->gui) - mwindow->gui->mainmenu->redo->update_caption(current_entry->description); - - current_entry->undo(); capture_state(); if(mwindow->gui) { + mwindow->gui->mainmenu->redo->update_caption(current_entry->description); + if(undo_stack.last) mwindow->gui->mainmenu->undo->update_caption(undo_stack.last->description); else @@ -149,12 +146,10 @@ int MainUndo::redo() if(current_entry) { - // move item to undo_stack redo_stack.remove_pointer(current_entry); + current_entry->undo(); undo_stack.append(current_entry); - - current_entry->redo(); capture_state(); if(mwindow->gui) @@ -232,11 +227,6 @@ void MainUndoStackItem::undo() load_from_undo(&file, load_flags); } -void MainUndoStackItem::redo() -{ - undo(); -} - int MainUndoStackItem::get_size() { return data_before ? strlen(data_before) : 0; diff --git a/cinelerra/mwindowedit.C b/cinelerra/mwindowedit.C index 062c5a1d..279d1690 100644 --- a/cinelerra/mwindowedit.C +++ b/cinelerra/mwindowedit.C @@ -1652,7 +1652,6 @@ class InPointUndoItem : public UndoStackItem public: InPointUndoItem(double old_position, double new_position, EDL *edl); void undo(); - void redo(); int get_size(); private: double old_position; @@ -1672,11 +1671,10 @@ InPointUndoItem::InPointUndoItem( void InPointUndoItem::undo() { edl->set_inpoint(old_position); -} - -void InPointUndoItem::redo() -{ - edl->set_inpoint(new_position); +// prepare to undo the undo + double tmp = new_position; + new_position = old_position; + old_position = tmp; } int InPointUndoItem::get_size() @@ -1723,7 +1721,6 @@ class OutPointUndoItem : public UndoStackItem public: OutPointUndoItem(double old_position, double new_position, EDL *edl); void undo(); - void redo(); int get_size(); private: double old_position; @@ -1743,11 +1740,10 @@ OutPointUndoItem::OutPointUndoItem( void OutPointUndoItem::undo() { edl->set_outpoint(old_position); -} - -void OutPointUndoItem::redo() -{ - edl->set_outpoint(new_position); +// prepare to undo the undo + double tmp = new_position; + new_position = old_position; + old_position = tmp; } int OutPointUndoItem::get_size() @@ -1877,7 +1873,6 @@ class LabelUndoItem : public UndoStackItem public: LabelUndoItem(double position1, double position2, EDL *edl); void undo(); - void redo(); int get_size(); private: double position1; @@ -1899,11 +1894,6 @@ void LabelUndoItem::undo() edl->labels->toggle_label(position1, position2); } -void LabelUndoItem::redo() -{ - edl->labels->toggle_label(position1, position2); -} - int LabelUndoItem::get_size() { return 20; diff --git a/cinelerra/undostackitem.C b/cinelerra/undostackitem.C index 35b37847..991f6f9e 100644 --- a/cinelerra/undostackitem.C +++ b/cinelerra/undostackitem.C @@ -23,10 +23,6 @@ void UndoStackItem::undo() { } -void UndoStackItem::redo() -{ -} - int UndoStackItem::get_size() { return 0; diff --git a/cinelerra/undostackitem.h b/cinelerra/undostackitem.h index 669bd6ed..44eda7da 100644 --- a/cinelerra/undostackitem.h +++ b/cinelerra/undostackitem.h @@ -12,12 +12,13 @@ public: void set_description(char *description); -// These two virtual functions allow derived objects to be pushed -// on to the undo stack that are more efficient in time and memory -// usage than the default action of saving before and after copies -// of the EDL. +// This function must be overridden in derived objects. +// It is called both to undo and to redo an operation. +// The override must do the following: +// - change the EDL to undo an operation; +// - change the internal information of the item so that the next invocation +// of undo() does a redo (i.e. undoes the undone operation). virtual void undo(); - virtual void redo(); // Return the amount of memory used for the data associated with this // object in order to enable limiting the amount of memory used by the -- 2.11.4.GIT