enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / libs / gtkmm2ext / keyboard.cc
index 0b7ac47471fa0f903bb6447af15ebb3d998d1f0f..569db5e1a8bd066774c1ea913498c8a04c00595b 100644 (file)
@@ -43,7 +43,7 @@
 #include "gtkmm2ext/keyboard.h"
 #include "gtkmm2ext/debug.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace PBD;
 using namespace Gtk;
@@ -57,9 +57,9 @@ guint Keyboard::delete_mod = GDK_SHIFT_MASK;
 guint Keyboard::insert_note_but = 1;
 guint Keyboard::insert_note_mod = GDK_CONTROL_MASK;
 
-#ifdef GTKOSX
+#ifdef __APPLE__
 
-uint Keyboard::PrimaryModifier = GDK_MOD2_MASK;   // Command
+uint Keyboard::PrimaryModifier = GDK_META_MASK|GDK_MOD2_MASK;   // Command
 guint Keyboard::SecondaryModifier = GDK_CONTROL_MASK; // Control
 guint Keyboard::TertiaryModifier = GDK_SHIFT_MASK; // Shift
 guint Keyboard::Level4Modifier = GDK_MOD1_MASK; // Alt/Option
@@ -72,6 +72,11 @@ const char* Keyboard::secondary_modifier_name() { return _("Control"); }
 const char* Keyboard::tertiary_modifier_name() { return S_("Key|Shift"); }
 const char* Keyboard::level4_modifier_name() { return _("Option"); }
 
+const char* Keyboard::primary_modifier_short_name() { return _("Cmd"); }
+const char* Keyboard::secondary_modifier_short_name() { return _("Ctrl"); }
+const char* Keyboard::tertiary_modifier_short_name() { return S_("Key|Shift"); }
+const char* Keyboard::level4_modifier_short_name() { return _("Opt"); }
+
 guint Keyboard::snap_mod = Keyboard::Level4Modifier|Keyboard::TertiaryModifier; // XXX this is probably completely wrong
 guint Keyboard::snap_delta_mod = Keyboard::Level4Modifier;
 
@@ -90,6 +95,11 @@ const char* Keyboard::secondary_modifier_name() { return _("Alt"); }
 const char* Keyboard::tertiary_modifier_name() { return S_("Key|Shift"); }
 const char* Keyboard::level4_modifier_name() { return _("Windows"); }
 
+const char* Keyboard::primary_modifier_short_name() { return _("Ctrl"); }
+const char* Keyboard::secondary_modifier_short_name() { return _("Alt"); }
+const char* Keyboard::tertiary_modifier_short_name() { return S_("Key|Shift"); }
+const char* Keyboard::level4_modifier_short_name() { return _("Win"); }
+
 guint Keyboard::snap_mod = Keyboard::SecondaryModifier;
 guint Keyboard::snap_delta_mod = Keyboard::SecondaryModifier|Keyboard::Level4Modifier;
 
@@ -111,8 +121,8 @@ bool Keyboard::can_save_keybindings = false;
 bool Keyboard::bindings_changed_after_save_became_legal = false;
 map<string,string> Keyboard::binding_files;
 string Keyboard::_current_binding_name;
+string Keyboard::binding_filename_suffix = X_(".keys");
 Gtk::Window* Keyboard::pre_dialog_active_window = 0;
-XMLNode* Keyboard::_bindings_node = 0;
 
 /* set this to initially contain the modifiers we care about, then track changes in ::set_edit_modifier() etc. */
 GdkModifierType Keyboard::RelevantModifierKeyMask;
@@ -215,7 +225,7 @@ Keyboard::get_state (void)
 int
 Keyboard::set_state (const XMLNode& node, int /*version*/)
 {
-       const XMLProperty* prop;
+       XMLProperty const * prop;
 
        if ((prop = node.property ("copy-modifier")) != 0) {
                sscanf (prop->value().c_str(), "%d", &CopyModifier);
@@ -372,7 +382,7 @@ Keyboard::snooper (GtkWidget *widget, GdkEventKey *event)
 #if 0
                        /* August 2015: we don't have any release bindings
                         */
-                       
+
                        for (map<AccelKey,two_strings,AccelKeyLess>::iterator k = release_keys.begin(); k != release_keys.end(); ++k) {
 
                                const AccelKey& ak (k->first);
@@ -477,6 +487,7 @@ Keyboard::leave_window (GdkEventCrossing *ev, Gtk::Window* /*win*/)
                        current_window = 0;
                }
        } else {
+               DEBUG_TRACE (DEBUG::Keyboard, "LEAVE window without event\n");
                current_window = 0;
        }
 
@@ -498,7 +509,9 @@ Keyboard::focus_out_window (GdkEventFocus * ev, Gtk::Window* win)
                state.clear ();
                current_window = 0;
        }  else {
-               current_window = 0;
+               if (win == current_window) {
+                       current_window = 0;
+               }
        }
 
        DEBUG_TRACE (DEBUG::Keyboard, string_compose ("Foucusing out window, title = %1\n", win->get_title()));
@@ -592,7 +605,7 @@ Keyboard::is_insert_note_event (GdkEventButton *ev)
 bool
 Keyboard::is_button2_event (GdkEventButton* ev)
 {
-#ifdef GTKOSX
+#ifdef __APPLE__
        return (ev->button == 2) ||
                ((ev->button == 1) &&
                 ((ev->state & Keyboard::button2_modifiers) == Keyboard::button2_modifiers));
@@ -668,7 +681,7 @@ Keyboard::load_keybindings (string const & path)
 
                /* Call to specific implementation to load bindings from path */
                read_keybindings (path);
-               
+
                _current_binding_name = _("Unknown");
 
                for (map<string,string>::iterator x = binding_files.begin(); x != binding_files.end(); ++x) {
@@ -697,8 +710,24 @@ Keyboard::read_keybindings (string const & path)
                return -1;
        }
 
-       _bindings_node = new XMLNode (*tree.root ()); /* copy operation. Sorry */
-       
+       /* toplevel node is "BindingSet; children are "Bindings" */
+
+       XMLNodeList const& children = tree.root()->children();
+
+       for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
+               XMLNode const * child = *i;
+               if (child->name() == X_("Bindings")) {
+                       XMLProperty const* name = child->property (X_("name"));
+                       if (!name) {
+                               warning << _("Keyboard binding found without a name") << endmsg;
+                               continue;
+                       }
+
+                       Bindings* b = new Bindings (name->value());
+                       b->load (**i);
+               }
+        }
+
        return 0;
 }
 
@@ -709,23 +738,21 @@ Keyboard::store_keybindings (string const & path)
        XMLNode* bnode;
        int ret = 0;
 
-       for (map<string,Bindings*>::const_iterator c = Bindings::bindings_for_state.begin(); c != Bindings::bindings_for_state.end(); ++c) {
+       for (list<Bindings*>::const_iterator b = Bindings::bindings.begin(); b != Bindings::bindings.end(); ++b) {
                bnode = new XMLNode (X_("Bindings"));
-               bnode->add_property (X_("name"), c->first);
-               c->second->save (*bnode);
+               bnode->add_property (X_("name"), (*b)->name());
+               (*b)->save (*bnode);
                node->add_child_nocopy (*bnode);
        }
 
        XMLTree tree;
-       tree.set_root (node);
+       tree.set_root (node); /* tree now owns root and will delete it */
 
        if (!tree.write (path)) {
                error << string_compose (_("Cannot save key bindings to %1"), path) << endmsg;
                ret = -1;
        }
 
-       delete node;
-       
        return ret;
 }
 
@@ -746,6 +773,7 @@ Keyboard::reset_bindings ()
        {
                PBD::Unwinder<bool> uw (can_save_keybindings, false);
                setup_keybindings ();
+               Bindings::associate_all ();
        }
 
        return 0;