mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-06 14:54:56 +01:00
design to handle "cloned" bindings/actions
This commit is contained in:
parent
7a8fbdd5b1
commit
87ed40a855
2 changed files with 74 additions and 18 deletions
|
|
@ -373,19 +373,21 @@ KeyboardKey::make_key (const string& str, KeyboardKey& k)
|
|||
|
||||
/*================================= Bindings =================================*/
|
||||
Bindings::Bindings (std::string const& name)
|
||||
: _name (name)
|
||||
: _parent (nullptr)
|
||||
, _name (name)
|
||||
{
|
||||
bindings.push_back (this);
|
||||
}
|
||||
|
||||
Bindings::Bindings (std::string const & name, Bindings const & other)
|
||||
: _name (name)
|
||||
, press_bindings (other.press_bindings)
|
||||
, release_bindings (other.release_bindings)
|
||||
, button_press_bindings (other.button_press_bindings)
|
||||
, button_release_bindings (other.button_release_bindings)
|
||||
Bindings::Bindings (std::string const & name, Bindings & other)
|
||||
: _parent (&other)
|
||||
, _name (name)
|
||||
{
|
||||
relativize ();
|
||||
PBD::stacktrace (std::cerr, 13);
|
||||
copy_from_parent (false);
|
||||
|
||||
BindingsChanged.connect_same_thread (bc, std::bind (&Bindings::parent_changed, this, _1));
|
||||
|
||||
bindings.push_back (this);
|
||||
}
|
||||
|
||||
|
|
@ -536,7 +538,9 @@ void
|
|||
Bindings::relativize ()
|
||||
{
|
||||
for (auto & [key,action_info] : press_bindings) {
|
||||
std::cerr << action_info.action_name << " ---------> ";
|
||||
action_info.action_name = _name + action_info.action_name;
|
||||
std::cerr << action_info.action_name << std::endl;
|
||||
}
|
||||
for (auto & [key,action_info] : release_bindings) {
|
||||
action_info.action_name = _name + action_info.action_name;
|
||||
|
|
@ -550,13 +554,8 @@ Bindings::relativize ()
|
|||
}
|
||||
|
||||
void
|
||||
Bindings::associate ()
|
||||
Bindings::associate (bool force)
|
||||
{
|
||||
#warning find a better solution than this
|
||||
if (_name == "Editing" || _name == "MIDI") {
|
||||
return;
|
||||
}
|
||||
|
||||
KeybindingMap::iterator k;
|
||||
|
||||
for (k = press_bindings.begin(); k != press_bindings.end(); ++k) {
|
||||
|
|
@ -595,6 +594,55 @@ Bindings::dissociate ()
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
Bindings::copy_from_parent (bool assoc)
|
||||
{
|
||||
assert (_parent);
|
||||
press_bindings.clear ();
|
||||
release_bindings.clear ();
|
||||
|
||||
_parent->clone_press (press_bindings);
|
||||
_parent->clone_release (release_bindings);
|
||||
|
||||
dissociate ();
|
||||
relativize ();
|
||||
|
||||
if (assoc) {
|
||||
associate (true);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Bindings::parent_changed (Bindings* changed)
|
||||
{
|
||||
if (_parent != changed) {
|
||||
return;
|
||||
}
|
||||
|
||||
press_bindings.clear();
|
||||
release_bindings.clear();
|
||||
|
||||
copy_from_parent (true);
|
||||
}
|
||||
|
||||
void
|
||||
Bindings::clone_press (KeybindingMap& target) const
|
||||
{
|
||||
clone_kbd_bindings (press_bindings, target);
|
||||
}
|
||||
|
||||
void
|
||||
Bindings::clone_release (KeybindingMap& target) const
|
||||
{
|
||||
clone_kbd_bindings (release_bindings, target);
|
||||
}
|
||||
|
||||
void
|
||||
Bindings::clone_kbd_bindings (KeybindingMap const & src, KeybindingMap& target) const
|
||||
{
|
||||
target = src;
|
||||
}
|
||||
|
||||
void
|
||||
Bindings::push_to_gtk (KeyboardKey kb, RefPtr<Action> what)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -118,14 +118,15 @@ class LIBGTKMM2EXT_API Bindings {
|
|||
typedef std::map<KeyboardKey,ActionInfo> KeybindingMap;
|
||||
|
||||
Bindings (std::string const& name);
|
||||
Bindings (std::string const & name, Bindings const & other);
|
||||
Bindings (std::string const & name, Bindings & other);
|
||||
~Bindings ();
|
||||
|
||||
std::string const& name() const { return _name; }
|
||||
Bindings const * parent() const { return _parent; }
|
||||
|
||||
void reassociate ();
|
||||
void associate ();
|
||||
void associate (bool force = false);
|
||||
void dissociate ();
|
||||
void reassociate ();
|
||||
|
||||
bool empty() const;
|
||||
bool empty_keys () const;
|
||||
|
|
@ -178,6 +179,7 @@ class LIBGTKMM2EXT_API Bindings {
|
|||
};
|
||||
|
||||
private:
|
||||
Bindings * _parent;
|
||||
std::string _name;
|
||||
KeybindingMap press_bindings;
|
||||
KeybindingMap release_bindings;
|
||||
|
|
@ -193,6 +195,12 @@ class LIBGTKMM2EXT_API Bindings {
|
|||
MouseButtonBindingMap& get_mousemap (Operation op);
|
||||
|
||||
void relativize ();
|
||||
void clone_press (KeybindingMap&) const;
|
||||
void clone_release (KeybindingMap&) const;
|
||||
void clone_kbd_bindings (KeybindingMap const&, KeybindingMap&) const;
|
||||
void copy_from_parent (bool associate);
|
||||
void parent_changed (Bindings*);
|
||||
PBD::ScopedConnection bc;
|
||||
|
||||
/* GTK has the following position a Gtk::Action:
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue