6 #include "filesystem.h"
10 #include "localsession.h"
14 #include "mwindowgui.h"
19 #define _(String) gettext(String)
20 #define gettext_noop(String) String
21 #define N_(String) gettext_noop (String)
27 Load::Load(MWindow *mwindow, MainMenu *mainmenu)
28 : BC_MenuItem(_("Load files..."), "o", 'o')
30 this->mwindow = mwindow;
31 this->mainmenu = mainmenu;
39 int Load::create_objects()
41 thread = new LoadFileThread(mwindow, this);
45 int Load::handle_event()
47 //printf("Load::handle_event 1\n");
48 if(!thread->running())
50 //printf("Load::handle_event 2\n");
61 LoadFileThread::LoadFileThread(MWindow *mwindow, Load *load)
64 this->mwindow = mwindow;
68 LoadFileThread::~LoadFileThread()
72 void LoadFileThread::run()
75 ArrayList<BC_ListBoxItem*> *dirlist;
77 ArrayList<char*> path_list;
78 path_list.set_array_delete();
79 char default_path[BCTEXTLEN];
82 int overwrite_reel = 0;
84 sprintf(default_path, "~");
85 mwindow->defaults->get("DEFAULT_LOADPATH", default_path);
86 load_mode = mwindow->defaults->get("LOAD_MODE", LOAD_REPLACE);
89 LoadFileWindow window(mwindow, this, default_path);
90 window.create_objects();
91 result = window.run_window();
93 if ((!result) && (load_mode == LOAD_REPLACE)) {
94 mwindow->set_filename(window.get_path(0));
97 // Collect all selected files
100 char *in_path, *out_path;
103 while(in_path = window.get_path(i))
106 for(j = 0; j < path_list.total; j++)
108 if(!strcmp(in_path, path_list.values[j])) break;
111 if(j == path_list.total)
113 path_list.append(out_path = new char[strlen(in_path) + 1]);
114 strcpy(out_path, in_path);
120 mwindow->defaults->update("DEFAULT_LOADPATH",
121 window.get_submitted_path());
122 mwindow->defaults->update("LOAD_MODE",
127 if(path_list.total == 0 || result == 1)
133 // ReelWindow rwindow(mwindow);
134 // rwindow.create_objects();
135 // result = rwindow.run_window();
142 // reel_name = rwindow.reel_name->get_text();
143 // reel_number = atol(rwindow.reel_number->get_text());
144 // overwrite_reel = rwindow.overwrite_reel;
151 mwindow->undo->update_undo_before(_("load"), LOAD_ALL);
152 mwindow->interrupt_indexes();
153 mwindow->gui->lock_window();
154 result = mwindow->load_filenames(&path_list, load_mode, 0, reel_name, reel_number, overwrite_reel);
155 mwindow->gui->mainmenu->add_load(path_list.values[0]);
156 mwindow->gui->unlock_window();
157 path_list.remove_all_objects();
160 mwindow->save_backup();
161 mwindow->restart_brender();
162 mwindow->undo->update_undo_after();
173 LoadFileWindow::LoadFileWindow(MWindow *mwindow,
174 LoadFileThread *thread,
175 char *init_directory)
176 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
177 mwindow->gui->get_abs_cursor_y(1) - BC_WindowBase::get_resources()->filebox_h / 2,
179 PROGRAM_NAME ": Load",
180 _("Select files to load:"),
181 mwindow->defaults, NULL,
185 mwindow->theme->loadfile_pad)
187 this->thread = thread;
188 this->mwindow = mwindow;
191 LoadFileWindow::~LoadFileWindow()
196 int LoadFileWindow::create_objects()
198 BC_FileBox::create_objects();
200 int x = get_w() / 2 - 200;
201 int y = get_h() - 90;
203 loadmode = new LoadMode(mwindow, this, x, y, &thread->load_mode, 0);
204 loadmode->create_objects();
209 int LoadFileWindow::resize_event(int w, int h)
213 draw_background(0, 0, w, h);
215 loadmode->reposition_window(x, y);
217 return BC_FileBox::resize_event(w, h);
226 NewTimeline::NewTimeline(int x, int y, LoadFileWindow *window)
229 window->thread->load_mode == LOAD_REPLACE,
230 _("Replace current project."))
232 this->window = window;
234 int NewTimeline::handle_event()
236 window->newtracks->set_value(0);
237 window->newconcatenate->set_value(0);
238 window->concatenate->set_value(0);
239 window->resourcesonly->set_value(0);
243 NewConcatenate::NewConcatenate(int x, int y, LoadFileWindow *window)
246 window->thread->load_mode == LOAD_REPLACE_CONCATENATE,
247 _("Replace current project and concatenate tracks."))
249 this->window = window;
251 int NewConcatenate::handle_event()
253 window->newtimeline->set_value(0);
254 window->newtracks->set_value(0);
255 window->concatenate->set_value(0);
256 window->resourcesonly->set_value(0);
260 AppendNewTracks::AppendNewTracks(int x, int y, LoadFileWindow *window)
263 window->thread->load_mode == LOAD_NEW_TRACKS,
264 _("Append in new tracks."))
266 this->window = window;
268 int AppendNewTracks::handle_event()
270 window->newtimeline->set_value(0);
271 window->newconcatenate->set_value(0);
272 window->concatenate->set_value(0);
273 window->resourcesonly->set_value(0);
277 EndofTracks::EndofTracks(int x, int y, LoadFileWindow *window)
280 window->thread->load_mode == LOAD_CONCATENATE,
281 _("Concatenate to existing tracks."))
283 this->window = window;
285 int EndofTracks::handle_event()
287 window->newtimeline->set_value(0);
288 window->newconcatenate->set_value(0);
289 window->newtracks->set_value(0);
290 window->resourcesonly->set_value(0);
294 ResourcesOnly::ResourcesOnly(int x, int y, LoadFileWindow *window)
297 window->thread->load_mode == LOAD_RESOURCESONLY,
298 _("Create new resources only."))
300 this->window = window;
302 int ResourcesOnly::handle_event()
305 window->newtimeline->set_value(0);
306 window->newconcatenate->set_value(0);
307 window->newtracks->set_value(0);
308 window->concatenate->set_value(0);
318 LocateFileWindow::LocateFileWindow(MWindow *mwindow,
319 char *init_directory,
321 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
322 mwindow->gui->get_abs_cursor_y(1),
324 PROGRAM_NAME ": Locate file",
327 this->mwindow = mwindow;
330 LocateFileWindow::~LocateFileWindow() {}
338 LoadPrevious::LoadPrevious(MWindow *mwindow)
339 : BC_MenuItem(""), Thread()
341 this->mwindow = mwindow;
342 this->loadfile = loadfile;
345 int LoadPrevious::handle_event()
347 ArrayList<char*> path_list;
348 path_list.set_array_delete();
350 int load_mode = mwindow->defaults->get("LOAD_MODE", LOAD_REPLACE);
352 mwindow->undo->update_undo_before(_("load previous"), LOAD_ALL);
354 path_list.append(out_path = new char[strlen(path) + 1]);
355 strcpy(out_path, path);
356 mwindow->load_filenames(&path_list, LOAD_REPLACE);
357 mwindow->gui->mainmenu->add_load(path_list.values[0]);
358 path_list.remove_all_objects();
361 mwindow->defaults->update("LOAD_MODE", load_mode);
362 mwindow->undo->update_undo_after();
363 mwindow->save_backup();
368 void LoadPrevious::run()
370 // loadfile->mwindow->load(path, loadfile->append);
373 int LoadPrevious::set_path(char *path)
375 strcpy(this->path, path);
385 LoadBackup::LoadBackup(MWindow *mwindow)
386 : BC_MenuItem(_("Load backup"))
388 this->mwindow = mwindow;
391 int LoadBackup::handle_event()
393 ArrayList<char*> path_list;
394 path_list.set_array_delete();
396 char string[BCTEXTLEN];
397 strcpy(string, BACKUP_PATH);
399 fs.complete_path(string);
401 path_list.append(out_path = new char[strlen(string) + 1]);
402 strcpy(out_path, string);
404 mwindow->undo->update_undo_before(_("load backup"), LOAD_ALL);
405 mwindow->load_filenames(&path_list, LOAD_REPLACE, 0);
406 mwindow->edl->local_session->clip_title[0] = 0;
407 // This is unique to backups since the path of the backup is different than the
408 // path of the project.
409 mwindow->set_filename(mwindow->edl->project_path);
410 path_list.remove_all_objects();
411 mwindow->undo->update_undo_after();
412 mwindow->save_backup();
419 // Dialog to set reel number/name
421 ReelWindow::ReelWindow(MWindow *mwindow)
422 : BC_Window(_("Please enter the reel name and number"),
423 mwindow->gui->get_abs_cursor_x(1) - 375 / 2,
424 mwindow->gui->get_abs_cursor_y(1) - 150 / 2,
433 this->mwindow = mwindow;
434 overwrite_reel = 0; // TODO: this should be loaded from previous time
437 ReelWindow::~ReelWindow()
439 delete reel_name_title;
441 delete reel_number_title;
446 int ReelWindow::create_objects()
451 add_subwindow(checkbox = new OverwriteReel(this, x, y, !overwrite_reel));
455 add_subwindow(reel_name_title = new BC_Title(x, y, _("Reel Name:")));
456 x += reel_name_title->get_w() + 20;
458 add_subwindow(reel_name = new BC_TextBox(x,
468 add_subwindow(reel_number_title = new BC_Title(x, y,
470 // line up the text boxes
471 x += reel_name_title->get_w() + 20;
473 add_subwindow(reel_number = new BC_TextBox(x,
479 add_subwindow(ok_button = new BC_OKButton(this));
481 add_subwindow(cancel_button = new BC_CancelButton(this));
483 // Disable reel_name and reel_number if the user doesn't want to overwrite
484 // (overwrite == accept default as well)
487 reel_name->disable();
488 reel_number->disable();
495 int ReelWindow::resize_event(int w, int h)
501 OverwriteReel::OverwriteReel(ReelWindow *rwindow,
502 int x, int y, int value)
503 : BC_CheckBox(x, y, value, _("Use default or previous name and number"))
505 this->rwindow = rwindow;
508 int OverwriteReel::handle_event()
510 rwindow->overwrite_reel = !get_value();
511 // If the checkbox is not enabled, we want to enable the reel_name and
512 // reel_number text boxes
515 rwindow->reel_name->enable();
516 rwindow->reel_number->enable();
520 rwindow->reel_name->disable();
521 rwindow->reel_number->disable();