225b21bd3db129968f42d682e21c97ffbb9e2136
[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 "proxypopup.h"
24 #include "awindow.h"
25 #include "awindowgui.h"
26 #include "bcsignals.h"
27 #include "clipedit.h"
28 #include "cwindow.h"
29 #include "cwindowgui.h"
30 #include "edit.h"
31 #include "edits.h"
32 #include "edl.h"
33 #include "filexml.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 "track.h"
41 #include "tracks.h"
42 #include "vwindow.h"
43 #include "vwindowgui.h"
44
45
46
47 ProxyPopup::ProxyPopup(MWindow *mwindow, AWindowGUI *gui)
48  : BC_PopupMenu(0, 0, 0, "", 0)
49 {
50         this->mwindow = mwindow;
51         this->gui = gui;
52 }
53
54 ProxyPopup::~ProxyPopup()
55 {
56 }
57
58 void ProxyPopup::create_objects()
59 {
60         add_item(info = new ProxyPopupInfo(mwindow, this));
61         add_item(format = new AWindowListFormat(mwindow, gui));
62         add_item(new ProxyPopupSort(mwindow, this));
63         add_item(view = new ProxyPopupView(mwindow, this));
64         add_item(view_window = new ProxyPopupViewWindow(mwindow, this));
65         add_item(new ProxyPopupCopy(mwindow, this));
66         add_item(new ProxyPopupPaste(mwindow, this));
67 }
68
69 void ProxyPopup::paste_assets()
70 {
71 // Collect items into the drag vectors for temporary storage
72         gui->lock_window("ProxyPopup::paste_assets");
73         mwindow->gui->lock_window("ProxyPopup::paste_assets");
74         mwindow->cwindow->gui->lock_window("ProxyPopup::paste_assets");
75
76         gui->collect_assets(1);
77         mwindow->paste_assets(mwindow->edl->local_session->get_selectionstart(1),
78                 mwindow->edl->tracks->first, 0);   // do not overwrite
79
80         gui->unlock_window();
81         mwindow->gui->unlock_window();
82         mwindow->cwindow->gui->unlock_window();
83 }
84
85 int ProxyPopup::update()
86 {
87         format->update();
88         gui->collect_assets(1);
89         return 0;
90 }
91
92
93 ProxyPopupInfo::ProxyPopupInfo(MWindow *mwindow, ProxyPopup *popup)
94  : BC_MenuItem(_("Info..."))
95 {
96         this->mwindow = mwindow;
97         this->popup = popup;
98 }
99
100 ProxyPopupInfo::~ProxyPopupInfo()
101 {
102 }
103
104 int ProxyPopupInfo::handle_event()
105 {
106         int cur_x, cur_y;
107         popup->gui->get_abs_cursor(cur_x, cur_y, 0);
108
109         if( mwindow->session->drag_assets->total ) {
110                 AssetEdit *asset_edit = mwindow->awindow->get_asset_editor();
111                 asset_edit->edit_asset(
112                         mwindow->session->drag_assets->values[0], cur_x, cur_y);
113         }
114         else
115         if( mwindow->session->drag_clips->total ) {
116                 popup->gui->awindow->clip_edit->edit_clip(
117                         mwindow->session->drag_clips->values[0], cur_x, cur_y);
118         }
119         return 1;
120 }
121
122
123 ProxyPopupSort::ProxyPopupSort(MWindow *mwindow, ProxyPopup *popup)
124  : BC_MenuItem(_("Sort items"))
125 {
126         this->mwindow = mwindow;
127         this->popup = popup;
128 }
129
130 ProxyPopupSort::~ProxyPopupSort()
131 {
132 }
133
134 int ProxyPopupSort::handle_event()
135 {
136         mwindow->awindow->gui->sort_assets(0);
137         return 1;
138 }
139
140
141 ProxyPopupView::ProxyPopupView(MWindow *mwindow, ProxyPopup *popup)
142  : BC_MenuItem(_("View"))
143 {
144         this->mwindow = mwindow;
145         this->popup = popup;
146 }
147
148 ProxyPopupView::~ProxyPopupView()
149 {
150 }
151
152 int ProxyPopupView::handle_event()
153 {
154         VWindow *vwindow = mwindow->get_viewer(1, DEFAULT_VWINDOW);
155
156         if( mwindow->session->drag_assets->total )
157                 vwindow->change_source(
158                         mwindow->session->drag_assets->values[0]);
159         else
160         if( mwindow->session->drag_clips->total )
161                 vwindow->change_source(
162                         mwindow->session->drag_clips->values[0]);
163
164         return 1;
165 }
166
167
168 ProxyPopupViewWindow::ProxyPopupViewWindow(MWindow *mwindow, ProxyPopup *popup)
169  : BC_MenuItem(_("View in new window"))
170 {
171         this->mwindow = mwindow;
172         this->popup = popup;
173 }
174
175 ProxyPopupViewWindow::~ProxyPopupViewWindow()
176 {
177 }
178
179 int ProxyPopupViewWindow::handle_event()
180 {
181         for( int i=0; i<mwindow->session->drag_assets->size(); ++i ) {
182                 VWindow *vwindow = mwindow->get_viewer(1);
183                 vwindow->gui->lock_window("ProxyPopupView::handle_event 1");
184                 vwindow->change_source(mwindow->session->drag_assets->get(i));
185                 vwindow->gui->unlock_window();
186         }
187         for( int i=0; i<mwindow->session->drag_clips->size(); ++i ) {
188                 VWindow *vwindow = mwindow->get_viewer(1);
189                 vwindow->gui->lock_window("ProxyPopupView::handle_event 2");
190                 vwindow->change_source(mwindow->session->drag_clips->get(i));
191                 vwindow->gui->unlock_window();
192         }
193         return 1;
194 }
195
196
197 ProxyPopupCopy::ProxyPopupCopy(MWindow *mwindow, ProxyPopup *popup)
198  : BC_MenuItem(_("Copy"))
199 {
200         this->mwindow = mwindow;
201         this->popup = popup;
202 }
203 ProxyPopupCopy::~ProxyPopupCopy()
204 {
205 }
206
207 int ProxyPopupCopy::handle_event()
208 {
209         MWindowGUI *gui = mwindow->gui;
210         gui->lock_window("ProxyPopupCopy::handle_event");
211         if( mwindow->session->drag_clips->total > 0 ) {
212                 EDL *edl = mwindow->session->drag_clips->values[0];
213                 EDL *copy_edl = new EDL; // no parent or assets wont be copied
214                 copy_edl->create_objects();
215                 copy_edl->copy_all(edl);
216                 FileXML file;
217                 double start = 0, end = edl->tracks->total_length();
218                 copy_edl->copy(start, end, 1, &file, "", 1);
219                 copy_edl->remove_user();
220                 const char *file_string = file.string();
221                 long file_length = strlen(file_string);
222                 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
223                 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
224         }
225         gui->unlock_window(); 
226         return 1;
227 }
228
229
230 ProxyPopupPaste::ProxyPopupPaste(MWindow *mwindow, ProxyPopup *popup)
231  : BC_MenuItem(_("Paste"))
232 {
233         this->mwindow = mwindow;
234         this->popup = popup;
235 }
236
237 ProxyPopupPaste::~ProxyPopupPaste()
238 {
239 }
240
241 int ProxyPopupPaste::handle_event()
242 {
243         popup->paste_assets();
244         return 1;
245 }
246
247
248 ProxyListMenu::ProxyListMenu(MWindow *mwindow, AWindowGUI *gui)
249  : BC_PopupMenu(0, 0, 0, "", 0)
250 {
251         this->mwindow = mwindow;
252         this->gui = gui;
253 }
254
255 ProxyListMenu::~ProxyListMenu()
256 {
257 }
258
259 void ProxyListMenu::create_objects()
260 {
261         add_item(format = new AWindowListFormat(mwindow, gui));
262         add_item(new AWindowListSort(mwindow, gui));
263         update();
264 }
265
266 void ProxyListMenu::update()
267 {
268         format->update();
269 }
270
271