re-add TLSF
[ardour.git] / gtk2_ardour / ardour_ui_ed.cc
index dd53b2f0c476c4090c5dfbe5275a03ab81a240e0..d10e67339625287203914377f1b47dc6485a4fe5 100644 (file)
 #include "editor.h"
 #include "actions.h"
 #include "meterbridge.h"
+#include "luawindow.h"
 #include "mixer_ui.h"
 #include "startup.h"
 #include "window_manager.h"
 #include "global_port_matrix.h"
 #include "location_ui.h"
 #include "main_clock.h"
+#include "rc_option_editor.h"
 
 #include <gtkmm2ext/application.h>
 
@@ -66,7 +68,7 @@
 
 #include "control_protocol/control_protocol.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
@@ -87,11 +89,31 @@ ARDOUR_UI::create_editor ()
                return -1;
        }
 
-        editor->signal_event().connect (sigc::bind (sigc::ptr_fun (&Keyboard::catch_user_event_for_pre_dialog_focus), editor));
+       // editor->signal_event().connect (sigc::bind (sigc::ptr_fun (&Keyboard::catch_user_event_for_pre_dialog_focus), editor));
 
        return 0;
 }
 
+int
+ARDOUR_UI::create_luawindow ()
+
+{
+       try {
+               luawindow = LuaWindow::instance ();
+       }
+       catch (failed_constructor& err) {
+               return -1;
+       }
+
+       return 0;
+}
+
+void
+ARDOUR_UI::escape ()
+{
+       Escape (); /* EMIT SIGNAL */
+}
+
 void
 ARDOUR_UI::install_actions ()
 {
@@ -99,6 +121,8 @@ ARDOUR_UI::install_actions ()
        Glib::RefPtr<ActionGroup> main_menu_actions = global_actions.create_action_group (X_("Main_menu"));
        Glib::RefPtr<Action> act;
 
+       global_actions.register_action (main_actions, X_("Escape"), _("Escape"), sigc::mem_fun (*this, &ARDOUR_UI::escape));
+
        /* menus + submenus that need action items */
 
        global_actions.register_action (main_menu_actions, X_("Session"), _("Session"));
@@ -112,7 +136,7 @@ ARDOUR_UI::install_actions ()
        global_actions.register_action (main_menu_actions, X_("PrefsMenu"), _("Preferences"));
        global_actions.register_action (main_menu_actions, X_("DetachMenu"), _("Detach"));
        global_actions.register_action (main_menu_actions, X_("Help"), _("Help"));
-       global_actions.register_action (main_menu_actions, X_("KeyMouseActions"), _("Misc. Shortcuts"));
+       global_actions.register_action (main_menu_actions, X_("KeyMouseActions"), _("Misc. Shortcuts"));
        global_actions.register_action (main_menu_actions, X_("AudioFileFormat"), _("Audio File Format"));
        global_actions.register_action (main_menu_actions, X_("AudioFileFormatHeader"), _("File Type"));
        global_actions.register_action (main_menu_actions, X_("AudioFileFormatData"), _("Sample Format"));
@@ -132,12 +156,11 @@ ARDOUR_UI::install_actions ()
        act = global_actions.register_action (main_actions, X_("Close"), _("Close"),  sigc::mem_fun(*this, &ARDOUR_UI::close_session));
        ActionManager::session_sensitive_actions.push_back (act);
 
-       act = global_actions.register_action (main_actions, X_("AddTrackBus"), _("Add Track or Bus..."),
-                                             sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::add_route), (Gtk::Window*) 0));
+       act = global_actions.register_action (main_actions, X_("AddTrackBus"), _("Add Track or Bus..."), sigc::mem_fun(*this, &ARDOUR_UI::add_route));
        ActionManager::session_sensitive_actions.push_back (act);
        ActionManager::write_sensitive_actions.push_back (act);
 
-       act = ActionManager::register_action (main_actions, X_("duplicate-routes"), _("Duplicate Tracks/Busses..."),
+       act = global_actions.register_action (main_actions, X_("duplicate-routes"), _("Duplicate Tracks/Busses..."),
                                              sigc::mem_fun(*this, &ARDOUR_UI::start_duplicate_routes));
        ActionManager::session_sensitive_actions.push_back (act);
        ActionManager::write_sensitive_actions.push_back (act);
@@ -147,36 +170,42 @@ ARDOUR_UI::install_actions ()
        ActionManager::session_sensitive_actions.push_back (act);
        ActionManager::write_sensitive_actions.push_back (act);
 
-       act = global_actions.register_action (main_actions, X_("OpenVideo"), _("Open Video"),
+       act = global_actions.register_action (main_actions, X_("Scripting"), S_("Session|Scripting"));
+       ActionManager::session_sensitive_actions.push_back (act);
+
+       act = global_actions.register_action (main_actions, X_("AddLuaScript"), _("Add Lua Script..."),
+                     sigc::mem_fun (*this, &ARDOUR_UI::add_lua_script));
+       ActionManager::session_sensitive_actions.push_back (act);
+
+       act = global_actions.register_action (main_actions, X_("RemoveLuaScript"), _("Remove Lua Script"),
+                     sigc::mem_fun (*this, &ARDOUR_UI::remove_lua_script));
+       ActionManager::session_sensitive_actions.push_back (act);
+
+       act = global_actions.register_action (main_actions, X_("OpenVideo"), _("Open Video..."),
                                              sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::add_video), (Gtk::Window*) 0));
        ActionManager::session_sensitive_actions.push_back (act);
        act = global_actions.register_action (main_actions, X_("CloseVideo"), _("Remove Video"),
                                              sigc::mem_fun (*this, &ARDOUR_UI::remove_video));
        act->set_sensitive (false);
-
-       act = global_actions.register_action (main_actions, X_("ExportVideo"), _("Export to Video File"),
+       act = global_actions.register_action (main_actions, X_("ExportVideo"), _("Export to Video File..."),
                                              hide_return (sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::export_video), false)));
        ActionManager::session_sensitive_actions.push_back (act);
 
        act = global_actions.register_action (main_actions, X_("SnapshotStay"), _("Snapshot (& keep working on current version) ..."), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::snapshot_session), false));
        ActionManager::session_sensitive_actions.push_back (act);
-       ActionManager::write_sensitive_actions.push_back (act);
 
        act = global_actions.register_action (main_actions, X_("SnapshotSwitch"), _("Snapshot (& switch to new version) ..."), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::snapshot_session), true));
        ActionManager::session_sensitive_actions.push_back (act);
-       ActionManager::write_sensitive_actions.push_back (act);
 
-       act = ActionManager::register_action (main_actions, X_("QuickSnapshotStay"), _("Quick Snapshot (& keep working on current version) ..."), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::quick_snapshot_session), false));
+       act = global_actions.register_action (main_actions, X_("QuickSnapshotStay"), _("Quick Snapshot (& keep working on current version) ..."), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::quick_snapshot_session), false));
        ActionManager::session_sensitive_actions.push_back (act);
-       ActionManager::write_sensitive_actions.push_back (act);
 
-       act = global_actions::register_action (main_actions, X_("QuickSnapshotSwitch"), _("Quick Snapshot (& switch to new version) ..."), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::quick_snapshot_session), true));
+       act = global_actions.register_action (main_actions, X_("QuickSnapshotSwitch"), _("Quick Snapshot (& switch to new version) ..."), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::quick_snapshot_session), true));
        ActionManager::session_sensitive_actions.push_back (act);
        ActionManager::write_sensitive_actions.push_back (act);
 
        act = global_actions.register_action (main_actions, X_("SaveAs"), _("Save As..."), sigc::mem_fun(*this, &ARDOUR_UI::save_session_as));
        ActionManager::session_sensitive_actions.push_back (act);
-       ActionManager::write_sensitive_actions.push_back (act);
 
        act = global_actions.register_action (main_actions, X_("Rename"), _("Rename..."), sigc::mem_fun(*this, &ARDOUR_UI::rename_session));
        ActionManager::session_sensitive_actions.push_back (act);
@@ -225,34 +254,58 @@ ARDOUR_UI::install_actions ()
        global_actions.register_action (common_actions, X_("show-editor"), _("Show"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::show_tabbable), editor));
        global_actions.register_action (common_actions, X_("show-mixer"), _("Show"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::show_tabbable), mixer));
        global_actions.register_action (common_actions, X_("show-preferences"), _("Show"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::show_tabbable), rc_option_editor));
+       global_actions.register_action (common_actions, X_("menu-show-preferences"), _("Preferences"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::show_tabbable), rc_option_editor));
 
        global_actions.register_action (common_actions, X_("hide-editor"), _("Hide"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::hide_tabbable), editor));
        global_actions.register_action (common_actions, X_("hide-mixer"), _("Hide"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::hide_tabbable), mixer));
        global_actions.register_action (common_actions, X_("hide-preferences"), _("Hide"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::hide_tabbable), rc_option_editor));
-       
+
        global_actions.register_action (common_actions, X_("attach-editor"), _("Attach"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::attach_tabbable), editor));
        global_actions.register_action (common_actions, X_("attach-mixer"), _("Attach"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::attach_tabbable), mixer));
        global_actions.register_action (common_actions, X_("attach-preferences"), _("Attach"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::attach_tabbable), rc_option_editor));
-       
+
        global_actions.register_action (common_actions, X_("detach-editor"), _("Detach"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::detach_tabbable), editor));
        global_actions.register_action (common_actions, X_("detach-mixer"), _("Detach"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::detach_tabbable), mixer));
        global_actions.register_action (common_actions, X_("detach-preferences"), _("Detach"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::detach_tabbable), rc_option_editor));
 
+       /* These "change" actions are not intended to be used inside menus, but
+          are for the tab/window control buttons, which have somewhat odd
+          semantics.
+       */
+       global_actions.register_action (common_actions, X_("change-editor-visibility"), _("Change"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::button_change_tabbable_visibility), editor));
+       global_actions.register_action (common_actions, X_("change-mixer-visibility"), _("Change"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::button_change_tabbable_visibility), mixer));
+       global_actions.register_action (common_actions, X_("change-preferences-visibility"), _("Change"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::button_change_tabbable_visibility), rc_option_editor));
+
+       /* These "change" actions are not intended to be used inside menus, but
+          are for the tab/window control key bindings, which have somewhat odd
+          semantics.
+       */
+       global_actions.register_action (common_actions, X_("key-change-editor-visibility"), _("Change"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::key_change_tabbable_visibility), editor));
+       global_actions.register_action (common_actions, X_("key-change-mixer-visibility"), _("Change"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::key_change_tabbable_visibility), mixer));
+       global_actions.register_action (common_actions, X_("key-change-preferences-visibility"), _("Change"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::key_change_tabbable_visibility), rc_option_editor));
+
+       global_actions.register_action (common_actions, X_("previous-tab"), _("Previous Tab"), sigc::mem_fun (*this, &ARDOUR_UI::step_up_through_tabs));
+       global_actions.register_action (common_actions, X_("next-tab"), _("Next Tab"), sigc::mem_fun (*this, &ARDOUR_UI::step_down_through_tabs));
+
+       global_actions.register_action (common_actions, X_("toggle-editor-and-mixer"), _("Toggle Editor & Mixer"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_editor_and_mixer));
+
        /* windows visibility actions */
 
        global_actions.register_toggle_action (common_actions, X_("ToggleMaximalEditor"), _("Maximise Editor Space"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_editing_space));
        global_actions.register_toggle_action (common_actions, X_("ToggleMaximalMixer"), _("Maximise Mixer Space"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_mixer_space));
        ActionManager::session_sensitive_actions.push_back (act);
 
-       act = ActionManager::register_toggle_action (common_actions, X_("ToggleMixerList"), _("Toggle Mixer List"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_mixer_list));
+       act = global_actions.register_toggle_action (common_actions, X_("ToggleMixerList"), _("Toggle Mixer List"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_mixer_list));
        ActionManager::session_sensitive_actions.push_back (act);
 
-       act = ActionManager::register_toggle_action (common_actions, X_("ToggleMonitorSection"), _("Toggle Monitor Section Visibility"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_monitor_section_visibility));
+       act = global_actions.register_toggle_action (common_actions, X_("ToggleMonitorSection"), _("Toggle Monitor Section Visibility"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_monitor_section_visibility));
        act->set_sensitive (false);
 
-if (Profile->get_mixbus())
-       global_actions.register_action (common_actions, X_("show-ui-prefs"), _("Show more UI preferences"), sigc::mem_fun (*this, &ARDOUR_UI::show_ui_prefs));
+       if (Profile->get_mixbus()) {
+               global_actions.register_action (common_actions, X_("show-ui-prefs"), _("Show more UI preferences"), sigc::mem_fun (*this, &ARDOUR_UI::show_ui_prefs));
+       }
 
+       global_actions.register_action (common_actions, X_("toggle-luawindow"), S_("Window|Scripting"),  sigc::mem_fun(*this, &ARDOUR_UI::toggle_luawindow));
        global_actions.register_action (common_actions, X_("toggle-meterbridge"), S_("Window|Meterbridge"),  sigc::mem_fun(*this, &ARDOUR_UI::toggle_meterbridge));
 
        act = global_actions.register_action (common_actions, X_("NewMIDITracer"), _("MIDI Tracer"), sigc::mem_fun(*this, &ARDOUR_UI::new_midi_tracer_window));
@@ -414,22 +467,22 @@ if (Profile->get_mixbus())
        ActionManager::session_sensitive_actions.push_back (act);
        ActionManager::transport_sensitive_actions.push_back (act);
 
-       act = global_actions.register_action (transport_actions, X_("primary-clock-timecode"), _("Timecode"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::Timecode));
+       act = global_actions.register_action (transport_actions, X_("primary-clock-timecode"), _("Timecode"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::Timecode, false));
        ActionManager::session_sensitive_actions.push_back (act);
-       act = global_actions.register_action (transport_actions, X_("primary-clock-bbt"), _("Bars & Beats"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::BBT));
+       act = global_actions.register_action (transport_actions, X_("primary-clock-bbt"), _("Bars & Beats"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::BBT, false));
        ActionManager::session_sensitive_actions.push_back (act);
-       act = global_actions.register_action (transport_actions, X_("primary-clock-minsec"), _("Minutes & Seconds"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::MinSec));
+       act = global_actions.register_action (transport_actions, X_("primary-clock-minsec"), _("Minutes & Seconds"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::MinSec, false));
        ActionManager::session_sensitive_actions.push_back (act);
-       act = global_actions.register_action (transport_actions, X_("primary-clock-samples"), _("Samples"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::Frames));
+       act = global_actions.register_action (transport_actions, X_("primary-clock-samples"), _("Samples"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::Frames, false));
        ActionManager::session_sensitive_actions.push_back (act);
 
-       act = global_actions.register_action (transport_actions, X_("secondary-clock-timecode"), _("Timecode"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::Timecode));
+       act = global_actions.register_action (transport_actions, X_("secondary-clock-timecode"), _("Timecode"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::Timecode, false));
        ActionManager::session_sensitive_actions.push_back (act);
-       act = global_actions.register_action (transport_actions, X_("secondary-clock-bbt"), _("Bars & Beats"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::BBT));
+       act = global_actions.register_action (transport_actions, X_("secondary-clock-bbt"), _("Bars & Beats"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::BBT, false));
        ActionManager::session_sensitive_actions.push_back (act);
-       act = global_actions.register_action (transport_actions, X_("secondary-clock-minsec"), _("Minutes & Seconds"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::MinSec));
+       act = global_actions.register_action (transport_actions, X_("secondary-clock-minsec"), _("Minutes & Seconds"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::MinSec, false));
        ActionManager::session_sensitive_actions.push_back (act);
-       act = global_actions.register_action (transport_actions, X_("secondary-clock-samples"), _("Samples"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::Frames));
+       act = global_actions.register_action (transport_actions, X_("secondary-clock-samples"), _("Samples"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::Frames, false));
        ActionManager::session_sensitive_actions.push_back (act);
 
        act = global_actions.register_toggle_action (transport_actions, X_("TogglePunchIn"), _("Punch In"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_punch_in));
@@ -480,7 +533,7 @@ if (Profile->get_mixbus())
        shuttle_actions->add (Action::create (X_("SetShuttleUnitsPercentage"), _("Percentage")), hide_return (sigc::bind (sigc::mem_fun (*Config, &RCConfiguration::set_shuttle_units), Percentage)));
        shuttle_actions->add (Action::create (X_("SetShuttleUnitsSemitones"), _("Semitones")), hide_return (sigc::bind (sigc::mem_fun (*Config, &RCConfiguration::set_shuttle_units), Semitones)));
 
-       Glib::RefPtr<ActionGroup> option_actions = global_actions.create_action_group ("options");
+       Glib::RefPtr<ActionGroup> option_actions = global_actions.create_action_group ("Options");
 
        act = global_actions.register_toggle_action (option_actions, X_("SendMTC"), _("Send MTC"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_send_mtc));
        ActionManager::session_sensitive_actions.push_back (act);
@@ -497,14 +550,6 @@ if (Profile->get_mixbus())
 
        Glib::RefPtr<ActionGroup> midi_actions = global_actions.create_action_group (X_("MIDI"));
        global_actions.register_action (midi_actions, X_("panic"), _("Panic"), sigc::mem_fun(*this, &ARDOUR_UI::midi_panic));
-
-       global_actions.install_action_group (shuttle_actions);
-       global_actions.install_action_group (option_actions);
-       global_actions.install_action_group (transport_actions);
-       global_actions.install_action_group (main_actions);
-       global_actions.install_action_group (main_menu_actions);
-       global_actions.install_action_group (common_actions);
-       global_actions.install_action_group (midi_actions);
 }
 
 void
@@ -546,22 +591,11 @@ ARDOUR_UI::build_menu_bar ()
        format_label.set_use_markup ();
 
 #ifndef TOP_MENUBAR
-       menu_hbox.pack_start (*menu_bar, false, false);
+       menu_hbox.pack_start (*menu_bar, false, false);
 #else
        use_menubar_as_top_menubar ();
 #endif
 
-       bool wall_clock = false;
-       bool disk_space = false;
-
-       if (!Profile->get_small_screen()) {
-#ifndef GTKOSX
-               // OSX provides its own wallclock, thank you very much
-               wall_clock = true;
-#endif
-               disk_space = true;
-       }
-
        hbox->pack_end (error_alert_button, false, false, 2);
 
        hbox->pack_end (wall_clock_label, false, false, 2);
@@ -579,10 +613,11 @@ ARDOUR_UI::build_menu_bar ()
        menu_bar_base.set_name ("MainMenuBar");
        menu_bar_base.add (menu_hbox);
 
-#ifndef GTKOSX
-       _status_bar_visibility.add (&wall_clock_label,      X_("WallClock"), _("Wall Clock"), wall_clock);
+#ifndef __APPLE__
+       // OSX provides its own wallclock, thank you very much
+       _status_bar_visibility.add (&wall_clock_label,      X_("WallClock"), _("Wall Clock"), true);
 #endif
-       _status_bar_visibility.add (&disk_space_label,      X_("Disk"),      _("Disk Space"), disk_space);
+       _status_bar_visibility.add (&disk_space_label,      X_("Disk"),      _("Disk Space"), !Profile->get_small_screen());
        _status_bar_visibility.add (&cpu_load_label,        X_("DSP"),       _("DSP"), true);
        _status_bar_visibility.add (&xrun_label,            X_("XRun"),      _("X-run"), false);
        _status_bar_visibility.add (&peak_thread_work_label,X_("Peakfile"),  _("Active Peak-file Work"), false);
@@ -620,7 +655,7 @@ ARDOUR_UI::use_menubar_as_top_menubar ()
                app->add_app_menu_item (group, dynamic_cast<MenuItem*>(widget));
         }
 
-       if ((widget = ActionManager::get_widget ("/ui/Main/Session/toggle-rc-options-editor"))) {
+       if ((widget = ActionManager::get_widget ("/ui/Main/Edit/menu-show-preferences"))) {
                app->add_app_menu_item (group, dynamic_cast<MenuItem*>(widget));
         }
 
@@ -638,6 +673,7 @@ ARDOUR_UI::save_ardour_state ()
           a different lifetime model from add_instant_xml().
        */
 
+       LocaleGuard lg; // one guard to rule them all
        XMLNode* node = new XMLNode (keyboard->get_state());
        Config->add_extra_xml (*node);
        Config->add_extra_xml (get_transport_controllable_state());
@@ -659,16 +695,16 @@ ARDOUR_UI::save_ardour_state ()
 
        string current_tab;
        int current_page_number = _tabs.get_current_page ();
-       if (editor && (current_page_number == _tabs.page_num (editor->contents()))) {
+       if (current_page_number == _tabs.page_num (editor->contents())) {
                current_tab = "editor";
-       } else if (mixer && (current_page_number == _tabs.page_num (mixer->contents()))) {
+       } else if (current_page_number == _tabs.page_num (mixer->contents())) {
                current_tab = "mixer";
-       } else if (rc_option_editor && (current_page_number == _tabs.page_num (rc_option_editor->contents()))) {
-               current_tab == "preferences";
+       } else if (current_page_number == _tabs.page_num (rc_option_editor->contents())) {
+               current_tab = "preferences";
        }
 
        main_window_node.add_property (X_("current-tab"), current_tab);
-       
+
        /* Windows */
 
        WM::Manager::instance().add_state (*window_node);
@@ -686,6 +722,7 @@ ARDOUR_UI::save_ardour_state ()
        XMLNode& enode (editor->get_state());
        XMLNode& mnode (mixer->get_state());
        XMLNode& bnode (meterbridge->get_state());
+       XMLNode& pnode (rc_option_editor->get_state());
 
        Config->add_extra_xml (*window_node);
        Config->add_extra_xml (audio_midi_setup->get_state());
@@ -698,6 +735,7 @@ ARDOUR_UI::save_ardour_state ()
                _session->add_instant_xml (main_window_node);
                _session->add_instant_xml (enode);
                _session->add_instant_xml (mnode);
+               _session->add_instant_xml (pnode);
                _session->add_instant_xml (bnode);
                if (location_ui) {
                        _session->add_instant_xml (location_ui->ui().get_state ());
@@ -706,12 +744,17 @@ ARDOUR_UI::save_ardour_state ()
                Config->add_instant_xml (main_window_node);
                Config->add_instant_xml (enode);
                Config->add_instant_xml (mnode);
+               Config->add_instant_xml (pnode);
                Config->add_instant_xml (bnode);
                if (location_ui) {
                        Config->add_instant_xml (location_ui->ui().get_state ());
                }
        }
+
        delete &enode;
+       delete &mnode;
+       delete &bnode;
+       delete &pnode;
 
        Keyboard::save_keybindings ();
 }
@@ -752,3 +795,21 @@ ARDOUR_UI::tabs()
 {
        return _tabs;
 }
+
+bool
+ARDOUR_UI::tabbable_visibility_button_press (GdkEventButton* ev, string const& tabbable_name)
+{
+       if (ev->button != 3) {
+               return false;
+       }
+
+       /* context menu is defined in *.menus.in
+        */
+
+       string menu_name = string ("/ui/") + tabbable_name + X_("TabbableButtonMenu");
+       Gtk::Menu* menu = dynamic_cast<Gtk::Menu*> (ActionManager::get_widget (menu_name.c_str()));
+       if (menu) {
+               menu->popup (3, ev->time);
+       }
+       return true;
+}