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