Hello,
trying to code a shortcuts window, so not using a XML file, the following code works for GTK4 (before and after GTK4.14.4), it compiles for GTK3, but in that case the shortcuts window appears empty (it displays the title of the window, the search button, but not shortcut sections, group, or buttons), any idea why ?
void show_the_widgets (GtkWidget * widg)
{
#ifdef GTK4
gtk_widget_set_visible (widg, TRUE);
#else
gtk_widget_show_all (widg);
#endif
}
void window_add_child (GtkWidget * win, GtkWidget * child)
{
#ifdef GTK3
gtk_container_add (GTK_CONTAINER(win), child);
#else
gtk_window_set_child ((GtkWindow *)win, child);
#endif
}
void add_box_child (GtkWidget * box, GtkWidget * child)
{
#ifdef GTK4
gtk_box_append (GTK_BOX(box), child);
#else
gtk_box_pack_start (GTK_BOX(box), child, FALSE, FALSE, 0);
#endif
}
shortcuts w_shortcuts[] = {
{ "About", "open about dialog", GDK_KEY_a, "<Ctrl>a" },
{ "Periodic table", "open periodic table", GDK_KEY_p, "<Ctrl>p" },
{ "Quit", "quit atomes", GDK_KEY_q, "<Ctrl>q" }
};
void shortcuts_window ()
{
GtkShortcutsWindow * win = g_object_new (GTK_TYPE_SHORTCUTS_WINDOW, "title", "Shortcuts", "section-name", "smain" , "modal", FALSE, "resizable", FALSE, NULL);
GtkShortcutsSection * short_cut_section = g_object_new (GTK_TYPE_SHORTCUTS_SECTION, "visible", TRUE, "view-name", "main", "section-name", "smain", NULL);
GtkShortcutsGroup * short_cut_group = g_object_new (GTK_TYPE_SHORTCUTS_GROUP, "visible", TRUE, "title", "Group", "view", "main", NULL);
GtkShortcutsShortcut * shortcut;
int i;
for (i=0; i<G_N_ELEMENTS(shortcuts); i++)
{
shortcut = g_object_new (GTK_TYPE_SHORTCUTS_SHORTCUT,
"visible", TRUE,
"icon-set", TRUE,
"shortcut-type", GTK_SHORTCUT_ACCELERATOR,
"accelerator", w_shortcuts[i].accelerator,
"title", w_shortcuts[i].description,
"subtitle", w_shortcuts[i].subtitle,
"subtitle-set", FALSE,
"direction", GTK_TEXT_DIR_LTR,
NULL );
#ifdef GTK4
#if GTK_MINOR_VERSION > 14 || (GTK_MINOR_VERSION == 14 && GTK_MICRO_VERSION >= 4)
gtk_shortcuts_group_add_shortcut (short_cut_group, shortcut);
#else
add_box_child ((GtkWidget *)short_cut_group, (GtkWidget *)shortcut);
#endif
#else
add_box_child ((GtkWidget *)short_cut_group, (GtkWidget *)shortcut);
#endif
}
#ifdef GTK4
#if GTK_MINOR_VERSION > 14 || (GTK_MINOR_VERSION == 14 && GTK_MICRO_VERSION >= 4)
gtk_shortcuts_section_add_group (short_cut_section, short_cut_group);
gtk_shortcuts_window_add_section (win, short_cut_section);
#else
add_box_child ((GtkWidget *)short_cut_section, (GtkWidget *)short_cut_group);
window_child ((GtkWidget *)win, (GtkWidget *)short_cut_section);
#endif
#else
add_box_child ((GtkWidget *)short_cut_section, (GtkWidget *)short_cut_group);
window_child ((GtkWidget *)win, (GtkWidget *)short_cut_section);
#endif
show_the_widgets ((GtkWidget *)win);
}