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;
60 EditPopup::~EditPopup()
64 void EditPopup::create_objects()
66 add_item(new EditPopupClearSelect(mwindow, this));
67 add_item(new EditPopupCopy(mwindow, this));
68 add_item(new EditPopupCut(mwindow, this));
69 add_item(new EditPopupMute(mwindow, this));
70 add_item(new EditPopupCopyPack(mwindow, this));
71 add_item(new EditPopupCutPack(mwindow, this));
72 add_item(new EditPopupMutePack(mwindow, this));
73 add_item(new EditPopupPaste(mwindow, this));
74 add_item(new EditPopupOverwrite(mwindow, this));
75 add_item(new EditPopupFindAsset(mwindow, this));
76 add_item(new EditPopupTitle(mwindow, this));
77 add_item(new EditPopupShow(mwindow, this));
80 int EditPopup::activate_menu(Track *track, Edit *edit,
81 PluginSet *pluginset, Plugin *plugin, double position)
85 this->pluginset = pluginset;
86 this->plugin = plugin;
87 this->position = position;
88 return BC_PopupMenu::activate_menu();
91 EditPopupClearSelect::EditPopupClearSelect(MWindow *mwindow, EditPopup *popup)
92 : BC_MenuItem(_("Clear Select"),_("Ctrl-Shift-A"),'A')
94 this->mwindow = mwindow;
100 int EditPopupClearSelect::handle_event()
102 mwindow->edl->tracks->clear_selected_edits();
103 popup->gui->draw_overlays(1);
107 EditPopupCopy::EditPopupCopy(MWindow *mwindow, EditPopup *popup)
108 : BC_MenuItem(_("Copy"),_("Ctrl-c"),'c')
110 this->mwindow = mwindow;
115 int EditPopupCopy::handle_event()
117 mwindow->selected_to_clipboard(0);
121 EditPopupCopyPack::EditPopupCopyPack(MWindow *mwindow, EditPopup *popup)
122 : BC_MenuItem(_("Copy pack"),_("Ctrl-Shift-C"),'C')
124 this->mwindow = mwindow;
130 int EditPopupCopyPack::handle_event()
132 mwindow->selected_to_clipboard(1);
136 EditPopupCut::EditPopupCut(MWindow *mwindow, EditPopup *popup)
137 : BC_MenuItem(_("Cut"),_("Ctrl-x"),'x')
139 this->mwindow = mwindow;
144 int EditPopupCut::handle_event()
146 mwindow->cut_selected_edits(1, 0);
150 EditPopupCutPack::EditPopupCutPack(MWindow *mwindow, EditPopup *popup)
151 : BC_MenuItem(_("Cut pack"),_("Ctrl-z"),'z')
153 this->mwindow = mwindow;
158 int EditPopupCutPack::handle_event()
160 mwindow->cut_selected_edits(1, 1);
164 EditPopupMute::EditPopupMute(MWindow *mwindow, EditPopup *popup)
165 : BC_MenuItem(_("Mute"),_("Ctrl-m"),'m')
167 this->mwindow = mwindow;
172 int EditPopupMute::handle_event()
174 mwindow->cut_selected_edits(0, 0);
178 EditPopupMutePack::EditPopupMutePack(MWindow *mwindow, EditPopup *popup)
179 : BC_MenuItem(_("Mute pack"),_("Ctrl-Shift-M"),'M')
181 this->mwindow = mwindow;
187 int EditPopupMutePack::handle_event()
189 mwindow->cut_selected_edits(0, 1);
193 EditPopupPaste::EditPopupPaste(MWindow *mwindow, EditPopup *popup)
194 : BC_MenuItem(_("Paste"),_("Ctrl-v"),'v')
196 this->mwindow = mwindow;
201 int EditPopupPaste::handle_event()
203 mwindow->paste(popup->position, popup->track, 0, 0);
204 mwindow->edl->tracks->clear_selected_edits();
205 popup->gui->draw_overlays(1);
206 if( mwindow->session->current_operation == DROP_TARGETING ) {
207 mwindow->session->current_operation = NO_OPERATION;
208 popup->gui->update_cursor();
213 EditPopupOverwrite::EditPopupOverwrite(MWindow *mwindow, EditPopup *popup)
214 : BC_MenuItem(_("Overwrite"),_("Ctrl-b"),'b')
216 this->mwindow = mwindow;
221 int EditPopupOverwrite::handle_event()
223 mwindow->paste(popup->position, popup->track, 0, -1);
224 mwindow->edl->tracks->clear_selected_edits();
225 popup->gui->draw_overlays(1);
226 if( mwindow->session->current_operation == DROP_TARGETING ) {
227 mwindow->session->current_operation = NO_OPERATION;
228 popup->gui->update_cursor();
233 EditPopupFindAsset::EditPopupFindAsset(MWindow *mwindow, EditPopup *popup)
234 : BC_MenuItem(_("Find in Resources"))
236 this->mwindow = mwindow;
240 int EditPopupFindAsset::handle_event()
242 Edit *edit = popup->edit;
244 Indexable *idxbl = (Indexable *)edit->asset;
245 if( !idxbl ) idxbl = (Indexable *)edit->nested_edl;
247 AWindowGUI *agui = mwindow->awindow->gui;
248 agui->lock_window("EditPopupFindAsset::handle_event");
249 AssetPicon *picon = 0;
250 for( int i=0, n=agui->assets.size(); i<n; ++i ) {
251 AssetPicon *ap = (AssetPicon *)agui->assets[i];
252 int found = ap->indexable && ( idxbl == ap->indexable ||
253 !strcmp(idxbl->path, ap->indexable->path) );
254 if( found && !picon ) picon = ap;
255 ap->set_selected(found);
258 int selected_folder = picon->indexable->folder_no;
259 mwindow->edl->session->awindow_folder = selected_folder;
260 for( int i=0,n=agui->folders.size(); i<n; ++i ) {
261 AssetPicon *folder_item = (AssetPicon *)agui->folders[i];
262 int selected = folder_item->foldernum == selected_folder ? 1 : 0;
263 folder_item->set_selected(selected);
266 agui->unlock_window();
267 agui->async_update_assets();
274 EditPopupTitle::EditPopupTitle(MWindow *mwindow, EditPopup *popup)
275 : BC_MenuItem(_("User title..."))
277 this->mwindow = mwindow;
279 dialog_thread = new EditTitleDialogThread(this);
282 EditPopupTitle::~EditPopupTitle()
284 delete dialog_thread;
287 int EditPopupTitle::handle_event()
290 dialog_thread->close_window();
291 int wx = mwindow->gui->get_abs_cursor_x(0) - 400 / 2;
292 int wy = mwindow->gui->get_abs_cursor_y(0) - 500 / 2;
293 dialog_thread->start(wx, wy);
298 void EditTitleDialogThread::start(int wx, int wy)
300 this->wx = wx; this->wy = wy;
301 BC_DialogThread::start();
304 EditTitleDialogThread::EditTitleDialogThread(EditPopupTitle *edit_title)
306 this->edit_title = edit_title;
309 EditTitleDialogThread::~EditTitleDialogThread()
314 BC_Window* EditTitleDialogThread::new_gui()
316 MWindow *mwindow = edit_title->mwindow;
317 EditPopup *popup = edit_title->popup;
318 window = new EditPopupTitleWindow(mwindow, popup, wx, wy);
319 window->create_objects();
323 void EditTitleDialogThread::handle_close_event(int result)
328 void EditTitleDialogThread::handle_done_event(int result)
331 MWindow *mwindow = edit_title->mwindow;
332 EditPopup *popup = edit_title->popup;
333 strcpy(popup->edit->user_title, window->title_text->get_text());
334 mwindow->gui->lock_window("EditTitleDialogThread::handle_done_event");
335 mwindow->gui->draw_canvas(1, 0);
336 mwindow->gui->flash_canvas(1);
337 mwindow->gui->unlock_window();
340 EditPopupTitleWindow::EditPopupTitleWindow(MWindow *mwindow,
341 EditPopup *popup, int wx, int wy)
342 : BC_Window(_(PROGRAM_NAME ": Set edit title"), wx, wy,
343 300, 130, 300, 130, 0, 0, 1)
345 this->mwindow = mwindow;
347 strcpy(new_text, !popup->edit ? "" : popup->edit->user_title);
350 EditPopupTitleWindow::~EditPopupTitleWindow()
354 void EditPopupTitleWindow::create_objects()
356 lock_window("EditPopupTitleWindow::create_objects");
358 add_subwindow(new BC_Title(x, y, _("User title:")));
359 title_text = new EditPopupTitleText(this, mwindow, x+15, y+20, new_text);
360 add_subwindow(title_text);
361 add_tool(new BC_OKButton(this));
362 add_tool(new BC_CancelButton(this));
371 EditPopupTitleText::EditPopupTitleText(EditPopupTitleWindow *window,
372 MWindow *mwindow, int x, int y, const char *text)
373 : BC_TextBox(x, y, 250, 1, text)
375 this->window = window;
376 this->mwindow = mwindow;
379 EditPopupTitleText::~EditPopupTitleText()
383 int EditPopupTitleText::handle_event()
385 if( get_keypress() == RETURN )
391 EditPopupShow::EditPopupShow(MWindow *mwindow, EditPopup *popup)
392 : BC_MenuItem(_("Show edit"))
394 this->mwindow = mwindow;
396 dialog_thread = new EditShowDialogThread(this);
399 EditPopupShow::~EditPopupShow()
401 delete dialog_thread;
404 int EditPopupShow::handle_event()
407 dialog_thread->close_window();
408 int wx = mwindow->gui->get_abs_cursor_x(0) - 400 / 2;
409 int wy = mwindow->gui->get_abs_cursor_y(0) - 500 / 2;
410 dialog_thread->start(wx, wy);
415 void EditShowDialogThread::start(int wx, int wy)
417 this->wx = wx; this->wy = wy;
418 BC_DialogThread::start();
421 EditShowDialogThread::EditShowDialogThread(EditPopupShow *edit_show)
423 this->edit_show = edit_show;
426 EditShowDialogThread::~EditShowDialogThread()
431 BC_Window* EditShowDialogThread::new_gui()
433 MWindow *mwindow = edit_show->mwindow;
434 EditPopup *popup = edit_show->popup;
435 window = new EditPopupShowWindow(mwindow, popup, wx, wy);
436 window->create_objects();
440 void EditShowDialogThread::handle_close_event(int result)
445 EditPopupShowWindow::EditPopupShowWindow(MWindow *mwindow,
446 EditPopup *popup, int wx, int wy)
447 : BC_Window(_(PROGRAM_NAME ": Show edit"), wx, wy,
448 300, 220, 300, 220, 0, 0, 1)
450 this->mwindow = mwindow;
454 EditPopupShowWindow::~EditPopupShowWindow()
458 void EditPopupShowWindow::create_objects()
460 lock_window("EditPopupShowWindow::create_objects");
463 char text[BCTEXTLEN];
464 Edit *edit = popup->edit;
465 Track *track = edit->track;
466 sprintf(text, _("Track %d:"), mwindow->edl->tracks->number_of(track)+1);
467 add_subwindow(title = new BC_Title(x, y, text));
468 int x1 = x + title->get_w() + 10;
469 int tw = get_w() - x1 - 20;
470 truncate_text(text, track->title, tw);
471 add_subwindow(new BC_Title(x1, y, text));
472 y += title->get_h() + 5;
473 sprintf(text, _("Edit %d:"), track->edits->number_of(edit)+1);
474 add_subwindow(title = new BC_Title(x, y, text));
475 char edit_title[BCTEXTLEN];
476 edit->get_title(edit_title);
477 truncate_text(text, edit_title, tw);
478 add_subwindow(new BC_Title(x1, y, text));
479 y += title->get_h() + 5;
481 EDLSession *session = mwindow->edl->session;
482 int time_format = session->time_format;
483 int sample_rate = session->sample_rate;
484 double frame_rate = session->frame_rate;
485 double frames_per_foot = session->frames_per_foot;
487 double startsource = track->from_units(edit->startsource);
488 double startproject = track->from_units(edit->startproject);
489 double length = track->from_units(edit->length);
491 char text_startsource[BCSTRLEN];
492 char text_startproject[BCSTRLEN];
493 char text_length[BCSTRLEN];
494 sprintf(text, _("StartSource: %s\nStartProject: %s\nLength: %s\n"),
495 Units::totext(text_startsource, startsource,
496 time_format, sample_rate, frame_rate, frames_per_foot),
497 Units::totext(text_startproject, startproject,
498 time_format, sample_rate, frame_rate, frames_per_foot),
499 Units::totext(text_length, length,
500 time_format, sample_rate, frame_rate, frames_per_foot));
501 show_text = new EditPopupShowText(this, mwindow, x+15, y+10, text);
502 add_subwindow(show_text);
503 add_tool(new BC_OKButton(this));
511 EditPopupShowText::EditPopupShowText(EditPopupShowWindow *window,
512 MWindow *mwindow, int x, int y, const char *text)
513 : BC_TextBox(x, y, 250, 4, text)
515 this->window = window;
516 this->mwindow = mwindow;
519 EditPopupShowText::~EditPopupShowText()