[amtk] test-headerbar: create a GtkShortcutsWindow manually



commit f24f9e1f5c3807daab624e7ce16ce2dd1fd56750
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Apr 13 18:13:36 2018 +0200

    test-headerbar: create a GtkShortcutsWindow manually
    
    Quick test to see if it's possible to create a GtkShortcutsWindow with
    code (not with a *.ui file). And the answer is yes, it's possible, it
    works. Note that all the GtkShortcuts* APIs don't have any public
    function, the documentation says that it's recommended to use a *.ui
    file :-(
    
    There is the GtkShortcutsShortcut:action-name property, but the API
    doesn't say whether it takes only the first accel or all accels. In
    Devhelp I want to take only the first accel if there are several.
    
    Another advantage with Amtk is that all the information is centralized,
    the GtkShortcutsShortcut:title will be defined in the AmtkActionInfo, so
    when modifying one piece of info we see all the other related info for
    the same action. So when renaming the label, we think about renaming the
    title for the GtkShortcutsShortcut too, since the two strings will be at
    the same place.

 tests/test-headerbar.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 50 insertions(+), 1 deletions(-)
---
diff --git a/tests/test-headerbar.c b/tests/test-headerbar.c
index bf83a75..1b7aabd 100644
--- a/tests/test-headerbar.c
+++ b/tests/test-headerbar.c
@@ -33,6 +33,7 @@ add_action_info_entries (void)
                /* action, icon, label, accel */
                { "win.show-side-panel", NULL, "_Side Panel", "F12" },
                { "win.print", NULL, "_Print", "<Control>p" },
+               { "win.shortcuts-window", NULL, "_Keyboard Shortcuts", NULL },
                { NULL }
        };
 
@@ -52,7 +53,7 @@ startup_cb (GApplication *g_app,
 }
 
 static void
-print_activate_cb (GSimpleAction *about_action,
+print_activate_cb (GSimpleAction *action,
                   GVariant      *parameter,
                   gpointer       user_data)
 {
@@ -60,6 +61,52 @@ print_activate_cb (GSimpleAction *about_action,
 }
 
 static void
+shortcuts_window_activate_cb (GSimpleAction *action,
+                             GVariant      *parameter,
+                             gpointer       user_data)
+{
+       GtkShortcutsWindow *window;
+       GtkWidget *section;
+       GtkWidget *group;
+       GtkWidget *shortcut;
+
+       /* TODO Add AmtkFactory function, and maybe some convenience functions
+        * too.
+        */
+
+       /* Create group */
+       group = g_object_new (GTK_TYPE_SHORTCUTS_GROUP,
+                             "visible", TRUE,
+                             "title", "General",
+                             NULL);
+
+       shortcut = g_object_new (GTK_TYPE_SHORTCUTS_SHORTCUT,
+                                "visible", TRUE,
+                                "title", "Find in current page",
+                                "accelerator", "<Control>f",
+                                NULL);
+       gtk_container_add (GTK_CONTAINER (group), shortcut);
+
+       shortcut = g_object_new (GTK_TYPE_SHORTCUTS_SHORTCUT,
+                                "visible", TRUE,
+                                "title", "Open a new tab",
+                                "accelerator", "<Control>t",
+                                NULL);
+       gtk_container_add (GTK_CONTAINER (group), shortcut);
+
+       /* Create section and window */
+       section = g_object_new (GTK_TYPE_SHORTCUTS_SECTION,
+                               "visible", TRUE,
+                               NULL);
+       gtk_container_add (GTK_CONTAINER (section), group);
+
+       window = g_object_new (GTK_TYPE_SHORTCUTS_WINDOW, NULL);
+       gtk_container_add (GTK_CONTAINER (window), section);
+
+       gtk_widget_show_all (GTK_WIDGET (window));
+}
+
+static void
 add_win_actions (GtkApplicationWindow *window,
                 GtkWidget            *side_panel)
 {
@@ -68,6 +115,7 @@ add_win_actions (GtkApplicationWindow *window,
        const GActionEntry entries[] =
        {
                { "print", print_activate_cb },
+               { "shortcuts-window", shortcuts_window_activate_cb },
                { NULL }
        };
 
@@ -91,6 +139,7 @@ create_window_menu (void)
        factory = amtk_factory_new_with_default_application ();
        amtk_gmenu_append_item (menu, amtk_factory_create_gmenu_item (factory, "win.show-side-panel"));
        amtk_gmenu_append_item (menu, amtk_factory_create_gmenu_item (factory, "win.print"));
+       amtk_gmenu_append_item (menu, amtk_factory_create_gmenu_item (factory, "win.shortcuts-window"));
        g_object_unref (factory);
 
        g_menu_freeze (menu);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]