I’m rewriting my software in GTK4/5 and, while at it, I wanted to switch to a proper coding methodology.
I now have the following:
struct _OTPClientWindow
{
AdwApplicationWindow parent;
GtkToggleButton *search_button;
};
...
static void
otpclient_window_show_searchbar (GSimpleAction *simple,
GVariant *parameter,
gpointer user_data)
{
OTPClientWindow *self = OTPCLIENT_WINDOW(user_data);
gtk_toggle_button_set_active (self->search_button, TRUE);
}
static void
otpclient_window_init (OTPClientWindow *self)
{
gtk_widget_init_template (GTK_WIDGET(self));
const GActionEntry win_entries[] = {
{ .name = "search", .activate = otpclient_window_show_searchbar, NULL, NULL, NULL },
};
g_action_map_add_action_entries (G_ACTION_MAP(self), win_entries, G_N_ELEMENTS(win_entries), self);
}
static void
otpclient_window_class_init (OTPClientWindowClass *class)
{
G_OBJECT_CLASS (class)->dispose = otpclient_window_dispose;
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS(class), "/com/github/paolostivanin/OTPClient/ui/window.ui");
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS(class), OTPClientWindow, search_button);
}
...
while in my application_startup
routine I have: set_accel_for_action (self, "win.search", "<Control>f");
.
In my ui file I have:
<object class="GtkToggleButton" id="search_button">
<property name="icon-name">system-search-symbolic</property>
</object>
now, when I compile everything and execute ctrl-f, I get:
(otpclient:9253): Gtk-CRITICAL **: 15:08:44.865: gtk_toggle_button_set_active: assertion 'GTK_IS_TOGGLE_BUTTON (toggle_button)' failed
what am I missing here?