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"
28 #include "editpopup.h"
30 #include "edlsession.h"
34 #include "localsession.h"
35 #include "mainerror.h"
36 #include "mainsession.h"
38 #include "mwindowgui.h"
39 #include "plugindialog.h"
40 #include "resizetrackthread.h"
43 #include "trackcanvas.h"
47 EditPopup::EditPopup(MWindow *mwindow, MWindowGUI *gui)
48 : BC_PopupMenu(0, 0, 0, "", 0)
50 this->mwindow = mwindow;
54 EditPopup::~EditPopup()
58 void EditPopup::create_objects()
60 add_item(new EditPopupClear(mwindow, this));
61 add_item(new EditPopupDelete(mwindow, this));
62 add_item(new EditPopupCopy(mwindow, this));
63 add_item(new EditPopupCut(mwindow, this));
64 add_item(new EditPopupCopyCut(mwindow, this));
65 add_item(new EditPopupPaste(mwindow, this));
66 add_item(new EditPopupFindAsset(mwindow, this));
67 add_item(new EditPopupTitle(mwindow, this));
68 add_item(new EditPopupShow(mwindow, this));
71 int EditPopup::update(Edit *edit)
78 EditPopupClear::EditPopupClear(MWindow *mwindow, EditPopup *popup)
79 : BC_MenuItem(_("Clear"),_("Ctrl-m"),'m')
81 this->mwindow = mwindow;
86 int EditPopupClear::handle_event()
88 mwindow->delete_edits(0);
92 EditPopupDelete::EditPopupDelete(MWindow *mwindow, EditPopup *popup)
93 : BC_MenuItem(_("Delete"),_("Ctrl-DEL"),DELETE)
95 this->mwindow = mwindow;
100 int EditPopupDelete::handle_event()
102 mwindow->delete_edits(1);
106 EditPopupCopy::EditPopupCopy(MWindow *mwindow, EditPopup *popup)
107 : BC_MenuItem(_("Copy"),_("Ctrl-c"),'c')
109 this->mwindow = mwindow;
114 int EditPopupCopy::handle_event()
116 mwindow->selected_to_clipboard();
120 EditPopupCut::EditPopupCut(MWindow *mwindow, EditPopup *popup)
121 : BC_MenuItem(_("Cut"),_("Ctrl-x"),'x')
123 this->mwindow = mwindow;
128 int EditPopupCut::handle_event()
130 mwindow->cut_selected_edits(1);
134 EditPopupCopyCut::EditPopupCopyCut(MWindow *mwindow, EditPopup *popup)
135 : BC_MenuItem(_("Copy cut"),_("Ctrl-z"),'z')
137 this->mwindow = mwindow;
142 int EditPopupCopyCut::handle_event()
144 mwindow->cut_selected_edits(0);
148 EditPopupPaste::EditPopupPaste(MWindow *mwindow, EditPopup *popup)
149 : BC_MenuItem(_("Paste"),_("Ctrl-v"),'v')
151 this->mwindow = mwindow;
156 int EditPopupPaste::handle_event()
162 EditPopupFindAsset::EditPopupFindAsset(MWindow *mwindow, EditPopup *popup)
163 : BC_MenuItem(_("Find in Resources"))
165 this->mwindow = mwindow;
169 int EditPopupFindAsset::handle_event()
171 Edit *edit = popup->edit;
173 Indexable *idxbl = (Indexable *)edit->asset;
174 if( !idxbl ) idxbl = (Indexable *)edit->nested_edl;
176 AWindowGUI *agui = mwindow->awindow->gui;
177 agui->lock_window("EditPopupFindAsset::handle_event");
178 AssetPicon *picon = 0;
179 for( int i=0, n=agui->assets.size(); i<n; ++i ) {
180 AssetPicon *ap = (AssetPicon *)agui->assets[i];
181 int found = ap->indexable && ( idxbl == ap->indexable ||
182 !strcmp(idxbl->path, ap->indexable->path) );
183 if( found && !picon ) picon = ap;
184 ap->set_selected(found);
187 int selected_folder = picon->indexable->folder_no;
188 mwindow->edl->session->awindow_folder = selected_folder;
189 for( int i=0,n=agui->folders.size(); i<n; ++i ) {
190 AssetPicon *folder_item = (AssetPicon *)agui->folders[i];
191 int selected = folder_item->foldernum == selected_folder ? 1 : 0;
192 folder_item->set_selected(selected);
195 agui->unlock_window();
196 agui->async_update_assets();
203 EditPopupTitle::EditPopupTitle(MWindow *mwindow, EditPopup *popup)
204 : BC_MenuItem(_("User title..."))
206 this->mwindow = mwindow;
208 dialog_thread = new EditTitleDialogThread(this);
211 EditPopupTitle::~EditPopupTitle()
213 delete dialog_thread;
216 int EditPopupTitle::handle_event()
219 dialog_thread->close_window();
220 int wx = mwindow->gui->get_abs_cursor_x(0) - 400 / 2;
221 int wy = mwindow->gui->get_abs_cursor_y(0) - 500 / 2;
222 dialog_thread->start(wx, wy);
227 void EditTitleDialogThread::start(int wx, int wy)
229 this->wx = wx; this->wy = wy;
230 BC_DialogThread::start();
233 EditTitleDialogThread::EditTitleDialogThread(EditPopupTitle *edit_title)
235 this->edit_title = edit_title;
238 EditTitleDialogThread::~EditTitleDialogThread()
243 BC_Window* EditTitleDialogThread::new_gui()
245 MWindow *mwindow = edit_title->mwindow;
246 EditPopup *popup = edit_title->popup;
247 window = new EditPopupTitleWindow(mwindow, popup, wx, wy);
248 window->create_objects();
252 void EditTitleDialogThread::handle_close_event(int result)
257 void EditTitleDialogThread::handle_done_event(int result)
260 MWindow *mwindow = edit_title->mwindow;
261 EditPopup *popup = edit_title->popup;
262 strcpy(popup->edit->user_title, window->title_text->get_text());
263 mwindow->gui->lock_window("EditTitleDialogThread::handle_done_event");
264 mwindow->gui->draw_canvas(1, 0);
265 mwindow->gui->flash_canvas(1);
266 mwindow->gui->unlock_window();
269 EditPopupTitleWindow::EditPopupTitleWindow(MWindow *mwindow,
270 EditPopup *popup, int wx, int wy)
271 : BC_Window(_(PROGRAM_NAME ": Set edit title"), wx, wy,
272 300, 130, 300, 130, 0, 0, 1)
274 this->mwindow = mwindow;
276 strcpy(new_text, !popup->edit ? "" : popup->edit->user_title);
279 EditPopupTitleWindow::~EditPopupTitleWindow()
283 void EditPopupTitleWindow::create_objects()
285 lock_window("EditPopupTitleWindow::create_objects");
287 add_subwindow(new BC_Title(x, y, _("User title:")));
288 title_text = new EditPopupTitleText(this, mwindow, x+15, y+20, new_text);
289 add_subwindow(title_text);
290 add_tool(new BC_OKButton(this));
291 add_tool(new BC_CancelButton(this));
300 EditPopupTitleText::EditPopupTitleText(EditPopupTitleWindow *window,
301 MWindow *mwindow, int x, int y, const char *text)
302 : BC_TextBox(x, y, 250, 1, text)
304 this->window = window;
305 this->mwindow = mwindow;
308 EditPopupTitleText::~EditPopupTitleText()
312 int EditPopupTitleText::handle_event()
314 if( get_keypress() == RETURN )
320 EditPopupShow::EditPopupShow(MWindow *mwindow, EditPopup *popup)
321 : BC_MenuItem(_("Show edit"))
323 this->mwindow = mwindow;
325 dialog_thread = new EditShowDialogThread(this);
328 EditPopupShow::~EditPopupShow()
330 delete dialog_thread;
333 int EditPopupShow::handle_event()
336 dialog_thread->close_window();
337 int wx = mwindow->gui->get_abs_cursor_x(0) - 400 / 2;
338 int wy = mwindow->gui->get_abs_cursor_y(0) - 500 / 2;
339 dialog_thread->start(wx, wy);
344 void EditShowDialogThread::start(int wx, int wy)
346 this->wx = wx; this->wy = wy;
347 BC_DialogThread::start();
350 EditShowDialogThread::EditShowDialogThread(EditPopupShow *edit_show)
352 this->edit_show = edit_show;
355 EditShowDialogThread::~EditShowDialogThread()
360 BC_Window* EditShowDialogThread::new_gui()
362 MWindow *mwindow = edit_show->mwindow;
363 EditPopup *popup = edit_show->popup;
364 window = new EditPopupShowWindow(mwindow, popup, wx, wy);
365 window->create_objects();
369 void EditShowDialogThread::handle_close_event(int result)
374 EditPopupShowWindow::EditPopupShowWindow(MWindow *mwindow,
375 EditPopup *popup, int wx, int wy)
376 : BC_Window(_(PROGRAM_NAME ": Show edit"), wx, wy,
377 300, 220, 300, 220, 0, 0, 1)
379 this->mwindow = mwindow;
383 EditPopupShowWindow::~EditPopupShowWindow()
387 void EditPopupShowWindow::create_objects()
389 lock_window("EditPopupShowWindow::create_objects");
392 char text[BCTEXTLEN];
393 Edit *edit = popup->edit;
394 Track *track = edit->track;
395 sprintf(text, _("Track %d:"), mwindow->edl->tracks->number_of(track)+1);
396 add_subwindow(title = new BC_Title(x, y, text));
397 int x1 = x + title->get_w() + 10;
398 int tw = get_w() - x1 - 20;
399 truncate_text(text, track->title, tw);
400 add_subwindow(new BC_Title(x1, y, text));
401 y += title->get_h() + 5;
402 sprintf(text, _("Edit %d:"), track->edits->number_of(edit)+1);
403 add_subwindow(title = new BC_Title(x, y, text));
404 char edit_title[BCTEXTLEN];
405 edit->get_title(edit_title);
406 truncate_text(text, edit_title, tw);
407 add_subwindow(new BC_Title(x1, y, text));
408 y += title->get_h() + 5;
410 EDLSession *session = mwindow->edl->session;
411 int time_format = session->time_format;
412 int sample_rate = session->sample_rate;
413 double frame_rate = session->frame_rate;
414 double frames_per_foot = session->frames_per_foot;
416 double startsource = track->from_units(edit->startsource);
417 double startproject = track->from_units(edit->startproject);
418 double length = track->from_units(edit->length);
420 char text_startsource[BCSTRLEN];
421 char text_startproject[BCSTRLEN];
422 char text_length[BCSTRLEN];
423 sprintf(text, _("StartSource: %s\nStartProject: %s\nLength: %s\n"),
424 Units::totext(text_startsource, startsource,
425 time_format, sample_rate, frame_rate, frames_per_foot),
426 Units::totext(text_startproject, startproject,
427 time_format, sample_rate, frame_rate, frames_per_foot),
428 Units::totext(text_length, length,
429 time_format, sample_rate, frame_rate, frames_per_foot));
430 show_text = new EditPopupShowText(this, mwindow, x+15, y+10, text);
431 add_subwindow(show_text);
432 add_tool(new BC_OKButton(this));
440 EditPopupShowText::EditPopupShowText(EditPopupShowWindow *window,
441 MWindow *mwindow, int x, int y, const char *text)
442 : BC_TextBox(x, y, 250, 4, text)
444 this->window = window;
445 this->mwindow = mwindow;
448 EditPopupShowText::~EditPopupShowText()