4 * Copyright (C) 2009 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
23 #include "bcsignals.h"
28 #include "filesystem.h"
29 #include "indexfile.h"
33 #include "localsession.h"
36 #include "mainsession.h"
38 #include "mwindowgui.h"
45 Load::Load(MWindow *mwindow, MainMenu *mainmenu)
46 : BC_MenuItem(_("Load files..."), "o", 'o')
48 this->mwindow = mwindow;
49 this->mainmenu = mainmenu;
57 void Load::create_objects()
59 thread = new LoadFileThread(mwindow, this);
62 int Load::handle_event()
64 mwindow->gui->unlock_window();
66 mwindow->gui->lock_window("Load::handle_event");
75 LoadFileThread::LoadFileThread(MWindow *mwindow, Load *load)
78 this->mwindow = mwindow;
82 LoadFileThread::~LoadFileThread()
87 BC_Window* LoadFileThread::new_gui()
89 char default_path[BCTEXTLEN];
91 sprintf(default_path, "~");
92 mwindow->defaults->get("DEFAULT_LOADPATH", default_path);
93 load_mode = mwindow->defaults->get("LOAD_MODE", LOADMODE_REPLACE);
95 mwindow->gui->lock_window("LoadFileThread::new_gui");
96 window = new LoadFileWindow(mwindow, this, default_path);
97 mwindow->gui->unlock_window();
99 window->create_objects();
103 void LoadFileThread::handle_done_event(int result)
105 window->lock_window("LoadFileThread::handle_done_event");
106 window->hide_window();
107 window->unlock_window();
109 if( !result ) load_apply();
112 void LoadFileThread::load_apply()
114 mwindow->defaults->update("DEFAULT_LOADPATH",
115 window->get_submitted_path());
116 mwindow->defaults->update("LOAD_MODE",
119 ArrayList<char*> path_list;
120 path_list.set_array_delete();
122 // Collect all selected files
124 for( int i=0; (in_path = window->get_path(i))!=0; ++i ) {
125 int k = path_list.size();
126 while( --k >= 0 && strcmp(in_path, path_list.values[k]) );
127 if( k < 0 ) path_list.append(cstrdup(in_path));
131 if( !path_list.size() ) return;
133 if( load_mode == LOADMODE_REPLACE )
134 mwindow->set_filename(path_list[0]);
136 mwindow->interrupt_indexes();
137 mwindow->gui->lock_window("LoadFileThread::run");
138 mwindow->load_filenames(&path_list, load_mode, 0);
139 mwindow->gui->mainmenu->add_load(path_list.values[0]);
140 mwindow->gui->unlock_window();
141 path_list.remove_all_objects();
143 mwindow->save_backup();
145 mwindow->restart_brender();
147 if(load_mode == LOADMODE_REPLACE || load_mode == LOADMODE_REPLACE_CONCATENATE)
148 mwindow->session->changes_made = 0;
150 mwindow->session->changes_made = 1;
154 LoadFileWindow::LoadFileWindow(MWindow *mwindow,
155 LoadFileThread *thread,
156 char *init_directory)
157 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
158 mwindow->gui->get_abs_cursor_y(1) -
159 BC_WindowBase::get_resources()->filebox_h / 2,
161 _(PROGRAM_NAME ": Load"),
162 _("Select files to load:"),
166 mwindow->theme->loadfile_pad)
168 this->thread = thread;
169 this->mwindow = mwindow;
172 LoadFileWindow::~LoadFileWindow()
174 lock_window("LoadFileWindow::~LoadFileWindow");
179 void LoadFileWindow::create_objects()
181 lock_window("LoadFileWindow::create_objects");
182 BC_FileBox::create_objects();
184 int x = get_w() / 2 -
185 LoadMode::calculate_w(this, mwindow->theme) / 2;
186 int y = get_cancel_button()->get_y() -
187 LoadMode::calculate_h(this, mwindow->theme);
188 loadmode = new LoadMode(mwindow, this, x, y, &thread->load_mode, 0);
189 loadmode->create_objects();
190 add_subwindow(load_file_apply = new LoadFileApply(this));
197 int LoadFileWindow::resize_event(int w, int h)
199 draw_background(0, 0, w, h);
201 int y = get_cancel_button()->get_y() -
202 LoadMode::calculate_h(this, mwindow->theme);
203 loadmode->reposition_window(x, y);
205 x = (w - BC_GenericButton::calculate_w(this, _("Apply")))/2;
206 y = h - BC_GenericButton::calculate_h() - 15;
207 load_file_apply->reposition_window(x, y);
209 return BC_FileBox::resize_event(w, h);
213 LoadFileApply::LoadFileApply(LoadFileWindow *load_file_window)
214 : BC_GenericButton( (load_file_window->get_w() -
215 BC_GenericButton::calculate_w(load_file_window, _("Apply")))/2,
216 load_file_window->get_h() - BC_GenericButton::calculate_h() - 15,
219 this->load_file_window = load_file_window;
222 int LoadFileApply::handle_event()
224 load_file_window->thread->load_apply();
229 LocateFileWindow::LocateFileWindow(MWindow *mwindow,
230 char *init_directory,
232 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
233 mwindow->gui->get_abs_cursor_y(1),
235 _(PROGRAM_NAME ": Locate file"),
238 this->mwindow = mwindow;
241 LocateFileWindow::~LocateFileWindow()
251 LoadPrevious::LoadPrevious(MWindow *mwindow, Load *loadfile)
252 : BC_MenuItem(""), Thread()
254 this->mwindow = mwindow;
255 this->loadfile = loadfile;
258 int LoadPrevious::handle_event()
260 ArrayList<char*> path_list;
261 path_list.set_array_delete();
263 int load_mode = mwindow->defaults->get("LOAD_MODE", LOADMODE_REPLACE);
265 path_list.append(out_path = new char[strlen(path) + 1]);
266 strcpy(out_path, path);
268 mwindow->load_filenames(&path_list, LOADMODE_REPLACE);
269 mwindow->gui->mainmenu->add_load(path_list.values[0]);
270 path_list.remove_all_objects();
272 mwindow->defaults->update("LOAD_MODE", load_mode);
273 mwindow->save_backup();
274 mwindow->session->changes_made = 0;
280 void LoadPrevious::run()
282 // loadfile->mwindow->load(path, loadfile->append);
285 int LoadPrevious::set_path(char *path)
287 strcpy(this->path, path);
293 LoadBackup::LoadBackup(MWindow *mwindow)
294 : BC_MenuItem(_("Load backup"))
296 this->mwindow = mwindow;
299 int LoadBackup::handle_event()
301 mwindow->load_backup();
302 mwindow->session->changes_made = 1;