1 #include "confirmsave.h"
7 #include "fileformat.h"
11 #include "mwindowgui.h"
13 #include "mainsession.h"
18 #define _(String) gettext(String)
19 #define gettext_noop(String) String
20 #define N_(String) gettext_noop (String)
30 SaveBackup::SaveBackup(MWindow *mwindow)
31 : BC_MenuItem(_("Save backup"))
33 this->mwindow = mwindow;
35 int SaveBackup::handle_event()
37 mwindow->save_backup();
38 mwindow->gui->show_message(_("Saved backup."));
52 Save::Save(MWindow *mwindow) : BC_MenuItem(_("Save"), "s", 's')
54 this->mwindow = mwindow;
58 int Save::create_objects(SaveAs *saveas)
60 this->saveas = saveas;
64 int Save::handle_event()
66 if(mwindow->session->filename[0] == 0)
73 // TODO: Move this into mwindow.
75 mwindow->edl->save_xml(mwindow->plugindb,
77 mwindow->session->filename,
80 file.terminate_string();
82 if(file.write_to_file(mwindow->session->filename))
85 sprintf(string2, _("Couldn't open %s"), mwindow->session->filename);
86 ErrorBox error(PROGRAM_NAME ": Error",
87 mwindow->gui->get_abs_cursor_x(1),
88 mwindow->gui->get_abs_cursor_y(1));
89 error.create_objects(string2);
95 char string[BCTEXTLEN];
96 sprintf(string, _("\"%s\" %dC written"), mwindow->session->filename, strlen(file.string));
97 mwindow->gui->show_message(string, BLACK);
99 mwindow->session->changes_made = 0;
100 if(saveas->quit_now) mwindow->gui->set_done(0);
105 int Save::save_before_quit()
107 saveas->quit_now = 1;
112 SaveAs::SaveAs(MWindow *mwindow)
113 : BC_MenuItem(_("Save as..."), ""), Thread()
115 this->mwindow = mwindow;
119 int SaveAs::set_mainmenu(MainMenu *mmenu)
125 int SaveAs::handle_event()
134 // ======================================= get path from user
136 //printf("SaveAs::run 1\n");
137 char directory[1024], filename[1024];
138 sprintf(directory, "~");
139 mwindow->defaults->get("DIRECTORY", directory);
141 // Loop if file exists
143 SaveFileWindow *window;
145 window = new SaveFileWindow(mwindow, directory);
146 window->create_objects();
147 result = window->run_window();
148 mwindow->defaults->update("DIRECTORY", window->get_submitted_path());
149 strcpy(filename, window->get_submitted_path());
152 // Extend the filename with .xml
153 if(strlen(filename) < 4 ||
154 strcasecmp(&filename[strlen(filename) - 4], ".xml"))
156 strcat(filename, ".xml");
159 // ======================================= try to save it
160 if(filename[0] == 0) return; // no filename given
161 if(result == 1) return; // user cancelled
162 result = ConfirmSave::test_file(mwindow, filename);
163 }while(result); // file exists so repeat
165 //printf("SaveAs::run 6 %s\n", filename);
172 mwindow->set_filename(filename); // update the project name
173 mwindow->edl->save_xml(mwindow->plugindb,
178 file.terminate_string();
180 if(file.write_to_file(filename))
183 mwindow->set_filename(""); // update the project name
184 sprintf(string2, _("Couldn't open %s."), filename);
185 ErrorBox error(PROGRAM_NAME ": Error",
186 mwindow->gui->get_abs_cursor_x(1),
187 mwindow->gui->get_abs_cursor_y(1));
188 error.create_objects(string2);
194 char string[BCTEXTLEN];
195 sprintf(string, _("\"%s\" %dC written"), filename, strlen(file.string));
196 mwindow->gui->lock_window();
197 mwindow->gui->show_message(string, BLACK);
198 mwindow->gui->unlock_window();
202 mwindow->session->changes_made = 0;
203 mmenu->add_load(filename);
204 if(quit_now) mwindow->gui->set_done(0);
215 SaveFileWindow::SaveFileWindow(MWindow *mwindow, char *init_directory)
216 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
217 mwindow->gui->get_abs_cursor_y(1) - BC_WindowBase::get_resources()->filebox_h / 2,
219 PROGRAM_NAME ": Save",
220 _("Enter a filename to save as"),
223 this->mwindow = mwindow;
226 SaveFileWindow::~SaveFileWindow() {}