introduce API to set widget bindings as a vector of Bindings

This commit is contained in:
Paul Davis 2025-03-10 13:02:25 -06:00
parent 8ac84c3ffd
commit 9472ca1a14
2 changed files with 23 additions and 2 deletions

View file

@ -628,8 +628,8 @@ Bindings::add (KeyboardKey kb, Operation op, string const& action_name, XMLPrope
(void) kbm.insert (new_pair).first; (void) kbm.insert (new_pair).first;
} }
DEBUG_TRACE (DEBUG::Bindings, string_compose ("add binding between %1 (%3) and %2, group [%3]\n", DEBUG_TRACE (DEBUG::Bindings, string_compose ("%5: add binding between %1 (%3) and %2, group [%3]\n",
kb, action_name, (group ? group->value() : string()), op)); kb, action_name, (group ? group->value() : string()), op, _name));
if (can_save) { if (can_save) {
Keyboard::keybindings_changed (); Keyboard::keybindings_changed ();
@ -1157,3 +1157,19 @@ std::ostream& operator<<(std::ostream& out, Gtkmm2ext::KeyboardKey const & k) {
return out << "Key " << k.key() << " (" << (gdk_name ? gdk_name : "no-key") << ") state " return out << "Key " << k.key() << " (" << (gdk_name ? gdk_name : "no-key") << ") state "
<< hex << k.state() << dec << ' ' << show_gdk_event_state (k.state()); << hex << k.state() << dec << ' ' << show_gdk_event_state (k.state());
} }
void
set_widget_bindings (Gtk::Widget& w, Bindings& b, char const * const name)
{
BindingSet* bs = new BindingSet;
bs->push_back (&b);
w.set_data (name, bs);
}
void
set_widget_bindings (Gtk::Widget& w, BindingSet& bs, char const * const name)
{
w.set_data (name, &bs);
}

View file

@ -210,6 +210,11 @@ class LIBGTKMM2EXT_API Bindings {
friend struct DragsBlockBindings; friend struct DragsBlockBindings;
}; };
typedef std::vector<Bindings*> BindingSet;
void set_widget_bindings (Gtk::Widget&, Bindings&, char const * const name);
void set_widget_bindings (Gtk::Widget&, BindingSet&, char const * const name);
} // namespace } // namespace
std::ostream& operator<<(std::ostream& out, Gtkmm2ext::KeyboardKey const & k); std::ostream& operator<<(std::ostream& out, Gtkmm2ext::KeyboardKey const & k);