radically change Keyboard/Binding API design to disconnect Gtk::Action lookup from...
[ardour.git] / gtk2_ardour / editor.cc
index f1dd0b2edd51cb018901e09b31d78e08c1de06fe..7cdd7d5b1f489fdd2de48ea9baa47f526ff94dde 100644 (file)
@@ -59,7 +59,6 @@
 #include "gtkmm2ext/bindings.h"
 #include "gtkmm2ext/grouped_buttons.h"
 #include "gtkmm2ext/gtk_ui.h"
-#include "gtkmm2ext/tearoff.h"
 #include "gtkmm2ext/utils.h"
 #include "gtkmm2ext/window_title.h"
 #include "gtkmm2ext/choice.h"
@@ -287,7 +286,6 @@ Editor::Editor ()
        , track_edit_playlist_submenu (0)
        , track_selection_edit_playlist_submenu (0)
        , _popup_region_menu_item (0)
-       , global_vpacker (key_bindings)
        , _track_canvas (0)
        , _track_canvas_viewport (0)
        , within_track_canvas (false)
@@ -398,10 +396,7 @@ Editor::Editor ()
        , bbt_beat_subdivision (4)
        , _visible_track_count (-1)
        ,  toolbar_selection_clock_table (2,3)
-       , _mouse_mode_tearoff (0)
        ,  automation_mode_button (_("mode"))
-       , _zoom_tearoff (0)
-       , _tools_tearoff (0)
        ,  _toolbar_viewport (*manage (new Gtk::Adjustment (0, 0, 1e10)), *manage (new Gtk::Adjustment (0, 0, 1e10)))
        , selection (new Selection (this))
        , cut_buffer (new Selection (this))
@@ -476,6 +471,8 @@ Editor::Editor ()
        last_event_time.tv_sec = 0;
        last_event_time.tv_usec = 0;
 
+       global_hpacker.set_data ("ardour-bindings", &bindings);
+
        selection_op_history.clear();
        before.clear();
 
@@ -746,13 +743,15 @@ Editor::Editor ()
        global_vpacker.pack_start (*hbox, true, true);
        global_hpacker.pack_start (global_vpacker, true, true);
 
+       /* need to show the "contents" widget so that notebook will show if tab is switched to
+        */
+
+       global_hpacker.show (); 
+
        /* register actions now so that set_state() can find them and set toggles/checks etc */
 
        register_actions ();
-       /* when we start using our own keybinding system for the editor, this
-        * will be uncommented
-        */
-       // load_bindings ();
+       load_bindings ();
 
        setup_toolbar ();
 
@@ -817,12 +816,12 @@ Editor::Editor ()
 
         /* Button bindings */
 
-        button_bindings = new Bindings;
+       button_bindings = new Bindings ("editor-mouse");
 
        XMLNode* node = button_settings();
         if (node) {
                 for (XMLNodeList::const_iterator i = node->children().begin(); i != node->children().end(); ++i) {
-                        button_bindings->load (**i);
+                        button_bindings->load_operation (**i);
                 }
         }
 
@@ -1336,8 +1335,6 @@ Editor::set_session (Session *t)
           the selected Marker; this needs the LocationMarker list to be available.
        */
        XMLNode* node = ARDOUR_UI::instance()->editor_settings();
-
-       cerr << "Editor - found state node " << node << endl;
        set_state (*node, Stateful::loading_state_version);
 
        /* catch up with the playhead */
@@ -2889,25 +2886,9 @@ Editor::setup_toolbar ()
        if (!ARDOUR::Profile->get_trx()) {
                mode_box->pack_start (edit_mode_selector, false, false);
        }
+       
        mode_box->pack_start (*mouse_mode_box, false, false);
-
-       _mouse_mode_tearoff = manage (new TearOff (*mode_box));
-       _mouse_mode_tearoff->set_name ("MouseModeBase");
-       _mouse_mode_tearoff->tearoff_window().signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press), &_mouse_mode_tearoff->tearoff_window()), false);
-
-       if (Profile->get_sae() || Profile->get_mixbus() ) {
-               _mouse_mode_tearoff->set_can_be_torn_off (false);
-       }
-
-       _mouse_mode_tearoff->Detach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
-                                                        &_mouse_mode_tearoff->tearoff_window()));
-       _mouse_mode_tearoff->Attach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
-                                                        &_mouse_mode_tearoff->tearoff_window(), 1));
-       _mouse_mode_tearoff->Hidden.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
-                                                        &_mouse_mode_tearoff->tearoff_window()));
-       _mouse_mode_tearoff->Visible.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
-                                                         &_mouse_mode_tearoff->tearoff_window(), 1));
-
+       
        /* Zoom */
 
        _zoom_box.set_spacing (2);
@@ -2978,23 +2959,6 @@ Editor::setup_toolbar ()
                _zoom_box.pack_start (tav_expand_button);
        }
 
-       if (!ARDOUR::Profile->get_trx()) {
-               _zoom_tearoff = manage (new TearOff (_zoom_box));
-
-               _zoom_tearoff->Detach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
-                                                          &_zoom_tearoff->tearoff_window()));
-               _zoom_tearoff->Attach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
-                                                          &_zoom_tearoff->tearoff_window(), 0));
-               _zoom_tearoff->Hidden.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
-                                                          &_zoom_tearoff->tearoff_window()));
-               _zoom_tearoff->Visible.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
-                                                           &_zoom_tearoff->tearoff_window(), 0));
-       }
-
-       if (Profile->get_sae() || Profile->get_mixbus() ) {
-               _zoom_tearoff->set_can_be_torn_off (false);
-       }
-
        snap_box.set_spacing (2);
        snap_box.set_border_width (2);
 
@@ -3027,37 +2991,19 @@ Editor::setup_toolbar ()
        HBox* hbox = manage (new HBox);
        hbox->set_spacing(2);
 
-       _tools_tearoff = manage (new TearOff (*hbox));
-       _tools_tearoff->set_name ("MouseModeBase");
-       _tools_tearoff->tearoff_window().signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press), &_tools_tearoff->tearoff_window()), false);
-
-       if (Profile->get_sae() || Profile->get_mixbus()) {
-               _tools_tearoff->set_can_be_torn_off (false);
-       }
-
-       _tools_tearoff->Detach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
-                                                   &_tools_tearoff->tearoff_window()));
-       _tools_tearoff->Attach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
-                                                   &_tools_tearoff->tearoff_window(), 0));
-       _tools_tearoff->Hidden.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast<Box*>(&toolbar_hbox),
-                                                   &_tools_tearoff->tearoff_window()));
-       _tools_tearoff->Visible.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast<Box*> (&toolbar_hbox),
-                                                    &_tools_tearoff->tearoff_window(), 0));
-
        toolbar_hbox.set_spacing (2);
        toolbar_hbox.set_border_width (1);
 
-       toolbar_hbox.pack_start (*_mouse_mode_tearoff, false, false);
+       toolbar_hbox.pack_start (*mode_box, false, false);
        if (!ARDOUR::Profile->get_trx()) {
-               toolbar_hbox.pack_start (*_zoom_tearoff, false, false);
-               toolbar_hbox.pack_start (*_tools_tearoff, false, false);
+               toolbar_hbox.pack_start (_zoom_box, false, false);
+               toolbar_hbox.pack_start (*hbox, false, false);
        }
 
        if (!ARDOUR::Profile->get_trx()) {
                hbox->pack_start (snap_box, false, false);
                hbox->pack_start (*nudge_box, false, false);
        }
-       hbox->pack_start (panic_box, false, false);
 
        hbox->show_all ();
 
@@ -3881,24 +3827,6 @@ Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
        }
 }
 
-void
-Editor::detach_tearoff (Box* /*b*/, Window* /*w*/)
-{
-       if ((_tools_tearoff->torn_off() || !_tools_tearoff->visible()) &&
-           (_mouse_mode_tearoff->torn_off() || !_mouse_mode_tearoff->visible()) &&
-           (_zoom_tearoff && (_zoom_tearoff->torn_off() || !_zoom_tearoff->visible()))) {
-               top_hbox.remove (toolbar_frame);
-       }
-}
-
-void
-Editor::reattach_tearoff (Box* /*b*/, Window* /*w*/, int32_t /*n*/)
-{
-       if (toolbar_frame.get_parent() == 0) {
-               top_hbox.pack_end (toolbar_frame);
-       }
-}
-
 void
 Editor::set_show_measures (bool yn)
 {
@@ -4178,25 +4106,6 @@ Editor::session_state_saved (string)
        _snapshots->redisplay ();
 }
 
-void
-Editor::update_tearoff_visibility()
-{
-       bool visible = UIConfiguration::instance().get_keep_tearoffs();
-       _mouse_mode_tearoff->set_visible (visible);
-       _tools_tearoff->set_visible (visible);
-       if (_zoom_tearoff) {
-               _zoom_tearoff->set_visible (visible);
-       }
-}
-
-void
-Editor::reattach_all_tearoffs ()
-{
-       if (_mouse_mode_tearoff) _mouse_mode_tearoff->put_it_back ();
-       if (_tools_tearoff) _tools_tearoff->put_it_back ();
-       if (_zoom_tearoff) _zoom_tearoff->put_it_back ();
-}
-
 void
 Editor::maximise_editing_space ()
 {
@@ -4204,9 +4113,12 @@ Editor::maximise_editing_space ()
                return;
        }
 
-       current_toplevel()->fullscreen ();
+       Gtk::Window* toplevel = current_toplevel();
 
-       _maximised = true;
+       if (toplevel) {
+               toplevel->fullscreen ();
+               _maximised = true;
+       }
 }
 
 void
@@ -4216,9 +4128,12 @@ Editor::restore_editing_space ()
                return;
        }
 
-       current_toplevel()->unfullscreen();
+       Gtk::Window* toplevel = current_toplevel();
 
-       _maximised = false;
+       if (toplevel) {
+               toplevel->unfullscreen();
+               _maximised = false;
+       }
 }
 
 /**
@@ -4990,7 +4905,6 @@ Editor::first_idle ()
        if (track_views.size() > 1) {
                Timers::TimerSuspender t;
                dialog = new MessageDialog (
-                       *current_toplevel(),
                        string_compose (_("Please wait while %1 loads visual data."), PROGRAM_NAME),
                        true
                        );
@@ -5948,6 +5862,7 @@ Editor::use_own_window (bool and_fill_it)
 
                // win->signal_realize().connect (*this, &Editor::on_realize);
                win->signal_event().connect (sigc::mem_fun (*this, &Editor::generic_event_handler));
+               win->set_data ("ardour-bindings", &bindings);
                
                update_title ();
        }