r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / mainundo.C
blob03d711598ee833f89291f9fea9de38bfd9115b79
1 #include "assets.h"
2 #include "edl.h"
3 #include "filexml.h"
4 #include "mainindexes.h"
5 #include "mainmenu.h"
6 #include "mainsession.h"
7 #include "mainundo.h"
8 #include "mwindow.h"
9 #include "mwindowgui.h"
10 #include <string.h>
12 MainUndo::MainUndo(MWindow *mwindow)
13
14         this->mwindow = mwindow;
15         undo_before_updated = 0;
18 MainUndo::~MainUndo()
22 void MainUndo::update_undo_before(char *description, uint32_t load_flags)
24         if(!undo_before_updated)
25         {
26                 FileXML file;
27                 mwindow->session->changes_made = 1;
28                 mwindow->edl->save_xml(mwindow->plugindb, 
29                         &file, 
30                         "",
31                         0,
32                         0);
33                 file.terminate_string();
35                 current_entry = undo_stack.push();
36                 current_entry->load_flags = load_flags;
37                 current_entry->set_data_before(file.string);
38                 current_entry->set_description(description);
40 // the after update is always without a description
41                 mwindow->gui->lock_window();
42                 mwindow->gui->mainmenu->undo->update_caption(description);
43                 mwindow->gui->mainmenu->redo->update_caption("");
44                 mwindow->gui->unlock_window();
46                 undo_before_updated = 1;
47         }
50 void MainUndo::update_undo_after()
52         if(undo_before_updated)
53         {
54                 FileXML file;
55                 mwindow->edl->save_xml(mwindow->plugindb, 
56                         &file, 
57                         "",
58                         0,
59                         0);
60                 file.terminate_string();
61                 current_entry->set_data_after(file.string);
62                 undo_before_updated = 0;
63         }
71 int MainUndo::undo()
73         if(undo_stack.current)
74         {
75                 current_entry = undo_stack.current;
76                 if(current_entry->description && mwindow->gui) 
77                         mwindow->gui->mainmenu->redo->update_caption(current_entry->description);
78                 
79                 FileXML file;
80                 
81                 file.read_from_string(current_entry->data_before);
82                 load_from_undo(&file, current_entry->load_flags);
83                 
84                 undo_stack.pull();    // move current back
85                 if(mwindow->gui)
86                 {
87                         current_entry = undo_stack.current;
88                         if(current_entry)
89                                 mwindow->gui->mainmenu->undo->update_caption(current_entry->description);
90                         else
91                                 mwindow->gui->mainmenu->undo->update_caption("");
92                 }
93         }
94         return 0;
97 int MainUndo::redo()
99         current_entry = undo_stack.pull_next();
100         
101         if(current_entry)
102         {
103                 FileXML file;
104                 file.read_from_string(current_entry->data_after);
105                 load_from_undo(&file, current_entry->load_flags);
107                 if(mwindow->gui)
108                 {
109                         mwindow->gui->mainmenu->undo->update_caption(current_entry->description);
110                         
111                         if(current_entry->next)
112                                 mwindow->gui->mainmenu->redo->update_caption(current_entry->next->description);
113                         else
114                                 mwindow->gui->mainmenu->redo->update_caption("");
115                 }
116         }
117         return 0;
121 // Here the master EDL loads 
122 int MainUndo::load_from_undo(FileXML *file, uint32_t load_flags)
124         mwindow->edl->load_xml(mwindow->plugindb, file, load_flags);
125         for(Asset *asset = mwindow->edl->assets->first;
126                 asset;
127                 asset = asset->next)
128         {
129                 mwindow->mainindexes->add_next_asset(asset);
130         }
131         mwindow->mainindexes->start_build();
132         return 0;