Я создал окно, которое отображает ярлыки с помощью GtkShortcutsWindow
. Однако я не хочу загружать внешний файл .ui, и для использования gtk_builder_new_from_string
требуется довольно большая строка. Я придумал краткое решение, создав необходимые объекты и упаковав их в окно и его контейнеры GtkShortcutsSection
и GtkShortcutsGroups
. Результат выглядит точно так же, как если бы я использовал gtk_builder_new_from_string
(я пробовал оба подхода), но когда не используется GtkBuilder
, встроенный поиск в верхней части окна не работает, не показывая результатов. Что мне здесь не хватает? Вот соответствующие части моего кода:
enum { FILE_HNDL_GRP, EDITING_GRP, FIND_GRP, VIEW_GRP, HELP_GRP, NUMBER_OF_SC_GROUPS };
gchar *accels[] = { "",
"<ctrl>N", "<ctrl>O", "<ctrl>S", "<ctrl><shift>S", "<ctrl>Q",
"",
"<ctrl>A", "<ctrl>backslash", "<ctrl>Z", "<ctrl>Y", "<ctrl>T",
"<ctrl>minus", "<ctrl>plus", "<ctrl>B", "<ctrl>R", "<ctrl><shift>R",
"",
"<ctrl>F", "<ctrl>H",
"",
"<shift><ctrl>X", "<shift><ctrl>C",
"",
"<ctrl>L", "<shift><ctrl>A"
};
gchar *accel_txts[] = { "File Handling",
"Create a new menu" , "Open a menu", "Save the menu",
"Save the menu as...", "Quit the application",
"Editing",
"Select all visible nodes", "Deselect all visible nodes", "Undo previous edit",
"Redo previous edit", "Move node to the top", "Move node up", "Move node down",
"Move node to the bottom", "Remove node", "Remove children from node",
"Find",
"Show/Hide Find Grid", "Open/Close\nFind & Replace Window",
"View",
"Expand all nodes", "Collapse all nodes",
"Help",
"Open/Close\nShortcuts Window", "About"
};
guint8 number_of_shortcuts = sizeof (accels) / sizeof (accels[0]);
GtkShortcutsWindow *shortcuts_window;
GtkShortcutsSection *shortcuts_section;
GtkShortcutsGroup *shortcuts_groups[NUMBER_OF_SC_GROUPS];
guint8 shortcuts_cnt;
gint8 groups_cnt = -1;
shortcuts_window = g_object_new (GTK_TYPE_SHORTCUTS_WINDOW, "modal", TRUE,
"resizable", TRUE,
"gravity", GDK_GRAVITY_CENTER,
NULL);
shortcuts_section = g_object_new (GTK_TYPE_SHORTCUTS_SECTION, "visible", TRUE, "max-height", 12, NULL);
gtk_container_add (GTK_CONTAINER (shortcuts_window), GTK_WIDGET (shortcuts_section));
for (shortcuts_cnt = 0; shortcuts_cnt < number_of_shortcuts; shortcuts_cnt++) {
if (!(accels[shortcuts_cnt][0] == '<')) {
groups_cnt++;
shortcuts_groups[groups_cnt] = g_object_new (GTK_TYPE_SHORTCUTS_GROUP, "title", accel_txts[shortcuts_cnt], NULL);
gtk_container_add (GTK_CONTAINER (shortcuts_section), GTK_WIDGET (shortcuts_groups[groups_cnt]));
}
else {
gtk_container_add (GTK_CONTAINER (shortcuts_groups[groups_cnt]),
GTK_WIDGET (g_object_new (GTK_TYPE_SHORTCUTS_SHORTCUT,
"accelerator", accels[shortcuts_cnt],
"title", accel_txts[shortcuts_cnt],
NULL)));
}
}
gtk_window_set_transient_for (GTK_WINDOW (shortcuts_window), GTK_WINDOW (window));
gtk_widget_show_all (GTK_WIDGET (shortcuts_window));