[devhelp] Revert "Revert the introduction of the amtk library"



commit 18369a6958664f10b68c9edb749dbd3af7cc731a
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Sep 21 15:35:07 2018 +0200

    Revert "Revert the introduction of the amtk library"
    
    This reverts commit 4540f1c6897369fbbb7daa16bd3d100683a20299.
    
    See the TODO file, I plan to continue the development of the software
    product line. Amtk is a great help for that.
    
    The use of Amtk also avoid information duplication… A really basic
    programming best-practice.

 .gitignore                     |   1 -
 README                         |   1 +
 flatpak/org.gnome.Devhelp.json |  11 ++
 meson.build                    |   1 +
 po/POTFILES.in                 |   3 -
 src/dh-app.c                   | 239 ++++++++++++++++++++++++++-----------
 src/dh-app.h                   |   2 +
 src/dh-main.c                  |   3 +
 src/dh-window.c                | 260 ++++++++++++++++++++++++++++++++++-------
 src/dh-window.ui               | 245 --------------------------------------
 src/dh.gresource.xml           |   5 -
 src/help-overlay.ui            | 117 -------------------
 src/menus.ui                   |  58 ---------
 13 files changed, 403 insertions(+), 543 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 47656a4c..567609b1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1 @@
 build/
-_build/
\ No newline at end of file
diff --git a/README b/README
index 5911ef8a..a243208a 100644
--- a/README
+++ b/README
@@ -16,6 +16,7 @@ Dependencies
 - glib >= 2.56
 - gtk+ >= 3.22
 - webkit2gtk-4.0 >= 2.20
+- Amtk >= 5.0 - https://wiki.gnome.org/Projects/Amtk
 - gsettings-desktop-schemas
 
 Description
diff --git a/flatpak/org.gnome.Devhelp.json b/flatpak/org.gnome.Devhelp.json
index db8825e3..99a4fd02 100644
--- a/flatpak/org.gnome.Devhelp.json
+++ b/flatpak/org.gnome.Devhelp.json
@@ -37,6 +37,17 @@
         "*.a"
     ],
     "modules" : [
+        {
+            "name" : "amtk",
+            "run-tests" : true,
+            "sources" : [
+                {
+                    "type" : "git",
+                    "url" : "https://gitlab.gnome.org/GNOME/amtk.git";,
+                    "branch" : "master"
+                }
+            ]
+        },
         {
             "name" : "devhelp",
             "buildsystem" : "meson",
diff --git a/meson.build b/meson.build
index 51c4f770..26a6604d 100644
--- a/meson.build
+++ b/meson.build
@@ -49,6 +49,7 @@ endforeach
 
 DEVHELP_APP_DEPS = [
         LIBDEVHELP_DEPS,
+        dependency('amtk-5', version : '>= 5.0'),
         dependency('gsettings-desktop-schemas'),
 ]
 
diff --git a/po/POTFILES.in b/po/POTFILES.in
index cd6e6ed8..db463e9e 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -42,6 +42,3 @@ src/dh-preferences.ui
 src/dh-settings-app.c
 src/dh-util-app.c
 src/dh-window.c
-src/dh-window.ui
-src/help-overlay.ui
-src/menus.ui
diff --git a/src/dh-app.c b/src/dh-app.c
index a9c3dfb9..26f280c1 100644
--- a/src/dh-app.c
+++ b/src/dh-app.c
@@ -25,12 +25,126 @@
 #include "config.h"
 #include "dh-app.h"
 #include <glib/gi18n.h>
+#include <amtk/amtk.h>
 #include "dh-assistant.h"
 #include "dh-preferences.h"
 #include "dh-settings-app.h"
 #include "dh-util-app.h"
 
-G_DEFINE_TYPE (DhApp, dh_app, GTK_TYPE_APPLICATION);
+struct _DhAppPrivate {
+        /* AmtkActionInfoStore for actions that are present in a menu. */
+        AmtkActionInfoStore *menu_action_info_store;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (DhApp, dh_app, GTK_TYPE_APPLICATION);
+
+static void
+add_menu_action_infos (DhApp *app)
+{
+        const gchar *accels[] = {NULL, NULL, NULL};
+        AmtkActionInfo *action_info;
+
+        const AmtkActionInfoEntry entries[] = {
+                /* action, icon, label, accel, tooltip */
+
+                /* App menu */
+                { "app.new-window", NULL, N_("New _Window"), "<Control>n",
+                  N_("Open a new window") },
+                { "app.preferences", NULL, N_("_Preferences") },
+                { "win.shortcuts-window", NULL, N_("_Keyboard Shortcuts") },
+                { "app.help", NULL, N_("_Help"), "F1" },
+                { "app.about", NULL, N_("_About") },
+                { "app.quit", NULL, N_("_Quit"), "<Control>q",
+                  N_("Close all windows") },
+
+                /* Window menu */
+                { "win.show-sidebar", NULL, N_("_Side Panel"), "F9",
+                  N_("Toggle side panel visibility") },
+                { "win.print", NULL, N_("_Print"), "<Control>p" },
+                { "win.find", NULL, N_("_Find"), "<Control>f",
+                  N_("Find in current page") },
+                { "win.zoom-in", NULL, N_("_Larger Text"), NULL,
+                  N_("Larger text") },
+                { "win.zoom-out", NULL, N_("S_maller Text"), "<Control>minus",
+                  N_("Smaller text") },
+                { "win.zoom-default", NULL, N_("_Normal Size"), "<Control>0",
+                  N_("Normal size") },
+                { NULL }
+        };
+
+        g_assert (app->priv->menu_action_info_store == NULL);
+        app->priv->menu_action_info_store = amtk_action_info_store_new ();
+
+        amtk_action_info_store_add_entries (app->priv->menu_action_info_store,
+                                            entries, -1,
+                                            GETTEXT_PACKAGE);
+
+        accels[0] = "<Control>F1";
+        accels[1] = "<Control>question";
+        action_info = amtk_action_info_store_lookup (app->priv->menu_action_info_store, 
"win.shortcuts-window");
+        amtk_action_info_set_accels (action_info, accels);
+
+        /* For "<Control>equal": Epiphany also has this keyboard shortcut for
+         * zoom-in. On keyboards the = and + are usually on the same key, but +
+         * is less convenient to type because Shift must be pressed too.
+         * Apparently it's usual on Windows to press Ctrl+= to zoom in.
+         * https://bugzilla.gnome.org/show_bug.cgi?id=743704
+         */
+        accels[0] = "<Control>plus";
+        accels[1] = "<Control>equal";
+        action_info = amtk_action_info_store_lookup (app->priv->menu_action_info_store, "win.zoom-in");
+        amtk_action_info_set_accels (action_info, accels);
+
+        amtk_action_info_store_set_all_accels_to_app (app->priv->menu_action_info_store,
+                                                      GTK_APPLICATION (app));
+}
+
+static void
+add_other_action_infos (DhApp *app)
+{
+        AmtkActionInfoStore *store;
+        AmtkActionInfo *action_info;
+        const gchar *accels[] = {NULL, NULL, NULL, NULL};
+
+        const AmtkActionInfoEntry entries[] = {
+                /* action, icon, label, accel, tooltip */
+                { "win.new-tab", NULL, NULL, "<Control>t", N_("Open a new tab") },
+                { "win.close-tab", NULL, NULL, "<Control>w", N_("Close the current tab") },
+                { "win.go-back", NULL, NULL, NULL, N_("Go back") },
+                { "win.go-forward", NULL, NULL, NULL, N_("Go forward") },
+                { "win.focus-search", NULL, NULL, NULL, N_("Focus global search") },
+                { NULL }
+        };
+
+        store = amtk_action_info_store_new ();
+        amtk_action_info_store_add_entries (store, entries, -1, GETTEXT_PACKAGE);
+
+        accels[0] = "<Alt>Left";
+        accels[1] = "Back";
+        action_info = amtk_action_info_store_lookup (store, "win.go-back");
+        amtk_action_info_set_accels (action_info, accels);
+
+        accels[0] = "<Alt>Right";
+        accels[1] = "Forward";
+        action_info = amtk_action_info_store_lookup (store, "win.go-forward");
+        amtk_action_info_set_accels (action_info, accels);
+
+        accels[0] = "<Control>k";
+        accels[1] = "<Control>s";
+        accels[2] = "<Control>l";
+        action_info = amtk_action_info_store_lookup (store, "win.focus-search");
+        amtk_action_info_set_accels (action_info, accels);
+
+        amtk_action_info_store_set_all_accels_to_app (store, GTK_APPLICATION (app));
+        g_object_unref (store);
+}
+
+static void
+add_action_infos (DhApp *app)
+{
+        add_menu_action_infos (app);
+        add_other_action_infos (app);
+}
 
 static DhAssistant *
 get_active_assistant_window (DhApp *app)
@@ -92,6 +206,8 @@ new_window_cb (GSimpleAction *action,
 
         new_window = dh_window_new (GTK_APPLICATION (app));
         gtk_widget_show_all (new_window);
+
+        amtk_action_info_store_check_all_used (app->priv->menu_action_info_store);
 }
 
 static void
@@ -252,10 +368,10 @@ add_action_entries (DhApp *app)
                 { "raise", raise_cb },
         };
 
-        g_action_map_add_action_entries (G_ACTION_MAP (app),
-                                         app_entries,
-                                         G_N_ELEMENTS (app_entries),
-                                         app);
+        amtk_action_map_add_action_entries_check_dups (G_ACTION_MAP (app),
+                                                       app_entries,
+                                                       G_N_ELEMENTS (app_entries),
+                                                       app);
 }
 
 static void
@@ -287,91 +403,58 @@ setup_go_to_tab_accelerators (GtkApplication *app)
 }
 
 static void
-setup_accelerators (GtkApplication *app)
+setup_additional_accelerators (GtkApplication *app)
 {
-        const gchar *accels[] = {NULL, NULL, NULL, NULL};
+        const gchar *accels[] = {NULL, NULL};
 
         setup_go_to_tab_accelerators (app);
 
-        accels[0] = "<Control>0";
-        gtk_application_set_accels_for_action (app, "win.zoom-default", accels);
-
-        accels[0] = "<Control>minus";
-        gtk_application_set_accels_for_action (app, "win.zoom-out", accels);
-
-        /* For "<Control>equal": Epiphany also has this keyboard shortcut for
-         * zoom-in. On keyboards the = and + are usually on the same key, but +
-         * is less convenient to type because Shift must be pressed too.
-         * Apparently it's usual on Windows to press Ctrl+= to zoom in.
-         * https://bugzilla.gnome.org/show_bug.cgi?id=743704
-         */
-        accels[0] = "<Control>plus";
-        accels[1] = "<Control>equal";
-        gtk_application_set_accels_for_action (app, "win.zoom-in", accels);
-        accels[1] = NULL;
-
-        accels[0] = "<Control>f";
-        gtk_application_set_accels_for_action (app, "win.find", accels);
-
         accels[0] = "<Control>c";
         gtk_application_set_accels_for_action (app, "win.copy", accels);
 
-        accels[0] = "<Control>p";
-        gtk_application_set_accels_for_action (app, "win.print", accels);
-
-        accels[0] = "<Control>t";
-        gtk_application_set_accels_for_action (app, "win.new-tab", accels);
-
-        accels[0] = "<Control>n";
-        gtk_application_set_accels_for_action (app, "app.new-window", accels);
-
         accels[0] = "<Control>Page_Down";
         gtk_application_set_accels_for_action (app, "win.next-tab", accels);
 
         accels[0] = "<Control>Page_Up";
         gtk_application_set_accels_for_action (app, "win.prev-tab", accels);
 
-        accels[0] = "<Control>w";
-        gtk_application_set_accels_for_action (app, "win.close-tab", accels);
-
-        accels[0] = "<Control>q";
-        gtk_application_set_accels_for_action (app, "app.quit", accels);
-
-        accels[0] = "F1";
-        gtk_application_set_accels_for_action (app, "app.help", accels);
-
-        accels[0] = "F9";
-        gtk_application_set_accels_for_action (app, "win.show-sidebar", accels);
-
         accels[0] = "F10";
         gtk_application_set_accels_for_action (app, "win.show-window-menu", accels);
-
-        accels[0] = "<Alt>Right";
-        accels[1] = "Forward";
-        gtk_application_set_accels_for_action (app, "win.go-forward", accels);
-
-        accels[0] = "<Alt>Left";
-        accels[1] = "Back";
-        gtk_application_set_accels_for_action (app, "win.go-back", accels);
-
-        accels[0] = "<Control>k";
-        accels[1] = "<Control>s";
-        accels[2] = "<Control>l";
-        gtk_application_set_accels_for_action (app, "win.focus-search", accels);
 }
 
 static void
-set_app_menu_if_needed (GtkApplication *app)
+create_app_menu_if_needed (GtkApplication *app)
 {
-        GMenu *manual_app_menu;
+        GMenu *app_menu;
+        GMenu *section;
+        AmtkFactory *factory;
+
+        if (!gtk_application_prefers_app_menu (app))
+                return;
 
-        manual_app_menu = gtk_application_get_menu_by_id (app, "manual-app-menu");
+        app_menu = g_menu_new ();
+        factory = amtk_factory_new (NULL);
 
-        /* Have the g_return in all cases, to catch problems in all cases. */
-        g_return_if_fail (manual_app_menu != NULL);
+        section = g_menu_new ();
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "app.new-window"));
+        amtk_gmenu_append_section (app_menu, NULL, section);
 
-        if (gtk_application_prefers_app_menu (app))
-                gtk_application_set_app_menu (app, G_MENU_MODEL (manual_app_menu));
+        section = g_menu_new ();
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "app.preferences"));
+        amtk_gmenu_append_section (app_menu, NULL, section);
+
+        section = g_menu_new ();
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "win.shortcuts-window"));
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "app.help"));
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "app.about"));
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "app.quit"));
+        amtk_gmenu_append_section (app_menu, NULL, section);
+
+        g_object_unref (factory);
+        g_menu_freeze (app_menu);
+
+        gtk_application_set_app_menu (app, G_MENU_MODEL (app_menu));
+        g_object_unref (app_menu);
 }
 
 static void
@@ -384,9 +467,10 @@ dh_app_startup (GApplication *application)
         if (G_APPLICATION_CLASS (dh_app_parent_class)->startup != NULL)
                 G_APPLICATION_CLASS (dh_app_parent_class)->startup (application);
 
+        add_action_infos (app);
         add_action_entries (app);
-        setup_accelerators (GTK_APPLICATION (app));
-        set_app_menu_if_needed (GTK_APPLICATION (app));
+        setup_additional_accelerators (GTK_APPLICATION (app));
+        create_app_menu_if_needed (GTK_APPLICATION (app));
 }
 
 static void
@@ -479,11 +563,24 @@ dh_app_command_line (GApplication            *g_app,
         return 0;
 }
 
+static void
+dh_app_dispose (GObject *object)
+{
+        DhApp *app = DH_APP (object);
+
+        g_clear_object (&app->priv->menu_action_info_store);
+
+        G_OBJECT_CLASS (dh_app_parent_class)->dispose (object);
+}
+
 static void
 dh_app_class_init (DhAppClass *klass)
 {
+        GObjectClass *object_class = G_OBJECT_CLASS (klass);
         GApplicationClass *application_class = G_APPLICATION_CLASS (klass);
 
+        object_class->dispose = dh_app_dispose;
+
         application_class->startup = dh_app_startup;
         application_class->activate = dh_app_activate;
         application_class->handle_local_options = dh_app_handle_local_options;
@@ -493,6 +590,8 @@ dh_app_class_init (DhAppClass *klass)
 static void
 dh_app_init (DhApp *app)
 {
+        app->priv = dh_app_get_instance_private (app);
+
         /* Translators: please don't translate "Devhelp" (it's marked as
          * translatable for transliteration only).
          */
diff --git a/src/dh-app.h b/src/dh-app.h
index 1d60918e..986b55ec 100644
--- a/src/dh-app.h
+++ b/src/dh-app.h
@@ -36,9 +36,11 @@ G_BEGIN_DECLS
 
 typedef struct _DhApp        DhApp;
 typedef struct _DhAppClass   DhAppClass;
+typedef struct _DhAppPrivate DhAppPrivate;
 
 struct _DhApp {
         GtkApplication parent_instance;
+        DhAppPrivate *priv;
 };
 
 struct _DhAppClass {
diff --git a/src/dh-main.c b/src/dh-main.c
index 545cf622..86510f62 100644
--- a/src/dh-main.c
+++ b/src/dh-main.c
@@ -23,6 +23,7 @@
 #include <locale.h>
 #include <glib/gi18n.h>
 #include <devhelp/devhelp.h>
+#include <amtk/amtk.h>
 #include "dh-app.h"
 #include "dh-settings-app.h"
 
@@ -36,11 +37,13 @@ main (int argc, char **argv)
         textdomain (GETTEXT_PACKAGE);
 
         dh_init ();
+        amtk_init ();
 
         application = dh_app_new ();
         status = g_application_run (G_APPLICATION (application), argc, argv);
         g_object_unref (application);
 
+        amtk_finalize ();
         dh_finalize ();
         dh_settings_app_unref_singleton ();
 
diff --git a/src/dh-window.c b/src/dh-window.c
index 460e7815..2b1f596e 100644
--- a/src/dh-window.c
+++ b/src/dh-window.c
@@ -25,17 +25,13 @@
 #include <glib/gi18n.h>
 #include <webkit2/webkit2.h>
 #include <devhelp/devhelp.h>
+#include <amtk/amtk.h>
 #include "dh-settings-app.h"
 #include "dh-util-app.h"
 
 typedef struct {
         GtkHeaderBar *header_bar;
         GtkMenuButton *window_menu_button;
-        GMenuModel *window_menu_plus_app_menu;
-
-        GtkPaned *hpaned;
-        GtkWidget *grid_sidebar;
-        GtkWidget *grid_documents;
 
         DhSidebar *sidebar;
         DhSearchBar *search_bar;
@@ -65,6 +61,8 @@ dh_window_dispose (GObject *object)
 {
         DhWindowPrivate *priv = dh_window_get_instance_private (DH_WINDOW (object));
 
+        priv->header_bar = NULL;
+        priv->window_menu_button = NULL;
         priv->sidebar = NULL;
         priv->search_bar = NULL;
         priv->notebook = NULL;
@@ -81,15 +79,6 @@ dh_window_class_init (DhWindowClass *klass)
         widget_class->delete_event = dh_window_delete_event;
 
         object_class->dispose = dh_window_dispose;
-
-        /* Bind class to template */
-        gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/devhelp/dh-window.ui");
-        gtk_widget_class_bind_template_child_private (widget_class, DhWindow, header_bar);
-        gtk_widget_class_bind_template_child_private (widget_class, DhWindow, window_menu_button);
-        gtk_widget_class_bind_template_child_private (widget_class, DhWindow, window_menu_plus_app_menu);
-        gtk_widget_class_bind_template_child_private (widget_class, DhWindow, hpaned);
-        gtk_widget_class_bind_template_child_private (widget_class, DhWindow, grid_sidebar);
-        gtk_widget_class_bind_template_child_private (widget_class, DhWindow, grid_documents);
 }
 
 /* Can return NULL during initialization and finalization, so it's better to
@@ -251,13 +240,8 @@ close_tab_cb (GSimpleAction *action,
         DhWindowPrivate *priv = dh_window_get_instance_private (window);
         gint page_num;
 
-        /* FIXME: the code here closes the current *tab*, but in help-overlay.ui
-         * it is documented as "Close the current window". Look for example at
-         * what gedit does, or other GNOME apps with a GtkNotebook plus Ctrl+W
-         * shortcut, and do the same.
-         */
-        page_num = gtk_notebook_get_current_page (priv->notebook);
-        gtk_notebook_remove_page (priv->notebook, page_num);
+        page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
+        gtk_notebook_remove_page (GTK_NOTEBOOK (priv->notebook), page_num);
 }
 
 static void
@@ -384,6 +368,54 @@ go_forward_cb (GSimpleAction *action,
                 webkit_web_view_go_forward (WEBKIT_WEB_VIEW (web_view));
 }
 
+static void
+shortcuts_window_cb (GSimpleAction *action,
+                     GVariant      *parameter,
+                     gpointer       user_data)
+{
+        DhWindow *app_window = DH_WINDOW (user_data);
+        GtkShortcutsWindow *shortcuts_window;
+        GtkContainer *section;
+        GtkContainer *group;
+        AmtkFactory *factory;
+
+        shortcuts_window = amtk_shortcuts_window_new (GTK_WINDOW (app_window));
+
+        section = amtk_shortcuts_section_new (NULL);
+        g_object_set (section,
+                      "max-height", 10,
+                      NULL);
+
+        factory = amtk_factory_new (NULL);
+        amtk_factory_set_default_flags (factory, AMTK_FACTORY_IGNORE_GACTION);
+
+        /* General group */
+        group = amtk_shortcuts_group_new (_("General"));
+        gtk_container_add (group, amtk_factory_create_shortcut (factory, "win.focus-search"));
+        gtk_container_add (group, amtk_factory_create_shortcut (factory, "win.find"));
+        gtk_container_add (group, amtk_factory_create_shortcut (factory, "app.new-window"));
+        gtk_container_add (group, amtk_factory_create_shortcut (factory, "win.new-tab"));
+        gtk_container_add (group, amtk_factory_create_shortcut (factory, "win.show-sidebar"));
+        gtk_container_add (group, amtk_factory_create_shortcut (factory, "win.go-back"));
+        gtk_container_add (group, amtk_factory_create_shortcut (factory, "win.go-forward"));
+        gtk_container_add (group, amtk_factory_create_shortcut (factory, "win.print"));
+        gtk_container_add (group, amtk_factory_create_shortcut (factory, "win.close-tab"));
+        gtk_container_add (group, amtk_factory_create_shortcut (factory, "app.quit"));
+        gtk_container_add (section, GTK_WIDGET (group));
+
+        /* Zoom group */
+        group = amtk_shortcuts_group_new (_("Zoom"));
+        gtk_container_add (group, amtk_factory_create_shortcut (factory, "win.zoom-in"));
+        gtk_container_add (group, amtk_factory_create_shortcut (factory, "win.zoom-out"));
+        gtk_container_add (group, amtk_factory_create_shortcut (factory, "win.zoom-default"));
+        gtk_container_add (section, GTK_WIDGET (group));
+
+        g_object_unref (factory);
+
+        gtk_container_add (GTK_CONTAINER (shortcuts_window), GTK_WIDGET (section));
+        gtk_widget_show_all (GTK_WIDGET (shortcuts_window));
+}
+
 static void
 add_actions (DhWindow *window)
 {
@@ -412,15 +444,18 @@ add_actions (DhWindow *window)
                 /* Go */
                 { "go-back", go_back_cb },
                 { "go-forward", go_forward_cb },
+
+                /* Help */
+                { "shortcuts-window", shortcuts_window_cb },
         };
 
-        g_action_map_add_action_entries (G_ACTION_MAP (window),
-                                         win_entries,
-                                         G_N_ELEMENTS (win_entries),
-                                         window);
+        amtk_action_map_add_action_entries_check_dups (G_ACTION_MAP (window),
+                                                       win_entries,
+                                                       G_N_ELEMENTS (win_entries),
+                                                       window);
 
         property_action = g_property_action_new ("show-sidebar",
-                                                 priv->grid_sidebar,
+                                                 priv->sidebar,
                                                  "visible");
         g_action_map_add_action (G_ACTION_MAP (window), G_ACTION (property_action));
         g_object_unref (property_action);
@@ -432,6 +467,141 @@ add_actions (DhWindow *window)
         g_object_unref (property_action);
 }
 
+static GMenuModel *
+create_window_menu_simple (void)
+{
+        GMenu *menu;
+        GMenu *section;
+        AmtkFactory *factory;
+
+        menu = g_menu_new ();
+        factory = amtk_factory_new (NULL);
+
+        section = g_menu_new ();
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "win.show-sidebar"));
+        amtk_gmenu_append_section (menu, NULL, section);
+
+        section = g_menu_new ();
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "win.print"));
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "win.find"));
+        amtk_gmenu_append_section (menu, NULL, section);
+
+        section = g_menu_new ();
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "win.zoom-in"));
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "win.zoom-out"));
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "win.zoom-default"));
+        amtk_gmenu_append_section (menu, NULL, section);
+
+        g_object_unref (factory);
+        g_menu_freeze (menu);
+
+        return G_MENU_MODEL (menu);
+}
+
+static GMenuModel *
+create_window_menu_plus_app_menu (void)
+{
+        GMenu *menu;
+        GMenu *section;
+        AmtkFactory *factory;
+
+        menu = g_menu_new ();
+        factory = amtk_factory_new (NULL);
+
+        section = g_menu_new ();
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "app.new-window"));
+        amtk_gmenu_append_section (menu, NULL, section);
+
+        section = g_menu_new ();
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "win.show-sidebar"));
+        amtk_gmenu_append_section (menu, NULL, section);
+
+        section = g_menu_new ();
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "win.print"));
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "win.find"));
+        amtk_gmenu_append_section (menu, NULL, section);
+
+        section = g_menu_new ();
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "win.zoom-in"));
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "win.zoom-out"));
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "win.zoom-default"));
+        amtk_gmenu_append_section (menu, NULL, section);
+
+        section = g_menu_new ();
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "app.preferences"));
+        amtk_gmenu_append_section (menu, NULL, section);
+
+        section = g_menu_new ();
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "win.shortcuts-window"));
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "app.help"));
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "app.about"));
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "app.quit"));
+        amtk_gmenu_append_section (menu, NULL, section);
+
+        g_object_unref (factory);
+        g_menu_freeze (menu);
+
+        return G_MENU_MODEL (menu);
+}
+
+static void
+init_header_bar (DhWindow *window)
+{
+        DhWindowPrivate *priv = dh_window_get_instance_private (window);
+        GtkWidget *back_forward_hgrid;
+        GtkStyleContext *style_context;
+        GtkWidget *back_button;
+        GtkWidget *forward_button;
+        GtkApplication *app;
+        GMenuModel *window_menu;
+        GtkWidget *new_tab_button;
+
+        g_assert (priv->header_bar == NULL);
+        g_assert (priv->window_menu_button == NULL);
+
+        priv->header_bar = GTK_HEADER_BAR (gtk_header_bar_new ());
+        gtk_header_bar_set_show_close_button (priv->header_bar, TRUE);
+
+        /* Back/forward buttons */
+        back_forward_hgrid = gtk_grid_new ();
+        style_context = gtk_widget_get_style_context (back_forward_hgrid);
+        gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_LINKED);
+
+        back_button = gtk_button_new_from_icon_name ("go-previous-symbolic", GTK_ICON_SIZE_BUTTON);
+        gtk_actionable_set_action_name (GTK_ACTIONABLE (back_button), "win.go-back");
+        gtk_widget_set_tooltip_text (back_button, _("Back"));
+
+        forward_button = gtk_button_new_from_icon_name ("go-next-symbolic", GTK_ICON_SIZE_BUTTON);
+        gtk_actionable_set_action_name (GTK_ACTIONABLE (forward_button), "win.go-forward");
+        gtk_widget_set_tooltip_text (forward_button, _("Forward"));
+
+        gtk_container_add (GTK_CONTAINER (back_forward_hgrid), back_button);
+        gtk_container_add (GTK_CONTAINER (back_forward_hgrid), forward_button);
+        gtk_header_bar_pack_start (priv->header_bar, back_forward_hgrid);
+
+        /* Menu */
+        priv->window_menu_button = GTK_MENU_BUTTON (gtk_menu_button_new ());
+        gtk_menu_button_set_direction (priv->window_menu_button, GTK_ARROW_NONE);
+        gtk_header_bar_pack_end (priv->header_bar, GTK_WIDGET (priv->window_menu_button));
+
+        app = GTK_APPLICATION (g_application_get_default ());
+        if (gtk_application_prefers_app_menu (app))
+                window_menu = create_window_menu_simple ();
+        else
+                window_menu = create_window_menu_plus_app_menu ();
+
+        gtk_menu_button_set_menu_model (priv->window_menu_button, window_menu);
+        g_object_unref (window_menu);
+
+        /* New tab button */
+        new_tab_button = gtk_button_new_from_icon_name ("tab-new-symbolic", GTK_ICON_SIZE_BUTTON);
+        gtk_actionable_set_action_name (GTK_ACTIONABLE (new_tab_button), "win.new-tab");
+        gtk_widget_set_tooltip_text (new_tab_button, _("New Tab"));
+        gtk_header_bar_pack_end (priv->header_bar, new_tab_button);
+
+        gtk_widget_show_all (GTK_WIDGET (priv->header_bar));
+}
+
 static void
 web_view_title_notify_cb (DhWebView  *web_view,
                           GParamSpec *param_spec,
@@ -508,36 +678,34 @@ static void
 dh_window_init (DhWindow *window)
 {
         DhWindowPrivate *priv = dh_window_get_instance_private (window);
-        GtkApplication *app;
+        GtkPaned *hpaned;
         DhSettingsApp *settings;
         GSettings *paned_settings;
+        GtkWidget *contents_vgrid;
 
-        gtk_widget_init_template (GTK_WIDGET (window));
+        /* Header bar */
+        init_header_bar (window);
+        gtk_window_set_titlebar (GTK_WINDOW (window), GTK_WIDGET (priv->header_bar));
 
-        add_actions (window);
-
-        app = GTK_APPLICATION (g_application_get_default ());
-        if (!gtk_application_prefers_app_menu (app)) {
-                gtk_menu_button_set_menu_model (priv->window_menu_button,
-                                                priv->window_menu_plus_app_menu);
-        }
+        /* Horizontal paned */
+        hpaned = GTK_PANED (gtk_paned_new (GTK_ORIENTATION_HORIZONTAL));
 
         settings = dh_settings_app_get_singleton ();
         paned_settings = dh_settings_app_peek_paned_settings (settings);
         g_settings_bind (paned_settings, "position",
-                         priv->hpaned, "position",
+                         hpaned, "position",
                          G_SETTINGS_BIND_DEFAULT |
                          G_SETTINGS_BIND_NO_SENSITIVITY);
 
-        /* Sidebar */
+        /* Left side of hpaned */
         priv->sidebar = dh_sidebar_new2 (NULL);
-        gtk_widget_show (GTK_WIDGET (priv->sidebar));
-        gtk_container_add (GTK_CONTAINER (priv->grid_sidebar),
-                           GTK_WIDGET (priv->sidebar));
+
+        /* Right side of hpaned */
+        contents_vgrid = gtk_grid_new ();
+        gtk_orientable_set_orientation (GTK_ORIENTABLE (contents_vgrid), GTK_ORIENTATION_VERTICAL);
 
         // DhNotebook
         priv->notebook = dh_notebook_new (NULL);
-        gtk_widget_show (GTK_WIDGET (priv->notebook));
 
         dh_application_window_bind_sidebar_and_notebook (priv->sidebar, priv->notebook);
 
@@ -558,12 +726,16 @@ dh_window_init (DhWindow *window)
 
         // DhSearchBar
         priv->search_bar = dh_search_bar_new (priv->notebook);
-        gtk_widget_show (GTK_WIDGET (priv->search_bar));
 
-        gtk_container_add (GTK_CONTAINER (priv->grid_documents),
+        /* Packing */
+        gtk_container_add (GTK_CONTAINER (contents_vgrid),
                            GTK_WIDGET (priv->search_bar));
-        gtk_container_add (GTK_CONTAINER (priv->grid_documents),
+        gtk_container_add (GTK_CONTAINER (contents_vgrid),
                            GTK_WIDGET (priv->notebook));
+        gtk_paned_pack1 (hpaned, GTK_WIDGET (priv->sidebar), FALSE, FALSE);
+        gtk_paned_add2 (hpaned, contents_vgrid);
+        gtk_widget_show_all (GTK_WIDGET (hpaned));
+        gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (hpaned));
 
         add_actions (window);
 
diff --git a/src/dh.gresource.xml b/src/dh.gresource.xml
index 6f58d062..c063d879 100644
--- a/src/dh.gresource.xml
+++ b/src/dh.gresource.xml
@@ -3,10 +3,5 @@
   <gresource prefix="/org/gnome/devhelp">
     <file preprocess="xml-stripblanks">dh-assistant.ui</file>
     <file preprocess="xml-stripblanks">dh-preferences.ui</file>
-    <file preprocess="xml-stripblanks">dh-window.ui</file>
-  </gresource>
-  <gresource prefix="/org/gnome/devhelp/gtk">
-    <file preprocess="xml-stripblanks">help-overlay.ui</file>
-    <file preprocess="xml-stripblanks">menus.ui</file>
   </gresource>
 </gresources>


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