awindowgui / mwindowedit / label rework
[goodguy/history.git] / cinelerra-5.1 / cinelerra / clippopup.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 "clippopup.h"
24 #include "assetremove.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 "edl.h"
32 #include "filexml.h"
33 #include "language.h"
34 #include "localsession.h"
35 #include "mainerror.h"
36 #include "mainsession.h"
37 #include "mwindow.h"
38 #include "mwindowgui.h"
39 #include "tracks.h"
40 #include "vwindow.h"
41 #include "vwindowgui.h"
42
43
44
45 ClipPopup::ClipPopup(MWindow *mwindow, AWindowGUI *gui)
46  : BC_PopupMenu(0, 0, 0, "", 0)
47 {
48         this->mwindow = mwindow;
49         this->gui = gui;
50 }
51
52 ClipPopup::~ClipPopup()
53 {
54 }
55
56 void ClipPopup::create_objects()
57 {
58         BC_MenuItem *menu_item;
59         BC_SubMenu *submenu;
60         add_item(info = new ClipPopupInfo(mwindow, this));
61         add_item(format = new AWindowListFormat(mwindow));
62         add_item(new ClipPopupSort(mwindow, this));
63         add_item(view = new ClipPopupView(mwindow, this));
64         add_item(view_window = new ClipPopupViewWindow(mwindow, this));
65         add_item(new ClipPopupCopy(mwindow, this));
66         add_item(new ClipPopupPaste(mwindow, this));
67         add_item(menu_item = new BC_MenuItem(_("Match...")));
68         menu_item->add_submenu(submenu = new BC_SubMenu());
69         submenu->add_submenuitem(new ClipMatchSize(mwindow, this));
70         submenu->add_submenuitem(new ClipMatchRate(mwindow, this));
71         submenu->add_submenuitem(new ClipMatchAll(mwindow, this));
72         add_item(menu_item = new BC_MenuItem(_("Remove...")));
73         menu_item->add_submenu(submenu = new BC_SubMenu());
74         submenu->add_submenuitem(new ClipPopupProjectRemove(mwindow, this));
75         submenu->add_submenuitem(new ClipPopupDiskRemove(mwindow, this));
76 }
77
78 void ClipPopup::paste_assets()
79 {
80 // Collect items into the drag vectors for temporary storage
81         gui->lock_window("ClipPopup::paste_assets");
82         mwindow->gui->lock_window("ClipPopup::paste_assets");
83         mwindow->cwindow->gui->lock_window("ClipPopup::paste_assets");
84
85         gui->collect_assets();
86         mwindow->paste_assets(mwindow->edl->local_session->get_selectionstart(1),
87                 mwindow->edl->tracks->first,
88                 0);   // do not overwrite
89
90         gui->unlock_window();
91         mwindow->gui->unlock_window();
92         mwindow->cwindow->gui->unlock_window();
93 }
94
95 void ClipPopup::match_size()
96 {
97 // Collect items into the drag vectors for temporary storage
98         gui->collect_assets();
99         mwindow->gui->lock_window("ClipPopup::match_size");
100         mwindow->asset_to_size();
101         mwindow->gui->unlock_window();
102 }
103
104 void ClipPopup::match_rate()
105 {
106 // Collect items into the drag vectors for temporary storage
107         gui->collect_assets();
108         mwindow->gui->lock_window("ClipPopup::match_rate");
109         mwindow->asset_to_rate();
110         mwindow->gui->unlock_window();
111 }
112
113 void ClipPopup::match_all()
114 {
115 // Collect items into the drag vectors for temporary storage
116         gui->collect_assets();
117         mwindow->gui->lock_window("ClipPopup::match_rate");
118         mwindow->asset_to_all();
119         mwindow->gui->unlock_window();
120 }
121
122 int ClipPopup::update()
123 {
124         format->update();
125         gui->collect_assets();
126         return 0;
127 }
128
129
130 ClipPopupInfo::ClipPopupInfo(MWindow *mwindow, ClipPopup *popup)
131  : BC_MenuItem(_("Info..."))
132 {
133         this->mwindow = mwindow;
134         this->popup = popup;
135 }
136
137 ClipPopupInfo::~ClipPopupInfo()
138 {
139 }
140
141 int ClipPopupInfo::handle_event()
142 {
143         if(mwindow->session->drag_assets->total)
144         {
145                 mwindow->awindow->asset_edit->edit_asset(
146                         mwindow->session->drag_assets->values[0]);
147         }
148         else
149         if(mwindow->session->drag_clips->total)
150         {
151                 popup->gui->awindow->clip_edit->edit_clip(
152                         mwindow->session->drag_clips->values[0]);
153         }
154         return 1;
155 }
156
157
158 ClipPopupSort::ClipPopupSort(MWindow *mwindow, ClipPopup *popup)
159  : BC_MenuItem(_("Sort items"))
160 {
161         this->mwindow = mwindow;
162         this->popup = popup;
163 }
164
165 ClipPopupSort::~ClipPopupSort()
166 {
167 }
168
169 int ClipPopupSort::handle_event()
170 {
171         mwindow->awindow->gui->sort_assets();
172         return 1;
173 }
174
175
176 ClipPopupView::ClipPopupView(MWindow *mwindow, ClipPopup *popup)
177  : BC_MenuItem(_("View"))
178 {
179         this->mwindow = mwindow;
180         this->popup = popup;
181 }
182
183 ClipPopupView::~ClipPopupView()
184 {
185 }
186
187 int ClipPopupView::handle_event()
188 {
189         VWindow *vwindow = mwindow->get_viewer(1, DEFAULT_VWINDOW);
190         vwindow->gui->lock_window("ClipPopupView::handle_event");
191
192         if(mwindow->session->drag_assets->total)
193                 vwindow->change_source(
194                         mwindow->session->drag_assets->values[0]);
195         else
196         if(mwindow->session->drag_clips->total)
197                 vwindow->change_source(
198                         mwindow->session->drag_clips->values[0]);
199
200         vwindow->gui->unlock_window();
201         return 1;
202 }
203
204
205 ClipPopupViewWindow::ClipPopupViewWindow(MWindow *mwindow, ClipPopup *popup)
206  : BC_MenuItem(_("View in new window"))
207 {
208         this->mwindow = mwindow;
209         this->popup = popup;
210 }
211
212 ClipPopupViewWindow::~ClipPopupViewWindow()
213 {
214 }
215
216 int ClipPopupViewWindow::handle_event()
217 {
218 // Find window with nothing
219         VWindow *vwindow = mwindow->get_viewer(1);
220
221 // TODO: create new vwindow or change current vwindow
222         vwindow->gui->lock_window("ClipPopupView::handle_event");
223
224         if(mwindow->session->drag_assets->total)
225                 vwindow->change_source(
226                         mwindow->session->drag_assets->values[0]);
227         else
228         if(mwindow->session->drag_clips->total)
229                 vwindow->change_source(
230                         mwindow->session->drag_clips->values[0]);
231
232         vwindow->gui->unlock_window();
233         return 1;
234 }
235
236
237 ClipPopupCopy::ClipPopupCopy(MWindow *mwindow, ClipPopup *popup)
238  : BC_MenuItem(_("Copy"))
239 {
240         this->mwindow = mwindow;
241         this->popup = popup;
242 }
243 ClipPopupCopy::~ClipPopupCopy()
244 {
245 }
246
247 int ClipPopupCopy::handle_event()
248 {
249         MWindowGUI *gui = mwindow->gui;
250         gui->lock_window("ClipPopupCopy::handle_event");
251         if( mwindow->session->drag_clips->total > 0 ) {
252                 FileXML file;
253                 EDL *edl = mwindow->session->drag_clips->values[0];
254                 double start = 0, end = edl->tracks->total_length();
255                 edl->copy(start, end, 1, 0, 0, &file, "", 1);
256                 const char *file_string = file.string();
257                 long file_length = strlen(file_string);
258                 gui->get_clipboard()->to_clipboard(file_string, file_length,
259                         SECONDARY_SELECTION);
260                 gui->get_clipboard()->to_clipboard(file_string, file_length,
261                         BC_PRIMARY_SELECTION);
262         }
263         gui->unlock_window(); 
264         return 1;
265 }
266
267
268 ClipPopupPaste::ClipPopupPaste(MWindow *mwindow, ClipPopup *popup)
269  : BC_MenuItem(_("Paste"))
270 {
271         this->mwindow = mwindow;
272         this->popup = popup;
273 }
274
275 ClipPopupPaste::~ClipPopupPaste()
276 {
277 }
278
279 int ClipPopupPaste::handle_event()
280 {
281         popup->paste_assets();
282         return 1;
283 }
284
285
286 ClipMatchSize::ClipMatchSize(MWindow *mwindow, ClipPopup *popup)
287  : BC_MenuItem(_("Match project size"))
288 {
289         this->mwindow = mwindow;
290         this->popup = popup;
291 }
292
293 int ClipMatchSize::handle_event()
294 {
295         popup->match_size();
296         return 1;
297 }
298
299
300 ClipMatchRate::ClipMatchRate(MWindow *mwindow, ClipPopup *popup)
301  : BC_MenuItem(_("Match frame rate"))
302 {
303         this->mwindow = mwindow;
304         this->popup = popup;
305 }
306
307 int ClipMatchRate::handle_event()
308 {
309         popup->match_rate();
310         return 1;
311 }
312
313
314 ClipMatchAll::ClipMatchAll(MWindow *mwindow, ClipPopup *popup)
315  : BC_MenuItem(_("Match all"))
316 {
317         this->mwindow = mwindow;
318         this->popup = popup;
319 }
320
321 int ClipMatchAll::handle_event()
322 {
323         popup->match_all();
324         return 1;
325 }
326
327
328 ClipPopupProjectRemove::ClipPopupProjectRemove(MWindow *mwindow, ClipPopup *popup)
329  : BC_MenuItem(_("Remove from project"))
330 {
331         this->mwindow = mwindow;
332         this->popup = popup;
333 }
334
335
336 ClipPopupProjectRemove::~ClipPopupProjectRemove()
337 {
338 }
339
340 int ClipPopupProjectRemove::handle_event()
341 {
342         mwindow->remove_assets_from_project(1,
343                 1,
344                 mwindow->session->drag_assets,
345                 mwindow->session->drag_clips);
346         return 1;
347 }
348
349
350 ClipPopupDiskRemove::ClipPopupDiskRemove(MWindow *mwindow, ClipPopup *popup)
351  : BC_MenuItem(_("Remove from disk"))
352 {
353         this->mwindow = mwindow;
354         this->popup = popup;
355 }
356
357 ClipPopupDiskRemove::~ClipPopupDiskRemove()
358 {
359 }
360
361 int ClipPopupDiskRemove::handle_event()
362 {
363         mwindow->awindow->asset_remove->start();
364         return 1;
365 }
366
367
368 ClipPasteToFolder::ClipPasteToFolder(MWindow *mwindow)
369  : BC_MenuItem(_("Paste Clip"))
370 {
371         this->mwindow = mwindow;
372 }
373
374 int ClipPasteToFolder::handle_event()
375 {
376         MWindowGUI *gui = mwindow->gui;
377         gui->lock_window("ClipPasteToFolder::handle_event 1");
378         int64_t len = gui->get_clipboard()->clipboard_len(SECONDARY_SELECTION);
379         if( len ) {
380                 char *string = new char[len + 1];
381                 gui->get_clipboard()->from_clipboard(string, len, BC_PRIMARY_SELECTION);
382                 const char *clip_header = "<EDL VERSION=";
383                 if( !strncmp(clip_header, string, strlen(clip_header)) ) {
384                         FileXML file;
385                         file.read_from_string(string);
386                         EDL *edl = mwindow->edl;
387                         EDL *new_edl = new EDL(mwindow->edl);
388                         new_edl->create_objects();
389                         new_edl->load_xml(&file, LOAD_ALL);
390                         edl->update_assets(new_edl);
391                         mwindow->save_clip(new_edl, _("paste clip: "));
392                 }
393                 else {
394                         char *cp = strchr(string, '\n');
395                         if( cp-string < 32 ) *cp = 0;
396                         else if( len > 32 ) string[32] = 0;
397                         eprintf("paste buffer is not EDL:\n%s", string);
398                 }
399                 delete [] string;
400         }
401         else {
402                 eprintf("paste buffer empty");
403         }
404         gui->unlock_window();
405         return 1;
406 }
407
408
409 ClipListMenu::ClipListMenu(MWindow *mwindow, AWindowGUI *gui)
410  : BC_PopupMenu(0, 0, 0, "", 0)
411 {
412         this->mwindow = mwindow;
413         this->gui = gui;
414 }
415
416 ClipListMenu::~ClipListMenu()
417 {
418 }
419
420 void ClipListMenu::create_objects()
421 {
422         add_item(format = new AWindowListFormat(mwindow));
423         add_item(new AWindowListSort(mwindow));
424         add_item(new ClipPasteToFolder(mwindow));
425         update();
426 }
427
428 void ClipListMenu::update()
429 {
430         format->update();
431 }
432