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 ArrayList<char*> path_list;
106 path_list.set_array_delete();
108 // Collect all selected files
111 char *in_path, *out_path;
113 window->lock_window("LoadFileThread::handle_done_event");
114 window->hide_window();
115 window->unlock_window();
117 while((in_path = window->get_path(i)))
120 for(j = 0; j < path_list.total; j++)
122 if(!strcmp(in_path, path_list.values[j])) break;
125 if(j == path_list.total)
127 path_list.append(out_path = new char[strlen(in_path) + 1]);
128 strcpy(out_path, in_path);
134 mwindow->defaults->update("DEFAULT_LOADPATH",
135 window->get_submitted_path());
136 mwindow->defaults->update("LOAD_MODE",
140 if(path_list.total == 0 || result == 1)
145 if( load_mode == LOADMODE_REPLACE )
146 mwindow->set_filename(path_list[0]);
148 mwindow->interrupt_indexes();
149 mwindow->gui->lock_window("LoadFileThread::run");
150 result = mwindow->load_filenames(&path_list, load_mode, 0);
151 mwindow->gui->mainmenu->add_load(path_list.values[0]);
152 mwindow->gui->unlock_window();
153 path_list.remove_all_objects();
155 mwindow->save_backup();
157 mwindow->restart_brender();
159 if(load_mode == LOADMODE_REPLACE || load_mode == LOADMODE_REPLACE_CONCATENATE)
160 mwindow->session->changes_made = 0;
162 mwindow->session->changes_made = 1;
167 LoadFileWindow::LoadFileWindow(MWindow *mwindow,
168 LoadFileThread *thread,
169 char *init_directory)
170 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
171 mwindow->gui->get_abs_cursor_y(1) -
172 BC_WindowBase::get_resources()->filebox_h / 2,
174 _(PROGRAM_NAME ": Load"),
175 _("Select files to load:"),
179 mwindow->theme->loadfile_pad)
181 this->thread = thread;
182 this->mwindow = mwindow;
185 LoadFileWindow::~LoadFileWindow()
187 lock_window("LoadFileWindow::~LoadFileWindow");
192 void LoadFileWindow::create_objects()
194 lock_window("LoadFileWindow::create_objects");
195 BC_FileBox::create_objects();
197 int x = get_w() / 2 -
198 LoadMode::calculate_w(this, mwindow->theme) / 2;
199 int y = get_cancel_button()->get_y() -
200 LoadMode::calculate_h(this, mwindow->theme);
201 loadmode = new LoadMode(mwindow, this, x, y, &thread->load_mode, 0);
202 loadmode->create_objects();
209 int LoadFileWindow::resize_event(int w, int h)
212 int y = get_cancel_button()->get_y() -
213 LoadMode::calculate_h(this, mwindow->theme);
214 draw_background(0, 0, w, h);
216 loadmode->reposition_window(x, y);
218 return BC_FileBox::resize_event(w, h);
233 LocateFileWindow::LocateFileWindow(MWindow *mwindow,
234 char *init_directory,
236 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
237 mwindow->gui->get_abs_cursor_y(1),
239 _(PROGRAM_NAME ": Locate file"),
242 this->mwindow = mwindow;
245 LocateFileWindow::~LocateFileWindow()
255 LoadPrevious::LoadPrevious(MWindow *mwindow, Load *loadfile)
256 : BC_MenuItem(""), Thread()
258 this->mwindow = mwindow;
259 this->loadfile = loadfile;
262 int LoadPrevious::handle_event()
264 ArrayList<char*> path_list;
265 path_list.set_array_delete();
267 int load_mode = mwindow->defaults->get("LOAD_MODE", LOADMODE_REPLACE);
269 path_list.append(out_path = new char[strlen(path) + 1]);
270 strcpy(out_path, path);
272 mwindow->load_filenames(&path_list, LOADMODE_REPLACE);
273 mwindow->gui->mainmenu->add_load(path_list.values[0]);
274 path_list.remove_all_objects();
276 mwindow->defaults->update("LOAD_MODE", load_mode);
277 mwindow->save_backup();
278 mwindow->session->changes_made = 0;
284 void LoadPrevious::run()
286 // loadfile->mwindow->load(path, loadfile->append);
289 int LoadPrevious::set_path(char *path)
291 strcpy(this->path, path);
297 LoadBackup::LoadBackup(MWindow *mwindow)
298 : BC_MenuItem(_("Load backup"))
300 this->mwindow = mwindow;
303 int LoadBackup::handle_event()
305 mwindow->load_backup();
306 mwindow->session->changes_made = 1;