undo nested clip bug, wheel zoom redraw fix, uninited vars, shortcuts doc
[goodguy/history.git] / cinelerra-5.1 / cinelerra / mainundo.C
index e688a06e3d4af5f44b81a85e9a47b1453de43f3c..14268e1d37709f5d0b57e17cb4b89c919c53450d 100644 (file)
@@ -2,26 +2,27 @@
 /*
  * CINELERRA
  * Copyright (C) 1997-2011 Adam Williams <broadcast at earthling dot net>
- * 
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- * 
+ *
  */
 
 #include "asset.h"
 #include "assets.h"
 #include "bctimer.h"
+#include "clipedls.h"
 #include "edl.h"
 #include "filexml.h"
 #include "mainindexes.h"
 #include "mainundo.h"
 #include "mwindow.h"
 #include "mwindowgui.h"
-#include "nestededls.h"
 #include <string.h>
 #include "undostack.h"
 
 MainUndo::MainUndo(MWindow *mwindow)
-{ 
+{
        this->mwindow = mwindow;
        undo_stack = new UndoStack;
        last_update = new Timer;
@@ -48,17 +48,14 @@ MainUndo::~MainUndo()
 }
 
 
-void MainUndo::update_undo_entry(const char *description, 
+void MainUndo::update_undo_entry(const char *description,
        uint32_t load_flags,
-       void *creator, 
+       void *creator,
        int changes_made)
 {
        FileXML file;
 
-       mwindow->edl->save_xml(&file, 
-               "",
-               0,
-               0);
+       mwindow->edl->save_xml(&file, "");
        file.terminate_string();
        if(changes_made) mwindow->session->changes_made = 1;
 
@@ -133,7 +130,7 @@ void MainUndo::update_undo_before(const char *description, void *creator)
        update_undo_entry("", 0, creator, 0);
 }
 
-void MainUndo::update_undo_after(const char *description, 
+void MainUndo::update_undo_after(const char *description,
        uint32_t load_flags,
        int changes_made)
 {
@@ -164,157 +161,133 @@ void MainUndo::update_undo_after(const char *description,
 }
 
 
-int MainUndo::undo()
+UndoStackItem *MainUndo::next_undo()
 {
-       UndoStackItem *current = undo_stack->current;
-       char after_description[BCTEXTLEN];
-       after_description[0] = 0;
+       return undo_stack->get_current_undo();
+}
 
-       mwindow->undo_commercial();
+UndoStackItem *MainUndo::next_redo()
+{
+       return undo_stack->get_current_redo();
+}
 
-//printf("MainUndo::undo 1\n");
-//dump();
+int MainUndo::undo_load_flags()
+{
+       UndoStackItem *item = next_undo();
+       return item ? item->get_flags() : 0;
+}
 
-// Rewind to an after entry
-       if(current && !(undo_stack->number_of(current) % 2))
-       {
-               current = PREVIOUS;
-       }
+int MainUndo::redo_load_flags()
+{
+       UndoStackItem *item = next_redo();
+       return item ? item->get_flags() : 0;
+}
 
-// Rewind to a before entry
-       if(current && (undo_stack->number_of(current) % 2))
-       {
-               strcpy(after_description, current->get_description());
-               current = PREVIOUS;
-       }
 
-// Now have an even number
-       if(current)
-       {
-               undo_stack->current = current;
+int MainUndo::undo()
+{
+       mwindow->undo_commercial();
+       UndoStackItem *current = undo_stack->current;
+       if( current ) {
+               undo_stack->current = next_undo();
+               if( undo_stack->number_of(current) % 2 )
+                       current = PREVIOUS; // Now have an even number
+       }
+       if( current ) {
 // Set the redo text to the current description
-               if(mwindow->gui) 
-                       mwindow->gui->mainmenu->redo->update_caption(
-                               after_description);
-
-               FileXML file;
+               if( mwindow->gui ) {
+                       UndoStackItem *next = NEXT;
+                       mwindow->gui->mainmenu->redo->
+                               update_caption(next ? next->get_description() : "");
+               }
                char *current_data = current->get_data();
-               if(current_data)
-               {
+               if( current_data ) {
+                       FileXML file;
                        file.read_from_string(current_data);
+                       delete [] current_data;
                        load_from_undo(&file, current->get_flags());
 //printf("MainUndo::undo %d %s\n", __LINE__, current->get_filename());
                        mwindow->set_filename(current->get_filename());
-                       delete [] current_data;
-
-// move current entry back one step
-                       undo_stack->pull();    
-
 
-                       if(mwindow->gui)
-                       {
+                       if( mwindow->gui ) {
 // Now update the menu with the after entry
-                               current = PREVIOUS;
-// Must be a previous entry to perform undo
-                               if(current)
-                                       mwindow->gui->mainmenu->undo->update_caption(
-                                               current->get_description());
-                               else
-                                       mwindow->gui->mainmenu->undo->update_caption("");
+                               UndoStackItem *prev = PREVIOUS;
+                               mwindow->gui->mainmenu->undo->
+                                       update_caption(prev ? prev->get_description() : "");
                        }
                }
        }
 
-
-//dump();
        reset_creators();
+       mwindow->reset_caches();
        return 0;
 }
 
+
 int MainUndo::redo()
 {
-       UndoStackItem *current = undo_stack->current;
-//printf("MainUndo::redo 1\n");
-//dump();
-
-// Get 1st entry
-       if(!current) current = undo_stack->first;
-
-// Advance to a before entry
-       if(current && (undo_stack->number_of(current) % 2))
-       {
-               current = NEXT;
-       }
-
-// Advance to an after entry
-       if(current && !(undo_stack->number_of(current) % 2))
-       {
-               current = NEXT;
-       }
-
-       if(current)
-       {
-               FileXML file;
-               char *current_data = current->get_data();
+       UndoStackItem *current = next_redo();
+       if( current ) {
                undo_stack->current = current;
-
-               if(current_data)
-               {
+               char *current_data = current->get_data();
+               if( current_data ) {
                        mwindow->set_filename(current->get_filename());
+                       FileXML file;
                        file.read_from_string(current_data);
                        load_from_undo(&file, current->get_flags());
                        delete [] current_data;
-
-                       if(mwindow->gui)
-                       {
 // Update menu
-                               mwindow->gui->mainmenu->undo->update_caption(current->get_description());
-
+                       mwindow->gui->mainmenu->undo->
+                               update_caption(current->get_description());
 // Get next after entry
-                               current = NEXT;                 
-                               if(current)
-                                       current = NEXT;
-
-                               if(current)
-                                       mwindow->gui->mainmenu->redo->update_caption(current->get_description());
-                               else
-                                       mwindow->gui->mainmenu->redo->update_caption("");
-                       }
+                       if( (current=NEXT) ) current = NEXT;
+                       mwindow->gui->mainmenu->redo->
+                               update_caption(current ? current->get_description() : "");
                }
        }
        reset_creators();
+       mwindow->reset_caches();
 //dump();
        return 0;
 }
 
 
-// Here the master EDL loads 
+// Here the master EDL loads
 int MainUndo::load_from_undo(FileXML *file, uint32_t load_flags)
 {
+       if( load_flags & LOAD_SESSION ) {
+               mwindow->gui->unlock_window();
+               mwindow->close_mixers();
+               mwindow->gui->lock_window("MainUndo::load_from_undo");
+       }
+       if( (load_flags & LOAD_ALL) == LOAD_ALL ) {
+               EDL *edl = new EDL;
+               edl->create_objects();
+               mwindow->edl->remove_user();
+               mwindow->edl = edl;
+       }
        mwindow->edl->load_xml(file, load_flags);
-       for(Asset *asset = mwindow->edl->assets->first;
-               asset;
-               asset = asset->next)
-       {
+       for( Asset *asset=mwindow->edl->assets->first; asset; asset=asset->next ) {
                mwindow->mainindexes->add_next_asset(0, asset);
        }
-       
-       for(int i = 0; i < mwindow->edl->nested_edls->size(); i++)
-       {
-               EDL *nested_edl = mwindow->edl->nested_edls->get(i);
+       for( int i=0; i<mwindow->edl->nested_edls.size(); ++i ) {
+               EDL *nested_edl = mwindow->edl->nested_edls[i];
                mwindow->mainindexes->add_next_asset(0, nested_edl);
        }
        mwindow->mainindexes->start_build();
+       mwindow->update_plugin_guis(1);
+       if( load_flags & LOAD_SESSION ) {
+               mwindow->gui->unlock_window();
+               mwindow->open_mixers();
+               mwindow->gui->lock_window("MainUndo::load_from_undo");
+       }
        return 0;
 }
 
 
 void MainUndo::reset_creators()
 {
-       for(UndoStackItem *current = undo_stack->first;
-               current;
-               current = NEXT)
-       {
+       for( UndoStackItem *current=undo_stack->first; current; current=NEXT ) {
                current->set_creator(0);
        }
 }
@@ -325,3 +298,30 @@ void MainUndo::dump(FILE *fp)
        undo_stack->dump(fp);
 }
 
+void MainUndo::save(FILE *fp)
+{
+       undo_stack->save(fp);
+}
+
+void MainUndo::load(FILE *fp)
+{
+       undo_stack->load(fp);
+       UndoStackItem *current = undo_stack->current;
+       char *current_data = current ? current->get_data() : 0;
+       if( !current_data ) return;
+       mwindow->gui->lock_window("MainUndo::load");
+       UndoStackItem *next = current->next;
+       mwindow->gui->mainmenu->redo->
+               update_caption(next ? next->get_description() : "");
+       mwindow->set_filename(current->get_filename());
+       FileXML file;
+       file.read_from_string(current_data);
+       load_from_undo(&file, LOAD_ALL);
+       delete [] current_data;
+       UndoStackItem *prev = current->previous;
+       mwindow->gui->mainmenu->undo->
+               update_caption(prev ? prev->get_description() : "");
+       mwindow->update_project(LOADMODE_REPLACE);
+       mwindow->gui->unlock_window();
+}
+