4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
25 #include "awindowgui.h"
27 #include "editpopup.h"
29 #include "edlsession.h"
33 #include "localsession.h"
34 #include "mainerror.h"
35 #include "mainsession.h"
37 #include "mwindowgui.h"
38 #include "plugindialog.h"
39 #include "resizetrackthread.h"
42 #include "trackcanvas.h"
46 EditPopup::EditPopup(MWindow *mwindow, MWindowGUI *gui)
47 : BC_PopupMenu(0, 0, 0, "", 0)
49 this->mwindow = mwindow;
53 EditPopup::~EditPopup()
57 void EditPopup::create_objects()
59 add_item(new EditAttachEffect(mwindow, this));
60 add_item(new EditMoveTrackUp(mwindow, this));
61 add_item(new EditMoveTrackDown(mwindow, this));
62 add_item(new EditPopupDeleteTrack(mwindow, this));
63 add_item(new EditPopupAddTrack(mwindow, this));
64 add_item(new EditPopupFindAsset(mwindow, this));
65 add_item(new EditPopupTitle(mwindow, this));
70 int EditPopup::update(Track *track, Edit *edit)
75 if(track->data_type == TRACK_VIDEO && !resize_option)
77 add_item(resize_option = new EditPopupResize(mwindow, this));
78 add_item(matchsize_option = new EditPopupMatchSize(mwindow, this));
81 if(track->data_type == TRACK_AUDIO && resize_option)
83 del_item(resize_option); resize_option = 0;
84 del_item(matchsize_option); matchsize_option = 0;
90 EditAttachEffect::EditAttachEffect(MWindow *mwindow, EditPopup *popup)
91 : BC_MenuItem(_("Attach effect..."))
93 this->mwindow = mwindow;
95 dialog_thread = new PluginDialogThread(mwindow);
98 EditAttachEffect::~EditAttachEffect()
100 delete dialog_thread;
103 int EditAttachEffect::handle_event()
105 dialog_thread->start_window(popup->track,
106 0, _(PROGRAM_NAME ": Attach Effect"),
107 0, popup->track->data_type);
112 EditMoveTrackUp::EditMoveTrackUp(MWindow *mwindow, EditPopup *popup)
113 : BC_MenuItem(_("Move up"))
115 this->mwindow = mwindow;
118 EditMoveTrackUp::~EditMoveTrackUp()
121 int EditMoveTrackUp::handle_event()
123 mwindow->move_track_up(popup->track);
129 EditMoveTrackDown::EditMoveTrackDown(MWindow *mwindow, EditPopup *popup)
130 : BC_MenuItem(_("Move down"))
132 this->mwindow = mwindow;
135 EditMoveTrackDown::~EditMoveTrackDown()
138 int EditMoveTrackDown::handle_event()
140 mwindow->move_track_down(popup->track);
145 EditPopupResize::EditPopupResize(MWindow *mwindow, EditPopup *popup)
146 : BC_MenuItem(_("Resize track..."))
148 this->mwindow = mwindow;
150 dialog_thread = new ResizeTrackThread(mwindow);
152 EditPopupResize::~EditPopupResize()
154 delete dialog_thread;
157 int EditPopupResize::handle_event()
159 dialog_thread->start_window(popup->track);
164 EditPopupMatchSize::EditPopupMatchSize(MWindow *mwindow, EditPopup *popup)
165 : BC_MenuItem(_("Match output size"))
167 this->mwindow = mwindow;
170 EditPopupMatchSize::~EditPopupMatchSize()
174 int EditPopupMatchSize::handle_event()
176 mwindow->match_output_size(popup->track);
181 EditPopupDeleteTrack::EditPopupDeleteTrack(MWindow *mwindow, EditPopup *popup)
182 : BC_MenuItem(_("Delete track"))
184 this->mwindow = mwindow;
187 int EditPopupDeleteTrack::handle_event()
189 mwindow->delete_track(popup->track);
194 EditPopupAddTrack::EditPopupAddTrack(MWindow *mwindow, EditPopup *popup)
195 : BC_MenuItem(_("Add track"))
197 this->mwindow = mwindow;
201 int EditPopupAddTrack::handle_event()
203 switch( popup->track->data_type ) {
205 mwindow->add_audio_track_entry(1, popup->track);
208 mwindow->add_video_track_entry(popup->track);
211 mwindow->add_subttl_track_entry(popup->track);
217 EditPopupFindAsset::EditPopupFindAsset(MWindow *mwindow, EditPopup *popup)
218 : BC_MenuItem(_("Find in Resources"))
220 this->mwindow = mwindow;
224 int EditPopupFindAsset::handle_event()
226 Edit *edit = popup->edit;
228 Indexable *idxbl = (Indexable *)edit->asset;
229 if( !idxbl ) idxbl = (Indexable *)edit->nested_edl;
231 AWindowGUI *agui = mwindow->awindow->gui;
232 agui->lock_window("EditPopupFindAsset::handle_event");
233 AssetPicon *picon = 0;
234 for( int i=0, n=agui->assets.size(); i<n; ++i ) {
235 AssetPicon *ap = (AssetPicon *)agui->assets[i];
236 int found = ap->indexable && ( idxbl == ap->indexable ||
237 !strcmp(idxbl->path, ap->indexable->path) );
238 if( found && !picon ) picon = ap;
239 ap->set_selected(found);
242 int selected_folder = picon->indexable->awindow_folder;
243 mwindow->edl->session->awindow_folder = selected_folder;
244 for( int i=0,n=agui->folders.size(); i<n; ++i ) {
245 AssetPicon *folder_item = (AssetPicon *)agui->folders[i];
246 int selected = folder_item->foldernum == selected_folder ? 1 : 0;
247 folder_item->set_selected(selected);
250 agui->unlock_window();
251 agui->async_update_assets();
258 EditPopupTitle::EditPopupTitle(MWindow *mwindow, EditPopup *popup)
259 : BC_MenuItem(_("User title..."))
261 this->mwindow = mwindow;
266 EditPopupTitle::~EditPopupTitle()
270 int EditPopupTitle::handle_event()
274 window = new EditPopupTitleWindow (mwindow, popup);
275 window->create_objects();
276 result = window->run_window();
277 if( !result && popup->edit ) {
278 strcpy(popup->edit->user_title, window->title_text->get_text());
279 mwindow->gui->draw_canvas(1, 0);
280 mwindow->gui->flash_canvas(1);
282 delete window; window = 0;
289 EditPopupTitleWindow::EditPopupTitleWindow (MWindow *mwindow, EditPopup *popup)
290 : BC_Window (_(PROGRAM_NAME ": Set edit title"),
291 mwindow->gui->get_abs_cursor_x(0) - 400 / 2,
292 mwindow->gui->get_abs_cursor_y(0) - 500 / 2,
293 300, 130, 300, 130, 0, 0, 1)
295 this->mwindow = mwindow;
298 strcpy(new_text, popup->edit->user_title);
302 EditPopupTitleWindow::~EditPopupTitleWindow()
306 int EditPopupTitleWindow::close_event()
312 void EditPopupTitleWindow::create_objects()
314 lock_window("EditPopupTitleWindow::create_objects");
317 add_subwindow (new BC_Title (x, y, _("User title:")));
318 title_text = new EditPopupTitleText (this, mwindow, x+15, y+20,
319 popup->edit ? popup->edit->user_title : "");
320 add_subwindow(title_text);
321 add_tool(new BC_OKButton(this));
322 add_tool(new BC_CancelButton(this));
331 EditPopupTitleText::EditPopupTitleText (EditPopupTitleWindow *window,
332 MWindow *mwindow, int x, int y, const char *text)
333 : BC_TextBox(x, y, 250, 1, text)
335 this->window = window;
336 this->mwindow = mwindow;
339 EditPopupTitleText::~EditPopupTitleText()
343 int EditPopupTitleText::handle_event()
345 if( get_keypress() == RETURN )