Strange problem with redefining Action callback
Hi, guys!
I have an GtkAction
with callback, and callback can change for that action. The action is called when a hotkey is pressed.
What I did:
First registered backspace as a hotkey using Gtk::AccelMap
for action-LayerRemove
:
Gtk::AccelMap::add_entry("<Actions>/action_group_layer_action_manager/action-LayerRemove", GDK_KEY_BackSpace, Gdk::ModifierType());
Also used ui_manager
(Gtk::UIManager) to link all together.
(Skipped some code which adds action to ActionGroup)
After that I call action manually:
GQuark accel_quark;
const auto accel_name = Gtk::AccelGroup::name(GDK_KEY_BackSpace, Gdk::ModifierType());
accel_quark = g_quark_from_string (accel_name.c_str());
Glib::RefPtr<Glib::Object>this_window = Glib::wrap(this->gobj_copy(), false);
if (ui_manager->get_accel_group()->activate(accel_quark, this_window, GDK_KEY_BackSpace,Gdk::ModifierType())) {
std::cout << "WORKS!" << endl;
}
Everything is working fine and the action callback is activated.
Next I want to redefine callback. So I remove all ActionGroups from UIManager:
// Remove old groups
auto old_groups = ui_manager->get_action_groups();
for (auto ag : old_groups) {
ui_manager->remove_action_group(ag);
}
ui_manager->ensure_update();
Next I create ActionGroup and add action to it:
auto action_group = Gtk::ActionGroup::create("action_group_layer_action_manager");
action_group->add(Gtk::Action::create("action-LayerRemove"),
sigc::bind<std::string>(&TestFunc, "test77")
);
ui_manager->insert_action_group(action_group);
ui_manager->ensure_update();
After that I call action again with the same code:
GQuark accel_quark;
const auto accel_name = Gtk::AccelGroup::name(GDK_KEY_BackSpace, Gdk::ModifierType());
accel_quark = g_quark_from_string (accel_name.c_str());
Glib::RefPtr<Glib::Object>this_window = Glib::wrap(this->gobj_copy(), false);
if (ui_manager->get_accel_group()->activate(accel_quark, this_window, GDK_KEY_BackSpace,Gdk::ModifierType())) {
std::cout << "WORKS!" << endl;
}
And it calls old callback :(
What I am doing wrong here?
P.S. TestFunc is just a boilerplate:
void TestFunc(std::string str) {
std::cout << str;
}