add syntactic sugar for fetching toggle and radio actions
[ardour.git] / libs / gtkmm2ext / bindings.cc
index 291cd6068693a128ea5cb600fb6a62685111109c..cf98bbca4dd6b2080411497d00b6a32436951bef 100644 (file)
@@ -781,12 +781,13 @@ Bindings::save_all_bindings_as_html (ostream& ostr)
        ostr << "<html>\n<head>\n<title>";
        ostr << PROGRAM_NAME;
        ostr << "</title>\n";
+       ostr << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n";
 
        ostr << "</head>\n<body>\n";
 
        ostr << "<table border=\"2\" cellpadding=\"6\"><tbody>\n\n";
        ostr << "<tr>\n\n";
-       
+
        /* first column: separate by group */
        ostr << "<td>\n\n";
        for (list<Bindings*>::const_iterator b = bindings.begin(); b != bindings.end(); ++b) {
@@ -825,17 +826,21 @@ Bindings::save_all_bindings_as_html (ostream& ostr)
 
                for (p = paths.begin(), k = keys.begin(), l = labels.begin(); p != paths.end(); ++k, ++p, ++l) {
 
+                       string print_path = *p;
+                       /* strip <Actions>/ from the start */
+                       print_path = print_path.substr (10);
+
                        if ((*k).empty()) {
-                               ostr << *p  << " ( " << *l << " ) "  << "</br>" << endl;
+                               ostr << print_path  << " ( " << *l << " ) "  << "</br>" << endl;
                        } else {
-                               ostr << *p << " ( " << *l << " ) " << " => " << *k << "</br>" << endl;
+                               ostr << print_path << " ( " << *l << " ) " << " => " << *k << "</br>" << endl;
                        }
                }
        }
        ostr << "</td>\n\n";
        ostr << "</tr>\n\n";
        ostr << "</tbody></table>\n\n";
-       
+
        ostr << "</body>\n";
        ostr << "</html>\n";
 }
@@ -857,7 +862,7 @@ Bindings::save_as_html (ostream& ostr, bool categorize) const
                GroupMap group_map;
 
                for (KeybindingMap::const_iterator k = press_bindings.begin(); k != press_bindings.end(); ++k) {
-                       
+
                        if (k->first.name().empty()) {
                                continue;
                        }
@@ -879,13 +884,13 @@ Bindings::save_as_html (ostream& ostr, bool categorize) const
                        }
                }
 
-               
+
                for (GroupMap::const_iterator gm = group_map.begin(); gm != group_map.end(); ++gm) {
 
                        if (categorize) {
                                ostr << "<h3>" << gm->first << "</h3>\n";
                        }
-                       
+
                        for (vector<KeybindingMap::const_iterator>::const_iterator k = gm->second.begin(); k != gm->second.end(); ++k) {
 
                                if ((*k)->first.name().empty()) {
@@ -934,7 +939,7 @@ Bindings::save_as_html (ostream& ostr, bool categorize) const
                                                key_name.replace (pos, strlen (targets[n]), replacements[n]);
                                        }
                                }
-                               
+
                                key_name.append(" ");
 
                                while (key_name.length()<28)
@@ -946,7 +951,7 @@ Bindings::save_as_html (ostream& ostr, bool categorize) const
                        ostr << "\n\n";
 
                }
-               
+
                ostr << "\n";
        }
 }
@@ -1169,6 +1174,7 @@ ActionMap::get_actions (ActionMap::Actions& acts)
        }
 }
 
+
 RefPtr<Action>
 ActionMap::find_action (const string& name)
 {
@@ -1178,9 +1184,76 @@ ActionMap::find_action (const string& name)
                return a->second;
        }
 
+       cerr << "Failed to find action: [" << name << ']' << endl;
+       return RefPtr<Action>();
+}
+
+RefPtr<ToggleAction>
+ActionMap::find_toggle_action (const string& name)
+{
+       RefPtr<Action> act = find_action (name);
+
+       if (!act) {
+               return RefPtr<ToggleAction>();
+       }
+
+       return Glib::RefPtr<ToggleAction>::cast_dynamic (act);
+}
+
+RefPtr<RadioAction>
+ActionMap::find_radio_action (const string& name)
+{
+       RefPtr<Action> act = find_action (name);
+
+       if (!act) {
+               return RefPtr<RadioAction>();
+       }
+
+       return Glib::RefPtr<RadioAction>::cast_dynamic (act);
+}
+
+RefPtr<Action>
+ActionMap::find_action (char const * group_name, char const * action_name)
+{
+       string fullpath (group_name);
+       fullpath += '/';
+       fullpath += action_name;
+
+       _ActionMap::iterator a = _actions.find (fullpath);
+
+       if (a != _actions.end()) {
+               return a->second;
+       }
+
+       cerr << "Failed to find action (2): [" << fullpath << ']' << endl;
        return RefPtr<Action>();
 }
 
+RefPtr<ToggleAction>
+ActionMap::find_toggle_action (char const * group_name, char const * action_name)
+{
+       RefPtr<Action> act = find_action (group_name, action_name);
+
+       if (!act) {
+               return RefPtr<ToggleAction>();
+       }
+
+       return Glib::RefPtr<ToggleAction>::cast_dynamic (act);
+}
+
+RefPtr<RadioAction>
+ActionMap::find_radio_action (char const * group_name, char const * action_name)
+{
+       RefPtr<Action> act = find_action (group_name, action_name);
+
+       if (!act) {
+               return RefPtr<RadioAction>();
+       }
+
+       return Glib::RefPtr<RadioAction>::cast_dynamic (act);
+}
+
+
 RefPtr<ActionGroup>
 ActionMap::create_action_group (const string& name)
 {