[epiphany/wip/gtkaction-to-gaction] Restore the bookmarks submenu in the page menu



commit bed80ddab4d893d53e76fb2a4631bd35fa38fff5
Author: Iulian Radu <iulian radu67 gmail com>
Date:   Fri Jul 1 17:14:26 2016 +0300

    Restore the bookmarks submenu in the page menu

 src/Makefile.am                     |    1 -
 src/bookmarks/ephy-bookmarks-menu.c |   56 ++++++++-----------
 src/bookmarks/ephy-bookmarks-menu.h |    2 +-
 src/bookmarks/ephy-bookmarks-ui.c   |  101 ++++++++++++++++++++++-------------
 src/ephy-lockdown.c                 |    6 +-
 src/ephy-window.c                   |   46 ++++------------
 src/epiphany.gresource.xml          |    1 -
 src/resources/epiphany-ui.xml       |    8 ---
 src/resources/gtk/menus.ui          |   22 ++++----
 src/window-commands.c               |   45 ++++++++++-----
 src/window-commands.h               |    8 ++-
 src/xchat-bookmarks                 |   21 +++++++
 12 files changed, 171 insertions(+), 146 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index c82c63b..19d37ce 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -108,7 +108,6 @@ RESOURCE_FILES = \
        resources/encoding-row.ui                 \
        resources/epiphany-application-menu.ui    \
        resources/epiphany-bookmark-editor-ui.xml \
-       resources/epiphany-ui.xml                 \
        resources/epiphany.css                    \
        resources/error.html                      \
        resources/history-dialog.ui               \
diff --git a/src/bookmarks/ephy-bookmarks-menu.c b/src/bookmarks/ephy-bookmarks-menu.c
index e6cd7d5..9b92ba1 100644
--- a/src/bookmarks/ephy-bookmarks-menu.c
+++ b/src/bookmarks/ephy-bookmarks-menu.c
@@ -47,30 +47,34 @@ enum {
 /* Construct a block of bookmark actions. Note that no bookmark action appears
  * more than once in a menu, so no need to supply names. */
 static void
-append_bookmarks (GString         *string,
+append_bookmarks (GMenu         *menu,
                   const GPtrArray *bookmarks)
 {
   EphyNode *child;
-  char name[EPHY_BOOKMARK_ACTION_NAME_BUFFER_SIZE];
+  const gchar *action_name;
 
   long i;
 
   for (i = 0; i < bookmarks->len; i++) {
     child = g_ptr_array_index (bookmarks, i);
 
-    EPHY_BOOKMARK_ACTION_NAME_PRINTF (name, child);
+    action_name = g_action_print_detailed_name ("win.open-bookmark",
+                                                g_variant_new_string (ephy_node_get_property_string (child, 
EPHY_NODE_BMK_PROP_LOCATION)));
 
-    g_string_append_printf (string, "<menuitem action=\"%s\"/>", name);
+    g_menu_append (menu,
+                   ephy_node_get_property_string (child, EPHY_NODE_BMK_PROP_TITLE),
+                   action_name);
   }
 }
 
 /* Build a menu of the given bookmarks categorised by the given topics.
  * Shows categorisation using subdivisions, submenus, or a mix of both. */
 static void
-append_menu (GString *string, const GPtrArray *topics, const GPtrArray *bookmarks, guint flags)
+append_menu (GMenu *menu, const GPtrArray *topics, const GPtrArray *bookmarks, guint flags)
 {
   GPtrArray *uncovered;
   guint i, j;
+  GMenu *submenu, *section;
 
   gboolean use_subdivis = flags & BUILD_SUBDIVIS;
   gboolean use_submenus = flags & BUILD_SUBMENUS;
@@ -81,7 +85,7 @@ append_menu (GString *string, const GPtrArray *topics, const GPtrArray *bookmark
     EphyNode *topic;
     gint size, total;
     gboolean separate = FALSE;
-    char name[EPHY_TOPIC_ACTION_NAME_BUFFER_SIZE];
+    const gchar *name;
 
     /* Get the subtopics, uncovered bookmarks, and subtopic sizes. */
     sizes = g_array_sized_new (FALSE, FALSE, sizeof (int), topics->len);
@@ -124,12 +128,12 @@ append_menu (GString *string, const GPtrArray *topics, const GPtrArray *bookmark
       topic = g_ptr_array_index (submenus, i);
       ephy_nodes_get_covered (topic, bookmarks, subset);
 
-      EPHY_TOPIC_ACTION_NAME_PRINTF (name, topic);
+      name = ephy_node_get_property_string (topic, EPHY_NODE_KEYWORD_PROP_NAME);
+
+      submenu = g_menu_new ();
+      g_menu_append_submenu (menu, name, G_MENU_MODEL (submenu));
+      append_menu (G_MENU (submenu), topics, subset, flags);
 
-      g_string_append_printf (string, "<menu action=\"%s\">",
-                              name);
-      append_menu (string, topics, subset, flags);
-      g_string_append (string, "</menu>");
       separate = TRUE;
     }
 
@@ -144,8 +148,12 @@ append_menu (GString *string, const GPtrArray *topics, const GPtrArray *bookmark
       ephy_nodes_get_covered (topic, unused, subset);
       g_ptr_array_sort (subset, ephy_bookmarks_compare_bookmark_pointers);
 
-      if (separate) g_string_append (string, "<separator/>");
-      append_bookmarks (string, subset);
+      if (separate) {
+        section = g_menu_new ();
+        g_menu_append_section (menu, NULL, G_MENU_MODEL (section));
+      }
+
+      append_bookmarks (G_MENU (section), subset);
       separate = TRUE;
 
       /* Record that each bookmark has been added. */
@@ -160,8 +168,6 @@ append_menu (GString *string, const GPtrArray *topics, const GPtrArray *bookmark
     g_ptr_array_free (submenus, TRUE);
     g_ptr_array_free (subset, TRUE);
     g_ptr_array_free (unused, TRUE);
-
-    if (separate && uncovered->len) g_string_append (string, "<separator/>");
   } else {
     uncovered = g_ptr_array_sized_new (bookmarks->len);
     for (i = 0; i < bookmarks->len; i++)
@@ -171,12 +177,12 @@ append_menu (GString *string, const GPtrArray *topics, const GPtrArray *bookmark
 
   /* Create the final subdivision (uncovered bookmarks). */
   g_ptr_array_sort (uncovered, ephy_bookmarks_compare_bookmark_pointers);
-  append_bookmarks (string, uncovered);
+  append_bookmarks (menu, uncovered);
   g_ptr_array_free (uncovered, TRUE);
 }
 
 void
-ephy_bookmarks_menu_build (GString *string, EphyNode *parent)
+ephy_bookmarks_menu_build (GMenu *menu, EphyNode *parent)
 {
   GPtrArray *children, *topics;
   EphyBookmarks *eb;
@@ -223,21 +229,7 @@ ephy_bookmarks_menu_build (GString *string, EphyNode *parent)
       g_ptr_array_add (topics, ephy_bookmarks_get_local (eb));
     }
 
-    append_menu (string, topics, children, flags);
-    g_ptr_array_free (topics, TRUE);
-  }
-  /* Otherwise, build the menu with "Open in tabs". */
-  else {
-    char name[EPHY_OPEN_TABS_ACTION_NAME_BUFFER_SIZE];
-
-    append_menu (string, topics, children, flags);
+    append_menu (menu, topics, children, flags);
     g_ptr_array_free (topics, TRUE);
-
-    if (children->len > 1) {
-      EPHY_OPEN_TABS_ACTION_NAME_PRINTF (name, node);
-
-      g_string_append_printf
-        (string, "<separator/><menuitem action=\"%s\" name=\"OpenTabs\"/>", name);
-    }
   }
 }
diff --git a/src/bookmarks/ephy-bookmarks-menu.h b/src/bookmarks/ephy-bookmarks-menu.h
index 9bf6fd2..eaa3e61 100644
--- a/src/bookmarks/ephy-bookmarks-menu.h
+++ b/src/bookmarks/ephy-bookmarks-menu.h
@@ -25,6 +25,6 @@
 
 #include <gtk/gtk.h>
 
-void ephy_bookmarks_menu_build (GString *string, EphyNode *parent);
+void ephy_bookmarks_menu_build (GMenu *menu, EphyNode *parent);
 
 #endif
diff --git a/src/bookmarks/ephy-bookmarks-ui.c b/src/bookmarks/ephy-bookmarks-ui.c
index 465ca40..37efa19 100644
--- a/src/bookmarks/ephy-bookmarks-ui.c
+++ b/src/bookmarks/ephy-bookmarks-ui.c
@@ -37,6 +37,7 @@
 #include "ephy-settings.h"
 #include "ephy-shell.h"
 #include "ephy-string.h"
+#include "ephy-toolbar.h"
 #include "ephy-topic-action-group.h"
 #include "ephy-topic-action.h"
 
@@ -47,7 +48,7 @@
 #define BM_WINDOW_DATA_KEY "bookmarks-window-data"
 
 typedef struct {
-  guint bookmarks_menu;
+  GMenu *bookmarks_menu;
   guint toolbar_menu;
 } BookmarksWindowData;
 
@@ -56,7 +57,6 @@ enum {
   RESPONSE_NEW_BOOKMARK = 2
 };
 
-static GString *bookmarks_menu_string = 0;
 static GHashTable *properties_dialogs = 0;
 
 static GtkAction *
@@ -74,43 +74,74 @@ find_action (GtkUIManager *manager, const char *name)
   return NULL;
 }
 
-static void
-activate_bookmarks_menu (GtkAction *action, EphyWindow *window)
+static GMenu *
+find_bookmarks_menu (EphyWindow *window)
 {
-  BookmarksWindowData *data = g_object_get_data (G_OBJECT (window), BM_WINDOW_DATA_KEY);
-  if (data && !data->bookmarks_menu) {
-    GtkUIManager *manager = ephy_window_get_ui_manager (window);
-    gtk_ui_manager_ensure_update (manager);
-
-    if (!bookmarks_menu_string->len) {
-      g_string_append (bookmarks_menu_string,
-                       "<ui><popup name=\"PagePopup\" action=\"PagePopupAction\"><menu 
name=\"BookmarksMenu\" action=\"Bookmarks\">");
-      ephy_bookmarks_menu_build (bookmarks_menu_string, 0);
-      g_string_append (bookmarks_menu_string, "</menu></popup></ui>");
+  GMenu *page_menu;
+  gint n_items, i;
+
+  /* Page menu */
+  page_menu = ephy_toolbar_get_page_menu (EPHY_TOOLBAR (ephy_window_get_toolbar (window)));
+
+  /* Number of sections in the model */
+  n_items = g_menu_model_get_n_items (G_MENU_MODEL (page_menu));
+
+  for (i = 0; i < n_items; i++) {
+    GVariant *section_label;
+
+    /* Looking for the bookmarks section */
+    section_label = g_menu_model_get_item_attribute_value (G_MENU_MODEL (page_menu), i, "id", 
G_VARIANT_TYPE_STRING);
+    if (section_label != NULL && g_strcmp0 (g_variant_get_string (section_label, NULL), "bookmarks-section") 
== 0) {
+      GMenuModel *bookmarks_section_model, *bookmarks_menu_model;
+
+      /* Bookmarks section should contain the bookmarks menu */
+      bookmarks_section_model = g_menu_model_get_item_link (G_MENU_MODEL (page_menu), i, 
G_MENU_LINK_SECTION);
+      bookmarks_menu_model = g_menu_model_get_item_link (bookmarks_section_model, 0, G_MENU_LINK_SUBMENU);
+
+      return G_MENU (bookmarks_menu_model);
     }
+  }
+
+  return NULL;
+}
+
+static bool
+activate_bookmarks_menu (GSimpleAction *action,
+                         GdkEvent      *event,
+                         gpointer       user_data)
+{
+  GMenu *menu;
+  BookmarksWindowData *data = g_object_get_data (G_OBJECT (user_data), BM_WINDOW_DATA_KEY);
 
-    data->bookmarks_menu = gtk_ui_manager_add_ui_from_string
-                             (manager, bookmarks_menu_string->str, bookmarks_menu_string->len, 0);
+  if (event->type != GDK_BUTTON_PRESS)
+    return G_SOURCE_REMOVE;
 
-    gtk_ui_manager_ensure_update (manager);
+  if (data && !data->bookmarks_menu) {
+    menu = g_menu_new ();
+    ephy_bookmarks_menu_build (menu, 0);
+
+    data->bookmarks_menu = G_MENU(find_bookmarks_menu (EPHY_WINDOW (user_data)));
+    if (data->bookmarks_menu == NULL)
+      return G_SOURCE_REMOVE;
+
+    g_menu_append_section (data->bookmarks_menu, NULL, G_MENU_MODEL (menu));
   }
+
+  return G_SOURCE_REMOVE;
 }
 
 static void
 erase_bookmarks_menu (EphyWindow *window)
 {
   BookmarksWindowData *data;
-  GtkUIManager *manager;
 
-  manager = ephy_window_get_ui_manager (window);
   data = g_object_get_data (G_OBJECT (window), BM_WINDOW_DATA_KEY);
 
-  if (data != NULL && data->bookmarks_menu != 0) {
-    gtk_ui_manager_remove_ui (manager, data->bookmarks_menu);
-    data->bookmarks_menu = 0;
+  if (data != NULL && data->bookmarks_menu != NULL) {
+    g_menu_remove_all (data->bookmarks_menu);
+    g_object_unref (data->bookmarks_menu);
+    data->bookmarks_menu = NULL;
   }
-
-  g_string_truncate (bookmarks_menu_string, 0);
 }
 
 static void
@@ -158,7 +189,7 @@ ephy_bookmarks_ui_attach_window (EphyWindow *window)
   BookmarksWindowData *data;
   GtkUIManager *manager;
   GtkActionGroup *actions;
-  GtkAction *action;
+  GtkWidget *page_menu_button;
 
   eb = ephy_shell_get_bookmarks (ephy_shell_get_default ());
   bookmarks = ephy_bookmarks_get_bookmarks (eb);
@@ -216,14 +247,8 @@ ephy_bookmarks_ui_attach_window (EphyWindow *window)
                            G_CALLBACK (tree_changed_cb),
                            G_OBJECT (window), 0);
 
-  /* Setup empty menu strings and add signal handlers to build the menus on demand */
-  if (!bookmarks_menu_string)
-    bookmarks_menu_string = g_string_new ("");
-
-  action = find_action (manager, "Bookmarks");
-  g_signal_connect_object (action, "activate",
-                           G_CALLBACK (activate_bookmarks_menu),
-                           G_OBJECT (window), 0);
+  page_menu_button = ephy_toolbar_get_page_menu_button (EPHY_TOOLBAR (ephy_window_get_toolbar (window)));
+  g_signal_connect (GTK_WIDGET (page_menu_button), "button-press-event", G_CALLBACK 
(activate_bookmarks_menu), window);
 }
 
 void
@@ -239,8 +264,11 @@ ephy_bookmarks_ui_detach_window (EphyWindow *window)
 
   g_return_if_fail (data != 0);
 
-  if (data->bookmarks_menu)
-    gtk_ui_manager_remove_ui (manager, data->bookmarks_menu);
+  if (data->bookmarks_menu) {
+    g_menu_remove_all (data->bookmarks_menu);
+    g_object_unref (data->bookmarks_menu);
+    data->bookmarks_menu = NULL;
+  }
 
   g_object_set_data (G_OBJECT (window), BM_WINDOW_DATA_KEY, 0);
 
@@ -348,6 +376,3 @@ ephy_bookmarks_ui_show_bookmark (GtkWindow *parent, EphyNode *bookmark)
   gtk_window_present_with_time (GTK_WINDOW (dialog),
                                 gtk_get_current_event_time ());
 }
-
-
-
diff --git a/src/ephy-lockdown.c b/src/ephy-lockdown.c
index 85abc1f..50cefbf 100644
--- a/src/ephy-lockdown.c
+++ b/src/ephy-lockdown.c
@@ -99,8 +99,6 @@ typedef struct {
 } BindAction;
 
 static const BindAction window_actions[] = {
-  { EPHY_PREFS_LOCKDOWN_BOOKMARK_EDITING, "FileBookmarkPage", "sensitive" },
-
   { EPHY_PREFS_LOCKDOWN_ARBITRARY_URL, "GoLocation", "sensitive" },
 
   { EPHY_PREFS_LOCKDOWN_FULLSCREEN, "ViewFullscreen", "sensitive" },
@@ -112,6 +110,8 @@ static const BindAction app_actions[] = {
 };
 
 static const BindAction new_window_actions[] = {
+  { EPHY_PREFS_LOCKDOWN_BOOKMARK_EDITING, "bookmark-page", "enabled" },
+
   { EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "save-as", "enabled" },
 
   { EPHY_PREFS_LOCKDOWN_PRINTING, "print", "enabled" }
@@ -126,7 +126,7 @@ static const BindAction popup_actions[] = {
 };
 
 static const BindAction tab_actions[] = {
-  EPHY_PREFS_LOCKDOWN_FULLSCREEN, "detach", "enabled"
+  { EPHY_PREFS_LOCKDOWN_FULLSCREEN, "detach", "enabled" }
 };
 
 static const BindAction toolbar_actions[] = {
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 8df411e..897e3b4 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -92,11 +92,6 @@ static const GtkActionEntry ephy_menu_entries [] = {
   { "EditPreferences", NULL, N_("Pr_eferences"), "<control>e", NULL,
     G_CALLBACK (window_cmd_edit_preferences) },
 
-  /* Bookmarks actions. */
-
-  { "FileBookmarkPage", NULL, N_("_Add Bookmark…"), "<control>D", NULL,
-    G_CALLBACK (window_cmd_file_bookmark_page) },
-
   /* Go actions. */
 
   { "GoLocation", NULL, N_("_Location…"), "<control>L", NULL,
@@ -192,7 +187,6 @@ static const struct {
 #ifdef HAVE_X11_XF86KEYSYM_H
   { XF86XK_Go, 0, "GoLocation", FALSE },
   { XF86XK_OpenURL, 0, "GoLocation", FALSE },
-  { XF86XK_AddFavorite, 0, "FileBookmarkPage", FALSE },
   { XF86XK_Send, 0, "FileSendTo", FALSE },
   /* FIXME: what about ScrollUp, ScrollDown, Menu*, Option, LogOff, Save,.. any others? */
 #endif /* HAVE_X11_XF86KEYSYM_H */
@@ -219,6 +213,7 @@ const struct {
   { "win.find", { "<Primary>F", "Search", NULL } },
   { "win.find-prev", { "<shift><Primary>G", NULL } },
   { "win.find-next", { "<Primary>G", NULL } },
+  { "win.bookmark-page", { "<Primary>D", "AddFavorite", NULL } },
   { "win.encoding", { NULL } },
   { "win.page-source", { "<Primary>U", NULL } },
   { "win.toggle-inspector", { "<shift><Primary>I", "F12", NULL } },
@@ -938,6 +933,8 @@ edit_menu_hide_cb (GtkWidget  *menu,
 static void
 init_menu_updaters (EphyWindow *window)
 {
+  return;
+
   GtkWidget *edit_menu;
 
   edit_menu = gtk_ui_manager_get_widget
@@ -980,8 +977,8 @@ static const GActionEntry window_entries [] =
   { "find", window_cmd_edit_find },
   { "find-prev", window_cmd_edit_find_prev },
   { "find-next", window_cmd_edit_find_next },
-  // { "bookmarks", },
-  // { "bookmark-page", },
+  { "open-bookmark", window_cmd_open_bookmark, "s" },
+  { "bookmark-page", window_cmd_file_bookmark_page },
   { "encoding", window_cmd_view_encoding },
   { "page-source", window_cmd_view_page_source },
   { "toggle-inspector", window_cmd_view_toggle_inspector },
@@ -1037,9 +1034,6 @@ setup_ui_manager (EphyWindow *window)
   window->action_group = action_group;
   g_object_unref (action_group);
 
-  action = gtk_action_group_get_action (action_group, "FileBookmarkPage");
-  g_object_set (action, "short_label", _("Bookmark"), NULL);
-
   action_group = gtk_action_group_new ("PopupsActions");
   gtk_action_group_set_translation_domain (action_group, NULL);
   gtk_action_group_add_actions (action_group, ephy_popups_entries,
@@ -1093,13 +1087,13 @@ _ephy_window_set_default_actions_sensitive (EphyWindow *window,
   GtkAction *action;
   GAction *new_action;
   int i;
-  const char *action_group_actions[] = { "FileSendTo", "FileBookmarkPage",
+  const char *action_group_actions[] = { "FileSendTo",
                                          NULL };
 
   const char *new_action_group_actions[] = { "save-as", "save-as-application",
                                          "zoom-in", "zoom-out", "print",
                                          "find", "find-prev", "find-next",
-                                         "encoding", "page-source",
+                                         "bookmark-page", "encoding", "page-source",
                                          NULL };
 
   action_group = window->action_group;
@@ -3032,12 +3026,11 @@ setup_location_controller (EphyWindow  *window,
   return location_controller;
 }
 
-static const char *disabled_actions_for_app_mode[] = { "FileBookmarkPage" };
-
-static const char *new_disabled_actions_for_app_mode[] = { "open",
+static const char *disabled_actions_for_app_mode[] = { "open",
                                                        "save-as",
                                                        "save-as-application",
                                                        "encoding",
+                                                       "bookmark-page",
                                                        "page-source",
                                                        "toggle-inspector" };
 
@@ -3075,7 +3068,7 @@ ephy_window_constructor (GType                  type,
   GAction *new_action;
   GActionGroup *action_group;
   GSimpleActionGroup *simple_action_group;
-  GError *error = NULL;
+
   guint settings_connection;
   GtkCssProvider *css_provider;
   guint i;
@@ -3156,16 +3149,6 @@ ephy_window_constructor (GType                  type,
 
   window->notebook = setup_notebook (window);
 
-  /* Now load the UI definition (needed by EphyToolbar). */
-  gtk_ui_manager_add_ui_from_resource (window->manager,
-                                       "/org/gnome/epiphany/epiphany-ui.xml",
-                                       &error);
-  if (error != NULL) {
-    g_warning ("Could not merge epiphany-ui.xml: %s", error->message);
-    g_error_free (error);
-    error = NULL;
-  }
-
   /* Setup the toolbar. */
   window->toolbar = setup_toolbar (window);
   window->location_controller = setup_location_controller (window, EPHY_TOOLBAR (window->toolbar));
@@ -3232,15 +3215,8 @@ ephy_window_constructor (GType                  type,
     gtk_action_set_visible (action, FALSE);
 
     for (i = 0; i < G_N_ELEMENTS (disabled_actions_for_app_mode); i++) {
-      action = gtk_action_group_get_action (window->action_group,
-                                            disabled_actions_for_app_mode[i]);
-      ephy_action_change_sensitivity_flags (action, SENS_FLAG_CHROME, TRUE);
-      gtk_action_set_visible (action, FALSE);
-    }
-
-    for (i = 0; i < G_N_ELEMENTS (new_disabled_actions_for_app_mode); i++) {
       new_action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
-                                       new_disabled_actions_for_app_mode[i]);
+                                           disabled_actions_for_app_mode[i]);
       new_ephy_action_change_sensitivity_flags (G_SIMPLE_ACTION (new_action),
                                             SENS_FLAG_CHROME, TRUE);
     }
diff --git a/src/epiphany.gresource.xml b/src/epiphany.gresource.xml
index 9d0d9c2..ba5cb7e 100644
--- a/src/epiphany.gresource.xml
+++ b/src/epiphany.gresource.xml
@@ -13,7 +13,6 @@
     <file preprocess="xml-stripblanks" compressed="true">passwords-dialog.ui</file>
     <file preprocess="xml-stripblanks" compressed="true">gtk/menus.ui</file>
     <file preprocess="xml-stripblanks">epiphany-application-menu.ui</file>
-    <file preprocess="xml-stripblanks">epiphany-ui.xml</file>
     <file preprocess="xml-stripblanks">epiphany-bookmark-editor-ui.xml</file>
     <file>epiphany.css</file>
     <file alias="page-templates/error.html" compressed="true">error.html</file>
diff --git a/src/resources/epiphany-ui.xml b/src/resources/epiphany-ui.xml
index 2c99692..e69de29 100644
--- a/src/resources/epiphany-ui.xml
+++ b/src/resources/epiphany-ui.xml
@@ -1,8 +0,0 @@
-<ui>
-       <popup name="PagePopup" action="PagePopupAction" accelerators="true">
-               <menu name="BookmarksMenu" action="Bookmarks">
-                       <menuitem name="BookmarksAddBookmarkMenu" action="FileBookmarkPage"/>
-                       <separator name="BookmarksSep1"/>
-               </menu>
-       </popup>
-</ui>
diff --git a/src/resources/gtk/menus.ui b/src/resources/gtk/menus.ui
index b13ff7c..e66f2cc 100644
--- a/src/resources/gtk/menus.ui
+++ b/src/resources/gtk/menus.ui
@@ -66,18 +66,20 @@
         <attribute name="action">win.find</attribute>
       </item>
     </section>
-    <!-- <section>
-      <item>
-        <attribute name="label" translatable="yes">Edit _Bookmarks</attribute>
-        <attribute name="action">win.bookmarks</attribute>
-      </item>
+    <section id="bookmarks-section">
+      <attribute name="id">bookmarks-section</attribute>
       <submenu id="bookmarks-menu">
-        <item>
-          <attribute name="label" translatable="yes">_Add Bookmark…</attribute>
-          <attribute name="action">win.bookmark-page</attribute>
-        </item>
+        <attribute name="label" translatable="yes">_Bookmarks</attribute>
+        <section>
+          <item>
+            <attribute name="label" translatable="yes">_Add Bookmark…</attribute>
+            <attribute name="action">win.bookmark-page</attribute>
+          </item>
+        </section>
+        <section id="bookmarks-section">
+        </section>
       </submenu>
-    </section> -->
+    </section>
     <section>
       <item>
         <attribute name="label" translatable="yes">Text _Encoding</attribute>
diff --git a/src/window-commands.c b/src/window-commands.c
index 7971e64..fcce56e 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -279,21 +279,6 @@ window_cmd_go_location (GtkAction  *action,
 }
 
 void
-window_cmd_file_bookmark_page (GtkAction  *action,
-                               EphyWindow *window)
-{
-  EphyEmbed *embed;
-
-  embed = ephy_embed_container_get_active_child
-            (EPHY_EMBED_CONTAINER (window));
-  g_return_if_fail (embed != NULL);
-
-  ephy_bookmarks_ui_add_bookmark (GTK_WINDOW (window),
-                                  ephy_web_view_get_address (ephy_embed_get_web_view (embed)),
-                                  ephy_embed_get_title (embed));
-}
-
-void
 window_cmd_file_quit (GtkAction  *action,
                       EphyWindow *window)
 {
@@ -1210,6 +1195,36 @@ window_cmd_edit_find_next (GSimpleAction *action,
 }
 
 void
+window_cmd_open_bookmark (GSimpleAction *action,
+                          GVariant      *value,
+                          gpointer       user_data)
+{
+  const gchar *address;
+  EphyLinkFlags flags;
+
+  address = g_variant_get_string (value, NULL);
+  flags = ephy_link_flags_from_current_event () | EPHY_LINK_BOOKMARK;
+
+  ephy_link_open (EPHY_LINK (user_data), address, NULL, flags);
+}
+
+void
+window_cmd_file_bookmark_page (GSimpleAction *action,
+                               GVariant      *value,
+                               gpointer       user_data)
+{
+  EphyEmbed *embed;
+
+  embed = ephy_embed_container_get_active_child
+            (EPHY_EMBED_CONTAINER (user_data));
+  g_return_if_fail (embed != NULL);
+
+  ephy_bookmarks_ui_add_bookmark (GTK_WINDOW (user_data),
+                                  ephy_web_view_get_address (ephy_embed_get_web_view (embed)),
+                                  ephy_embed_get_title (embed));
+}
+
+void
 window_cmd_view_zoom_in (GSimpleAction *action,
                          GVariant      *value,
                          gpointer       user_data)
diff --git a/src/window-commands.h b/src/window-commands.h
index 9f4a2b3..d2e5da7 100644
--- a/src/window-commands.h
+++ b/src/window-commands.h
@@ -41,8 +41,6 @@ void window_cmd_combined_stop_reload      (GSimpleAction *action,
                                            gpointer       user_data);
 void window_cmd_go_location               (GtkAction  *action,
                                            EphyWindow *window);
-void window_cmd_file_bookmark_page        (GtkAction  *action,
-                                           EphyWindow *window);
 void window_cmd_undo_close_tab            (GtkAction *action,
                                            EphyWindow *window);
 void window_cmd_file_send_to              (GtkAction  *action,
@@ -91,6 +89,12 @@ void window_cmd_edit_find_prev            (GSimpleAction *action,
 void window_cmd_edit_find_next            (GSimpleAction *action,
                                            GVariant      *value,
                                            gpointer       user_data);
+void window_cmd_open_bookmark             (GSimpleAction *action,
+                                           GVariant      *value,
+                                           gpointer       user_data);
+void window_cmd_file_bookmark_page        (GSimpleAction *action,
+                                           GVariant      *value,
+                                           gpointer       user_data);
 void window_cmd_view_zoom_in              (GSimpleAction *action,
                                            GVariant      *value,
                                            gpointer       user_data);
diff --git a/src/xchat-bookmarks b/src/xchat-bookmarks
new file mode 100644
index 0000000..ae07adc
--- /dev/null
+++ b/src/xchat-bookmarks
@@ -0,0 +1,21 @@
+<mcatanzaro> OK, so what exactly are you uncertain about... I guess it's not as easy to do with GAction, 
since the bookmarks list has to be procedurally-generated?
+<iulianradu> Exactly
+<iulianradu> By loading the epiphany-ui.xml file and appending things to it
+<iulianradu> I need to get rid of that file to get rid of GtkUIManager
+<mcatanzaro> Hahahaha
+<mcatanzaro> Oh wow, that is hacky indeed
+<mcatanzaro> OK, let's think about this....
+<mcatanzaro> Each GAction has a GVariant parameter that we normally ignore. 
+<mcatanzaro> We could use that for bookmarks to contain the URL of the page to load. Hm, but that doesn't 
answer the question of how to construct the menu.
+<mcatanzaro> OK, I think I've got it; this might require a bit of trial and error, though
+<mcatanzaro> You'll have to create the GMenu from C code, not from a .ui file (but that's to be expected for 
a complex menu like this)
+<mcatanzaro> When you use g_menu_append https://developer.gnome.org/gio/stable/GMenu.html#GMenuItem, you see 
the third parameter there is "detailed_action"? It is like signal details: you can use the "detail" to pass 
an argument to the action name.
+<mcatanzaro> E.g. "open_bookmark::"https://gnome.org""; could be the action name (I guess that's the right 
syntax)
+<mcatanzaro> That way you only need to make one GAction, but you'll need to add it to the GMenu n times... 
(and update the menu each time a new bookmark is added or removed).
+<iulianradu> Hmm, ok
+<iulianradu> So I should do this on the old code?
+<mcatanzaro> ...on the old code?
+<iulianradu> You said I should get rid of the old bookmarks code and start anew
+<iulianradu> After I get rid of GtkAction/GtkUIManager
+<iulianradu> But I can't get rid of those unless I do the changes that you mentioned above
+<mcatanzaro> Yeah, do this on the old code. Let's finish the GtkAction/GtkUIManager purge first before 
deleting the entire bookmarks subsystem. :)
\ No newline at end of file


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