4 * Copyright (C) 1997-2012 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 "assetedit.h"
24 #include "assetpopup.h"
25 #include "assetremove.h"
27 #include "awindowgui.h"
28 #include "bcdisplayinfo.h"
29 #include "bcsignals.h"
33 #include "cwindowgui.h"
35 #include "edlsession.h"
38 #include "localsession.h"
39 #include "mainerror.h"
40 #include "mainindexes.h"
41 #include "mainsession.h"
43 #include "mwindowgui.h"
46 #include "vwindowgui.h"
49 AssetPopup::AssetPopup(MWindow *mwindow, AWindowGUI *gui)
50 : BC_PopupMenu(0, 0, 0, "", 0)
52 this->mwindow = mwindow;
56 AssetPopup::~AssetPopup()
60 void AssetPopup::create_objects()
62 BC_MenuItem *menu_item;
64 add_item(info = new AssetPopupInfo(mwindow, this));
65 add_item(format = new AWindowListFormat(mwindow));
66 add_item(new AssetPopupSort(mwindow, this));
67 add_item(index = new AssetPopupBuildIndex(mwindow, this));
68 add_item(view = new AssetPopupView(mwindow, this));
69 add_item(view_window = new AssetPopupViewWindow(mwindow, this));
70 add_item(new AssetPopupPaste(mwindow, this));
71 add_item(menu_item = new BC_MenuItem(_("Match...")));
72 menu_item->add_submenu(submenu = new BC_SubMenu());
73 submenu->add_submenuitem(new AssetMatchSize(mwindow, this));
74 submenu->add_submenuitem(new AssetMatchRate(mwindow, this));
75 submenu->add_submenuitem(new AssetMatchAll(mwindow, this));
76 add_item(menu_item = new BC_MenuItem(_("Remove...")));
77 menu_item->add_submenu(submenu = new BC_SubMenu());
78 submenu->add_submenuitem(new AssetPopupProjectRemove(mwindow, this));
79 submenu->add_submenuitem(new AssetPopupDiskRemove(mwindow, this));
82 void AssetPopup::paste_assets()
84 // Collect items into the drag vectors for temporary storage
85 gui->lock_window("AssetPopup::paste_assets");
86 mwindow->gui->lock_window("AssetPopup::paste_assets");
87 mwindow->cwindow->gui->lock_window("AssetPopup::paste_assets");
89 gui->collect_assets();
90 mwindow->paste_assets(mwindow->edl->local_session->get_selectionstart(1),
91 mwindow->edl->tracks->first,
92 0); // do not overwrite
95 mwindow->gui->unlock_window();
96 mwindow->cwindow->gui->unlock_window();
99 void AssetPopup::match_size()
101 // Collect items into the drag vectors for temporary storage
102 gui->collect_assets();
103 mwindow->gui->lock_window("AssetPopup::match_size");
104 mwindow->asset_to_size();
105 mwindow->gui->unlock_window();
108 void AssetPopup::match_rate()
110 // Collect items into the drag vectors for temporary storage
111 gui->collect_assets();
112 mwindow->gui->lock_window("AssetPopup::match_rate");
113 mwindow->asset_to_rate();
114 mwindow->gui->unlock_window();
117 void AssetPopup::match_all()
119 // Collect items into the drag vectors for temporary storage
120 gui->collect_assets();
121 mwindow->gui->lock_window("AssetPopup::match_rate");
122 mwindow->asset_to_all();
123 mwindow->gui->unlock_window();
126 int AssetPopup::update()
129 gui->collect_assets();
134 AssetPopupInfo::AssetPopupInfo(MWindow *mwindow, AssetPopup *popup)
135 : BC_MenuItem(_("Info..."))
137 this->mwindow = mwindow;
141 AssetPopupInfo::~AssetPopupInfo()
145 int AssetPopupInfo::handle_event()
147 if(mwindow->session->drag_assets->total)
149 mwindow->awindow->asset_edit->edit_asset(
150 mwindow->session->drag_assets->values[0]);
153 if(mwindow->session->drag_clips->total)
155 popup->gui->awindow->clip_edit->edit_clip(
156 mwindow->session->drag_clips->values[0]);
162 AssetPopupBuildIndex::AssetPopupBuildIndex(MWindow *mwindow, AssetPopup *popup)
163 : BC_MenuItem(_("Rebuild index"))
165 this->mwindow = mwindow;
169 AssetPopupBuildIndex::~AssetPopupBuildIndex()
173 int AssetPopupBuildIndex::handle_event()
175 //printf("AssetPopupBuildIndex::handle_event 1\n");
176 mwindow->rebuild_indices();
181 AssetPopupSort::AssetPopupSort(MWindow *mwindow, AssetPopup *popup)
182 : BC_MenuItem(_("Sort items"))
184 this->mwindow = mwindow;
188 AssetPopupSort::~AssetPopupSort()
192 int AssetPopupSort::handle_event()
194 mwindow->awindow->gui->sort_assets();
199 AssetPopupView::AssetPopupView(MWindow *mwindow, AssetPopup *popup)
200 : BC_MenuItem(_("View"))
202 this->mwindow = mwindow;
206 AssetPopupView::~AssetPopupView()
210 int AssetPopupView::handle_event()
212 VWindow *vwindow = mwindow->get_viewer(1, DEFAULT_VWINDOW);
213 vwindow->gui->lock_window("AssetPopupView::handle_event");
215 if(mwindow->session->drag_assets->total)
216 vwindow->change_source(
217 mwindow->session->drag_assets->values[0]);
219 if(mwindow->session->drag_clips->total)
220 vwindow->change_source(
221 mwindow->session->drag_clips->values[0]);
223 vwindow->gui->unlock_window();
228 AssetPopupViewWindow::AssetPopupViewWindow(MWindow *mwindow, AssetPopup *popup)
229 : BC_MenuItem(_("View in new window"))
231 this->mwindow = mwindow;
235 AssetPopupViewWindow::~AssetPopupViewWindow()
239 int AssetPopupViewWindow::handle_event()
241 // Find window with nothing
242 VWindow *vwindow = mwindow->get_viewer(1);
244 // TODO: create new vwindow or change current vwindow
245 vwindow->gui->lock_window("AssetPopupView::handle_event");
247 if(mwindow->session->drag_assets->total)
248 vwindow->change_source(
249 mwindow->session->drag_assets->values[0]);
251 if(mwindow->session->drag_clips->total)
252 vwindow->change_source(
253 mwindow->session->drag_clips->values[0]);
255 vwindow->gui->unlock_window();
260 AssetPopupPaste::AssetPopupPaste(MWindow *mwindow, AssetPopup *popup)
261 : BC_MenuItem(_("Paste"))
263 this->mwindow = mwindow;
267 AssetPopupPaste::~AssetPopupPaste()
271 int AssetPopupPaste::handle_event()
273 popup->paste_assets();
278 AssetMatchSize::AssetMatchSize(MWindow *mwindow, AssetPopup *popup)
279 : BC_MenuItem(_("Match project size"))
281 this->mwindow = mwindow;
285 int AssetMatchSize::handle_event()
291 AssetMatchRate::AssetMatchRate(MWindow *mwindow, AssetPopup *popup)
292 : BC_MenuItem(_("Match frame rate"))
294 this->mwindow = mwindow;
298 int AssetMatchRate::handle_event()
304 AssetMatchAll::AssetMatchAll(MWindow *mwindow, AssetPopup *popup)
305 : BC_MenuItem(_("Match all"))
307 this->mwindow = mwindow;
311 int AssetMatchAll::handle_event()
318 AssetPopupProjectRemove::AssetPopupProjectRemove(MWindow *mwindow, AssetPopup *popup)
319 : BC_MenuItem(_("Remove from project"))
321 this->mwindow = mwindow;
325 AssetPopupProjectRemove::~AssetPopupProjectRemove()
329 int AssetPopupProjectRemove::handle_event()
331 mwindow->remove_assets_from_project(1, 1,
332 mwindow->session->drag_assets,
333 mwindow->session->drag_clips);
338 AssetPopupDiskRemove::AssetPopupDiskRemove(MWindow *mwindow, AssetPopup *popup)
339 : BC_MenuItem(_("Remove from disk"))
341 this->mwindow = mwindow;
346 AssetPopupDiskRemove::~AssetPopupDiskRemove()
350 int AssetPopupDiskRemove::handle_event()
352 mwindow->awindow->asset_remove->start();
357 AssetListMenu::AssetListMenu(MWindow *mwindow, AWindowGUI *gui)
358 : BC_PopupMenu(0, 0, 0, "", 0)
360 this->mwindow = mwindow;
364 AssetListMenu::~AssetListMenu()
368 void AssetListMenu::create_objects()
370 add_item(format = new AWindowListFormat(mwindow));
371 add_item(new AWindowListSort(mwindow));
372 add_item(new AssetListCopy(mwindow));
373 add_item(new AssetListPaste(mwindow));
377 void AssetListMenu::update_titles()
382 AssetListCopy::AssetListCopy(MWindow *mwindow)
383 : BC_MenuItem(_("Copy file list"))
385 this->mwindow = mwindow;
388 AssetListCopy::~AssetListCopy()
393 int AssetListCopy::handle_event()
396 MWindowGUI *gui = mwindow->gui;
397 gui->lock_window("AssetListCopy::handle_event");
398 mwindow->awindow->gui->collect_assets();
399 int n = mwindow->session->drag_assets->total;
400 for( int i=0; i<n; ++i ) {
401 Indexable *indexable = mwindow->session->drag_assets->values[i];
402 const char *path = indexable->path;
403 if( !*path ) continue;
404 len += strlen(path) + 1;
406 char *text = new char[len+1], *cp = text;
407 for( int i=0; i<n; ++i ) {
408 Indexable *indexable = mwindow->session->drag_assets->values[i];
409 const char *path = indexable->path;
410 if( !*path ) continue;
411 cp += sprintf(cp, "%s\n", path);
414 gui->unlock_window();
418 copy_dialog = new AssetCopyDialog(this);
419 copy_dialog->start(text);
422 eprintf(_("Nothing selected"));
428 AssetCopyDialog::AssetCopyDialog(AssetListCopy *copy)
435 void AssetCopyDialog::start(char *text)
439 BC_DialogThread::start();
442 AssetCopyDialog::~AssetCopyDialog()
447 BC_Window* AssetCopyDialog::new_gui()
449 BC_DisplayInfo display_info;
450 int x = display_info.get_abs_cursor_x();
451 int y = display_info.get_abs_cursor_y();
453 copy_window = new AssetCopyWindow(this, x, y);
454 copy_window->create_objects();
458 void AssetCopyDialog::handle_done_event(int result)
460 delete [] text; text = 0;
463 void AssetCopyDialog::handle_close_event(int result)
469 AssetCopyWindow::AssetCopyWindow(AssetCopyDialog *copy_dialog, int x, int y)
470 : BC_Window(_(PROGRAM_NAME ": Copy File List"), x, y, 500, 200, 500, 200, 0, 0, 1)
472 this->copy_dialog = copy_dialog;
475 AssetCopyWindow::~AssetCopyWindow()
479 void AssetCopyWindow::create_objects()
482 int x = 10, y = 10, pad = 5;
483 add_subwindow(title = new BC_Title(x, y, _("List of asset paths:")));
484 y += title->get_h() + pad;
485 int text_w = get_w() - x - 10;
486 int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
487 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
488 char *text = copy_dialog->text;
489 int len = strlen(text) + BCTEXTLEN;
490 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, text, len);
491 file_list->create_objects();
493 add_subwindow(new BC_OKButton(this));
498 AssetListPaste::AssetListPaste(MWindow *mwindow)
499 : BC_MenuItem(_("Paste file list"))
501 this->mwindow = mwindow;
504 AssetListPaste::~AssetListPaste()
509 int AssetListPaste::handle_event()
512 paste_dialog = new AssetPasteDialog(this);
513 paste_dialog->start();
517 AssetPasteDialog::AssetPasteDialog(AssetListPaste *paste)
524 AssetPasteDialog::~AssetPasteDialog()
529 BC_Window* AssetPasteDialog::new_gui()
531 BC_DisplayInfo display_info;
532 int x = display_info.get_abs_cursor_x();
533 int y = display_info.get_abs_cursor_y();
535 paste_window = new AssetPasteWindow(this, x, y);
536 paste_window->create_objects();
540 void AssetPasteDialog::handle_done_event(int result)
543 const char *bp = paste_window->file_list->get_text(), *ep = bp+strlen(bp);
544 ArrayList<char*> path_list;
545 path_list.set_array_delete();
547 for( const char *cp=bp; cp<ep && *cp; ) {
548 const char *dp = strchr(cp, '\n');
550 char path[BCTEXTLEN], *pp = path;
551 int len = sizeof(path)-1;
552 while( --len>0 && cp<dp ) *pp++ = *cp++;
555 if( !strlen(path) ) continue;
556 path_list.append(cstrdup(path));
558 if( !path_list.size() ) return;
560 MWindow *mwindow = paste->mwindow;
561 mwindow->interrupt_indexes();
562 mwindow->gui->lock_window("AssetPasteDialog::handle_done_event");
563 result = mwindow->load_filenames(&path_list, LOADMODE_RESOURCESONLY, 0);
564 mwindow->gui->unlock_window();
565 path_list.remove_all_objects();
566 mwindow->save_backup();
567 mwindow->restart_brender();
568 mwindow->session->changes_made = 1;
571 void AssetPasteDialog::handle_close_event(int result)
577 AssetPasteWindow::AssetPasteWindow(AssetPasteDialog *paste_dialog, int x, int y)
578 : BC_Window(_(PROGRAM_NAME ": Paste File List"), x, y, 500, 200, 500, 200, 0, 0, 1)
580 this->paste_dialog = paste_dialog;
583 AssetPasteWindow::~AssetPasteWindow()
587 void AssetPasteWindow::create_objects()
590 int x = 10, y = 10, pad = 5;
591 add_subwindow(title = new BC_Title(x, y, _("Enter list of asset paths:")));
592 y += title->get_h() + pad;
593 int text_w = get_w() - x - 10;
594 int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
595 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
596 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, (char*)0, 65536);
597 file_list->create_objects();
598 add_subwindow(new BC_OKButton(this));
599 add_subwindow(new BC_CancelButton(this));