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
22 #include "assetedit.h"
23 #include "assetremove.h"
24 #include "proxypopup.h"
26 #include "awindowgui.h"
27 #include "bcsignals.h"
30 #include "cwindowgui.h"
36 #include "localsession.h"
37 #include "mainerror.h"
38 #include "mainsession.h"
40 #include "mwindowgui.h"
44 #include "vwindowgui.h"
48 ProxyPopup::ProxyPopup(MWindow *mwindow, AWindowGUI *gui)
49 : BC_PopupMenu(0, 0, 0, "", 0)
51 this->mwindow = mwindow;
55 ProxyPopup::~ProxyPopup()
59 void ProxyPopup::create_objects()
61 BC_MenuItem *menu_item;
63 add_item(info = new ProxyPopupInfo(mwindow, this));
64 add_item(format = new AWindowListFormat(mwindow, gui));
65 add_item(new ProxyPopupSort(mwindow, this));
66 add_item(view = new ProxyPopupView(mwindow, this));
67 add_item(view_window = new ProxyPopupViewWindow(mwindow, this));
68 add_item(new ProxyPopupCopy(mwindow, this));
69 add_item(new ProxyPopupPaste(mwindow, this));
70 add_item(menu_item = new BC_MenuItem(_("Remove...")));
71 menu_item->add_submenu(submenu = new BC_SubMenu());
72 submenu->add_submenuitem(new ProxyPopupProjectRemove(mwindow, this));
73 submenu->add_submenuitem(new ProxyPopupDiskRemove(mwindow, this));
76 void ProxyPopup::paste_assets()
78 // Collect items into the drag vectors for temporary storage
79 gui->lock_window("ProxyPopup::paste_assets");
80 mwindow->gui->lock_window("ProxyPopup::paste_assets");
81 mwindow->cwindow->gui->lock_window("ProxyPopup::paste_assets");
83 gui->collect_assets(1);
84 mwindow->paste_assets(mwindow->edl->local_session->get_selectionstart(1),
85 mwindow->edl->tracks->first, 0); // do not overwrite
88 mwindow->gui->unlock_window();
89 mwindow->cwindow->gui->unlock_window();
92 int ProxyPopup::update()
95 gui->collect_assets(1);
100 ProxyPopupInfo::ProxyPopupInfo(MWindow *mwindow, ProxyPopup *popup)
101 : BC_MenuItem(_("Info..."))
103 this->mwindow = mwindow;
107 ProxyPopupInfo::~ProxyPopupInfo()
111 int ProxyPopupInfo::handle_event()
114 popup->gui->get_abs_cursor(cur_x, cur_y, 0);
116 if( mwindow->session->drag_assets->total ) {
117 AssetEdit *asset_edit = mwindow->awindow->get_asset_editor();
118 asset_edit->edit_asset(
119 mwindow->session->drag_assets->values[0], cur_x, cur_y);
122 if( mwindow->session->drag_clips->total ) {
123 popup->gui->awindow->clip_edit->edit_clip(
124 mwindow->session->drag_clips->values[0], cur_x, cur_y);
130 ProxyPopupSort::ProxyPopupSort(MWindow *mwindow, ProxyPopup *popup)
131 : BC_MenuItem(_("Sort items"))
133 this->mwindow = mwindow;
137 ProxyPopupSort::~ProxyPopupSort()
141 int ProxyPopupSort::handle_event()
143 mwindow->awindow->gui->sort_assets();
148 ProxyPopupView::ProxyPopupView(MWindow *mwindow, ProxyPopup *popup)
149 : BC_MenuItem(_("View"))
151 this->mwindow = mwindow;
155 ProxyPopupView::~ProxyPopupView()
159 int ProxyPopupView::handle_event()
161 VWindow *vwindow = mwindow->get_viewer(1, DEFAULT_VWINDOW);
163 if( mwindow->session->drag_assets->total )
164 vwindow->change_source(
165 mwindow->session->drag_assets->values[0]);
167 if( mwindow->session->drag_clips->total )
168 vwindow->change_source(
169 mwindow->session->drag_clips->values[0]);
175 ProxyPopupViewWindow::ProxyPopupViewWindow(MWindow *mwindow, ProxyPopup *popup)
176 : BC_MenuItem(_("View in new window"))
178 this->mwindow = mwindow;
182 ProxyPopupViewWindow::~ProxyPopupViewWindow()
186 int ProxyPopupViewWindow::handle_event()
188 for( int i=0; i<mwindow->session->drag_assets->size(); ++i ) {
189 VWindow *vwindow = mwindow->get_viewer(1);
190 vwindow->gui->lock_window("ProxyPopupView::handle_event 1");
191 vwindow->change_source(mwindow->session->drag_assets->get(i));
192 vwindow->gui->unlock_window();
194 for( int i=0; i<mwindow->session->drag_clips->size(); ++i ) {
195 VWindow *vwindow = mwindow->get_viewer(1);
196 vwindow->gui->lock_window("ProxyPopupView::handle_event 2");
197 vwindow->change_source(mwindow->session->drag_clips->get(i));
198 vwindow->gui->unlock_window();
204 ProxyPopupCopy::ProxyPopupCopy(MWindow *mwindow, ProxyPopup *popup)
205 : BC_MenuItem(_("Copy"))
207 this->mwindow = mwindow;
210 ProxyPopupCopy::~ProxyPopupCopy()
214 int ProxyPopupCopy::handle_event()
216 MWindowGUI *gui = mwindow->gui;
217 gui->lock_window("ProxyPopupCopy::handle_event");
218 if( mwindow->session->drag_clips->total > 0 ) {
219 EDL *edl = mwindow->session->drag_clips->values[0];
220 EDL *copy_edl = new EDL; // no parent or assets wont be copied
221 copy_edl->create_objects();
222 copy_edl->copy_all(edl);
224 double start = 0, end = edl->tracks->total_length();
225 copy_edl->copy(COPY_EDL, start, end, &file, "", 1);
226 copy_edl->remove_user();
227 const char *file_string = file.string();
228 long file_length = strlen(file_string);
229 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
230 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
232 gui->unlock_window();
237 ProxyPopupPaste::ProxyPopupPaste(MWindow *mwindow, ProxyPopup *popup)
238 : BC_MenuItem(_("Paste"))
240 this->mwindow = mwindow;
244 ProxyPopupPaste::~ProxyPopupPaste()
248 int ProxyPopupPaste::handle_event()
250 popup->paste_assets();
255 ProxyPopupProjectRemove::ProxyPopupProjectRemove(MWindow *mwindow, ProxyPopup *popup)
256 : BC_MenuItem(_("Remove from project"))
258 this->mwindow = mwindow;
262 ProxyPopupProjectRemove::~ProxyPopupProjectRemove()
266 int ProxyPopupProjectRemove::handle_event()
268 popup->gui->collect_assets();
269 mwindow->remove_assets_from_project(1, 1, 1,
270 mwindow->session->drag_assets,
271 mwindow->session->drag_clips);
276 ProxyPopupDiskRemove::ProxyPopupDiskRemove(MWindow *mwindow, ProxyPopup *popup)
277 : BC_MenuItem(_("Remove from disk"))
279 this->mwindow = mwindow;
284 ProxyPopupDiskRemove::~ProxyPopupDiskRemove()
288 int ProxyPopupDiskRemove::handle_event()
290 popup->gui->collect_assets();
291 mwindow->awindow->asset_remove->start();
297 ProxyListMenu::ProxyListMenu(MWindow *mwindow, AWindowGUI *gui)
298 : BC_PopupMenu(0, 0, 0, "", 0)
300 this->mwindow = mwindow;
304 ProxyListMenu::~ProxyListMenu()
308 void ProxyListMenu::create_objects()
310 add_item(format = new AWindowListFormat(mwindow, gui));
311 add_item(select_used = new AssetSelectUsed(mwindow, gui));
313 select_used->add_submenu(submenu = new BC_SubMenu());
314 submenu->add_submenuitem(new AssetSelectUsedItem(select_used, _("All"), SELECT_ALL));
315 submenu->add_submenuitem(new AssetSelectUsedItem(select_used, _("Used"), SELECT_USED));
316 submenu->add_submenuitem(new AssetSelectUsedItem(select_used, _("Unused"), SELECT_UNUSED));
317 submenu->add_submenuitem(new AssetSelectUsedItem(select_used, _("None"), SELECT_NONE));
318 add_item(new AWindowListSort(mwindow, gui));
322 void ProxyListMenu::update()