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-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-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-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 if( mwindow->session->current_operation == DROP_TARGETING ) {
205 mwindow->session->current_operation = NO_OPERATION;
206 popup->gui->update_cursor();
211 EditPopupOverwrite::EditPopupOverwrite(MWindow *mwindow, EditPopup *popup)
212 : BC_MenuItem(_("Overwrite"),_("Ctrl-b"),'b')
214 this->mwindow = mwindow;
219 int EditPopupOverwrite::handle_event()
221 mwindow->paste(popup->position, popup->track, 0, -1);
222 if( mwindow->session->current_operation == DROP_TARGETING ) {
223 mwindow->session->current_operation = NO_OPERATION;
224 popup->gui->update_cursor();
229 EditPopupFindAsset::EditPopupFindAsset(MWindow *mwindow, EditPopup *popup)
230 : BC_MenuItem(_("Find in Resources"))
232 this->mwindow = mwindow;
236 int EditPopupFindAsset::handle_event()
238 Edit *edit = popup->edit;
240 Indexable *idxbl = (Indexable *)edit->asset;
241 if( !idxbl ) idxbl = (Indexable *)edit->nested_edl;
243 AWindowGUI *agui = mwindow->awindow->gui;
244 agui->lock_window("EditPopupFindAsset::handle_event");
245 AssetPicon *picon = 0;
246 for( int i=0, n=agui->assets.size(); i<n; ++i ) {
247 AssetPicon *ap = (AssetPicon *)agui->assets[i];
248 int found = ap->indexable && ( idxbl == ap->indexable ||
249 !strcmp(idxbl->path, ap->indexable->path) );
250 if( found && !picon ) picon = ap;
251 ap->set_selected(found);
254 int selected_folder = picon->indexable->folder_no;
255 mwindow->edl->session->awindow_folder = selected_folder;
256 for( int i=0,n=agui->folders.size(); i<n; ++i ) {
257 AssetPicon *folder_item = (AssetPicon *)agui->folders[i];
258 int selected = folder_item->foldernum == selected_folder ? 1 : 0;
259 folder_item->set_selected(selected);
262 agui->unlock_window();
263 agui->async_update_assets();
270 EditPopupTitle::EditPopupTitle(MWindow *mwindow, EditPopup *popup)
271 : BC_MenuItem(_("User title..."))
273 this->mwindow = mwindow;
275 dialog_thread = new EditTitleDialogThread(this);
278 EditPopupTitle::~EditPopupTitle()
280 delete dialog_thread;
283 int EditPopupTitle::handle_event()
286 dialog_thread->close_window();
287 int wx = mwindow->gui->get_abs_cursor_x(0) - 400 / 2;
288 int wy = mwindow->gui->get_abs_cursor_y(0) - 500 / 2;
289 dialog_thread->start(wx, wy);
294 void EditTitleDialogThread::start(int wx, int wy)
296 this->wx = wx; this->wy = wy;
297 BC_DialogThread::start();
300 EditTitleDialogThread::EditTitleDialogThread(EditPopupTitle *edit_title)
302 this->edit_title = edit_title;
305 EditTitleDialogThread::~EditTitleDialogThread()
310 BC_Window* EditTitleDialogThread::new_gui()
312 MWindow *mwindow = edit_title->mwindow;
313 EditPopup *popup = edit_title->popup;
314 window = new EditPopupTitleWindow(mwindow, popup, wx, wy);
315 window->create_objects();
319 void EditTitleDialogThread::handle_close_event(int result)
324 void EditTitleDialogThread::handle_done_event(int result)
327 MWindow *mwindow = edit_title->mwindow;
328 EditPopup *popup = edit_title->popup;
329 strcpy(popup->edit->user_title, window->title_text->get_text());
330 mwindow->gui->lock_window("EditTitleDialogThread::handle_done_event");
331 mwindow->gui->draw_canvas(1, 0);
332 mwindow->gui->flash_canvas(1);
333 mwindow->gui->unlock_window();
336 EditPopupTitleWindow::EditPopupTitleWindow(MWindow *mwindow,
337 EditPopup *popup, int wx, int wy)
338 : BC_Window(_(PROGRAM_NAME ": Set edit title"), wx, wy,
339 300, 130, 300, 130, 0, 0, 1)
341 this->mwindow = mwindow;
343 strcpy(new_text, !popup->edit ? "" : popup->edit->user_title);
346 EditPopupTitleWindow::~EditPopupTitleWindow()
350 void EditPopupTitleWindow::create_objects()
352 lock_window("EditPopupTitleWindow::create_objects");
354 add_subwindow(new BC_Title(x, y, _("User title:")));
355 title_text = new EditPopupTitleText(this, mwindow, x+15, y+20, new_text);
356 add_subwindow(title_text);
357 add_tool(new BC_OKButton(this));
358 add_tool(new BC_CancelButton(this));
367 EditPopupTitleText::EditPopupTitleText(EditPopupTitleWindow *window,
368 MWindow *mwindow, int x, int y, const char *text)
369 : BC_TextBox(x, y, 250, 1, text)
371 this->window = window;
372 this->mwindow = mwindow;
375 EditPopupTitleText::~EditPopupTitleText()
379 int EditPopupTitleText::handle_event()
381 if( get_keypress() == RETURN )
387 EditPopupShow::EditPopupShow(MWindow *mwindow, EditPopup *popup)
388 : BC_MenuItem(_("Show edit"))
390 this->mwindow = mwindow;
392 dialog_thread = new EditShowDialogThread(this);
395 EditPopupShow::~EditPopupShow()
397 delete dialog_thread;
400 int EditPopupShow::handle_event()
403 dialog_thread->close_window();
404 int wx = mwindow->gui->get_abs_cursor_x(0) - 400 / 2;
405 int wy = mwindow->gui->get_abs_cursor_y(0) - 500 / 2;
406 dialog_thread->start(wx, wy);
411 void EditShowDialogThread::start(int wx, int wy)
413 this->wx = wx; this->wy = wy;
414 BC_DialogThread::start();
417 EditShowDialogThread::EditShowDialogThread(EditPopupShow *edit_show)
419 this->edit_show = edit_show;
422 EditShowDialogThread::~EditShowDialogThread()
427 BC_Window* EditShowDialogThread::new_gui()
429 MWindow *mwindow = edit_show->mwindow;
430 EditPopup *popup = edit_show->popup;
431 window = new EditPopupShowWindow(mwindow, popup, wx, wy);
432 window->create_objects();
436 void EditShowDialogThread::handle_close_event(int result)
441 EditPopupShowWindow::EditPopupShowWindow(MWindow *mwindow,
442 EditPopup *popup, int wx, int wy)
443 : BC_Window(_(PROGRAM_NAME ": Show edit"), wx, wy,
444 300, 220, 300, 220, 0, 0, 1)
446 this->mwindow = mwindow;
450 EditPopupShowWindow::~EditPopupShowWindow()
454 void EditPopupShowWindow::create_objects()
456 lock_window("EditPopupShowWindow::create_objects");
459 char text[BCTEXTLEN];
460 Edit *edit = popup->edit;
461 Track *track = edit->track;
462 sprintf(text, _("Track %d:"), mwindow->edl->tracks->number_of(track)+1);
463 add_subwindow(title = new BC_Title(x, y, text));
464 int x1 = x + title->get_w() + 10;
465 int tw = get_w() - x1 - 20;
466 truncate_text(text, track->title, tw);
467 add_subwindow(new BC_Title(x1, y, text));
468 y += title->get_h() + 5;
469 sprintf(text, _("Edit %d:"), track->edits->number_of(edit)+1);
470 add_subwindow(title = new BC_Title(x, y, text));
471 char edit_title[BCTEXTLEN];
472 edit->get_title(edit_title);
473 truncate_text(text, edit_title, tw);
474 add_subwindow(new BC_Title(x1, y, text));
475 y += title->get_h() + 5;
477 EDLSession *session = mwindow->edl->session;
478 int time_format = session->time_format;
479 int sample_rate = session->sample_rate;
480 double frame_rate = session->frame_rate;
481 double frames_per_foot = session->frames_per_foot;
483 double startsource = track->from_units(edit->startsource);
484 double startproject = track->from_units(edit->startproject);
485 double length = track->from_units(edit->length);
487 char text_startsource[BCSTRLEN];
488 char text_startproject[BCSTRLEN];
489 char text_length[BCSTRLEN];
490 sprintf(text, _("StartSource: %s\nStartProject: %s\nLength: %s\n"),
491 Units::totext(text_startsource, startsource,
492 time_format, sample_rate, frame_rate, frames_per_foot),
493 Units::totext(text_startproject, startproject,
494 time_format, sample_rate, frame_rate, frames_per_foot),
495 Units::totext(text_length, length,
496 time_format, sample_rate, frame_rate, frames_per_foot));
497 show_text = new EditPopupShowText(this, mwindow, x+15, y+10, text);
498 add_subwindow(show_text);
499 add_tool(new BC_OKButton(this));
507 EditPopupShowText::EditPopupShowText(EditPopupShowWindow *window,
508 MWindow *mwindow, int x, int y, const char *text)
509 : BC_TextBox(x, y, 250, 4, text)
511 this->window = window;
512 this->mwindow = mwindow;
515 EditPopupShowText::~EditPopupShowText()