From 8859ebe56efb3a1be14ae464853ad7b9d2eec24d Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 10 Jul 2014 11:04:04 -0400 Subject: [PATCH] add Gtkmm2ext::Keyboard::reset_bindings() --- libs/gtkmm2ext/gtkmm2ext/keyboard.h | 2 ++ libs/gtkmm2ext/keyboard.cc | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) 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 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 #include +#include #include +#include + #include #include #include #include #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 uw (can_save_keybindings, false); + setup_keybindings (); + } + + return 0; +}