Fix playhead smoothing when auditioning.
[ardour.git] / gtk2_ardour / window_manager.cc
index 3ab742199d1ad44d51cb8ee4568ad3ddba073e16..1d63751c5ec369e9f1fe1eee4c768274206b02e0 100644 (file)
 
 #include "ardour/session_handle.h"
 
+#include "gtkmm2ext/bindings.h"
 #include "gtkmm2ext/visibility_tracker.h"
 
 #include "actions.h"
 #include "ardour_dialog.h"
+#include "ardour_ui.h"
 #include "ardour_window.h"
 #include "window_manager.h"
 #include "processor_box.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using std::string;
 using namespace WM;
@@ -64,13 +66,47 @@ Manager::register_window (ProxyBase* info)
        if (!info->menu_name().empty()) {
 
                if (!window_actions) {
-                       window_actions = Gtk::ActionGroup::create (X_("Window"));
-                       ActionManager::add_action_group (window_actions);
+                       window_actions = ARDOUR_UI::instance()->global_actions.create_action_group (X_("Window"));
                }
 
-               info->set_action (ActionManager::register_action (window_actions, info->action_name().c_str(), info->menu_name().c_str(),
-                                                                 sigc::bind (sigc::mem_fun (*this, &Manager::toggle_window), info)));
+               ARDOUR_UI::instance()->global_actions.register_toggle_action (window_actions,
+                                                                             info->action_name().c_str(), info->menu_name().c_str(),
+                                                                             sigc::bind (sigc::mem_fun (*this, &Manager::toggle_window), info));
+
+               info->signal_map.connect (sigc::bind (sigc::mem_fun (*this, &Manager::window_proxy_was_mapped), info));
+               info->signal_unmap.connect (sigc::bind (sigc::mem_fun (*this, &Manager::window_proxy_was_unmapped), info));
+
+       }
+}
+
+void
+Manager::window_proxy_was_mapped (ProxyBase* proxy)
+{
+       Glib::RefPtr<Gtk::Action> act = ARDOUR_UI::instance()->global_actions.find_action (string_compose ("%1/%2", window_actions->get_name(), proxy->action_name()));
+       if (!act) {
+               return;
+       }
+       Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic (act);
+       if (!tact) {
+               return;
+       }
+
+       tact->set_active (true);
+}
+
+void
+Manager::window_proxy_was_unmapped (ProxyBase* proxy)
+{
+       Glib::RefPtr<Gtk::Action> act = ARDOUR_UI::instance()->global_actions.find_action (string_compose ("%1/%2", window_actions->get_name(), proxy->action_name()));
+       if (!act) {
+               return;
        }
+       Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic (act);
+       if (!tact) {
+               return;
+       }
+
+       tact->set_active (false);
 }
 
 void
@@ -87,8 +123,19 @@ Manager::remove (const ProxyBase* info)
 void
 Manager::toggle_window (ProxyBase* proxy)
 {
-       if (proxy) {
-               proxy->toggle ();
+       Glib::RefPtr<Gtk::Action> act = ARDOUR_UI::instance()->global_actions.find_action (string_compose ("%1/%2", window_actions->get_name(), proxy->action_name()));
+       if (!act) {
+               return;
+       }
+       Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic (act);
+       if (!tact) {
+               return;
+       }
+
+       if (tact->get_active()) {
+               proxy->present ();
+       } else {
+               proxy->hide ();
        }
 }
 
@@ -97,12 +144,27 @@ Manager::show_visible() const
 {
        for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
                if ((*i)->visible()) {
-                       if (! (*i)->get (true)) {
+                       Gtk::Window* win = (*i)->get (true);
+                       if (!win) {
                                /* the window may be a plugin GUI for a plugin which
                                 * is disabled or longer present.
                                 */
                                continue;
                        }
+                       if (dynamic_cast<ArdourDialog*> (win)) {
+                               /* do not show dialogs at startup. Most
+                                * dialogs require some signal connection work
+                                * because we are trying to avoid recursive
+                                * event loops (connecting instead to
+                                * ::signal_response(). This means we need to
+                                * destroy the window as well, so that the code
+                                * which checks if it should be created will
+                                * find that it is missing and will create it
+                                * and connect to any necessary signals.
+                                */
+                               (*i)->drop_window ();
+                               continue;
+                       }
                        (*i)->show_all ();
                        (*i)->present ();
                }
@@ -115,15 +177,12 @@ Manager::add_state (XMLNode& root) const
        for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
                /* don't save state for temporary proxy windows
                 */
+
                if (dynamic_cast<ProxyTemporary*> (*i)) {
                        continue;
                }
-               if (dynamic_cast<ProcessorWindowProxy*> (*i)) {
-                       ProcessorWindowProxy *pi = dynamic_cast<ProcessorWindowProxy*> (*i);
-                       root.add_child_nocopy (pi->get_state());
-               } else {
-                       root.add_child_nocopy ((*i)->get_state());
-               }
+
+               root.add_child_nocopy ((*i)->get_state());
        }
 }
 
@@ -185,7 +244,8 @@ ProxyBase::setup ()
 {
        WindowProxy::setup ();
        set_session(_session);
-}      
+
+}
 
 /*-----------------------*/