Credit Andrew R for finding the direct copy mods for exr and ppm sequences
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / mainmenu.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2014 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 "assets.h"
23 #include "auto.h"
24 #include "batchrender.h"
25 #include "bcdisplayinfo.h"
26 #include "bchash.h"
27 #include "bcsignals.h"
28 #include "bdcreate.h"
29 #include "cache.h"
30 #include "channelinfo.h"
31 #include "convert.h"
32 #include "cplayback.h"
33 #include "cropvideo.h"
34 #include "cwindow.h"
35 #include "cwindowgui.h"
36 #include "dbwindow.h"
37 #include "dvdcreate.h"
38 #include "edl.h"
39 #include "edlsession.h"
40 #include "exportedl.h"
41 #include "file.h"
42 #include "filesystem.h"
43 #include "filexml.h"
44 #include "floatauto.h"
45 #include "keys.h"
46 #include "language.h"
47 #include "levelwindow.h"
48 #include "loadfile.h"
49 #include "localsession.h"
50 #include "mainclock.h"
51 #include "mainmenu.h"
52 #include "mainsession.h"
53 #include "mainundo.h"
54 #include "menuattacheffect.h"
55 #include "menuattachtransition.h"
56 #include "menuaeffects.h"
57 #include "menueditlength.h"
58 #include "menutransitionlength.h"
59 #include "menuveffects.h"
60 #include "mixersalign.h"
61 #include "mwindowgui.h"
62 #include "mwindow.h"
63 #include "new.h"
64 #include "patchbay.h"
65 #include "playbackengine.h"
66 #include "preferences.h"
67 #include "proxy.h"
68 #include "preferencesthread.h"
69 #include "quit.h"
70 #include "record.h"
71 #include "render.h"
72 #include "savefile.h"
73 #include "setformat.h"
74 #include "swindow.h"
75 #include "timebar.h"
76 #include "trackcanvas.h"
77 #include "tracks.h"
78 #include "transition.h"
79 #include "transportque.h"
80 #include "viewmenu.h"
81 #include "zoombar.h"
82 #include "zwindow.h"
83 #include "zwindowgui.h"
84
85 #include <string.h>
86
87
88 MainMenu::MainMenu(MWindow *mwindow, MWindowGUI *gui, int w)
89  : BC_MenuBar(0, 0, w)
90 {
91         this->gui = gui;
92         this->mwindow = mwindow;
93 // *** CONTEXT_HELP ***
94         context_help_set_keyword("Program Window");
95 }
96
97 MainMenu::~MainMenu()
98 {
99 }
100
101 void MainMenu::create_objects()
102 {
103         BC_Menu *viewmenu, *windowmenu, *settingsmenu, *trackmenu;
104         PreferencesMenuitem *preferences;
105
106         add_menu(filemenu = new BC_Menu(_("File")));
107         filemenu->add_item(new_project = new NewProject(mwindow));
108         new_project->create_objects();
109
110 // file loaders
111         filemenu->add_item(load_file = new Load(mwindow, this));
112         load_file->create_objects();
113         filemenu->add_item(load_recent = new LoadRecent(mwindow, this));
114         load_recent->create_objects();
115
116 // new and load can be undone so no need to prompt save
117         Save *save;                   //  affected by saveas
118         filemenu->add_item(save = new Save(mwindow));
119         SaveAs *saveas;
120         filemenu->add_item(saveas = new SaveAs(mwindow));
121         save->create_objects(saveas);
122         saveas->set_mainmenu(this);
123         filemenu->add_item(new SaveProject(mwindow));
124         filemenu->add_item(new SaveSession(mwindow));
125
126         filemenu->add_item(record_menu_item = new RecordMenuItem(mwindow));
127 #ifdef HAVE_DVB
128         filemenu->add_item(new ChannelScan(mwindow));
129 #endif
130 #ifdef HAVE_COMMERCIAL
131         if( mwindow->has_commercials() )
132                 filemenu->add_item(new DbWindowScan(mwindow));
133 #endif
134         filemenu->add_item(new SubttlSWin(mwindow));
135
136         filemenu->add_item(render = new RenderItem(mwindow));
137         filemenu->add_item(new ExportEDLItem(mwindow));
138         filemenu->add_item(new BatchRenderMenuItem(mwindow));
139         filemenu->add_item(new CreateBD_MenuItem(mwindow));
140         filemenu->add_item(new CreateDVD_MenuItem(mwindow));
141         filemenu->add_item(new BC_MenuItem("-"));
142         filemenu->add_item(quit_program = new Quit(mwindow));
143         quit_program->create_objects(save);
144         filemenu->add_item(dump_menu = new MainDumpsMenu(mwindow));
145         dump_menu->create_objects();
146         filemenu->add_item(new LoadBackup(mwindow));
147         filemenu->add_item(new SaveBackup(mwindow));
148
149         BC_Menu *editmenu;
150         add_menu(editmenu = new BC_Menu(_("Edit")));
151         editmenu->add_item(undo = new Undo(mwindow));
152         editmenu->add_item(redo = new Redo(mwindow));
153         editmenu->add_item(new BC_MenuItem("-"));
154         editmenu->add_item(new Cut(mwindow));
155         editmenu->add_item(new Copy(mwindow));
156         editmenu->add_item(new Paste(mwindow));
157         editmenu->add_item(new PasteSilence(mwindow));
158         editmenu->add_item(clear_menu = new EditClearMenu(mwindow));
159         clear_menu->create_objects();
160         editmenu->add_item(new TrimSelection(mwindow));
161         editmenu->add_item(new SelectAll(mwindow));
162         editmenu->add_item(new BC_MenuItem("-"));
163         editmenu->add_item(new MenuEditShuffle(mwindow));
164         editmenu->add_item(new MenuEditReverse(mwindow));
165         editmenu->add_item(new MenuEditLength(mwindow));
166         editmenu->add_item(new MenuEditAlign(mwindow));
167         editmenu->add_item(new MenuTransitionLength(mwindow));
168         editmenu->add_item(new DetachTransitions(mwindow));
169         editmenu->add_item(new BC_MenuItem("-"));
170         editmenu->add_item(new CutCommercials(mwindow));
171         editmenu->add_item(new PasteSubttl(mwindow));
172
173         BC_Menu *keyframemenu;
174         add_menu(keyframemenu = new BC_Menu(_("Keyframes")));
175         keyframemenu->add_item(new CutKeyframes(mwindow));
176         keyframemenu->add_item(new CopyKeyframes(mwindow));
177         keyframemenu->add_item(new PasteKeyframes(mwindow));
178         keyframemenu->add_item(new ClearKeyframes(mwindow));
179         keyframemenu->add_item(set_auto_curves = new SetAutomationCurveMode(mwindow));
180         set_auto_curves->create_objects();
181         keyframemenu->add_item(keyframe_curve_type = new KeyframeCurveType(mwindow));
182         keyframe_curve_type->create_objects();
183         keyframe_curve_type->update(mwindow->edl->local_session->floatauto_type);
184         keyframemenu->add_item(keyframe_create = new KeyframeCreate(mwindow));
185         keyframe_create->create_objects();
186         keyframemenu->add_item(new BC_MenuItem("-"));
187         keyframemenu->add_item(new CopyDefaultKeyframe(mwindow));
188         keyframemenu->add_item(new PasteDefaultKeyframe(mwindow));
189
190
191
192
193         add_menu(audiomenu = new BC_Menu(_("Audio")));
194         audiomenu->add_item(new AddAudioTrack(mwindow));
195         audiomenu->add_item(new DefaultATransition(mwindow));
196         audiomenu->add_item(new MapAudio1(mwindow));
197         audiomenu->add_item(new MapAudio2(mwindow));
198         audiomenu->add_item(new MenuAttachTransition(mwindow, TRACK_AUDIO));
199         audiomenu->add_item(new MenuAttachEffect(mwindow, TRACK_AUDIO));
200         audiomenu->add_item(aeffects = new MenuAEffects(mwindow));
201
202         add_menu(videomenu = new BC_Menu(_("Video")));
203         videomenu->add_item(new AddVideoTrack(mwindow));
204         videomenu->add_item(new DefaultVTransition(mwindow));
205         videomenu->add_item(new MenuAttachTransition(mwindow, TRACK_VIDEO));
206         videomenu->add_item(new MenuAttachEffect(mwindow, TRACK_VIDEO));
207         videomenu->add_item(veffects = new MenuVEffects(mwindow));
208
209         add_menu(trackmenu = new BC_Menu(_("Tracks")));
210         trackmenu->add_item(new MoveTracksUp(mwindow));
211         trackmenu->add_item(new MoveTracksDown(mwindow));
212         trackmenu->add_item(new RollTracksUp(mwindow));
213         trackmenu->add_item(new RollTracksDown(mwindow));
214         trackmenu->add_item(new DeleteTracks(mwindow));
215         trackmenu->add_item(new DeleteFirstTrack(mwindow));
216         trackmenu->add_item(new DeleteLastTrack(mwindow));
217         trackmenu->add_item(new ConcatenateTracks(mwindow));
218         trackmenu->add_item(new AlignTimecodes(mwindow));
219         AppendTracks *append_tracks;
220         trackmenu->add_item(append_tracks = new AppendTracks(mwindow));
221         append_tracks->create_objects();
222         trackmenu->add_item(new AddSubttlTrack(mwindow));
223
224         add_menu(settingsmenu = new BC_Menu(_("Settings")));
225
226         settingsmenu->add_item(new SetFormat(mwindow));
227         settingsmenu->add_item(preferences = new PreferencesMenuitem(mwindow));
228         settingsmenu->add_item(proxy = new ProxyMenuItem(mwindow));
229         proxy->create_objects();
230         ConvertMenuItem *convert;
231         settingsmenu->add_item(convert = new ConvertMenuItem(mwindow));
232         convert->create_objects();
233         mwindow->preferences_thread = preferences->thread;
234         settingsmenu->add_item(cursor_on_frames = new CursorOnFrames(mwindow));
235         settingsmenu->add_item(labels_follow_edits = new LabelsFollowEdits(mwindow));
236         settingsmenu->add_item(plugins_follow_edits = new PluginsFollowEdits(mwindow));
237         settingsmenu->add_item(keyframes_follow_edits = new KeyframesFollowEdits(mwindow));
238         settingsmenu->add_item(typeless_keyframes = new TypelessKeyframes(mwindow));
239         settingsmenu->add_item(new BC_MenuItem("-"));
240         settingsmenu->add_item(new SaveSettingsNow(mwindow));
241         settingsmenu->add_item(loop_playback = new LoopPlayback(mwindow));
242         settingsmenu->add_item(brender_active = new SetBRenderActive(mwindow));
243 // set scrubbing speed
244 //      ScrubSpeed *scrub_speed;
245 //      settingsmenu->add_item(scrub_speed = new ScrubSpeed(mwindow));
246 //      if(mwindow->edl->session->scrub_speed == .5)
247 //              scrub_speed->set_text(_("Fast Shuttle"));
248
249
250
251
252
253
254         add_menu(viewmenu = new BC_Menu(_("View")));
255         viewmenu->add_item(show_assets = new ShowAssets(mwindow, "0"));
256         viewmenu->add_item(show_titles = new ShowTitles(mwindow, "1"));
257         viewmenu->add_item(show_transitions = new ShowTransitions(mwindow, "2"));
258         viewmenu->add_item(fade_automation = new ShowAutomation(mwindow, _("Fade"), "3", AUTOMATION_FADE));
259         viewmenu->add_item(mute_automation = new ShowAutomation(mwindow, _("Mute"), "4", AUTOMATION_MUTE));
260         viewmenu->add_item(mode_automation = new ShowAutomation(mwindow, _("Overlay mode"), "5", AUTOMATION_MODE));
261         viewmenu->add_item(pan_automation = new ShowAutomation(mwindow, _("Pan"), "6", AUTOMATION_PAN));
262         viewmenu->add_item(plugin_automation = new PluginAutomation(mwindow, "7"));
263         viewmenu->add_item(mask_automation = new ShowAutomation(mwindow, _("Mask"), "8", AUTOMATION_MASK));
264         viewmenu->add_item(speed_automation = new ShowAutomation(mwindow, _("Speed"), "9", AUTOMATION_SPEED));
265
266         camera_x = new ShowAutomation(mwindow, _("Camera X"), "Ctrl-Shift-X", AUTOMATION_CAMERA_X);
267         camera_x->set_ctrl();  camera_x->set_shift();   viewmenu->add_item(camera_x);
268         camera_y = new ShowAutomation(mwindow, _("Camera Y"), "Ctrl-Shift-Y", AUTOMATION_CAMERA_Y);
269         camera_y->set_ctrl();  camera_y->set_shift();   viewmenu->add_item(camera_y);
270         camera_z = new ShowAutomation(mwindow, _("Camera Z"), "Ctrl-Shift-Z", AUTOMATION_CAMERA_Z);
271         camera_z->set_ctrl();  camera_z->set_shift();  viewmenu->add_item(camera_z);
272         project_x = new ShowAutomation(mwindow, _("Projector X"), "Alt-Shift-X", AUTOMATION_PROJECTOR_X);
273         project_x->set_alt();  project_x->set_shift();  viewmenu->add_item(project_x);
274         project_y = new ShowAutomation(mwindow, _("Projector Y"), "Alt-Shift-Y", AUTOMATION_PROJECTOR_Y);
275         project_y->set_alt();  project_y->set_shift();  viewmenu->add_item(project_y);
276         project_z = new ShowAutomation(mwindow, _("Projector Z"), "Alt-Shift-Z", AUTOMATION_PROJECTOR_Z);
277         project_z->set_alt();  project_z->set_shift();  viewmenu->add_item(project_z);
278
279         add_menu(windowmenu = new BC_Menu(_("Window")));
280         windowmenu->add_item(show_vwindow = new ShowVWindow(mwindow));
281         windowmenu->add_item(show_awindow = new ShowAWindow(mwindow));
282         windowmenu->add_item(show_cwindow = new ShowCWindow(mwindow));
283         windowmenu->add_item(show_gwindow = new ShowGWindow(mwindow));
284         windowmenu->add_item(show_lwindow = new ShowLWindow(mwindow));
285         windowmenu->add_item(new BC_MenuItem("-"));
286         windowmenu->add_item(split_x = new SplitX(mwindow));
287         windowmenu->add_item(split_y = new SplitY(mwindow));
288         windowmenu->add_item(mixer_items = new MixerItems(mwindow));
289         mixer_items->create_objects();
290         windowmenu->add_item(new TileWindows(mwindow,_("Tile left"),0));
291         windowmenu->add_item(new TileWindows(mwindow,_("Tile right"),1));
292         windowmenu->add_item(new BC_MenuItem("-"));
293
294         windowmenu->add_item(new TileWindows(mwindow,_("Default positions"),-1,_("Ctrl-P"),'p'));
295         windowmenu->add_item(load_layout = new LoadLayout(mwindow, _("Load layout..."),LAYOUT_LOAD));
296         load_layout->create_objects();
297         windowmenu->add_item(save_layout = new LoadLayout(mwindow, _("Save layout..."),LAYOUT_SAVE));
298         save_layout->create_objects();
299 }
300
301 int MainMenu::load_defaults(BC_Hash *defaults)
302 {
303         init_loads(defaults);
304         init_aeffects(defaults);
305         init_veffects(defaults);
306         return 0;
307 }
308
309 void MainMenu::update_toggles(int use_lock)
310 {
311         if(use_lock) lock_window("MainMenu::update_toggles");
312         labels_follow_edits->set_checked(mwindow->edl->session->labels_follow_edits);
313         plugins_follow_edits->set_checked(mwindow->edl->session->plugins_follow_edits);
314         keyframes_follow_edits->set_checked(mwindow->edl->session->autos_follow_edits);
315         typeless_keyframes->set_checked(mwindow->edl->session->typeless_keyframes);
316         cursor_on_frames->set_checked(mwindow->edl->session->cursor_on_frames);
317         loop_playback->set_checked(mwindow->edl->local_session->loop_playback);
318
319         show_assets->set_checked(mwindow->edl->session->show_assets);
320         show_titles->set_checked(mwindow->edl->session->show_titles);
321         show_transitions->set_checked(mwindow->edl->session->auto_conf->transitions);
322         fade_automation->update_toggle();
323         mute_automation->update_toggle();
324         pan_automation->update_toggle();
325         camera_x->update_toggle();
326         camera_y->update_toggle();
327         camera_z->update_toggle();
328         project_x->update_toggle();
329         project_y->update_toggle();
330         project_z->update_toggle();
331         plugin_automation->set_checked(mwindow->edl->session->auto_conf->plugins);
332         mode_automation->update_toggle();
333         mask_automation->update_toggle();
334         speed_automation->update_toggle();
335         split_x->set_checked(mwindow->gui->pane[TOP_RIGHT_PANE] != 0);
336         split_y->set_checked(mwindow->gui->pane[BOTTOM_LEFT_PANE] != 0);
337
338         if(use_lock) mwindow->gui->unlock_window();
339 }
340
341 int MainMenu::save_defaults(BC_Hash *defaults)
342 {
343         save_loads(defaults);
344         save_aeffects(defaults);
345         save_veffects(defaults);
346         return 0;
347 }
348
349
350
351
352
353 int MainMenu::quit()
354 {
355         quit_program->handle_event();
356         return 0;
357 }
358
359
360
361
362
363 // ================================== load most recent
364
365 int MainMenu::init_aeffects(BC_Hash *defaults)
366 {
367         total_aeffects = defaults->get((char*)"TOTAL_AEFFECTS", 0);
368
369         char string[BCTEXTLEN], title[BCTEXTLEN];
370         if(total_aeffects) audiomenu->add_item(new BC_MenuItem("-"));
371
372         for(int i = 0; i < total_aeffects; i++)
373         {
374                 sprintf(string, "AEFFECTRECENT%d", i);
375                 defaults->get(string, title);
376                 audiomenu->add_item(aeffect[i] = new MenuAEffectItem(aeffects, title));
377         }
378         return 0;
379 }
380
381 int MainMenu::init_veffects(BC_Hash *defaults)
382 {
383         total_veffects = defaults->get((char*)"TOTAL_VEFFECTS", 0);
384
385         char string[BCTEXTLEN], title[BCTEXTLEN];
386         if(total_veffects) videomenu->add_item(new BC_MenuItem("-"));
387
388         for(int i = 0; i < total_veffects; i++)
389         {
390                 sprintf(string, "VEFFECTRECENT%d", i);
391                 defaults->get(string, title);
392                 videomenu->add_item(veffect[i] = new MenuVEffectItem(veffects, title));
393         }
394         return 0;
395 }
396
397 void MainMenu::init_loads(BC_Hash *defaults)
398 {
399 // total_loads for legacy xml
400         int total_loads = defaults->get((char*)"TOTAL_LOADS", 0);
401         int loads_total = defaults->get((char*)"LOADS_TOTAL", 0);
402         if( loads_total < total_loads ) loads_total = total_loads;
403
404         char string[BCTEXTLEN], path[BCTEXTLEN];
405         FileSystem dir;
406 //printf("MainMenu::init_loads 2\n");
407
408         for( int i=0; i<loads_total; ++i ) {
409                 sprintf(string, "LOADPREVIOUS%d", i);
410 //printf("MainMenu::init_loads 3\n");
411                 defaults->get(string, path);
412                 if( load.size() < TOTAL_LOADS )
413                         load.append(new LoadRecentItem(path));
414         }
415 }
416
417 // ============================ save most recent
418
419 int MainMenu::save_aeffects(BC_Hash *defaults)
420 {
421         defaults->update((char*)"TOTAL_AEFFECTS", total_aeffects);
422         char string[BCTEXTLEN];
423         for(int i = 0; i < total_aeffects; i++)
424         {
425                 sprintf(string, "AEFFECTRECENT%d", i);
426                 defaults->update(string, aeffect[i]->get_text());
427         }
428         return 0;
429 }
430
431 int MainMenu::save_veffects(BC_Hash *defaults)
432 {
433         defaults->update((char*)"TOTAL_VEFFECTS", total_veffects);
434         char string[BCTEXTLEN];
435         for(int i = 0; i < total_veffects; i++)
436         {
437                 sprintf(string, "VEFFECTRECENT%d", i);
438                 defaults->update(string, veffect[i]->get_text());
439         }
440         return 0;
441 }
442
443 int MainMenu::save_loads(BC_Hash *defaults)
444 {
445 // legacy to prevent segv, older code cant tolerate total_loads>10
446         int loads_total = load.size();
447         int total_loads = MIN(10, loads_total);
448         defaults->update((char*)"LOADS_TOTAL", loads_total);
449         defaults->update((char*)"TOTAL_LOADS", total_loads);
450         char string[BCTEXTLEN];
451         for( int i=0; i<loads_total; ++i ) {
452                 sprintf(string, "LOADPREVIOUS%d", i);
453                 defaults->update(string, load[i]->path);
454         }
455         return 0;
456 }
457
458 // =================================== add most recent
459
460 int MainMenu::add_aeffect(char *title)
461 {
462 // add bar for first effect
463         if(total_aeffects == 0)
464         {
465                 audiomenu->add_item(new BC_MenuItem("-"));
466         }
467
468 // test for existing copy of effect
469         for(int i = 0; i < total_aeffects; i++)
470         {
471                 if(!strcmp(aeffect[i]->get_text(), title))     // already exists
472                 {                                // swap for top effect
473                         for(int j = i; j > 0; j--)   // move preceeding effects down
474                         {
475                                 aeffect[j]->set_text(aeffect[j - 1]->get_text());
476                         }
477                         aeffect[0]->set_text(title);
478                         return 1;
479                 }
480         }
481
482 // add another blank effect
483         if(total_aeffects < TOTAL_EFFECTS)
484         {
485                 audiomenu->add_item(
486                         aeffect[total_aeffects] = new MenuAEffectItem(aeffects, (char*)""));
487                 total_aeffects++;
488         }
489
490 // cycle effect down
491         for(int i = total_aeffects - 1; i > 0; i--)
492         {
493         // set menu item text
494                 aeffect[i]->set_text(aeffect[i - 1]->get_text());
495         }
496
497 // set up the new effect
498         aeffect[0]->set_text(title);
499         return 0;
500 }
501
502 int MainMenu::add_veffect(char *title)
503 {
504 // add bar for first effect
505         if(total_veffects == 0)
506         {
507                 videomenu->add_item(new BC_MenuItem("-"));
508         }
509
510 // test for existing copy of effect
511         for(int i = 0; i < total_veffects; i++)
512         {
513                 if(!strcmp(veffect[i]->get_text(), title))     // already exists
514                 {                                // swap for top effect
515                         for(int j = i; j > 0; j--)   // move preceeding effects down
516                         {
517                                 veffect[j]->set_text(veffect[j - 1]->get_text());
518                         }
519                         veffect[0]->set_text(title);
520                         return 1;
521                 }
522         }
523
524 // add another blank effect
525         if(total_veffects < TOTAL_EFFECTS)
526         {
527                 videomenu->add_item(veffect[total_veffects] =
528                         new MenuVEffectItem(veffects, (char*)""));
529                 total_veffects++;
530         }
531
532 // cycle effect down
533         for(int i = total_veffects - 1; i > 0; i--)
534         {
535 // set menu item text
536                 veffect[i]->set_text(veffect[i - 1]->get_text());
537         }
538
539 // set up the new effect
540         veffect[0]->set_text(title);
541         return 0;
542 }
543
544 int MainMenu::add_load(char *path)
545 {
546         return load.add_load(path);
547 }
548
549
550
551 // ================================== menu items
552
553 MainDumpsSubMenu::MainDumpsSubMenu(BC_MenuItem *menu_item)
554  : BC_SubMenu()
555 {
556         this->menu_item = menu_item;
557 }
558 MainDumpsSubMenu::~MainDumpsSubMenu()
559 {
560 }
561
562
563 MainDumpsMenu::MainDumpsMenu(MWindow *mwindow)
564  : BC_MenuItem(_("Dumps..."))
565 {
566         this->mwindow = mwindow;
567         this->dumps_menu = 0;
568 }
569 MainDumpsMenu::~MainDumpsMenu()
570 {
571 }
572
573 void MainDumpsMenu::create_objects()
574 {
575         add_submenu(dumps_menu = new MainDumpsSubMenu(this));
576 //      dumps_menu->add_item(new DumpCICache(mwindow));
577         dumps_menu->add_item(new DumpEDL(mwindow));
578         dumps_menu->add_item(new DumpPlugins(mwindow));
579         dumps_menu->add_item(new DumpAssets(mwindow));
580         dumps_menu->add_item(new DumpUndo(mwindow));
581 };
582
583
584 DumpCICache::DumpCICache(MWindow *mwindow)
585  : BC_MenuItem(_("Dump CICache"))
586 { this->mwindow = mwindow; }
587
588 int DumpCICache::handle_event()
589 {
590 //      mwindow->cache->dump();
591         return 1;
592 }
593
594 DumpEDL::DumpEDL(MWindow *mwindow)
595  : BC_MenuItem(_("Dump EDL"))
596 {
597         this->mwindow = mwindow;
598 }
599
600 int DumpEDL::handle_event()
601 {
602         mwindow->dump_edl();
603         return 1;
604 }
605
606 DumpPlugins::DumpPlugins(MWindow *mwindow)
607  : BC_MenuItem(_("Dump Plugins"))
608 {
609         this->mwindow = mwindow;
610 }
611
612 int DumpPlugins::handle_event()
613 {
614         mwindow->dump_plugins();
615         return 1;
616 }
617
618 DumpAssets::DumpAssets(MWindow *mwindow)
619  : BC_MenuItem(_("Dump Assets"))
620 { this->mwindow = mwindow; }
621
622 int DumpAssets::handle_event()
623 {
624         mwindow->edl->assets->dump();
625         return 1;
626 }
627
628 DumpUndo::DumpUndo(MWindow *mwindow)
629  : BC_MenuItem(_("Dump Undo"))
630 {
631         this->mwindow = mwindow;
632 }
633
634 int DumpUndo::handle_event()
635 {
636         mwindow->dump_undo();
637         return 1;
638 }
639
640 // ================================================= edit
641
642 Undo::Undo(MWindow *mwindow) : BC_MenuItem(_("Undo"), "z or Ctrl-z", 'z')
643 {
644         this->mwindow = mwindow;
645 }
646 int Undo::handle_event()
647 {
648         if( mwindow->session->current_operation == NO_OPERATION )
649                 mwindow->undo_entry(mwindow->gui);
650         return 1;
651 }
652 int Undo::update_caption(const char *new_caption)
653 {
654         char string[BCTEXTLEN];
655         sprintf(string, _("Undo %s"), new_caption);
656         set_text(string);
657         return 0;
658 }
659
660
661 Redo::Redo(MWindow *mwindow) : BC_MenuItem(_("Redo"), _("Shift-Z"), 'Z')
662 {
663         set_shift(1);
664         this->mwindow = mwindow;
665 }
666
667 int Redo::handle_event()
668 {
669         if( mwindow->session->current_operation == NO_OPERATION )
670                 mwindow->redo_entry(mwindow->gui);
671         return 1;
672 }
673 int Redo::update_caption(const char *new_caption)
674 {
675         char string[BCTEXTLEN];
676         sprintf(string, _("Redo %s"), new_caption);
677         set_text(string);
678         return 0;
679 }
680
681 CutKeyframes::CutKeyframes(MWindow *mwindow)
682  : BC_MenuItem(_("Cut keyframes"), _("Shift-X"), 'X')
683 {
684         set_shift();
685         this->mwindow = mwindow;
686 }
687
688 int CutKeyframes::handle_event()
689 {
690         if( mwindow->session->current_operation == NO_OPERATION )
691                 mwindow->cut_automation();
692         return 1;
693 }
694
695 CopyKeyframes::CopyKeyframes(MWindow *mwindow)
696  : BC_MenuItem(_("Copy keyframes"), _("Shift-C"), 'C')
697 {
698         set_shift();
699         this->mwindow = mwindow;
700 }
701
702 int CopyKeyframes::handle_event()
703 {
704         if( mwindow->session->current_operation == NO_OPERATION )
705                 mwindow->copy_automation();
706         return 1;
707 }
708
709 PasteKeyframes::PasteKeyframes(MWindow *mwindow)
710  : BC_MenuItem(_("Paste keyframes"), _("Shift-V"), 'V')
711 {
712         set_shift();
713         this->mwindow = mwindow;
714 }
715
716 int PasteKeyframes::handle_event()
717 {
718         if( mwindow->session->current_operation == NO_OPERATION )
719                 mwindow->paste_automation();
720         return 1;
721 }
722
723 ClearKeyframes::ClearKeyframes(MWindow *mwindow)
724  : BC_MenuItem(_("Clear keyframes"), _("Shift-Del"), DELETE)
725 {
726         set_shift();
727         this->mwindow = mwindow;
728 }
729
730 int ClearKeyframes::handle_event()
731 {
732         if( mwindow->session->current_operation == NO_OPERATION )
733                 mwindow->clear_automation();
734         return 1;
735 }
736
737
738 SetAutomationCurveItem::SetAutomationCurveItem(SetAutomationCurveMode *set_curve_mode, int id)
739  : BC_MenuItem(FloatAuto::curve_name(id))
740 {
741         this->set_curve_mode = set_curve_mode;
742         this->id = id;
743 }
744
745 int SetAutomationCurveItem::handle_event()
746 {
747         set_curve_mode->mwindow->set_automation_mode((FloatAuto::t_mode)id);
748         return 1;
749 }
750
751 SetAutoCurveModeMenu::SetAutoCurveModeMenu(SetAutomationCurveMode *curve_mode)
752 : BC_SubMenu()
753 {
754         this->curve_mode = curve_mode;
755 }
756
757 SetAutomationCurveMode::SetAutomationCurveMode(MWindow *mwindow)
758  : BC_MenuItem(_("Set curve modes..."))
759 {
760         this->mwindow = mwindow;
761         curve_mode_menu = 0;
762 }
763
764 void SetAutomationCurveMode::create_objects()
765 {
766         add_submenu(curve_mode_menu = new SetAutoCurveModeMenu(this));
767         for( int id=FloatAuto::SMOOTH; id<=FloatAuto::BUMP; ++id )
768                 curve_mode_menu->add_item(new SetAutomationCurveItem(this, id));
769 }
770
771
772 KeyframeCurveType::KeyframeCurveType(MWindow *mwindow)
773  : BC_MenuItem(_("Create curve type..."))
774 {
775         this->mwindow = mwindow;
776         this->curve_menu = 0;
777 }
778 KeyframeCurveType::~KeyframeCurveType()
779 {
780 }
781
782 void KeyframeCurveType::create_objects()
783 {
784         add_submenu(curve_menu = new KeyframeCurveTypeMenu(this));
785         for( int i=FloatAuto::SMOOTH; i<=FloatAuto::BUMP; ++i ) {
786                 KeyframeCurveTypeItem *curve_type_item = new KeyframeCurveTypeItem(i, this);
787                 curve_menu->add_submenuitem(curve_type_item);
788         }
789 }
790
791 void KeyframeCurveType::update(int curve_type)
792 {
793         for( int i=0; i<curve_menu->total_items(); ++i ) {
794                 KeyframeCurveTypeItem *curve_type_item = (KeyframeCurveTypeItem *)curve_menu->get_item(i);
795                 curve_type_item->set_checked(curve_type_item->type == curve_type);
796         }
797 }
798
799 int KeyframeCurveType::handle_event()
800 {
801         return 1;
802 }
803
804 KeyframeCurveTypeMenu::KeyframeCurveTypeMenu(KeyframeCurveType *menu_item)
805  : BC_SubMenu()
806 {
807         this->menu_item = menu_item;
808 }
809 KeyframeCurveTypeMenu::~KeyframeCurveTypeMenu()
810 {
811 }
812
813 KeyframeCurveTypeItem::KeyframeCurveTypeItem(int type, KeyframeCurveType *main_item)
814  : BC_MenuItem(FloatAuto::curve_name(type))
815 {
816         this->type = type;
817         this->main_item = main_item;
818 }
819 KeyframeCurveTypeItem::~KeyframeCurveTypeItem()
820 {
821 }
822
823 int KeyframeCurveTypeItem::handle_event()
824 {
825         main_item->update(type);
826         main_item->mwindow->set_keyframe_type(type);
827         return 1;
828 }
829
830
831 KeyframeCreateItem::KeyframeCreateItem(KeyframeCreate *keyframe_create,
832                         const char *text, int mask)
833  : BC_MenuItem(text)
834 {
835         this->keyframe_create = keyframe_create;
836         this->mask = mask;
837 }
838
839 int KeyframeCreateItem::handle_event()
840 {
841         MWindow *mwindow = keyframe_create->mwindow;
842         int mode = mwindow->edl->local_session->floatauto_type;
843         int mask = this->mask;
844         if( !mask ) { // visible
845                 int *autos = mwindow->edl->session->auto_conf->autos;
846                 int modes = (1<<AUTOMATION_FADE) + (1<<AUTOMATION_SPEED) + 
847                         (7<<AUTOMATION_CAMERA_X) + (7<<AUTOMATION_PROJECTOR_X);
848                 for( int i=0; i<AUTOMATION_TOTAL; modes>>=1, ++i ) {
849                         if( !(modes & 1) ) continue;
850                         if( autos[i] ) mask |= (1<<i);
851                 }
852         }
853         mwindow->create_keyframes(mask, mode);
854         return 1;
855 }
856
857 KeyframeCreateMenu::KeyframeCreateMenu(KeyframeCreate *keyframe_create)
858 : BC_SubMenu()
859 {
860         this->keyframe_create = keyframe_create;
861 }
862
863 KeyframeCreate::KeyframeCreate(MWindow *mwindow)
864  : BC_MenuItem(_("Create keyframes..."))
865 {
866         this->mwindow = mwindow;
867         keyframe_create_menu = 0;
868 }
869
870 void KeyframeCreate::create_objects()
871 {
872         add_submenu(keyframe_create_menu = new KeyframeCreateMenu(this));
873         keyframe_create_menu->add_item(new KeyframeCreateItem(this, _("Visible"), 0));
874         keyframe_create_menu->add_item(new KeyframeCreateItem(this, _("Fade"),
875                                 (1<<AUTOMATION_FADE)));
876         keyframe_create_menu->add_item(new KeyframeCreateItem(this, _("Speed"),
877                                 (1<<AUTOMATION_SPEED)));
878         keyframe_create_menu->add_item(new KeyframeCreateItem(this, _("Camera XYZ"),
879                                 (7<<AUTOMATION_CAMERA_X)));
880         keyframe_create_menu->add_item(new KeyframeCreateItem(this, _("Projector XYZ"),
881                                 (7<<AUTOMATION_PROJECTOR_X)));
882         keyframe_create_menu->add_item(new KeyframeCreateItem(this, _("Fade+Speed+XYZ"),
883                                 (1<<AUTOMATION_FADE) + (1<<AUTOMATION_SPEED) + 
884                                 (7<<AUTOMATION_CAMERA_X) + (7<<AUTOMATION_PROJECTOR_X)));
885 }
886
887
888 CutDefaultKeyframe::CutDefaultKeyframe(MWindow *mwindow)
889  : BC_MenuItem(_("Cut default keyframe"), _("Alt-x"), 'x')
890 {
891         set_alt();
892         this->mwindow = mwindow;
893 }
894
895 int CutDefaultKeyframe::handle_event()
896 {
897         if( mwindow->session->current_operation == NO_OPERATION )
898                 mwindow->cut_default_keyframe();
899         return 1;
900 }
901
902 CopyDefaultKeyframe::CopyDefaultKeyframe(MWindow *mwindow)
903  : BC_MenuItem(_("Copy default keyframe"), _("Alt-c"), 'c')
904 {
905         set_alt();
906         this->mwindow = mwindow;
907 }
908
909 int CopyDefaultKeyframe::handle_event()
910 {
911         if( mwindow->session->current_operation == NO_OPERATION )
912                 mwindow->copy_default_keyframe();
913         return 1;
914 }
915
916 PasteDefaultKeyframe::PasteDefaultKeyframe(MWindow *mwindow)
917  : BC_MenuItem(_("Paste default keyframe"), _("Alt-v"), 'v')
918 {
919         set_alt();
920         this->mwindow = mwindow;
921 }
922
923 int PasteDefaultKeyframe::handle_event()
924 {
925         if( mwindow->session->current_operation == NO_OPERATION )
926                 mwindow->paste_default_keyframe();
927         return 1;
928 }
929
930 ClearDefaultKeyframe::ClearDefaultKeyframe(MWindow *mwindow)
931  : BC_MenuItem(_("Clear default keyframe"), _("Alt-Del"), DELETE)
932 {
933         set_alt();
934         this->mwindow = mwindow;
935 }
936
937 int ClearDefaultKeyframe::handle_event()
938 {
939         if( mwindow->session->current_operation == NO_OPERATION )
940                 mwindow->clear_default_keyframe();
941         return 1;
942 }
943
944 Cut::Cut(MWindow *mwindow)
945  : BC_MenuItem(_("Split | Cut"), "x", 'x')
946 {
947         this->mwindow = mwindow;
948 }
949
950 int Cut::handle_event()
951 {
952         if( mwindow->session->current_operation == NO_OPERATION )
953                 mwindow->cut();
954         return 1;
955 }
956
957 Copy::Copy(MWindow *mwindow)
958  : BC_MenuItem(_("Copy"), "c", 'c')
959 {
960         this->mwindow = mwindow;
961 }
962
963 int Copy::handle_event()
964 {
965         if( mwindow->session->current_operation == NO_OPERATION )
966                 mwindow->copy();
967         return 1;
968 }
969
970 Paste::Paste(MWindow *mwindow)
971  : BC_MenuItem(_("Paste"), "v", 'v')
972 {
973         this->mwindow = mwindow;
974 }
975
976 int Paste::handle_event()
977 {
978         if( mwindow->session->current_operation == NO_OPERATION )
979                 mwindow->paste();
980         return 1;
981 }
982
983 EditClearSubMenu::EditClearSubMenu(BC_MenuItem *menu_item)
984  : BC_SubMenu()
985 {
986         this->menu_item = menu_item;
987 }
988 EditClearSubMenu::~EditClearSubMenu()
989 {
990 }
991
992 EditClearMenu::EditClearMenu(MWindow *mwindow)
993  : BC_MenuItem(_("Clear..."))
994 {
995         this->mwindow = mwindow;
996         this->clear_sub_menu = 0;
997 }
998 EditClearMenu::~EditClearMenu()
999 {
1000 }
1001
1002 void EditClearMenu::create_objects()
1003 {
1004         add_submenu(clear_sub_menu = new EditClearSubMenu(this));
1005         clear_sub_menu->add_item(new Clear(mwindow));
1006         clear_sub_menu->add_item(new MuteSelection(mwindow));
1007         clear_sub_menu->add_item(new ClearSelect(mwindow));
1008         clear_sub_menu->add_item(new ClearLabels(mwindow));
1009         clear_sub_menu->add_item(new ClearHardEdges(mwindow));
1010 };
1011
1012 Clear::Clear(MWindow *mwindow)
1013  : BC_MenuItem(_("Clear"), _("Del"), DELETE)
1014 {
1015         this->mwindow = mwindow;
1016 }
1017
1018 int Clear::handle_event()
1019 {
1020         if( mwindow->session->current_operation == NO_OPERATION ) {
1021                 mwindow->clear_entry();
1022         }
1023         return 1;
1024 }
1025
1026 PasteSilence::PasteSilence(MWindow *mwindow)
1027  : BC_MenuItem(_("Paste silence"), _("Shift-Space"), ' ')
1028 {
1029         this->mwindow = mwindow;
1030         set_shift();
1031 }
1032
1033 int PasteSilence::handle_event()
1034 {
1035         if( mwindow->session->current_operation == NO_OPERATION )
1036                 mwindow->paste_silence();
1037         return 1;
1038 }
1039
1040 SelectAll::SelectAll(MWindow *mwindow)
1041  : BC_MenuItem(_("Select All"), "a", 'a')
1042 {
1043         this->mwindow = mwindow;
1044 }
1045
1046 int SelectAll::handle_event()
1047 {
1048         if( mwindow->session->current_operation == NO_OPERATION )
1049                 mwindow->select_all();
1050         return 1;
1051 }
1052
1053 ClearHardEdges::ClearHardEdges(MWindow *mwindow) : BC_MenuItem(_("Clear Hard Edges"))
1054 {
1055         this->mwindow = mwindow;
1056 }
1057
1058 int ClearHardEdges::handle_event()
1059 {
1060         mwindow->clear_hard_edges();
1061         return 1;
1062 }
1063
1064 ClearLabels::ClearLabels(MWindow *mwindow) : BC_MenuItem(_("Clear labels"))
1065 {
1066         this->mwindow = mwindow;
1067 }
1068
1069 int ClearLabels::handle_event()
1070 {
1071         mwindow->clear_labels();
1072         return 1;
1073 }
1074
1075 ClearSelect::ClearSelect(MWindow *mwindow) : BC_MenuItem(_("Clear Select"),"Ctrl-Shift-A",'A')
1076 {
1077         set_ctrl(1);
1078         set_shift(1);
1079         this->mwindow = mwindow;
1080 }
1081
1082 int ClearSelect::handle_event()
1083 {
1084         mwindow->clear_select();
1085         return 1;
1086 }
1087
1088 CutCommercials::CutCommercials(MWindow *mwindow) : BC_MenuItem(_("Cut ads"))
1089 {
1090         this->mwindow = mwindow;
1091 }
1092
1093 int CutCommercials::handle_event()
1094 {
1095         mwindow->cut_commercials();
1096         return 1;
1097 }
1098
1099 DetachTransitions::DetachTransitions(MWindow *mwindow)
1100  : BC_MenuItem(_("Detach transitions"))
1101 {
1102         this->mwindow = mwindow;
1103 }
1104
1105 int DetachTransitions::handle_event()
1106 {
1107         mwindow->detach_transitions();
1108         return 1;
1109 }
1110
1111 MuteSelection::MuteSelection(MWindow *mwindow)
1112  : BC_MenuItem(_("Mute Region"), "m", 'm')
1113 {
1114         this->mwindow = mwindow;
1115 }
1116
1117 int MuteSelection::handle_event()
1118 {
1119         if( mwindow->session->current_operation == NO_OPERATION )
1120                 mwindow->mute_selection();
1121         return 1;
1122 }
1123
1124
1125 TrimSelection::TrimSelection(MWindow *mwindow)
1126  : BC_MenuItem(_("Trim Selection"))
1127 {
1128         this->mwindow = mwindow;
1129 }
1130
1131 int TrimSelection::handle_event()
1132 {
1133         mwindow->trim_selection();
1134         return 1;
1135 }
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148 // ============================================= audio
1149
1150 AddAudioTrack::AddAudioTrack(MWindow *mwindow)
1151  : BC_MenuItem(_("Add track"), "t", 't')
1152 {
1153         this->mwindow = mwindow;
1154 }
1155
1156 int AddAudioTrack::handle_event()
1157 {
1158         if( mwindow->session->current_operation == NO_OPERATION )
1159                 mwindow->add_audio_track_entry(0, 0);
1160         return 1;
1161 }
1162
1163 DeleteAudioTrack::DeleteAudioTrack(MWindow *mwindow)
1164  : BC_MenuItem(_("Delete track"))
1165 {
1166         this->mwindow = mwindow;
1167 }
1168
1169 int DeleteAudioTrack::handle_event()
1170 {
1171         return 1;
1172 }
1173
1174 DefaultATransition::DefaultATransition(MWindow *mwindow)
1175  : BC_MenuItem(_("Default Transition"), "u", 'u')
1176 {
1177         this->mwindow = mwindow;
1178 }
1179
1180 int DefaultATransition::handle_event()
1181 {
1182         if( mwindow->session->current_operation == NO_OPERATION )
1183                 mwindow->paste_audio_transition();
1184         return 1;
1185 }
1186
1187
1188 MapAudio1::MapAudio1(MWindow *mwindow)
1189  : BC_MenuItem(_("Map 1:1"))
1190 {
1191         this->mwindow = mwindow;
1192 }
1193
1194 int MapAudio1::handle_event()
1195 {
1196         mwindow->map_audio(MWindow::AUDIO_1_TO_1);
1197         return 1;
1198 }
1199
1200 MapAudio2::MapAudio2(MWindow *mwindow)
1201  : BC_MenuItem(_("Map 5.1:2"))
1202 {
1203         this->mwindow = mwindow;
1204 }
1205
1206 int MapAudio2::handle_event()
1207 {
1208         mwindow->map_audio(MWindow::AUDIO_5_1_TO_2);
1209         return 1;
1210 }
1211
1212
1213
1214
1215 // ============================================= video
1216
1217
1218 AddVideoTrack::AddVideoTrack(MWindow *mwindow)
1219  : BC_MenuItem(_("Add track"), _("Shift-T"), 'T')
1220 {
1221         set_shift();
1222         this->mwindow = mwindow;
1223 }
1224
1225 int AddVideoTrack::handle_event()
1226 {
1227         if( mwindow->session->current_operation == NO_OPERATION )
1228                 mwindow->add_video_track_entry(1, 0);
1229         return 1;
1230 }
1231
1232
1233 DeleteVideoTrack::DeleteVideoTrack(MWindow *mwindow)
1234  : BC_MenuItem(_("Delete track"))
1235 {
1236         this->mwindow = mwindow;
1237 }
1238
1239 int DeleteVideoTrack::handle_event()
1240 {
1241         return 1;
1242 }
1243
1244
1245
1246 ResetTranslation::ResetTranslation(MWindow *mwindow)
1247  : BC_MenuItem(_("Reset Translation"))
1248 {
1249         this->mwindow = mwindow;
1250 }
1251
1252 int ResetTranslation::handle_event()
1253 {
1254         return 1;
1255 }
1256
1257
1258
1259 DefaultVTransition::DefaultVTransition(MWindow *mwindow)
1260  : BC_MenuItem(_("Default Transition"), _("Shift-U"), 'U')
1261 {
1262         set_shift();
1263         this->mwindow = mwindow;
1264 }
1265
1266 int DefaultVTransition::handle_event()
1267 {
1268         if( mwindow->session->current_operation == NO_OPERATION )
1269                 mwindow->paste_video_transition();
1270         return 1;
1271 }
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286 // ============================================ settings
1287
1288 DeleteTracks::DeleteTracks(MWindow *mwindow)
1289  : BC_MenuItem(_("Delete tracks"))
1290 {
1291         this->mwindow = mwindow;
1292 }
1293
1294 int DeleteTracks::handle_event()
1295 {
1296         mwindow->delete_tracks();
1297         return 1;
1298 }
1299
1300 DeleteFirstTrack::DeleteFirstTrack(MWindow *mwindow)
1301  : BC_MenuItem(_("Delete first track"), "Shift-D", 'D')
1302 {
1303         set_shift(1);
1304         this->mwindow = mwindow;
1305 }
1306
1307 int DeleteFirstTrack::handle_event()
1308 {
1309         if( mwindow->session->current_operation == NO_OPERATION ) {
1310                 Track *track = mwindow->edl->tracks->first;
1311                 if( track ) mwindow->delete_track(track);
1312         }
1313         return 1;
1314 }
1315
1316 DeleteLastTrack::DeleteLastTrack(MWindow *mwindow)
1317  : BC_MenuItem(_("Delete last track"), "Ctrl-d", 'd')
1318 {
1319         set_ctrl(1);
1320         this->mwindow = mwindow;
1321 }
1322
1323 int DeleteLastTrack::handle_event()
1324 {
1325         if( mwindow->session->current_operation == NO_OPERATION ) {
1326                 Track *track = mwindow->edl->tracks->last;
1327                 if( track ) mwindow->delete_track(track);
1328         }
1329         return 1;
1330 }
1331
1332 MoveTracksUp::MoveTracksUp(MWindow *mwindow)
1333  : BC_MenuItem(_("Move tracks up"), _("Shift-Up"), UP)
1334 {
1335         this->mwindow = mwindow;
1336         set_shift();
1337 }
1338
1339 int MoveTracksUp::handle_event()
1340 {
1341         if( mwindow->session->current_operation == NO_OPERATION )
1342                 mwindow->move_tracks_up();
1343         return 1;
1344 }
1345
1346 MoveTracksDown::MoveTracksDown(MWindow *mwindow)
1347  : BC_MenuItem(_("Move tracks down"), _("Shift-Down"), DOWN)
1348 {
1349         this->mwindow = mwindow;
1350         set_shift();
1351 }
1352
1353 int MoveTracksDown::handle_event()
1354 {
1355         if( mwindow->session->current_operation == NO_OPERATION )
1356                 mwindow->move_tracks_down();
1357         return 1;
1358 }
1359
1360
1361 RollTracksUp::RollTracksUp(MWindow *mwindow)
1362  : BC_MenuItem(_("Roll tracks up"), _("Ctrl-Shift-Up"), UP)
1363 {
1364         this->mwindow = mwindow;
1365         set_ctrl();
1366         set_shift();
1367 }
1368
1369 int RollTracksUp::handle_event()
1370 {
1371         if( mwindow->session->current_operation == NO_OPERATION )
1372                 mwindow->roll_tracks_up();
1373         return 1;
1374 }
1375
1376 RollTracksDown::RollTracksDown(MWindow *mwindow)
1377  : BC_MenuItem(_("Roll tracks down"), _("Ctrl-Shift-Down"), DOWN)
1378 {
1379         this->mwindow = mwindow;
1380         set_ctrl();
1381         set_shift();
1382 }
1383
1384 int RollTracksDown::handle_event()
1385 {
1386         if( mwindow->session->current_operation == NO_OPERATION )
1387                 mwindow->roll_tracks_down();
1388         return 1;
1389 }
1390
1391
1392
1393
1394 ConcatenateTracks::ConcatenateTracks(MWindow *mwindow)
1395  : BC_MenuItem(_("Concatenate tracks"))
1396 {
1397         set_shift();
1398         this->mwindow = mwindow;
1399 }
1400
1401 int ConcatenateTracks::handle_event()
1402 {
1403         mwindow->concatenate_tracks();
1404         return 1;
1405 }
1406
1407
1408
1409
1410
1411 LoopPlayback::LoopPlayback(MWindow *mwindow)
1412  : BC_MenuItem(_("Loop Playback"), _("Shift-L"), 'L')
1413 {
1414         this->mwindow = mwindow;
1415         set_checked(mwindow->edl->local_session->loop_playback);
1416         set_shift();
1417 }
1418
1419 int LoopPlayback::handle_event()
1420 {
1421         if( mwindow->session->current_operation == NO_OPERATION ) {
1422                 mwindow->toggle_loop_playback();
1423                 set_checked(mwindow->edl->local_session->loop_playback);
1424         }
1425         return 1;
1426 }
1427
1428
1429
1430 // ============================================= subtitle
1431
1432
1433 AddSubttlTrack::AddSubttlTrack(MWindow *mwindow)
1434  : BC_MenuItem(_("Add subttl"), _("Shift-Y"), 'Y')
1435 {
1436         set_shift();
1437         this->mwindow = mwindow;
1438 }
1439
1440 int AddSubttlTrack::handle_event()
1441 {
1442         if( mwindow->session->current_operation == NO_OPERATION )
1443                 mwindow->add_subttl_track_entry(1, 0);
1444         return 1;
1445 }
1446
1447 PasteSubttl::PasteSubttl(MWindow *mwindow)
1448  : BC_MenuItem(_("paste subttl"), "y", 'y')
1449 {
1450         this->mwindow = mwindow;
1451 }
1452
1453 int PasteSubttl::handle_event()
1454 {
1455         if( mwindow->session->current_operation == NO_OPERATION )
1456                 mwindow->gui->swindow->paste_subttl();
1457         return 1;
1458 }
1459
1460
1461 SetBRenderActive::SetBRenderActive(MWindow *mwindow)
1462  : BC_MenuItem(_("Toggle background rendering"),_("Shift-G"),'G')
1463 {
1464         this->mwindow = mwindow;
1465         set_shift(1);
1466 }
1467
1468 int SetBRenderActive::handle_event()
1469 {
1470         if( mwindow->session->current_operation == NO_OPERATION ) {
1471                 int v = mwindow->brender_active ? 0 : 1;
1472                 set_checked(v);
1473                 mwindow->set_brender_active(v);
1474         }
1475         return 1;
1476 }
1477
1478
1479 LabelsFollowEdits::LabelsFollowEdits(MWindow *mwindow)
1480  : BC_MenuItem(_("Edit labels"))
1481 {
1482         this->mwindow = mwindow;
1483         set_checked(mwindow->edl->session->labels_follow_edits);
1484 }
1485
1486 int LabelsFollowEdits::handle_event()
1487 {
1488         set_checked(get_checked() ^ 1);
1489         mwindow->set_labels_follow_edits(get_checked());
1490         return 1;
1491 }
1492
1493
1494
1495
1496 PluginsFollowEdits::PluginsFollowEdits(MWindow *mwindow)
1497  : BC_MenuItem(_("Edit effects"))
1498 {
1499         this->mwindow = mwindow;
1500         set_checked(mwindow->edl->session->plugins_follow_edits);
1501 }
1502
1503 int PluginsFollowEdits::handle_event()
1504 {
1505         set_checked(get_checked() ^ 1);
1506         mwindow->edl->session->plugins_follow_edits = get_checked();
1507         return 1;
1508 }
1509
1510
1511
1512
1513 KeyframesFollowEdits::KeyframesFollowEdits(MWindow *mwindow)
1514  : BC_MenuItem(_("Keyframes follow edits"))
1515 {
1516         this->mwindow = mwindow;
1517         set_checked(mwindow->edl->session->autos_follow_edits);
1518 }
1519
1520 int KeyframesFollowEdits::handle_event()
1521 {
1522         mwindow->edl->session->autos_follow_edits ^= 1;
1523         set_checked(!get_checked());
1524         return 1;
1525 }
1526
1527
1528 CursorOnFrames::CursorOnFrames(MWindow *mwindow)
1529  : BC_MenuItem(_("Align cursor on frames"),_("Ctrl-a"),'a')
1530 {
1531         this->mwindow = mwindow;
1532         set_checked(mwindow->edl->session->cursor_on_frames);
1533         set_ctrl(1);
1534 }
1535
1536 int CursorOnFrames::handle_event()
1537 {
1538         mwindow->edl->session->cursor_on_frames = !mwindow->edl->session->cursor_on_frames;
1539         set_checked(mwindow->edl->session->cursor_on_frames);
1540         return 1;
1541 }
1542
1543
1544 TypelessKeyframes::TypelessKeyframes(MWindow *mwindow)
1545  : BC_MenuItem(_("Typeless keyframes"))
1546 {
1547         this->mwindow = mwindow;
1548         set_checked(mwindow->edl->session->typeless_keyframes);
1549 }
1550
1551 int TypelessKeyframes::handle_event()
1552 {
1553         mwindow->edl->session->typeless_keyframes = !mwindow->edl->session->typeless_keyframes;
1554         set_checked(mwindow->edl->session->typeless_keyframes);
1555         return 1;
1556 }
1557
1558
1559 ScrubSpeed::ScrubSpeed(MWindow *mwindow)
1560  : BC_MenuItem(_("Slow Shuttle"))
1561 {
1562         this->mwindow = mwindow;
1563 }
1564
1565 int ScrubSpeed::handle_event()
1566 {
1567         if(mwindow->edl->session->scrub_speed == .5)
1568         {
1569                 mwindow->edl->session->scrub_speed = 2;
1570                 set_text(_("Slow Shuttle"));
1571         }
1572         else
1573         {
1574                 mwindow->edl->session->scrub_speed = .5;
1575                 set_text(_("Fast Shuttle"));
1576         }
1577         return 1;
1578 }
1579
1580 SaveSettingsNow::SaveSettingsNow(MWindow *mwindow)
1581  : BC_MenuItem(_("Save settings now"),_("Ctrl-Shift-S"),'S')
1582 {
1583         this->mwindow = mwindow;
1584         set_ctrl(1);
1585         set_shift(1);
1586 }
1587
1588 int SaveSettingsNow::handle_event()
1589 {
1590         mwindow->save_defaults();
1591         mwindow->save_backup();
1592         mwindow->gui->show_message(_("Saved settings."));
1593         return 1;
1594 }
1595
1596
1597
1598 // ============================================ window
1599
1600
1601
1602
1603
1604 ShowVWindow::ShowVWindow(MWindow *mwindow)
1605  : BC_MenuItem(_("Show Viewer"))
1606 {
1607         this->mwindow = mwindow;
1608         set_checked(mwindow->session->show_vwindow);
1609 }
1610 int ShowVWindow::handle_event()
1611 {
1612         if( mwindow->session->current_operation == NO_OPERATION ) {
1613                 mwindow->gui->unlock_window();
1614                 if( !mwindow->session->show_vwindow )
1615                         mwindow->show_vwindow(1);
1616                 else
1617                         mwindow->hide_vwindow(1);
1618                 mwindow->gui->lock_window("ShowVWindow::handle_event");
1619                 set_checked(mwindow->session->show_vwindow);
1620         }
1621         return 1;
1622 }
1623
1624 ShowAWindow::ShowAWindow(MWindow *mwindow)
1625  : BC_MenuItem(_("Show Resources"))
1626 {
1627         this->mwindow = mwindow;
1628         set_checked(mwindow->session->show_awindow);
1629 }
1630 int ShowAWindow::handle_event()
1631 {
1632         if( mwindow->session->current_operation == NO_OPERATION ) {
1633                 mwindow->gui->unlock_window();
1634                 if( !mwindow->session->show_awindow )
1635                         mwindow->show_awindow();
1636                 else
1637                         mwindow->hide_awindow();
1638                 mwindow->gui->lock_window("ShowAWindow::handle_event");
1639                 set_checked(mwindow->session->show_awindow);
1640
1641         }
1642         return 1;
1643 }
1644
1645 ShowCWindow::ShowCWindow(MWindow *mwindow)
1646  : BC_MenuItem(_("Show Compositor"))
1647 {
1648         this->mwindow = mwindow;
1649         set_checked(mwindow->session->show_cwindow);
1650 }
1651 int ShowCWindow::handle_event()
1652 {
1653         if( mwindow->session->current_operation == NO_OPERATION ) {
1654                 mwindow->gui->unlock_window();
1655                 if( !mwindow->session->show_cwindow )
1656                         mwindow->show_cwindow();
1657                 else
1658                         mwindow->hide_cwindow();
1659                 mwindow->gui->lock_window("ShowCWindow::handle_event");
1660                 set_checked(mwindow->session->show_cwindow);
1661         }
1662         return 1;
1663 }
1664
1665
1666 ShowGWindow::ShowGWindow(MWindow *mwindow)
1667  : BC_MenuItem(_("Show Overlays"), _("Ctrl-0"), '0')
1668 {
1669         this->mwindow = mwindow;
1670         set_ctrl(1);
1671         set_checked(mwindow->session->show_gwindow);
1672 }
1673 int ShowGWindow::handle_event()
1674 {
1675         if( mwindow->session->current_operation == NO_OPERATION ) {
1676                 mwindow->gui->unlock_window();
1677                 if( !mwindow->session->show_gwindow )
1678                         mwindow->show_gwindow();
1679                 else
1680                         mwindow->hide_gwindow();
1681                 mwindow->gui->lock_window("ShowGWindow::handle_event");
1682                 set_checked(mwindow->session->show_gwindow);
1683         }
1684         return 1;
1685 }
1686
1687
1688 ShowLWindow::ShowLWindow(MWindow *mwindow)
1689  : BC_MenuItem(_("Show Levels"))
1690 {
1691         this->mwindow = mwindow;
1692         set_checked(mwindow->session->show_lwindow);
1693 }
1694 int ShowLWindow::handle_event()
1695 {
1696         if( mwindow->session->current_operation == NO_OPERATION ) {
1697
1698                 mwindow->gui->unlock_window();
1699                 if( !mwindow->session->show_lwindow )
1700                         mwindow->show_lwindow();
1701                 else
1702                         mwindow->hide_lwindow();
1703                 mwindow->gui->lock_window("ShowLWindow::handle_event");
1704                 set_checked(mwindow->session->show_lwindow);
1705         }
1706         return 1;
1707 }
1708
1709 TileWindows::TileWindows(MWindow *mwindow, const char *item_title, int config,
1710                 const char *hot_keytext, int hot_key)
1711  : BC_MenuItem(item_title, hot_keytext, hot_key)
1712 {
1713         this->mwindow = mwindow;
1714         this->config = config;
1715         if( hot_key ) set_ctrl(1);
1716 }
1717 int TileWindows::handle_event()
1718 {
1719         if( mwindow->session->current_operation == NO_OPERATION ) {
1720                 int window_config = config >= 0 ? config :
1721                         mwindow->session->window_config;
1722                 if( mwindow->tile_windows(window_config) ) {
1723                         mwindow->restart_status = 1;
1724                         mwindow->gui->set_done(0);
1725                 }
1726         }
1727         return 1;
1728 }
1729
1730 SplitX::SplitX(MWindow *mwindow)
1731  : BC_MenuItem(_("Split X pane"), _("Ctrl-1"), '1')
1732 {
1733         this->mwindow = mwindow;
1734         set_ctrl(1);
1735         set_checked(mwindow->gui->pane[TOP_RIGHT_PANE] != 0);
1736 }
1737 int SplitX::handle_event()
1738 {
1739         if( mwindow->session->current_operation == NO_OPERATION )
1740                 mwindow->split_x();
1741         return 1;
1742 }
1743
1744 SplitY::SplitY(MWindow *mwindow)
1745  : BC_MenuItem(_("Split Y pane"), _("Ctrl-2"), '2')
1746 {
1747         this->mwindow = mwindow;
1748         set_ctrl(1);
1749         set_checked(mwindow->gui->pane[BOTTOM_LEFT_PANE] != 0);
1750 }
1751 int SplitY::handle_event()
1752 {
1753         if( mwindow->session->current_operation == NO_OPERATION )
1754                 mwindow->split_y();
1755         return 1;
1756 }
1757
1758
1759 MixerItems::MixerItems(MWindow *mwindow)
1760  : BC_MenuItem(_("Mixers..."))
1761 {
1762         this->mwindow = mwindow;
1763 }
1764
1765 void MixerItems::create_objects()
1766 {
1767         BC_SubMenu *mixer_submenu = new BC_SubMenu();
1768         add_submenu(mixer_submenu);
1769         mixer_submenu->add_submenuitem(new MixerViewer(this));
1770         mixer_submenu->add_submenuitem(new DragTileMixers(this));
1771         mixer_submenu->add_submenuitem(new AlignMixers(this));
1772         mixer_submenu->add_submenuitem(new MixMasters(this));
1773 }
1774
1775 int MixerItems::activate_submenu()
1776 {
1777         BC_SubMenu *mixer_submenu = (BC_SubMenu *)get_submenu();
1778         int k = mixer_submenu->total_items();
1779         while( --k >= 0 ) {
1780                 MixerItem *mixer_item = (MixerItem *)mixer_submenu->get_item(k);
1781                 if( mixer_item->idx < 0 ) continue;
1782                 mixer_submenu->del_item(mixer_item);
1783         }
1784         int n = mwindow->edl->mixers.size();
1785         for( int i=0; i<n; ++i ) {
1786                 Mixer *mixer = mwindow->edl->mixers[i];
1787                 if( !mixer ) continue;
1788                 MixerItem *mixer_item = new MixerItem(this, mixer->title, mixer->idx);
1789                 mixer_submenu->add_submenuitem(mixer_item);
1790         }
1791         return BC_MenuItem::activate_submenu();
1792 }
1793
1794 MixerItem::MixerItem(MixerItems *mixer_items, const char *text, int idx)
1795  : BC_MenuItem(text)
1796 {
1797         this->mixer_items = mixer_items;
1798         this->idx = idx;
1799 }
1800
1801 MixerItem::MixerItem(MixerItems *mixer_items, const char *text, const char *hotkey_text, int hotkey)
1802  : BC_MenuItem(text, hotkey_text, hotkey)
1803 {
1804         this->mixer_items = mixer_items;
1805         this->idx = -1;
1806 }
1807
1808 int MixerItem::handle_event()
1809 {
1810         if( idx < 0 ) return 0;
1811         MWindow *mwindow = mixer_items->mwindow;
1812         Mixer *mixer = mwindow->edl->mixers.get_mixer(idx);
1813         if( !mixer ) return 0;
1814         ZWindow *zwindow = mwindow->get_mixer(idx);
1815         if( !zwindow )
1816                 zwindow = mwindow->get_mixer(mixer);
1817         if( !zwindow->zgui ) {
1818                 zwindow->set_title(mixer->title);
1819                 zwindow->start();
1820         }
1821         zwindow->zgui->lock_window("MixerItem::handle_event");
1822         zwindow->zgui->raise_window();
1823         zwindow->zgui->unlock_window();
1824         mwindow->refresh_mixers();
1825         return 1;
1826 }
1827
1828 MixerViewer::MixerViewer(MixerItems *mixer_items)
1829  : MixerItem(mixer_items, _("Mixer Viewer"), _("Shift-M"), 'M')
1830 {
1831         set_shift(1);
1832 }
1833
1834 int MixerViewer::handle_event()
1835 {
1836         MWindow *mwindow = mixer_items->mwindow;
1837         mwindow->start_mixer();
1838         return 1;
1839 }
1840
1841 DragTileMixers::DragTileMixers(MixerItems *mixer_items)
1842  : MixerItem(mixer_items, _("Drag Tile mixers"), "Alt-t", 't')
1843 {
1844         set_alt();
1845         drag_box = 0;
1846 }
1847
1848 DragTileMixers::~DragTileMixers()
1849 {
1850         delete drag_box;
1851 }
1852
1853 int DragTileMixers::handle_event()
1854 {
1855         if( !drag_box ) {
1856                 MWindow *mwindow = mixer_items->mwindow;
1857                 drag_box = new TileMixersDragBox(mwindow->gui);
1858         }
1859         if( !drag_box->running() )
1860                 drag_box->start(this);
1861         return 1;
1862 }
1863
1864 TileMixersDragBox::TileMixersDragBox(MWindowGUI *gui)
1865  : BC_DragBox(gui)
1866 {
1867         tile_mixers = 0;
1868 }
1869
1870 void TileMixersDragBox::start(DragTileMixers *tile_mixers)
1871 {
1872         this->tile_mixers = tile_mixers;
1873         start_drag();
1874 }
1875
1876 int TileMixersDragBox::handle_done_event(int x0, int y0, int x1, int y1)
1877 {
1878         MWindow *mwindow = tile_mixers->mixer_items->mwindow;
1879         if( x0 >= x1 || y0 >= y1 ) x0 = x1 = y0 = y1 = 0;
1880         mwindow->session->tile_mixers_x = x0;
1881         mwindow->session->tile_mixers_y = y0;
1882         mwindow->session->tile_mixers_w = x1 - x0;
1883         mwindow->session->tile_mixers_h = y1 - y0;
1884         mwindow->tile_mixers(x0, y0, x1, y1);
1885         tile_mixers = 0;
1886         return 1;
1887 }
1888
1889 AlignMixers::AlignMixers(MixerItems *mixer_items)
1890  : MixerItem(mixer_items, _("Align mixers"), "", 0)
1891 {
1892 }
1893
1894 int AlignMixers::handle_event()
1895 {
1896         MWindow *mwindow = mixer_items->mwindow;
1897         int wx, wy;
1898         mwindow->gui->get_abs_cursor(wx, wy);
1899         mwindow->mixers_align->start_dialog(wx, wy);
1900         return 1;
1901 }
1902
1903 MixMasters::MixMasters(MixerItems *mixer_items)
1904  : MixerItem(mixer_items, _("Mix masters"), "", 0)
1905 {
1906 }
1907
1908 int MixMasters::handle_event()
1909 {
1910         MWindow *mwindow = mixer_items->mwindow;
1911         mwindow->mix_masters();
1912         return 1;
1913 }
1914
1915
1916 AlignTimecodes::AlignTimecodes(MWindow *mwindow)
1917  : BC_MenuItem(_("Align Timecodes"))
1918 {
1919         this->mwindow = mwindow;
1920 }
1921
1922 int AlignTimecodes::handle_event()
1923 {
1924         mwindow->align_timecodes();
1925         return 1;
1926 }
1927
1928
1929 LoadLayoutItem::LoadLayoutItem(LoadLayout *load_layout, const char *text, int idx, int hotkey)
1930  : BC_MenuItem(text, "", hotkey)
1931 {
1932         this->idx = idx;
1933         this->load_layout = load_layout;
1934         if( hotkey ) {
1935                 char hot_txt[BCSTRLEN];
1936                 sprintf(hot_txt, _("Ctrl-Shift+F%d"), hotkey-KEY_F1+1);
1937                 set_ctrl();  set_shift();
1938                 set_hotkey_text(hot_txt);
1939         }
1940 }
1941
1942
1943 int LoadLayoutItem::handle_event()
1944 {
1945 // key_press hotkey skips over activate_submenu
1946         load_layout->update();
1947         MWindow *mwindow = load_layout->mwindow;
1948         switch( load_layout->action ) {
1949         case LAYOUT_LOAD:
1950                 mwindow->load_layout(layout_file);
1951                 break;
1952         case LAYOUT_SAVE: {
1953                 int wx = 0, wy = 0;
1954                 mwindow->gui->get_abs_cursor(wx, wy);
1955                 load_layout->layout_dialog->start_confirm_dialog(wx, wy, idx);
1956                 break; }
1957         }
1958         return 1;
1959 }
1960
1961 LoadLayout::LoadLayout(MWindow *mwindow, const char *text, int action)
1962  : BC_MenuItem(text)
1963 {
1964         this->mwindow = mwindow;
1965         this->action = action;
1966         this->layout_dialog = new LoadLayoutDialog(this);
1967 }
1968
1969 LoadLayout::~LoadLayout()
1970 {
1971         delete layout_dialog;
1972 }
1973
1974 void LoadLayout::create_objects()
1975 {
1976         BC_SubMenu *layout_submenu = new BC_SubMenu();
1977         add_submenu(layout_submenu);
1978
1979         for( int i=0; i<LAYOUTS_MAX; ++i ) {
1980                 char text[BCSTRLEN];
1981                 sprintf(text, _("Layout %d"), i+1);
1982                 LoadLayoutItem *item = new LoadLayoutItem(this, text, i,
1983                                 action==LAYOUT_LOAD ? KEY_F1+i : 0);
1984                 layout_submenu->add_submenuitem(item);
1985         }
1986 }
1987
1988 int LoadLayout::activate_submenu()
1989 {
1990         update();
1991         return BC_MenuItem::activate_submenu();
1992 }
1993
1994 void LoadLayout::update()
1995 {
1996         FileSystem fs;
1997         fs.set_filter("layout*_rc");
1998         int ret = fs.update(File::get_config_path());
1999         int sz = !ret ? fs.dir_list.size() : 0;
2000         BC_SubMenu *layout_submenu = get_submenu();
2001
2002         for( int i=0; i<LAYOUTS_MAX; ++i ) {
2003                 LoadLayoutItem* item = (LoadLayoutItem *)
2004                         layout_submenu->get_item(i);
2005                 char layout_text[BCSTRLEN];  layout_text[0] = 0;
2006                 int n = sz, id = i+1;
2007                 while( --n >= 0 ) {
2008                         char *np = fs.dir_list[n]->name;
2009                         char *cp = strrchr(np, '_'), *bp = 0;
2010                         int no = strtol(np+6, &bp, 10);
2011                         if( no != id || !bp ) continue;
2012                         if( bp == cp ) {  n = -1;  break; }
2013                         if( *bp++ == '_' && bp < cp && !strcmp(cp, "_rc") ) {
2014                                 int k = cp - bp;  char *tp = layout_text;
2015                                 if( k > LAYOUT_NAME_LEN ) k = LAYOUT_NAME_LEN;
2016                                 while( --k >= 0 ) *tp++ = *bp++;
2017                                 *tp = 0;
2018                                 break;
2019                         }
2020                 }
2021                 strcpy(item->layout_text, layout_text);
2022                 char *lp = item->layout_file;
2023                 int k = sprintf(lp, LAYOUT_FILE, id);
2024                 if( n >= 0 && layout_text[0] )
2025                         sprintf(lp + k-2, "%s_rc", layout_text);
2026                 else
2027                         sprintf(layout_text, _("Layout %d"), id);
2028                 item->set_text(layout_text);
2029         }
2030 }
2031
2032 LoadLayoutDialog::LoadLayoutDialog(LoadLayout *load_layout)
2033 {
2034         this->load_layout = load_layout;
2035         wx = 0;  wy = 0;
2036         idx = -1;
2037         lgui = 0;
2038 }
2039
2040 LoadLayoutDialog::~LoadLayoutDialog()
2041 {
2042         close_window();
2043 }
2044
2045 void LoadLayoutDialog::handle_done_event(int result)
2046 {
2047         if( result ) return;
2048         char layout_file[BCSTRLEN];
2049         BC_SubMenu *layout_submenu = load_layout->get_submenu();
2050         LoadLayoutItem* item =
2051                 (LoadLayoutItem *) layout_submenu->get_item(idx);
2052         snprintf(layout_file, sizeof(layout_file), "%s", item->layout_file);
2053         load_layout->mwindow->delete_layout(layout_file);
2054         int k = sprintf(layout_file, LAYOUT_FILE, idx+1);
2055         const char *text = lgui->name_text->get_text();
2056         if( text[0] )
2057                 snprintf(layout_file + k-2, sizeof(layout_file)-k+2, "%s_rc", text);
2058         load_layout->mwindow->save_layout(layout_file);
2059 }
2060
2061 void LoadLayoutDialog::handle_close_event(int result)
2062 {
2063         lgui = 0;
2064 }
2065
2066 BC_Window *LoadLayoutDialog::new_gui()
2067 {
2068         lgui = new LoadLayoutConfirm(this, wx, wy);
2069         lgui->create_objects();
2070         return lgui;
2071 }
2072
2073 void LoadLayoutDialog::start_confirm_dialog(int wx, int wy, int idx)
2074 {
2075         close_window();
2076         this->wx = wx;  this->wy = wy;
2077         this->idx = idx;
2078         start();
2079 }
2080
2081 LoadLayoutNameText::LoadLayoutNameText(LoadLayoutConfirm *confirm,
2082                 int x, int y, int w, const char *text)
2083  : BC_TextBox(x, y, w, 1, text)
2084 {
2085         this->confirm = confirm;
2086 }
2087
2088 LoadLayoutNameText::~LoadLayoutNameText()
2089 {
2090 }
2091
2092 int LoadLayoutNameText::handle_event()
2093 {
2094         const char *text = get_text();
2095         int len = strlen(text), k = 0;
2096         char new_text[BCTEXTLEN];
2097         for( int i=0; i<len; ++i ) {
2098                 int ch = text[i];
2099                 if( (ch>='A' && ch<='Z') || (ch>='a' && ch<='z') ||
2100                     (ch>='0' && ch<='9') || ch=='_' )
2101                         new_text[k++] = ch;
2102         }
2103         new_text[k] = 0;  len = k;
2104         int i = len - LAYOUT_NAME_LEN;
2105         if( i >= 0 ) {
2106                 k = 0;
2107                 while( i < len ) new_text[k++] = new_text[i++];
2108                 new_text[k] = 0;
2109         }
2110         update(new_text);
2111         return 1;
2112 }
2113
2114 LoadLayoutConfirm::LoadLayoutConfirm(LoadLayoutDialog *layout_dialog, int x, int y)
2115  : BC_Window(_(PROGRAM_NAME ": Layout"), x, y, xS(300),yS(140), xS(300),yS(140), 0)
2116 {
2117         this->layout_dialog = layout_dialog;
2118 // *** CONTEXT_HELP ***
2119         context_help_set_keyword("Window Layouts");
2120 }
2121
2122 LoadLayoutConfirm::~LoadLayoutConfirm()
2123 {
2124 }
2125
2126 void LoadLayoutConfirm::create_objects()
2127 {
2128         int xs10 = xS(10), xs20 = xS(20);
2129         int ys10 = yS(10);
2130         lock_window("LoadLayoutConfirm::create_objects");
2131         int x = xs10, y = ys10;
2132         BC_SubMenu *layout_submenu = layout_dialog->load_layout->get_submenu();
2133         LoadLayoutItem *item = (LoadLayoutItem *)
2134                 layout_submenu->get_item(layout_dialog->idx);
2135         BC_Title *title;
2136         add_subwindow(title = new BC_Title(x, y, _("Layout Name:")));
2137         int x1 = x + title->get_w() + xs10;
2138         add_subwindow(title = new BC_Title(x1, y, item->get_text()));
2139         y += title->get_h() + ys10;
2140         add_subwindow(name_text = new LoadLayoutNameText(this,
2141                 x, y, get_w()-x-xs20, item->layout_text));
2142         y += name_text->get_h();
2143         x1 = x + xS(80);
2144         char legend[BCTEXTLEN];
2145         sprintf(legend, _("a-z,A-Z,0-9_ only, %dch max"), LAYOUT_NAME_LEN);
2146         add_subwindow(title = new BC_Title(x1, y, legend));
2147         add_subwindow(new BC_OKButton(this));
2148         add_subwindow(new BC_CancelButton(this));
2149         unlock_window();
2150 }
2151
2152
2153 LoadRecentItem::LoadRecentItem(const char *path)
2154 {
2155         this->path = cstrdup(path);
2156 }
2157
2158 LoadRecentItem::~LoadRecentItem()
2159 {
2160         delete [] path;
2161 }
2162
2163 int LoadRecentItems::add_load(char *path)
2164 {
2165 // test for existing copy
2166         FileSystem fs;
2167         char name[BCTEXTLEN], text[BCTEXTLEN];
2168         fs.extract_name(name, path);
2169         int loads_total = size();
2170         int ret = 0, k = loads_total;
2171         LoadRecentItem *load_item = 0;
2172
2173         for( int i=0; !ret && i<loads_total; ++i ) {
2174                 load_item = get(i);
2175                 fs.extract_name(text, load_item->path);
2176                 if( strcmp(name, text) ) continue;
2177                 k = i;  ret = 1; // already exists, move to top
2178         }
2179         if( !ret ) { // adding a new one
2180                 while( loads_total >= TOTAL_LOADS )
2181                         remove_object_number(--loads_total);
2182                 insert(new LoadRecentItem(path), 0);
2183         }
2184         else if( k > 0 ) { // cycle loads
2185                 while( --k >= 0 ) set(k+1, get(k));
2186                 set(0, load_item);
2187         }
2188         return ret;
2189 }
2190
2191 LoadRecentItems::LoadRecentItems()
2192 {
2193 }
2194
2195 LoadRecentItems::~LoadRecentItems()
2196 {
2197         remove_all_objects();
2198 }
2199
2200 LoadRecent::LoadRecent(MWindow *mwindow, MainMenu *main_menu)
2201  : BC_MenuItem(_("Load Recent..."))
2202 {
2203         this->mwindow = mwindow;
2204         this->main_menu = main_menu;
2205         total_items = 0;
2206 }
2207 LoadRecent::~LoadRecent()
2208 {
2209 }
2210
2211 void LoadRecent::create_objects()
2212 {
2213         add_submenu(submenu = new LoadRecentSubMenu(this));
2214 }
2215
2216 LoadPrevious *LoadRecent::get_next_item()
2217 {
2218         int k = total_items++;
2219         if( k < submenu->total_items() )
2220                 return (LoadPrevious *)submenu->get_item(k);
2221         LoadPrevious *load_prev = new LoadPrevious(mwindow, main_menu->load_file);
2222         submenu->add_item(load_prev);
2223         return load_prev;
2224 }
2225
2226 int LoadRecent::activate_submenu()
2227 {
2228         total_items = 0;
2229         scan_items(1);
2230         if( total_items > 0 ) {
2231                 LoadPrevious *load_prev = get_next_item();
2232                 load_prev->set_text("-");
2233                 load_prev->set_path("");
2234         }
2235         scan_items(0);
2236         while( total_items < submenu->total_items() )
2237                 submenu->del_item(0);
2238         return BC_MenuItem::activate_submenu();
2239 }
2240
2241 void LoadRecent::scan_items(int use_xml)
2242 {
2243         FileSystem fs;
2244         int loads_total = main_menu->load.size();
2245         for( int i=0; i<loads_total; ++i ) {
2246                 LoadRecentItem *recent = main_menu->load[i];
2247                 char name[BCTEXTLEN];
2248                 fs.extract_name(name, recent->path);
2249                 const char *cp = strrchr(name, '.');
2250                 if( !cp || strcasecmp(cp+1,"xml") ? use_xml : !use_xml ) continue;
2251                 LoadPrevious *load_prev = get_next_item();
2252                 load_prev->set_text(name);
2253                 load_prev->set_path(recent->path);
2254         }
2255 }
2256
2257 LoadRecentSubMenu::LoadRecentSubMenu(LoadRecent *load_recent)
2258  : BC_SubMenu()
2259 {
2260         this->load_recent = load_recent;
2261 }
2262
2263 LoadRecentSubMenu::~LoadRecentSubMenu()
2264 {
2265 }
2266