button hacks and more
[ardour.git] / gtk2_ardour / actions.cc
index 8a5928c3f83d3f469a8ba7e89875a637a0dc01d9..264f9fe7c510bc6b1a9f29384e9eeaca9e824df9 100644 (file)
 */
 
 #include <vector>
+
 #include <gtk/gtkaccelmap.h>
+#include <gtk/gtkuimanager.h>
+#include <gtk/gtkactiongroup.h>
+
 #include <gtkmm/accelmap.h>
 #include <gtkmm/uimanager.h>
 
@@ -41,6 +45,8 @@ vector<RefPtr<Gtk::Action> > ActionManager::track_selection_sensitive_actions;
 vector<RefPtr<Gtk::Action> > ActionManager::plugin_selection_sensitive_actions;
 vector<RefPtr<Gtk::Action> > ActionManager::range_sensitive_actions;
 vector<RefPtr<Gtk::Action> > ActionManager::jack_sensitive_actions;
+vector<RefPtr<Gtk::Action> > ActionManager::jack_opposite_sensitive_actions;
+vector<RefPtr<Gtk::Action> > ActionManager::transport_sensitive_actions;
 RefPtr<UIManager> ActionManager::ui_manager;
 string ActionManager::unbound_string = "--";
 
@@ -50,13 +56,12 @@ ActionManager::init ()
        ui_manager = UIManager::create ();
 
        try {
-         ui_manager->add_ui_from_file (ARDOUR::find_config_file("ardour-menus.xml"));
+               ui_manager->add_ui_from_file (ARDOUR::find_config_file("ardour-menus.xml"));
        } catch (Glib::MarkupError& err) {
                error << "badly formatted UI definition file" << endmsg;
        } catch (...) {
-         std::cerr << "ardour action xml file not found" << endl;
+               error << "Ardour menu definition file not found" << endmsg;
        }
-    
 }
 
 RefPtr<Action>
@@ -192,5 +197,58 @@ ActionManager::get_widget (ustring name)
 RefPtr<Action>
 ActionManager::get_action (ustring name)
 {
-       return ui_manager->get_action (name);
+       /* the C++ API for functions used here appears to be broken in
+          gtkmm2.6, so we fall back to the C level.
+       */
+
+       GList* list = gtk_ui_manager_get_action_groups (ui_manager->gobj());
+       GList* node;
+       RefPtr<Action> act;
+
+       if (name.substr (0,9) != "<Actions>") {
+               error << "badly specified action name: " << name << endmsg;
+               return act;
+       }
+
+       ustring::size_type last_slash = name.find_last_of ('/');
+       ustring group_name = name.substr (10, last_slash - 10);
+       ustring action_name = name.substr (last_slash+1);
+       
+       for (node = list; node; node = g_list_next (node)) {
+
+               GtkActionGroup* _ag = (GtkActionGroup*) node->data;
+               
+               if (group_name == gtk_action_group_get_name (_ag)) {
+
+                       GtkAction* _act;
+                       
+                       if ((_act = gtk_action_group_get_action (_ag, action_name.c_str())) != 0) {
+                               act = Glib::wrap (_act);
+                               break;
+                       }
+               }
+       }
+
+       return act;
+}
+
+void 
+ActionManager::set_sensitive (vector<RefPtr<Action> >& actions, bool state)
+{
+       for (vector<RefPtr<Action> >::iterator i = actions.begin(); i != actions.end(); ++i) {
+               (*i)->set_sensitive (state);
+       }
+}
+
+void
+ActionManager::uncheck_toggleaction (const std::string& actionname)
+{
+        RefPtr<Action> act = get_action (actionname);
+       if (act) {
+               RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
+                       tact->set_active (false);
+       } else {
+               error << "Invalid action name: " << actionname << endmsg;
+       }
 }
+