4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "confirmsave.h"
24 #include "bcrecentlist.h"
28 #include "fileformat.h"
29 #include "indexfile.h"
31 #include "mainerror.h"
34 #include "mwindowgui.h"
35 #include "playback3d.h"
37 #include "mainsession.h"
42 SaveBackup::SaveBackup(MWindow *mwindow)
43 : BC_MenuItem(_("Save backup"), "b", 'b')
45 this->mwindow = mwindow;
47 int SaveBackup::handle_event()
49 mwindow->save_backup();
50 mwindow->gui->show_message(_("Saved backup."));
55 Save::Save(MWindow *mwindow) : BC_MenuItem(_("Save"), "s", 's')
57 this->mwindow = mwindow;
61 void Save::create_objects(SaveAs *saveas)
63 this->saveas = saveas;
66 int Save::handle_event()
68 mwindow->gui->unlock_window();
69 int ret = mwindow->save(0);
70 mwindow->gui->lock_window("Save::handle_event");
72 mwindow->session->changes_made = 0;
73 // Last command in program
74 if( saveas->quit_now )
80 int Save::save_before_quit()
82 mwindow->gui->lock_window("Save::save_before_quit");
85 mwindow->gui->unlock_window();
89 SaveAs::SaveAs(MWindow *mwindow)
90 : BC_MenuItem(_("Save as..."), "Shift-S", 'S'), Thread()
93 this->mwindow = mwindow;
97 int SaveAs::set_mainmenu(MainMenu *mmenu)
103 int SaveAs::handle_event()
112 if( mwindow->save(1) )
114 mwindow->session->changes_made = 0;
121 int SaveProjectModeItem::handle_event()
123 ((SaveProjectMode *)get_popup_menu())->update(id);
127 SaveProjectMode::SaveProjectMode(SaveProjectWindow *gui, int x, int y)
128 : BC_PopupMenu(x, y, xS(100), "")
131 save_modes[SAVE_PROJECT_COPY] = _("Copy");
132 save_modes[SAVE_PROJECT_SYMLINK] = _("SymLink");
133 save_modes[SAVE_PROJECT_RELLINK] = _("RelLink");
136 SaveProjectMode::~SaveProjectMode()
140 void SaveProjectMode::create_objects()
142 add_item(new SaveProjectModeItem(save_modes[SAVE_PROJECT_COPY], SAVE_PROJECT_COPY));
143 add_item(new SaveProjectModeItem(save_modes[SAVE_PROJECT_SYMLINK], SAVE_PROJECT_SYMLINK));
144 add_item(new SaveProjectModeItem(save_modes[SAVE_PROJECT_RELLINK], SAVE_PROJECT_RELLINK));
145 set_text(save_modes[gui->save_mode]);
148 void SaveProjectMode::update(int mode)
150 if( gui->save_mode == mode ) return;
151 set_text(save_modes[gui->save_mode = mode]);
154 SaveProjectTextBox::SaveProjectTextBox(SaveProjectWindow *gui, int x, int y, int w)
155 : BC_TextBox(x, y, w, 1, gui->dir_path)
159 SaveProjectTextBox::~SaveProjectTextBox()
163 int SaveProjectTextBox::handle_event()
168 SaveProjectWindow::SaveProjectWindow(MWindow *mwindow, const char *dir_path,
169 int save_mode, int overwrite, int reload)
170 : BC_Window(_(PROGRAM_NAME ": Export Project"),
171 mwindow->gui->get_abs_cursor_x(1),
172 mwindow->gui->get_abs_cursor_y(1) -
173 BC_WindowBase::get_resources()->filebox_h / 2,
174 xS(540), yS(220), xS(540), yS(220), 0)
176 this->mwindow = mwindow;
177 strcpy(this->dir_path, dir_path);
178 this->overwrite = overwrite;
179 this->save_mode = save_mode;
180 this->reload = reload;
182 SaveProjectWindow::~SaveProjectWindow()
186 void SaveProjectWindow::create_objects()
188 int xs10 = xS(10), xs20 = xS(20);
189 int ys10 = yS(10), ys20 = yS(20);
190 int x = xs20, y = ys20, x1 = get_w()-xS(80);
192 add_subwindow(title = new BC_Title(x, y, _("Project Directory:")));
193 y += title->get_h() + ys10;
194 add_subwindow(textbox = new SaveProjectTextBox(this, x, y, x1-x));
196 add_subwindow(recent_project = new BC_RecentList("RECENT_PROJECT",
197 mwindow->defaults, textbox, 10, x1, y, xS(300), yS(100)));
198 recent_project->load_items("RECENT_PROJECT");
199 x1 += recent_project->get_w() + xs10;
200 add_subwindow(browse_button = new BrowseButton(mwindow->theme, this,
201 textbox, x1, y-yS(5), "", "", "", 1));
202 y += textbox->get_h() + ys20;
203 add_subwindow(mode_popup = new SaveProjectMode(this, x, y));
204 mode_popup->create_objects();
205 y += mode_popup->get_h() + ys10;
207 BC_CheckBox *overwrite_files, *reload_project;
208 add_subwindow(overwrite_files = new BC_CheckBox(x1, y, &overwrite, _("Overwrite files")));
209 x1 += overwrite_files->get_w() + xs20;
210 add_subwindow(reload_project = new BC_CheckBox(x1, y, &reload, _("Reload project")));
211 add_subwindow(new BC_OKButton(this));
212 add_subwindow(new BC_CancelButton(this));
216 SaveProject::SaveProject(MWindow *mwindow)
217 : BC_MenuItem(_("Export Project..."), "Alt-s", 's'), Thread()
220 this->mwindow = mwindow;
223 int SaveProject::handle_event()
229 void SaveProject::run()
231 char dir_path[1024]; sprintf(dir_path, "~");
232 mwindow->defaults->get("PROJECT_DIRECTORY", dir_path);
233 int reload = mwindow->defaults->get("PROJECT_RELOAD", 0);
234 int overwrite = mwindow->defaults->get("PROJECT_OVERWRITE", 0);
235 int save_mode = mwindow->defaults->get("PROJECT_SAVE_MODE", 0);
237 SaveProjectWindow window(mwindow, dir_path, save_mode, overwrite, reload);
238 window.lock_window("SaveProject::run");
239 window.create_objects();
240 window.unlock_window();
241 int result = window.run_window();
244 strcpy(dir_path, window.textbox->get_text());
245 window.recent_project->add_item("RECENT_PROJECT", dir_path);
246 reload = window.get_reload();
247 overwrite = window.get_overwrite();
248 save_mode = window.get_save_mode();
249 mwindow->defaults->update("PROJECT_DIRECTORY", dir_path);
250 mwindow->defaults->update("PROJECT_RELOAD", reload);
251 mwindow->defaults->update("PROJECT_OVERWRITE", overwrite);
252 mwindow->defaults->update("PROJECT_SAVE_MODE", save_mode);
253 mwindow->save_project(dir_path, save_mode, overwrite, reload);