add new variant of ActionMap::find_action()
[ardour.git] / libs / gtkmm2ext / bindings.cc
index 9100ddabc6bd73720860fa21812f13904e028e8f..b1abcb0507f0cafc55d1d8107bfb2a0c0938c4f5 100644 (file)
@@ -177,18 +177,6 @@ KeyboardKey::display_label () const
 
        uint32_t mod = state();
 
-#ifdef __APPLE__
-       /* We use both bits (MOD2|META) for Primary on OS X,
-        * but we don't want MOD2 showing up in listings. So remove
-        * it and add back META.
-        */
-
-       if (mod & GDK_MOD2_MASK) {
-               mod = (mod & ~GDK_MOD2_MASK) | GDK_META_MASK;
-       }
-#endif
-
-
        return gtk_accelerator_get_label (key(), (GdkModifierType) mod);
 }
 
@@ -601,16 +589,6 @@ Bindings::push_to_gtk (KeyboardKey kb, RefPtr<Action> what)
 
 
                int mod = kb.state();
-#ifdef __APPLE__
-               /* See comments in Keyboard::Keyboard about GTK handling of MOD2, META and the Command key.
-                *
-                * If we do not do this, GTK+ won't show the correct text for shortcuts in menus.
-                */
-
-               if (mod & GDK_MOD2_MASK) {
-                       mod =  mod | GDK_META_MASK;
-               }
-#endif
 
                Gtk::AccelMap::add_entry (what->get_accel_path(), kb.key(), (Gdk::ModifierType) mod);
        }
@@ -752,16 +730,16 @@ Bindings::save (XMLNode& root)
                }
 
                child = new XMLNode (X_("Binding"));
-               child->add_property (X_("key"), k->first.name());
-               child->add_property (X_("action"), k->second.action_name);
+               child->set_property (X_("key"), k->first.name());
+               child->set_property (X_("action"), k->second.action_name);
                presses->add_child_nocopy (*child);
        }
 
        for (MouseButtonBindingMap::iterator k = button_press_bindings.begin(); k != button_press_bindings.end(); ++k) {
                XMLNode* child;
                child = new XMLNode (X_("Binding"));
-               child->add_property (X_("button"), k->first.name());
-               child->add_property (X_("action"), k->second.action_name);
+               child->set_property (X_("button"), k->first.name());
+               child->set_property (X_("action"), k->second.action_name);
                presses->add_child_nocopy (*child);
        }
 
@@ -775,16 +753,16 @@ Bindings::save (XMLNode& root)
                }
 
                child = new XMLNode (X_("Binding"));
-               child->add_property (X_("key"), k->first.name());
-               child->add_property (X_("action"), k->second.action_name);
+               child->set_property (X_("key"), k->first.name());
+               child->set_property (X_("action"), k->second.action_name);
                releases->add_child_nocopy (*child);
        }
 
        for (MouseButtonBindingMap::iterator k = button_release_bindings.begin(); k != button_release_bindings.end(); ++k) {
                XMLNode* child;
                child = new XMLNode (X_("Binding"));
-               child->add_property (X_("button"), k->first.name());
-               child->add_property (X_("action"), k->second.action_name);
+               child->set_property (X_("button"), k->first.name());
+               child->set_property (X_("action"), k->second.action_name);
                releases->add_child_nocopy (*child);
        }
 
@@ -803,61 +781,97 @@ Bindings::save_all_bindings_as_html (ostream& ostr)
        ostr << "<html>\n<head>\n<title>";
        ostr << PROGRAM_NAME;
        ostr << "</title>\n";
-
-
-       ostr << "<style>\n";
-       ostr << "\n\
-.key-name-even, .key-name-odd\n\
-{\n\
-    font-weight: bold;\n\
-}\n\
-\n\
-.key-action-odd, .key-action-even\n\
-{\n\
-    font-weight: normal;\n\
-    font-style: italic;\n\
-}";
-       ostr << "</style>\n";
+       ostr << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n";
 
        ostr << "</head>\n<body>\n";
 
-       ostr << "<div class=\"container\">\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) {
-               (*b)->save_as_html (ostr);
+               (*b)->save_as_html (ostr, true);
        }
+       ostr << "</td>\n\n";
+
+       //second column
+       ostr << "<td style=\"vertical-align:top\">\n\n";
+       for (list<Bindings*>::const_iterator b = bindings.begin(); b != bindings.end(); ++b) {
+               (*b)->save_as_html (ostr, false);
+       }
+       ostr << "</td>\n\n";
+
+
+       ostr << "</tr>\n\n";
+       ostr << "</tbody></table>\n\n";
+
+       ostr << "</br></br>\n\n";
+       ostr << "<table border=\"2\" cellpadding=\"6\"><tbody>\n\n";
+       ostr << "<tr>\n\n";
+       ostr << "<td>\n\n";
+       ostr << "<h2><u> Partial List of Available Actions { => with current shortcut, where applicable } </u></h2>\n\n";
+       {
+               vector<string> paths;
+               vector<string> labels;
+               vector<string> tooltips;
+               vector<string> keys;
+               vector<Glib::RefPtr<Gtk::Action> > actions;
+
+               Gtkmm2ext::ActionMap::get_all_actions (paths, labels, tooltips, keys, actions);
+
+               vector<string>::iterator k;
+               vector<string>::iterator p;
+               vector<string>::iterator l;
+
+               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 << print_path  << " ( " << *l << " ) "  << "</br>" << endl;
+                       } else {
+                               ostr << print_path << " ( " << *l << " ) " << " => " << *k << "</br>" << endl;
+                       }
+               }
+       }
+       ostr << "</td>\n\n";
+       ostr << "</tr>\n\n";
+       ostr << "</tbody></table>\n\n";
 
-       ostr << "</div>\n";
        ostr << "</body>\n";
        ostr << "</html>\n";
 }
 
 void
-Bindings::save_as_html (ostream& ostr) const
+Bindings::save_as_html (ostream& ostr, bool categorize) const
 {
 
        if (!press_bindings.empty()) {
 
-               ostr << "<div class=\"binding-set\">\n";
-               ostr << "<h1>";
-               ostr << name();
-               ostr << "</h1>\n\n";
-
-               /* first pass: separate by group */
+               ostr << "<h2><u>";
+               if (categorize)
+                       ostr << _("Window") << ": " << name() << _(" (Categorized)");
+               else
+                       ostr << _("Window") << ": " << name() << _(" (Alphabetical)");
+               ostr << "</u></h2>\n\n";
 
                typedef std::map<std::string, std::vector<KeybindingMap::const_iterator> > GroupMap;
                GroupMap group_map;
 
                for (KeybindingMap::const_iterator k = press_bindings.begin(); k != press_bindings.end(); ++k) {
+
                        if (k->first.name().empty()) {
                                continue;
                        }
 
                        string group_name;
-                       if (!k->second.group_name.empty()) {
+                       if (categorize && !k->second.group_name.empty()) {
                                group_name = k->second.group_name;
                        } else {
-                               group_name = X_("nogroup");
+                               group_name = _("Uncategorized");
                        }
 
                        GroupMap::iterator gm = group_map.find (group_name);
@@ -870,10 +884,12 @@ Bindings::save_as_html (ostream& ostr) const
                        }
                }
 
+
                for (GroupMap::const_iterator gm = group_map.begin(); gm != group_map.end(); ++gm) {
 
-                       ostr << "<div class=\"group\">\n";
-                       ostr << "<div class=\"group-name\">" << gm->first << "</div>\n";
+                       if (categorize) {
+                               ostr << "<h3>" << gm->first << "</h3>\n";
+                       }
 
                        for (vector<KeybindingMap::const_iterator>::const_iterator k = gm->second.begin(); k != gm->second.end(); ++k) {
 
@@ -897,6 +913,7 @@ Bindings::save_as_html (ostream& ostr) const
 
                                string key_name = (*k)->first.native_short_name ();
                                replace_all (key_name, X_("KP_"), X_("Numpad "));
+                               replace_all (key_name, X_("nabla"), X_("Tab"));
 
                                string::size_type pos;
 
@@ -923,13 +940,19 @@ Bindings::save_as_html (ostream& ostr) const
                                        }
                                }
 
-                               ostr << "<div class=\"key\">" << key_name << "</div>";
-                               ostr << "<div class=\"action\">" << action->get_label() << "</div>\n";
+                               key_name.append(" ");
+
+                               while (key_name.length()<28)
+                                       key_name.append("-");
+
+                               ostr << "<span style=\"font-family:monospace;\">" << key_name;
+                               ostr << "<i>" << action->get_label() << "</i></span></br>\n";
                        }
-                       ostr << "</div>\n\n";
+                       ostr << "\n\n";
+
                }
 
-               ostr << "</div>\n";
+               ostr << "\n";
        }
 }
 
@@ -1069,6 +1092,17 @@ Bindings::is_bound (KeyboardKey const& kb, Operation op) const
        return km.find(kb) != km.end();
 }
 
+std::string
+Bindings::bound_name (KeyboardKey const& kb, Operation op) const
+{
+       const KeybindingMap& km = get_keymap(op);
+       KeybindingMap::const_iterator b = km.find(kb);
+       if (b == km.end()) {
+               return "";
+       }
+       return b->second.action_name;
+}
+
 bool
 Bindings::is_registered (Operation op, std::string const& action_name) const
 {
@@ -1149,12 +1183,39 @@ ActionMap::find_action (const string& name)
                return a->second;
        }
 
+       cerr << "Failed to find action: [" << name << ']' << endl;
+       return RefPtr<Action>();
+}
+
+RefPtr<Action>
+ActionMap::find_action (char const * group_name, char const * action_name)
+{
+       string fullpath;
+
+       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<ActionGroup>
 ActionMap::create_action_group (const string& name)
 {
+       Glib::ListHandle<Glib::RefPtr<ActionGroup> > agl =  ActionManager::ui_manager->get_action_groups ();
+       for (Glib::ListHandle<Glib::RefPtr<ActionGroup> >::iterator i = agl.begin (); i != agl.end (); ++i) {
+               if ((*i)->get_name () == name) {
+                       return *i;
+               }
+       }
+
        RefPtr<ActionGroup> g = ActionGroup::create (name);
 
        /* this is one of the places where our own Action management code