315b4078d42455b88c7aa2a57e54870b5d9cccb4
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / editpopup.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 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 "asset.h"
23 #include "assets.h"
24 #include "awindow.h"
25 #include "awindowgui.h"
26 #include "edit.h"
27 #include "edits.h"
28 #include "editpopup.h"
29 #include "edl.h"
30 #include "edlsession.h"
31 #include "file.h"
32 #include "filexml.h"
33 #include "keys.h"
34 #include "language.h"
35 #include "localsession.h"
36 #include "mainerror.h"
37 #include "mainsession.h"
38 #include "mwindow.h"
39 #include "mwindowgui.h"
40 #include "plugindialog.h"
41 #include "resizetrackthread.h"
42 #include "track.h"
43 #include "tracks.h"
44 #include "trackcanvas.h"
45
46 #include <string.h>
47
48 EditPopup::EditPopup(MWindow *mwindow, MWindowGUI *gui)
49  : BC_PopupMenu(0, 0, 0, "", 0)
50 {
51         this->mwindow = mwindow;
52         this->gui = gui;
53
54         track = 0;
55         edit = 0;
56         plugin = 0;
57         pluginset = 0;
58         position = 0;
59         open_edl = 0;
60 }
61
62 EditPopup::~EditPopup()
63 {
64 }
65
66 void EditPopup::create_objects()
67 {
68         add_item(open_edl = new EditPopupOpenEDL(mwindow, this));
69         add_item(new EditPopupClearSelect(mwindow, this));
70         add_item(new EditPopupCopy(mwindow, this));
71         add_item(new EditPopupCut(mwindow, this));
72         add_item(new EditPopupMute(mwindow, this));
73         add_item(new EditPopupCopyPack(mwindow, this));
74         add_item(new EditPopupCutPack(mwindow, this));
75         add_item(new EditPopupMutePack(mwindow, this));
76         add_item(new EditPopupPaste(mwindow, this));
77         add_item(new EditPopupOverwrite(mwindow, this));
78         add_item(new BC_MenuItem("-"));
79         add_item(new EditPopupOverwritePlugins(mwindow, this));
80         add_item(new EditCollectEffects(mwindow, this));
81         add_item(new EditPasteEffects(mwindow, this));
82 }
83
84 int EditPopup::activate_menu(Track *track, Edit *edit,
85                 PluginSet *pluginset, Plugin *plugin, double position)
86 {
87         this->track = track;
88         this->edit = edit;
89         this->pluginset = pluginset;
90         this->plugin = plugin;
91         this->position = position;
92         int enable = !edit ? 0 :
93                 edit->nested_edl ? 1 :
94                 !edit->asset ? 0 :
95                 edit->asset->format == FILE_REF ? 1 : 0;
96         open_edl->set_enabled(enable);
97         return BC_PopupMenu::activate_menu();
98 }
99
100 EditPopupOpenEDL::EditPopupOpenEDL(MWindow *mwindow, EditPopup *popup)
101  : BC_MenuItem(_("Open EDL"))
102 {
103         this->mwindow = mwindow;
104         this->popup = popup;
105         set_ctrl(1);
106         set_shift(1);
107 }
108
109 int EditPopupOpenEDL::handle_event()
110 {
111         Edit *edit = popup->edit;
112         if( !edit ) return 1;
113         EDL *edl = 0;
114         Indexable *idxbl = 0;
115         if( edit->asset && edit->asset->format == FILE_REF ) {
116                 FileXML xml_file;
117                 const char *filename = edit->asset->path;
118                 if( xml_file.read_from_file(filename, 1) ) {
119                         eprintf(_("Error: unable to open:\n  %s"), filename);
120                         return 1;
121                 }
122                 edl = new EDL;
123                 edl->create_objects();
124                 if( edl->load_xml(&xml_file, LOAD_ALL) ) {
125                         eprintf(_("Error: unable to load:\n  %s"), filename);
126                         edl->remove_user();
127                         return 1;
128                 }
129                 idxbl = edit->asset;
130         }
131         else if( edit->nested_edl ) {
132                 edl = edit->nested_edl;
133                 edl->add_user();
134                 idxbl = edl;
135         }
136         else {
137                 char edit_title[BCTEXTLEN];
138                 edit->get_title(edit_title);
139                 eprintf(_("Edit is not EDL: %s"), edit_title);
140                 return 1;
141         }
142         mwindow->stack_push(edl, idxbl);
143         return 1;
144 }
145
146 EditPopupClearSelect::EditPopupClearSelect(MWindow *mwindow, EditPopup *popup)
147  : BC_MenuItem(_("Clear Select"),_("Ctrl-Shift-A"),'A')
148 {
149         this->mwindow = mwindow;
150         this->popup = popup;
151         set_ctrl(1);
152         set_shift(1);
153 }
154
155 int EditPopupClearSelect::handle_event()
156 {
157         mwindow->clear_select();
158         return 1;
159 }
160
161 EditPopupCopy::EditPopupCopy(MWindow *mwindow, EditPopup *popup)
162  : BC_MenuItem(_("Copy"),_("Ctrl-c"),'c')
163 {
164         this->mwindow = mwindow;
165         this->popup = popup;
166         set_ctrl(1);
167 }
168
169 int EditPopupCopy::handle_event()
170 {
171         mwindow->selected_edits_to_clipboard(0);
172         return 1;
173 }
174
175 EditPopupCopyPack::EditPopupCopyPack(MWindow *mwindow, EditPopup *popup)
176  : BC_MenuItem(_("Copy pack"),_("Ctrl-Shift-C"),'C')
177 {
178         this->mwindow = mwindow;
179         this->popup = popup;
180         set_ctrl(1);
181         set_shift(1);
182 }
183
184 int EditPopupCopyPack::handle_event()
185 {
186         mwindow->selected_edits_to_clipboard(1);
187         return 1;
188 }
189
190 EditPopupCut::EditPopupCut(MWindow *mwindow, EditPopup *popup)
191  : BC_MenuItem(_("Cut"),_("Ctrl-x"),'x')
192 {
193         this->mwindow = mwindow;
194         this->popup = popup;
195         set_ctrl(1);
196 }
197
198 int EditPopupCut::handle_event()
199 {
200         mwindow->cut_selected_edits(1, 0);
201         return 1;
202 }
203
204 EditPopupCutPack::EditPopupCutPack(MWindow *mwindow, EditPopup *popup)
205  : BC_MenuItem(_("Cut pack"),_("Ctrl-z"),'z')
206 {
207         this->mwindow = mwindow;
208         this->popup = popup;
209         set_ctrl(1);
210 }
211
212 int EditPopupCutPack::handle_event()
213 {
214         mwindow->cut_selected_edits(1, 1);
215         return 1;
216 }
217
218 EditPopupMute::EditPopupMute(MWindow *mwindow, EditPopup *popup)
219  : BC_MenuItem(C_("Mute"),_("Ctrl-m"),'m')
220 {
221         this->mwindow = mwindow;
222         this->popup = popup;
223         set_ctrl(1);
224 }
225
226 int EditPopupMute::handle_event()
227 {
228         mwindow->cut_selected_edits(0, 0);
229         return 1;
230 }
231
232 EditPopupMutePack::EditPopupMutePack(MWindow *mwindow, EditPopup *popup)
233  : BC_MenuItem(_("Mute pack"),_("Ctrl-Shift-M"),'M')
234 {
235         this->mwindow = mwindow;
236         this->popup = popup;
237         set_ctrl(1);
238         set_shift(1);
239 }
240
241 int EditPopupMutePack::handle_event()
242 {
243         mwindow->cut_selected_edits(0, 1);
244         return 1;
245 }
246
247 EditPopupPaste::EditPopupPaste(MWindow *mwindow, EditPopup *popup)
248  : BC_MenuItem(_("Paste"),_("Ctrl-v"),'v')
249 {
250         this->mwindow = mwindow;
251         this->popup = popup;
252         set_ctrl(1);
253 }
254
255 int EditPopupPaste::handle_event()
256 {
257         mwindow->paste(popup->position, popup->track, 0, 0);
258         mwindow->edl->tracks->clear_selected_edits();
259         popup->gui->draw_overlays(1);
260         if( mwindow->session->current_operation == DROP_TARGETING ) {
261                 mwindow->session->current_operation = NO_OPERATION;
262                 popup->gui->update_cursor();
263         }
264         return 1;
265 }
266
267 EditPopupOverwrite::EditPopupOverwrite(MWindow *mwindow, EditPopup *popup)
268  : BC_MenuItem(_("Overwrite"),_("Ctrl-b"),'b')
269 {
270         this->mwindow = mwindow;
271         this->popup = popup;
272         set_ctrl(1);
273 }
274
275 int EditPopupOverwrite::handle_event()
276 {
277         mwindow->paste(popup->position, popup->track, 0, -1);
278         mwindow->edl->tracks->clear_selected_edits();
279         popup->gui->draw_overlays(1);
280         if( mwindow->session->current_operation == DROP_TARGETING ) {
281                 mwindow->session->current_operation = NO_OPERATION;
282                 popup->gui->update_cursor();
283         }
284         return 1;
285 }
286
287 EditPopupOverwritePlugins::EditPopupOverwritePlugins(MWindow *mwindow, EditPopup *popup)
288  : BC_MenuItem(_("Overwrite Plugins"),_("Ctrl-Shift-P"),'P')
289 {
290         this->mwindow = mwindow;
291         this->popup = popup;
292         set_ctrl(1);
293         set_shift(1);
294 }
295
296 int EditPopupOverwritePlugins::handle_event()
297 {
298         mwindow->paste_clipboard(popup->track, popup->position, 1, 0,
299                         mwindow->edl->session->labels_follow_edits,
300                         mwindow->edl->session->autos_follow_edits,
301                         mwindow->edl->session->plugins_follow_edits);
302         mwindow->edl->tracks->clear_selected_edits();
303         if( mwindow->session->current_operation == DROP_TARGETING ) {
304                 mwindow->session->current_operation = NO_OPERATION;
305                 popup->gui->update_cursor();
306         }
307         return 1;
308 }
309
310
311 EditCollectEffects::EditCollectEffects(MWindow *mwindow, EditPopup *popup)
312  : BC_MenuItem(_("Collect Effects"))
313 {
314         this->mwindow = mwindow;
315         this->popup = popup;
316         set_ctrl(1);
317 }
318
319 int EditCollectEffects::handle_event()
320 {
321         if( mwindow->session->current_operation == NO_OPERATION )
322                 mwindow->collect_effects();
323         return 1;
324 }
325
326 EditPasteEffects::EditPasteEffects(MWindow *mwindow, EditPopup *popup)
327  : BC_MenuItem(_("Paste Effects"))
328 {
329         this->mwindow = mwindow;
330         this->popup = popup;
331         set_ctrl(1);
332         set_shift(1);
333 }
334
335 int EditPasteEffects::handle_event()
336 {
337         if( mwindow->session->current_operation == NO_OPERATION )
338                 mwindow->paste_effects();
339         return 1;
340 }
341
342