diff options
Diffstat (limited to 'libs/gtkmm2ext')
-rw-r--r-- | libs/gtkmm2ext/bindings.cc | 23 | ||||
-rw-r--r-- | libs/gtkmm2ext/gtkmm2ext/bindings.h | 6 | ||||
-rw-r--r-- | libs/gtkmm2ext/keyboard.cc | 26 |
3 files changed, 53 insertions, 2 deletions
diff --git a/libs/gtkmm2ext/bindings.cc b/libs/gtkmm2ext/bindings.cc index 83e2dcf5b5..8803edc540 100644 --- a/libs/gtkmm2ext/bindings.cc +++ b/libs/gtkmm2ext/bindings.cc @@ -43,6 +43,7 @@ using namespace Gtkmm2ext; using namespace PBD; uint32_t Bindings::_ignored_state = 0; +map<string,Bindings*> Bindings::bindings_for_state; MouseButton::MouseButton (uint32_t state, uint32_t keycode) { @@ -227,6 +228,9 @@ Bindings::Bindings () Bindings::~Bindings() { + if (!_name.empty()) { + remove_bindings_for_state (_name, *this); + } } bool @@ -507,6 +511,10 @@ Bindings::load (string const & name) error << string_compose (_("No keyboard binding information when loading bindings for \"%1\""), name) << endmsg; return false; } + + if (!_name.empty()) { + remove_bindings_for_state (_name, *this); + } const XMLNodeList& children (node->children()); bool found = false; @@ -543,6 +551,9 @@ Bindings::load (string const & name) load (**i); } + add_bindings_for_state (_name, *this); + _name = name; + return true; } @@ -832,6 +843,18 @@ ActionMap::register_toggle_action (RefPtr<ActionGroup> group, return RefPtr<Action>(); } +void +Bindings::add_bindings_for_state (std::string const& name, Bindings& bindings) +{ + bindings_for_state.insert (make_pair (name, &bindings)); +} + +void +Bindings::remove_bindings_for_state (std::string const& name, Bindings& bindings) +{ + bindings_for_state.erase (name); +} + std::ostream& operator<<(std::ostream& out, Gtkmm2ext::KeyboardKey const & k) { return out << "Key " << k.key() << " (" << (k.key() > 0 ? gdk_keyval_name (k.key()) : "no-key") << ") state " << k.state(); } diff --git a/libs/gtkmm2ext/gtkmm2ext/bindings.h b/libs/gtkmm2ext/gtkmm2ext/bindings.h index 8dff6d2372..93e2ff78c5 100644 --- a/libs/gtkmm2ext/gtkmm2ext/bindings.h +++ b/libs/gtkmm2ext/gtkmm2ext/bindings.h @@ -151,9 +151,15 @@ class LIBGTKMM2EXT_API Bindings { std::vector<std::string>& tooltips, std::vector<KeyboardKey>& bindings); + static std::map<std::string,Bindings*> bindings_for_state; + + static void add_bindings_for_state (std::string const &, Bindings&); + static void remove_bindings_for_state (std::string const &, Bindings&); + private: typedef std::map<KeyboardKey,Glib::RefPtr<Gtk::Action> > KeybindingMap; + std::string _name; KeybindingMap press_bindings; KeybindingMap release_bindings; diff --git a/libs/gtkmm2ext/keyboard.cc b/libs/gtkmm2ext/keyboard.cc index 7e1473931f..0b7ac47471 100644 --- a/libs/gtkmm2ext/keyboard.cc +++ b/libs/gtkmm2ext/keyboard.cc @@ -38,8 +38,9 @@ #include "pbd/debug.h" #include "pbd/unwind.h" -#include "gtkmm2ext/keyboard.h" #include "gtkmm2ext/actions.h" +#include "gtkmm2ext/bindings.h" +#include "gtkmm2ext/keyboard.h" #include "gtkmm2ext/debug.h" #include "i18n.h" @@ -704,7 +705,28 @@ Keyboard::read_keybindings (string const & path) int Keyboard::store_keybindings (string const & path) { - return 0; + XMLNode* node = new XMLNode (X_("BindingSet")); + XMLNode* bnode; + int ret = 0; + + for (map<string,Bindings*>::const_iterator c = Bindings::bindings_for_state.begin(); c != Bindings::bindings_for_state.end(); ++c) { + bnode = new XMLNode (X_("Bindings")); + bnode->add_property (X_("name"), c->first); + c->second->save (*bnode); + node->add_child_nocopy (*bnode); + } + + XMLTree tree; + tree.set_root (node); + + if (!tree.write (path)) { + error << string_compose (_("Cannot save key bindings to %1"), path) << endmsg; + ret = -1; + } + + delete node; + + return ret; } int |