6 #include "filesystem.h"
11 #include "localsession.h"
14 #include "mainsession.h"
16 #include "mwindowgui.h"
23 Load::Load(MWindow *mwindow, MainMenu *mainmenu)
24 : BC_MenuItem(_("Load files..."), "o", 'o')
26 this->mwindow = mwindow;
27 this->mainmenu = mainmenu;
35 int Load::create_objects()
37 thread = new LoadFileThread(mwindow, this);
41 int Load::handle_event()
43 //printf("Load::handle_event 1\n");
44 if(!thread->running())
46 //printf("Load::handle_event 2\n");
57 LoadFileThread::LoadFileThread(MWindow *mwindow, Load *load)
60 this->mwindow = mwindow;
64 LoadFileThread::~LoadFileThread()
68 void LoadFileThread::run()
71 ArrayList<BC_ListBoxItem*> *dirlist;
73 ArrayList<char*> path_list;
74 path_list.set_array_delete();
75 char default_path[BCTEXTLEN];
78 int overwrite_reel = 0;
80 sprintf(default_path, "~");
81 mwindow->defaults->get("DEFAULT_LOADPATH", default_path);
82 load_mode = mwindow->defaults->get("LOAD_MODE", LOAD_REPLACE);
85 LoadFileWindow window(mwindow, this, default_path);
86 window.create_objects();
87 result = window.run_window();
89 if ((!result) && (load_mode == LOAD_REPLACE)) {
90 mwindow->set_filename(window.get_path(0));
93 // Collect all selected files
96 char *in_path, *out_path;
99 while((in_path = window.get_path(i)))
102 for(j = 0; j < path_list.total; j++)
104 if(!strcmp(in_path, path_list.values[j])) break;
107 if(j == path_list.total)
109 path_list.append(out_path = new char[strlen(in_path) + 1]);
110 strcpy(out_path, in_path);
116 mwindow->defaults->update("DEFAULT_LOADPATH",
117 window.get_submitted_path());
118 mwindow->defaults->update("LOAD_MODE",
123 if(path_list.total == 0 || result == 1)
129 // ReelWindow rwindow(mwindow);
130 // rwindow.create_objects();
131 // result = rwindow.run_window();
138 // reel_name = rwindow.reel_name->get_text();
139 // reel_number = atol(rwindow.reel_number->get_text());
140 // overwrite_reel = rwindow.overwrite_reel;
147 mwindow->interrupt_indexes();
148 mwindow->gui->lock_window("LoadFileThread::run");
149 result = mwindow->load_filenames(&path_list, load_mode, 0, reel_name, reel_number, overwrite_reel);
150 mwindow->gui->mainmenu->add_load(path_list.values[0]);
151 mwindow->gui->unlock_window();
152 path_list.remove_all_objects();
155 mwindow->save_backup();
156 mwindow->restart_brender();
157 // mwindow->undo->update_undo(_("load"), LOAD_ALL);
159 if(load_mode == LOAD_REPLACE || load_mode == LOAD_REPLACE_CONCATENATE)
160 mwindow->session->changes_made = 0;
162 mwindow->session->changes_made = 1;
174 LoadFileWindow::LoadFileWindow(MWindow *mwindow,
175 LoadFileThread *thread,
176 char *init_directory)
177 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
178 mwindow->gui->get_abs_cursor_y(1) - BC_WindowBase::get_resources()->filebox_h / 2,
180 PROGRAM_NAME ": Load",
181 _("Select files to load:"),
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_cancel_button()->get_y() - 50;
202 loadmode = new LoadMode(mwindow, this, x, y, &thread->load_mode, 0);
203 loadmode->create_objects();
208 int LoadFileWindow::resize_event(int w, int h)
211 int y = get_cancel_button()->get_y() - 50;
212 draw_background(0, 0, w, h);
214 loadmode->reposition_window(x, y);
216 return BC_FileBox::resize_event(w, h);
225 NewTimeline::NewTimeline(int x, int y, LoadFileWindow *window)
228 window->thread->load_mode == LOAD_REPLACE,
229 _("Replace current project."))
231 this->window = window;
233 int NewTimeline::handle_event()
235 window->newtracks->set_value(0);
236 window->newconcatenate->set_value(0);
237 window->concatenate->set_value(0);
238 window->resourcesonly->set_value(0);
242 NewConcatenate::NewConcatenate(int x, int y, LoadFileWindow *window)
245 window->thread->load_mode == LOAD_REPLACE_CONCATENATE,
246 _("Replace current project and concatenate tracks."))
248 this->window = window;
250 int NewConcatenate::handle_event()
252 window->newtimeline->set_value(0);
253 window->newtracks->set_value(0);
254 window->concatenate->set_value(0);
255 window->resourcesonly->set_value(0);
259 AppendNewTracks::AppendNewTracks(int x, int y, LoadFileWindow *window)
262 window->thread->load_mode == LOAD_NEW_TRACKS,
263 _("Append in new tracks."))
265 this->window = window;
267 int AppendNewTracks::handle_event()
269 window->newtimeline->set_value(0);
270 window->newconcatenate->set_value(0);
271 window->concatenate->set_value(0);
272 window->resourcesonly->set_value(0);
276 EndofTracks::EndofTracks(int x, int y, LoadFileWindow *window)
279 window->thread->load_mode == LOAD_CONCATENATE,
280 _("Concatenate to existing tracks."))
282 this->window = window;
284 int EndofTracks::handle_event()
286 window->newtimeline->set_value(0);
287 window->newconcatenate->set_value(0);
288 window->newtracks->set_value(0);
289 window->resourcesonly->set_value(0);
293 ResourcesOnly::ResourcesOnly(int x, int y, LoadFileWindow *window)
296 window->thread->load_mode == LOAD_RESOURCESONLY,
297 _("Create new resources only."))
299 this->window = window;
301 int ResourcesOnly::handle_event()
304 window->newtimeline->set_value(0);
305 window->newconcatenate->set_value(0);
306 window->newtracks->set_value(0);
307 window->concatenate->set_value(0);
317 LocateFileWindow::LocateFileWindow(MWindow *mwindow,
318 char *init_directory,
320 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
321 mwindow->gui->get_abs_cursor_y(1),
323 PROGRAM_NAME ": Locate file",
326 this->mwindow = mwindow;
329 LocateFileWindow::~LocateFileWindow()
339 LoadPrevious::LoadPrevious(MWindow *mwindow)
340 : BC_MenuItem(""), Thread()
342 this->mwindow = mwindow;
343 this->loadfile = loadfile;
346 int LoadPrevious::handle_event()
348 ArrayList<char*> path_list;
349 path_list.set_array_delete();
351 int load_mode = mwindow->defaults->get("LOAD_MODE", LOAD_REPLACE);
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(_("load previous"), LOAD_ALL);
363 mwindow->save_backup();
364 mwindow->session->changes_made = 0;
370 void LoadPrevious::run()
372 // loadfile->mwindow->load(path, loadfile->append);
375 int LoadPrevious::set_path(char *path)
377 strcpy(this->path, path);
387 LoadBackup::LoadBackup(MWindow *mwindow)
388 : BC_MenuItem(_("Load backup"))
390 this->mwindow = mwindow;
393 int LoadBackup::handle_event()
395 ArrayList<char*> path_list;
396 path_list.set_array_delete();
398 char string[BCTEXTLEN];
399 strcpy(string, BACKUP_PATH);
401 fs.complete_path(string);
403 path_list.append(out_path = new char[strlen(string) + 1]);
404 strcpy(out_path, string);
406 mwindow->load_filenames(&path_list, LOAD_REPLACE, 0);
407 mwindow->edl->local_session->clip_title[0] = 0;
408 // This is unique to backups since the path of the backup is different than the
409 // path of the project.
410 mwindow->set_filename(mwindow->edl->project_path);
411 path_list.remove_all_objects();
412 mwindow->undo->update_undo(_("load backup"), LOAD_ALL, 0, 0);
413 mwindow->save_backup();
414 // We deliberately mark the project changed, because the backup is most likely
415 // not identical to the project file that it refers to.
416 mwindow->session->changes_made = 1;
423 // Dialog to set reel number/name
425 ReelWindow::ReelWindow(MWindow *mwindow)
426 : BC_Window(_("Please enter the reel name and number"),
427 mwindow->gui->get_abs_cursor_x(1) - 375 / 2,
428 mwindow->gui->get_abs_cursor_y(1) - 150 / 2,
437 this->mwindow = mwindow;
438 overwrite_reel = 0; // TODO: this should be loaded from previous time
441 ReelWindow::~ReelWindow()
443 delete reel_name_title;
445 delete reel_number_title;
450 int ReelWindow::create_objects()
455 add_subwindow(checkbox = new OverwriteReel(this, x, y, !overwrite_reel));
459 add_subwindow(reel_name_title = new BC_Title(x, y, _("Reel Name:")));
460 x += reel_name_title->get_w() + 20;
462 add_subwindow(reel_name = new BC_TextBox(x,
472 add_subwindow(reel_number_title = new BC_Title(x, y,
474 // line up the text boxes
475 x += reel_name_title->get_w() + 20;
477 add_subwindow(reel_number = new BC_TextBox(x,
483 add_subwindow(ok_button = new BC_OKButton(this));
485 add_subwindow(cancel_button = new BC_CancelButton(this));
487 // Disable reel_name and reel_number if the user doesn't want to overwrite
488 // (overwrite == accept default as well)
491 reel_name->disable();
492 reel_number->disable();
499 int ReelWindow::resize_event(int w, int h)
505 OverwriteReel::OverwriteReel(ReelWindow *rwindow,
506 int x, int y, int value)
507 : BC_CheckBox(x, y, value, _("Use default or previous name and number"))
509 this->rwindow = rwindow;
512 int OverwriteReel::handle_event()
514 rwindow->overwrite_reel = !get_value();
515 // If the checkbox is not enabled, we want to enable the reel_name and
516 // reel_number text boxes
519 rwindow->reel_name->enable();
520 rwindow->reel_number->enable();
524 rwindow->reel_name->disable();
525 rwindow->reel_number->disable();