rework set default transtion, nested proxy edl fixes, doubleclick proxy media fix...
[goodguy/history.git] / cinelerra-5.1 / cinelerra / proxypopup.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2012 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "assetedit.h"
23 #include "assetremove.h"
24 #include "proxypopup.h"
25 #include "awindow.h"
26 #include "awindowgui.h"
27 #include "bcsignals.h"
28 #include "clipedit.h"
29 #include "cwindow.h"
30 #include "cwindowgui.h"
31 #include "edit.h"
32 #include "edits.h"
33 #include "edl.h"
34 #include "filexml.h"
35 #include "language.h"
36 #include "localsession.h"
37 #include "mainerror.h"
38 #include "mainsession.h"
39 #include "mwindow.h"
40 #include "mwindowgui.h"
41 #include "track.h"
42 #include "tracks.h"
43 #include "vwindow.h"
44 #include "vwindowgui.h"
45
46
47
48 ProxyPopup::ProxyPopup(MWindow *mwindow, AWindowGUI *gui)
49  : BC_PopupMenu(0, 0, 0, "", 0)
50 {
51         this->mwindow = mwindow;
52         this->gui = gui;
53 }
54
55 ProxyPopup::~ProxyPopup()
56 {
57 }
58
59 void ProxyPopup::create_objects()
60 {
61         BC_MenuItem *menu_item;
62         BC_SubMenu *submenu;
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));
74 }
75
76 void ProxyPopup::paste_assets()
77 {
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");
82
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
86
87         gui->unlock_window();
88         mwindow->gui->unlock_window();
89         mwindow->cwindow->gui->unlock_window();
90 }
91
92 int ProxyPopup::update()
93 {
94         format->update();
95         gui->collect_assets(1);
96         return 0;
97 }
98
99
100 ProxyPopupInfo::ProxyPopupInfo(MWindow *mwindow, ProxyPopup *popup)
101  : BC_MenuItem(_("Info..."))
102 {
103         this->mwindow = mwindow;
104         this->popup = popup;
105 }
106
107 ProxyPopupInfo::~ProxyPopupInfo()
108 {
109 }
110
111 int ProxyPopupInfo::handle_event()
112 {
113         int cur_x, cur_y;
114         popup->gui->get_abs_cursor(cur_x, cur_y, 0);
115
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);
120         }
121         else
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);
125         }
126         return 1;
127 }
128
129
130 ProxyPopupSort::ProxyPopupSort(MWindow *mwindow, ProxyPopup *popup)
131  : BC_MenuItem(_("Sort items"))
132 {
133         this->mwindow = mwindow;
134         this->popup = popup;
135 }
136
137 ProxyPopupSort::~ProxyPopupSort()
138 {
139 }
140
141 int ProxyPopupSort::handle_event()
142 {
143         mwindow->awindow->gui->sort_assets(0);
144         return 1;
145 }
146
147
148 ProxyPopupView::ProxyPopupView(MWindow *mwindow, ProxyPopup *popup)
149  : BC_MenuItem(_("View"))
150 {
151         this->mwindow = mwindow;
152         this->popup = popup;
153 }
154
155 ProxyPopupView::~ProxyPopupView()
156 {
157 }
158
159 int ProxyPopupView::handle_event()
160 {
161         VWindow *vwindow = mwindow->get_viewer(1, DEFAULT_VWINDOW);
162
163         if( mwindow->session->drag_assets->total )
164                 vwindow->change_source(
165                         mwindow->session->drag_assets->values[0]);
166         else
167         if( mwindow->session->drag_clips->total )
168                 vwindow->change_source(
169                         mwindow->session->drag_clips->values[0]);
170
171         return 1;
172 }
173
174
175 ProxyPopupViewWindow::ProxyPopupViewWindow(MWindow *mwindow, ProxyPopup *popup)
176  : BC_MenuItem(_("View in new window"))
177 {
178         this->mwindow = mwindow;
179         this->popup = popup;
180 }
181
182 ProxyPopupViewWindow::~ProxyPopupViewWindow()
183 {
184 }
185
186 int ProxyPopupViewWindow::handle_event()
187 {
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();
193         }
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();
199         }
200         return 1;
201 }
202
203
204 ProxyPopupCopy::ProxyPopupCopy(MWindow *mwindow, ProxyPopup *popup)
205  : BC_MenuItem(_("Copy"))
206 {
207         this->mwindow = mwindow;
208         this->popup = popup;
209 }
210 ProxyPopupCopy::~ProxyPopupCopy()
211 {
212 }
213
214 int ProxyPopupCopy::handle_event()
215 {
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);
223                 FileXML file;
224                 double start = 0, end = edl->tracks->total_length();
225                 copy_edl->copy(start, end, 1, &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);
231         }
232         gui->unlock_window(); 
233         return 1;
234 }
235
236
237 ProxyPopupPaste::ProxyPopupPaste(MWindow *mwindow, ProxyPopup *popup)
238  : BC_MenuItem(_("Paste"))
239 {
240         this->mwindow = mwindow;
241         this->popup = popup;
242 }
243
244 ProxyPopupPaste::~ProxyPopupPaste()
245 {
246 }
247
248 int ProxyPopupPaste::handle_event()
249 {
250         popup->paste_assets();
251         return 1;
252 }
253
254
255 ProxyPopupProjectRemove::ProxyPopupProjectRemove(MWindow *mwindow, ProxyPopup *popup)
256  : BC_MenuItem(_("Remove from project"))
257 {
258         this->mwindow = mwindow;
259         this->popup = popup;
260 }
261
262 ProxyPopupProjectRemove::~ProxyPopupProjectRemove()
263 {
264 }
265
266 int ProxyPopupProjectRemove::handle_event()
267 {
268         popup->gui->collect_assets();
269         mwindow->remove_assets_from_project(1, 1,
270                 mwindow->session->drag_assets,
271                 mwindow->session->drag_clips);
272         return 1;
273 }
274
275
276 ProxyPopupDiskRemove::ProxyPopupDiskRemove(MWindow *mwindow, ProxyPopup *popup)
277  : BC_MenuItem(_("Remove from disk"))
278 {
279         this->mwindow = mwindow;
280         this->popup = popup;
281 }
282
283
284 ProxyPopupDiskRemove::~ProxyPopupDiskRemove()
285 {
286 }
287
288 int ProxyPopupDiskRemove::handle_event()
289 {
290         popup->gui->collect_assets();
291         mwindow->awindow->asset_remove->start();
292         return 1;
293 }
294
295
296
297 ProxyListMenu::ProxyListMenu(MWindow *mwindow, AWindowGUI *gui)
298  : BC_PopupMenu(0, 0, 0, "", 0)
299 {
300         this->mwindow = mwindow;
301         this->gui = gui;
302 }
303
304 ProxyListMenu::~ProxyListMenu()
305 {
306 }
307
308 void ProxyListMenu::create_objects()
309 {
310         add_item(format = new AWindowListFormat(mwindow, gui));
311         add_item(new AWindowListSort(mwindow, gui));
312         update();
313 }
314
315 void ProxyListMenu::update()
316 {
317         format->update();
318 }
319
320