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 // 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;
143 mwindow->undo->update_undo_before(_("load"), LOAD_ALL);
144 mwindow->interrupt_indexes();
145 mwindow->gui->lock_window();
146 result = mwindow->load_filenames(&path_list, load_mode, 0, reel_name, reel_number, overwrite_reel);
147 mwindow->gui->mainmenu->add_load(path_list.values[0]);
148 mwindow->gui->unlock_window();
149 path_list.remove_all_objects();
152 mwindow->save_backup();
153 mwindow->restart_brender();
154 mwindow->undo->update_undo_after();
165 LoadFileWindow::LoadFileWindow(MWindow *mwindow,
166 LoadFileThread *thread,
167 char *init_directory)
168 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
169 mwindow->gui->get_abs_cursor_y(1) - BC_WindowBase::get_resources()->filebox_h / 2,
171 PROGRAM_NAME ": Load",
172 _("Select files to load:"),
173 mwindow->defaults, NULL,
177 mwindow->theme->loadfile_pad)
179 this->thread = thread;
180 this->mwindow = mwindow;
183 LoadFileWindow::~LoadFileWindow()
188 int LoadFileWindow::create_objects()
190 BC_FileBox::create_objects();
192 int x = get_w() / 2 - 200;
193 int y = get_h() - 90;
195 loadmode = new LoadMode(mwindow, this, x, y, &thread->load_mode, 0);
196 loadmode->create_objects();
201 int LoadFileWindow::resize_event(int w, int h)
205 draw_background(0, 0, w, h);
207 loadmode->reposition_window(x, y);
209 return BC_FileBox::resize_event(w, h);
218 NewTimeline::NewTimeline(int x, int y, LoadFileWindow *window)
221 window->thread->load_mode == LOAD_REPLACE,
222 _("Replace current project."))
224 this->window = window;
226 int NewTimeline::handle_event()
228 window->newtracks->set_value(0);
229 window->newconcatenate->set_value(0);
230 window->concatenate->set_value(0);
231 window->resourcesonly->set_value(0);
235 NewConcatenate::NewConcatenate(int x, int y, LoadFileWindow *window)
238 window->thread->load_mode == LOAD_REPLACE_CONCATENATE,
239 _("Replace current project and concatenate tracks."))
241 this->window = window;
243 int NewConcatenate::handle_event()
245 window->newtimeline->set_value(0);
246 window->newtracks->set_value(0);
247 window->concatenate->set_value(0);
248 window->resourcesonly->set_value(0);
252 AppendNewTracks::AppendNewTracks(int x, int y, LoadFileWindow *window)
255 window->thread->load_mode == LOAD_NEW_TRACKS,
256 _("Append in new tracks."))
258 this->window = window;
260 int AppendNewTracks::handle_event()
262 window->newtimeline->set_value(0);
263 window->newconcatenate->set_value(0);
264 window->concatenate->set_value(0);
265 window->resourcesonly->set_value(0);
269 EndofTracks::EndofTracks(int x, int y, LoadFileWindow *window)
272 window->thread->load_mode == LOAD_CONCATENATE,
273 _("Concatenate to existing tracks."))
275 this->window = window;
277 int EndofTracks::handle_event()
279 window->newtimeline->set_value(0);
280 window->newconcatenate->set_value(0);
281 window->newtracks->set_value(0);
282 window->resourcesonly->set_value(0);
286 ResourcesOnly::ResourcesOnly(int x, int y, LoadFileWindow *window)
289 window->thread->load_mode == LOAD_RESOURCESONLY,
290 _("Create new resources only."))
292 this->window = window;
294 int ResourcesOnly::handle_event()
297 window->newtimeline->set_value(0);
298 window->newconcatenate->set_value(0);
299 window->newtracks->set_value(0);
300 window->concatenate->set_value(0);
310 LocateFileWindow::LocateFileWindow(MWindow *mwindow,
311 char *init_directory,
313 : BC_FileBox(mwindow->gui->get_abs_cursor_x(1),
314 mwindow->gui->get_abs_cursor_y(1),
316 PROGRAM_NAME ": Locate file",
319 this->mwindow = mwindow;
322 LocateFileWindow::~LocateFileWindow() {}
330 LoadPrevious::LoadPrevious(MWindow *mwindow)
331 : BC_MenuItem(""), Thread()
333 this->mwindow = mwindow;
334 this->loadfile = loadfile;
337 int LoadPrevious::handle_event()
339 ArrayList<char*> path_list;
340 path_list.set_array_delete();
342 int load_mode = mwindow->defaults->get("LOAD_MODE", LOAD_REPLACE);
344 mwindow->undo->update_undo_before(_("load previous"), LOAD_ALL);
346 path_list.append(out_path = new char[strlen(path) + 1]);
347 strcpy(out_path, path);
348 mwindow->load_filenames(&path_list, LOAD_REPLACE);
349 mwindow->gui->mainmenu->add_load(path_list.values[0]);
350 path_list.remove_all_objects();
353 mwindow->defaults->update("LOAD_MODE", load_mode);
354 mwindow->undo->update_undo_after();
355 mwindow->save_backup();
360 void LoadPrevious::run()
362 // loadfile->mwindow->load(path, loadfile->append);
365 int LoadPrevious::set_path(char *path)
367 strcpy(this->path, path);
377 LoadBackup::LoadBackup(MWindow *mwindow)
378 : BC_MenuItem(_("Load backup"))
380 this->mwindow = mwindow;
383 int LoadBackup::handle_event()
385 ArrayList<char*> path_list;
386 path_list.set_array_delete();
388 char string[BCTEXTLEN];
389 strcpy(string, BACKUP_PATH);
391 fs.complete_path(string);
393 path_list.append(out_path = new char[strlen(string) + 1]);
394 strcpy(out_path, string);
396 mwindow->undo->update_undo_before(_("load backup"), LOAD_ALL);
397 mwindow->load_filenames(&path_list, LOAD_REPLACE, 0);
398 mwindow->edl->local_session->clip_title[0] = 0;
399 // This is unique to backups since the path of the backup is different than the
400 // path of the project.
401 mwindow->set_filename(mwindow->edl->project_path);
402 path_list.remove_all_objects();
403 mwindow->undo->update_undo_after();
404 mwindow->save_backup();
411 // Dialog to set reel number/name
413 ReelWindow::ReelWindow(MWindow *mwindow)
414 : BC_Window(_("Please enter the reel name and number"),
415 mwindow->gui->get_abs_cursor_x(1) - 375 / 2,
416 mwindow->gui->get_abs_cursor_y(1) - 150 / 2,
425 this->mwindow = mwindow;
426 overwrite_reel = 0; // TODO: this should be loaded from previous time
429 ReelWindow::~ReelWindow()
431 delete reel_name_title;
433 delete reel_number_title;
438 int ReelWindow::create_objects()
443 add_subwindow(checkbox = new OverwriteReel(this, x, y, !overwrite_reel));
447 add_subwindow(reel_name_title = new BC_Title(x, y, _("Reel Name:")));
448 x += reel_name_title->get_w() + 20;
450 add_subwindow(reel_name = new BC_TextBox(x,
460 add_subwindow(reel_number_title = new BC_Title(x, y,
462 // line up the text boxes
463 x += reel_name_title->get_w() + 20;
465 add_subwindow(reel_number = new BC_TextBox(x,
471 add_subwindow(ok_button = new BC_OKButton(this));
473 add_subwindow(cancel_button = new BC_CancelButton(this));
475 // Disable reel_name and reel_number if the user doesn't want to overwrite
476 // (overwrite == accept default as well)
479 reel_name->disable();
480 reel_number->disable();
487 int ReelWindow::resize_event(int w, int h)
493 OverwriteReel::OverwriteReel(ReelWindow *rwindow,
494 int x, int y, int value)
495 : BC_CheckBox(x, y, value, _("Use default or previous name and number"))
497 this->rwindow = rwindow;
500 int OverwriteReel::handle_event()
502 rwindow->overwrite_reel = !get_value();
503 // If the checkbox is not enabled, we want to enable the reel_name and
504 // reel_number text boxes
507 rwindow->reel_name->enable();
508 rwindow->reel_number->enable();
512 rwindow->reel_name->disable();
513 rwindow->reel_number->disable();