diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2014-07-10 11:04:04 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2014-07-10 11:04:04 -0400 |
commit | 8859ebe56efb3a1be14ae464853ad7b9d2eec24d (patch) | |
tree | fb40fc7699df32f49c34efe3c4292e9c0e8fa775 /libs | |
parent | 6cadefcb1982c98f4a2a9c78b88e80e9222ed1dc (diff) |
add Gtkmm2ext::Keyboard::reset_bindings()
Diffstat (limited to 'libs')
-rw-r--r-- | libs/gtkmm2ext/gtkmm2ext/keyboard.h | 2 | ||||
-rw-r--r-- | libs/gtkmm2ext/keyboard.cc | 26 |
2 files changed, 28 insertions, 0 deletions
diff --git a/libs/gtkmm2ext/gtkmm2ext/keyboard.h b/libs/gtkmm2ext/gtkmm2ext/keyboard.h index 2123e6ff69..d756c6199e 100644 --- a/libs/gtkmm2ext/gtkmm2ext/keyboard.h +++ b/libs/gtkmm2ext/gtkmm2ext/keyboard.h @@ -156,6 +156,8 @@ class LIBGTKMM2EXT_API Keyboard : public sigc::trackable, PBD::Stateful static std::string current_binding_name () { return _current_binding_name; } static std::map<std::string,std::string> binding_files; + int reset_bindings (); + struct AccelKeyLess { bool operator() (const Gtk::AccelKey a, const Gtk::AccelKey b) const { if (a.get_key() != b.get_key()) { diff --git a/libs/gtkmm2ext/keyboard.cc b/libs/gtkmm2ext/keyboard.cc index 2bfb5fa58b..48fcae8482 100644 --- a/libs/gtkmm2ext/keyboard.cc +++ b/libs/gtkmm2ext/keyboard.cc @@ -23,18 +23,23 @@ #include <fstream> #include <iostream> +#include <cerrno> #include <ctype.h> +#include <glib/gstdio.h> + #include <gtkmm/widget.h> #include <gtkmm/window.h> #include <gtkmm/accelmap.h> #include <gdk/gdkkeysyms.h> #include "pbd/error.h" +#include "pbd/convert.h" #include "pbd/file_utils.h" #include "pbd/search_path.h" #include "pbd/xml++.h" #include "pbd/debug.h" +#include "pbd/unwind.h" #include "gtkmm2ext/keyboard.h" #include "gtkmm2ext/actions.h" @@ -585,3 +590,24 @@ Keyboard::load_keybindings (string path) return true; } +int +Keyboard::reset_bindings () +{ + if (Glib::file_test (user_keybindings_path, Glib::FILE_TEST_EXISTS)) { + + string new_path = user_keybindings_path; + new_path += ".old"; + + if (::g_rename (user_keybindings_path.c_str(), new_path.c_str())) { + error << string_compose (_("Cannot rename your own keybinding file (%1)"), strerror (errno)) << endmsg; + return -1; + } + } + + { + PBD::Unwinder<bool> uw (can_save_keybindings, false); + setup_keybindings (); + } + + return 0; +} |