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;
58 void Load::create_objects()
60 thread = new LoadFileThread(mwindow, this);
63 int Load::handle_event()
65 mwindow->gui->unlock_window();
67 mwindow->gui->lock_window("Load::handle_event");
76 LoadFileThread::LoadFileThread(MWindow *mwindow, Load *load)
79 this->mwindow = mwindow;
84 LoadFileThread::~LoadFileThread()
89 BC_Window* LoadFileThread::new_gui()
91 char default_path[BCTEXTLEN];
93 sprintf(default_path, "~");
94 mwindow->defaults->get("DEFAULT_LOADPATH", default_path);
95 load_mode = mwindow->defaults->get("LOAD_MODE", LOADMODE_REPLACE);
97 mwindow->gui->lock_window("LoadFileThread::new_gui");
98 window = new LoadFileWindow(mwindow, this, default_path);
99 mwindow->gui->unlock_window();
101 window->create_objects();
105 void LoadFileThread::handle_done_event(int result)
107 window->lock_window("LoadFileThread::handle_done_event");
108 window->hide_window();
109 window->unlock_window();
111 if( !result ) load_apply();
114 void LoadFileThread::load_apply()
116 mwindow->defaults->update("DEFAULT_LOADPATH",
117 window->get_submitted_path());
118 mwindow->defaults->update("LOAD_MODE",
121 ArrayList<char*> path_list;
122 path_list.set_array_delete();
124 // Collect all selected files
126 for( int i=0; (in_path = window->get_path(i))!=0; ++i ) {
127 int k = path_list.size();
128 while( --k >= 0 && strcmp(in_path, path_list.values[k]) );
129 if( k < 0 ) path_list.append(cstrdup(in_path));
133 if( !path_list.size() ) return;
135 if( load_mode == LOADMODE_REPLACE )
136 mwindow->set_filename(path_list[0]);
138 mwindow->interrupt_indexes();
139 mwindow->gui->lock_window("LoadFileThread::run");
140 mwindow->load_filenames(&path_list, load_mode, 0);
141 mwindow->gui->mainmenu->add_load(path_list.values[0]);
142 mwindow->gui->unlock_window();
143 path_list.remove_all_objects();
145 mwindow->save_backup();
147 mwindow->restart_brender();
149 if(load_mode == LOADMODE_REPLACE || load_mode == LOADMODE_REPLACE_CONCATENATE)
150 mwindow->session->changes_made = 0;
152 mwindow->session->changes_made = 1;
156 LoadFileWindow::LoadFileWindow(MWindow *mwindow,
157 LoadFileThread *thread,
158 char *init_directory)
159 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
160 mwindow->gui->get_abs_cursor_y(1) -
161 BC_WindowBase::get_resources()->filebox_h / 2,
163 _(PROGRAM_NAME ": Load"),
164 _("Select files to load:"),
168 mwindow->theme->loadfile_pad)
170 this->thread = thread;
171 this->mwindow = mwindow;
174 LoadFileWindow::~LoadFileWindow()
176 lock_window("LoadFileWindow::~LoadFileWindow");
181 void LoadFileWindow::create_objects()
183 lock_window("LoadFileWindow::create_objects");
184 BC_FileBox::create_objects();
186 int x = get_w() / 2 -
187 LoadMode::calculate_w(this, mwindow->theme) / 2;
188 int y = get_cancel_button()->get_y() -
189 LoadMode::calculate_h(this, mwindow->theme);
190 loadmode = new LoadMode(mwindow, this, x, y, &thread->load_mode, 0);
191 loadmode->create_objects();
192 add_subwindow(load_file_apply = new LoadFileApply(this));
199 int LoadFileWindow::resize_event(int w, int h)
201 draw_background(0, 0, w, h);
203 int y = get_cancel_button()->get_y() -
204 LoadMode::calculate_h(this, mwindow->theme);
205 loadmode->reposition_window(x, y);
207 x = (w - BC_GenericButton::calculate_w(this, _("Apply")))/2;
208 y = h - BC_GenericButton::calculate_h() - 15;
209 load_file_apply->reposition_window(x, y);
211 return BC_FileBox::resize_event(w, h);
215 LoadFileApply::LoadFileApply(LoadFileWindow *load_file_window)
216 : BC_GenericButton( (load_file_window->get_w() -
217 BC_GenericButton::calculate_w(load_file_window, _("Apply")))/2,
218 load_file_window->get_h() - BC_GenericButton::calculate_h() - 15,
221 this->load_file_window = load_file_window;
224 int LoadFileApply::handle_event()
226 load_file_window->thread->load_apply();
231 LocateFileWindow::LocateFileWindow(MWindow *mwindow,
232 char *init_directory,
234 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
235 mwindow->gui->get_abs_cursor_y(1),
237 _(PROGRAM_NAME ": Locate file"),
240 this->mwindow = mwindow;
243 LocateFileWindow::~LocateFileWindow()
253 LoadPrevious::LoadPrevious(MWindow *mwindow, Load *loadfile)
254 : BC_MenuItem(""), Thread()
256 this->mwindow = mwindow;
257 this->loadfile = loadfile;
260 int LoadPrevious::handle_event()
262 ArrayList<char*> path_list;
263 path_list.set_array_delete();
265 int load_mode = mwindow->defaults->get("LOAD_MODE", LOADMODE_REPLACE);
267 path_list.append(out_path = new char[strlen(path) + 1]);
268 strcpy(out_path, path);
270 mwindow->load_filenames(&path_list, LOADMODE_REPLACE);
271 mwindow->gui->mainmenu->add_load(path_list.values[0]);
272 path_list.remove_all_objects();
274 mwindow->defaults->update("LOAD_MODE", load_mode);
275 mwindow->save_backup();
276 mwindow->session->changes_made = 0;
282 void LoadPrevious::run()
284 // loadfile->mwindow->load(path, loadfile->append);
287 int LoadPrevious::set_path(char *path)
289 strcpy(this->path, path);
295 LoadBackup::LoadBackup(MWindow *mwindow)
296 : BC_MenuItem(_("Load backup"))
298 this->mwindow = mwindow;
301 int LoadBackup::handle_event()
303 mwindow->load_backup();
304 mwindow->session->changes_made = 1;