mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-07 07:14:56 +01:00
initial compilable version of saving key bindings with "new" scheme
This commit is contained in:
parent
4d5cf08bb7
commit
04a9ce757c
3 changed files with 53 additions and 2 deletions
|
|
@ -43,6 +43,7 @@ using namespace Gtkmm2ext;
|
||||||
using namespace PBD;
|
using namespace PBD;
|
||||||
|
|
||||||
uint32_t Bindings::_ignored_state = 0;
|
uint32_t Bindings::_ignored_state = 0;
|
||||||
|
map<string,Bindings*> Bindings::bindings_for_state;
|
||||||
|
|
||||||
MouseButton::MouseButton (uint32_t state, uint32_t keycode)
|
MouseButton::MouseButton (uint32_t state, uint32_t keycode)
|
||||||
{
|
{
|
||||||
|
|
@ -227,6 +228,9 @@ Bindings::Bindings ()
|
||||||
|
|
||||||
Bindings::~Bindings()
|
Bindings::~Bindings()
|
||||||
{
|
{
|
||||||
|
if (!_name.empty()) {
|
||||||
|
remove_bindings_for_state (_name, *this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
@ -507,6 +511,10 @@ Bindings::load (string const & name)
|
||||||
error << string_compose (_("No keyboard binding information when loading bindings for \"%1\""), name) << endmsg;
|
error << string_compose (_("No keyboard binding information when loading bindings for \"%1\""), name) << endmsg;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_name.empty()) {
|
||||||
|
remove_bindings_for_state (_name, *this);
|
||||||
|
}
|
||||||
|
|
||||||
const XMLNodeList& children (node->children());
|
const XMLNodeList& children (node->children());
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
@ -543,6 +551,9 @@ Bindings::load (string const & name)
|
||||||
load (**i);
|
load (**i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
add_bindings_for_state (_name, *this);
|
||||||
|
_name = name;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -832,6 +843,18 @@ ActionMap::register_toggle_action (RefPtr<ActionGroup> group,
|
||||||
return RefPtr<Action>();
|
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) {
|
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();
|
return out << "Key " << k.key() << " (" << (k.key() > 0 ? gdk_keyval_name (k.key()) : "no-key") << ") state " << k.state();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -151,9 +151,15 @@ class LIBGTKMM2EXT_API Bindings {
|
||||||
std::vector<std::string>& tooltips,
|
std::vector<std::string>& tooltips,
|
||||||
std::vector<KeyboardKey>& bindings);
|
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:
|
private:
|
||||||
typedef std::map<KeyboardKey,Glib::RefPtr<Gtk::Action> > KeybindingMap;
|
typedef std::map<KeyboardKey,Glib::RefPtr<Gtk::Action> > KeybindingMap;
|
||||||
|
|
||||||
|
std::string _name;
|
||||||
KeybindingMap press_bindings;
|
KeybindingMap press_bindings;
|
||||||
KeybindingMap release_bindings;
|
KeybindingMap release_bindings;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,9 @@
|
||||||
#include "pbd/debug.h"
|
#include "pbd/debug.h"
|
||||||
#include "pbd/unwind.h"
|
#include "pbd/unwind.h"
|
||||||
|
|
||||||
#include "gtkmm2ext/keyboard.h"
|
|
||||||
#include "gtkmm2ext/actions.h"
|
#include "gtkmm2ext/actions.h"
|
||||||
|
#include "gtkmm2ext/bindings.h"
|
||||||
|
#include "gtkmm2ext/keyboard.h"
|
||||||
#include "gtkmm2ext/debug.h"
|
#include "gtkmm2ext/debug.h"
|
||||||
|
|
||||||
#include "i18n.h"
|
#include "i18n.h"
|
||||||
|
|
@ -704,7 +705,28 @@ Keyboard::read_keybindings (string const & path)
|
||||||
int
|
int
|
||||||
Keyboard::store_keybindings (string const & path)
|
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
|
int
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue