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 - LoadMode::calculate_w(this, mwindow->theme) / 2;
187 int y = get_y_margin();
188 loadmode = new LoadMode(mwindow, this, x, y, &thread->load_mode, 0, 1);
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);
200 BC_FileBox::resize_event(w, h);
201 int x = w / 2 - LoadMode::calculate_w(this, mwindow->theme) / 2;
202 int y = get_y_margin();
203 loadmode->reposition_window(x, y);
204 x = (w - BC_GenericButton::calculate_w(this, _("Apply")))/2;
205 y = h - BC_GenericButton::calculate_h() - 15;
206 load_file_apply->reposition_window(x, y);
212 LoadFileApply::LoadFileApply(LoadFileWindow *load_file_window)
213 : BC_GenericButton( (load_file_window->get_w() -
214 BC_GenericButton::calculate_w(load_file_window, _("Apply")))/2,
215 load_file_window->get_h() - BC_GenericButton::calculate_h() - 15,
218 this->load_file_window = load_file_window;
221 int LoadFileApply::handle_event()
223 load_file_window->thread->load_apply();
228 LocateFileWindow::LocateFileWindow(MWindow *mwindow,
229 char *init_directory,
231 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
232 mwindow->gui->get_abs_cursor_y(1),
234 _(PROGRAM_NAME ": Locate file"),
237 this->mwindow = mwindow;
240 LocateFileWindow::~LocateFileWindow()
250 LoadPrevious::LoadPrevious(MWindow *mwindow, Load *loadfile)
253 this->mwindow = mwindow;
254 this->loadfile = loadfile;
257 int LoadPrevious::handle_event()
259 if( !path[0] ) return 1;
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;
278 int LoadPrevious::set_path(const char *path)
280 strcpy(this->path, path);
286 LoadBackup::LoadBackup(MWindow *mwindow)
287 : BC_MenuItem(_("Load backup"))
289 this->mwindow = mwindow;
292 int LoadBackup::handle_event()
294 mwindow->load_backup();
295 mwindow->session->changes_made = 1;