[epiphany/wip/bookmarks: 48/76] Rework 'Add bookmark' popover



commit 86e6aa1f232fcbeeaacce4afd2bf7f27e42993bc
Author: Iulian Radu <iulian radu67 gmail com>
Date:   Wed Sep 21 11:02:32 2016 +0300

    Rework 'Add bookmark' popover

 lib/widgets/ephy-location-entry.c   |   43 ++++++++
 lib/widgets/ephy-location-entry.h   |   53 +++++----
 src/Makefile.am                     |    2 +
 src/ephy-add-bookmark-popover.c     |  205 +++++++++++++++++++++++++++++++++++
 src/ephy-add-bookmark-popover.h     |   38 +++++++
 src/ephy-bookmark-properties-grid.c |    3 +-
 src/ephy-header-bar.c               |   99 +++--------------
 src/ephy-header-bar.h               |    1 +
 src/ephy-window.c                   |   26 -----
 src/window-commands.c               |   19 ++--
 10 files changed, 347 insertions(+), 142 deletions(-)
---
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index 2d9520b..ba1cc6e 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -61,6 +61,8 @@ struct _EphyLocationEntry {
 
   GBinding *paste_binding;
 
+  GtkPopover *add_bookmark_popover;
+
   char *before_completion;
   char *saved_text;
 
@@ -278,6 +280,28 @@ ephy_location_entry_finalize (GObject *object)
 }
 
 static void
+ephy_location_entry_size_allocate (GtkWidget     *widget,
+                                   GtkAllocation *allocation)
+{
+  EphyLocationEntry *entry = EPHY_LOCATION_ENTRY (widget);
+
+  if (gtk_widget_is_visible (widget)) {
+    GdkRectangle pointing_to;
+
+    gtk_entry_get_icon_area (GTK_ENTRY (entry),
+                             GTK_ENTRY_ICON_SECONDARY,
+                             &pointing_to);
+    /* FIXME: GTK+ sets "margin-left: 6px" for the icon. Add 3px to the
+     * rectangle so the popover is centered on the star.
+     */
+    pointing_to.x = pointing_to.x + 3;
+    gtk_popover_set_pointing_to (entry->add_bookmark_popover, &pointing_to);
+  }
+
+  GTK_WIDGET_CLASS (ephy_location_entry_parent_class)->size_allocate (widget, allocation);
+}
+
+static void
 ephy_location_entry_get_preferred_width (GtkWidget *widget,
                                          gint      *minimum_width,
                                          gint      *natural_width)
@@ -344,7 +368,10 @@ ephy_location_entry_class_init (EphyLocationEntryClass *klass)
   object_class->get_property = ephy_location_entry_get_property;
   object_class->set_property = ephy_location_entry_set_property;
   object_class->finalize = ephy_location_entry_finalize;
+
+  widget_class->size_allocate = ephy_location_entry_size_allocate;
   widget_class->get_preferred_width = ephy_location_entry_get_preferred_width;
+
   entry_class->copy_clipboard = ephy_location_entry_copy_clipboard;
   entry_class->cut_clipboard = ephy_location_entry_cut_clipboard;
 
@@ -1179,6 +1206,22 @@ ephy_location_entry_set_lock_tooltip (EphyLocationEntry *entry,
                                    tooltip);
 }
 
+void
+ephy_location_entry_set_add_bookmark_popover (EphyLocationEntry *entry,
+                                              GtkPopover        *popover)
+{
+  g_return_if_fail (EPHY_IS_LOCATION_ENTRY (entry));
+  g_return_if_fail (GTK_IS_POPOVER (popover));
+
+  entry->add_bookmark_popover = popover;
+}
+
+GtkPopover *
+ephy_location_entry_get_add_bookmark_popover (EphyLocationEntry *entry)
+{
+  return entry->add_bookmark_popover;
+}
+
 /**
  * ephy_location_entry_get_search_terms:
  * @entry: an #EphyLocationEntry widget
diff --git a/lib/widgets/ephy-location-entry.h b/lib/widgets/ephy-location-entry.h
index 7d5d2a4..cb1b03f 100644
--- a/lib/widgets/ephy-location-entry.h
+++ b/lib/widgets/ephy-location-entry.h
@@ -31,39 +31,44 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (EphyLocationEntry, ephy_location_entry, EPHY, LOCATION_ENTRY, GtkEntry)
 
-GtkWidget      *ephy_location_entry_new                 (void);
+GtkWidget      *ephy_location_entry_new                        (void);
 
-void            ephy_location_entry_set_completion      (EphyLocationEntry *entry,
-                                                         GtkTreeModel *model,
-                                                         guint text_col,
-                                                         guint action_col,
-                                                         guint keywords_col,
-                                                         guint relevance_col,
-                                                         guint url_col,
-                                                         guint extra_col,
-                                                         guint favicon_col);
+void            ephy_location_entry_set_completion             (EphyLocationEntry *entry,
+                                                                GtkTreeModel      *model,
+                                                                guint              text_col,
+                                                                guint              action_col,
+                                                                guint              keywords_col,
+                                                                guint              relevance_col,
+                                                                guint              url_col,
+                                                                guint              extra_col,
+                                                                guint              favicon_col);
 
-void            ephy_location_entry_set_match_func      (EphyLocationEntry *entry,
-                                                         GtkEntryCompletionMatchFunc match_func,
-                                                         gpointer user_data,
-                                                         GDestroyNotify notify);
+void            ephy_location_entry_set_match_func             (EphyLocationEntry           *entry,
+                                                                GtkEntryCompletionMatchFunc  match_func,
+                                                                gpointer                     user_data,
+                                                                GDestroyNotify               notify);
 
-gboolean        ephy_location_entry_get_can_undo        (EphyLocationEntry *entry);
+gboolean        ephy_location_entry_get_can_undo               (EphyLocationEntry *entry);
 
-gboolean        ephy_location_entry_get_can_redo        (EphyLocationEntry *entry);
+gboolean        ephy_location_entry_get_can_redo               (EphyLocationEntry *entry);
 
-GSList         *ephy_location_entry_get_search_terms    (EphyLocationEntry *entry);
+GSList         *ephy_location_entry_get_search_terms           (EphyLocationEntry *entry);
 
-gboolean        ephy_location_entry_reset               (EphyLocationEntry *entry);
+gboolean        ephy_location_entry_reset                      (EphyLocationEntry *entry);
 
-void            ephy_location_entry_undo_reset          (EphyLocationEntry *entry);
+void            ephy_location_entry_undo_reset                 (EphyLocationEntry *entry);
 
-void            ephy_location_entry_activate            (EphyLocationEntry *entry);
+void            ephy_location_entry_activate                   (EphyLocationEntry *entry);
 
-void          ephy_location_entry_set_bookmarked_status (EphyLocationEntry *entry,
-                                                         gboolean           is_bookmarked);
+void            ephy_location_entry_set_bookmarked_status      (EphyLocationEntry *entry,
+                                                                gboolean           is_bookmarked);
 
-void            ephy_location_entry_set_lock_tooltip    (EphyLocationEntry *entry,
-                                                         const char *tooltip);
+void            ephy_location_entry_set_lock_tooltip           (EphyLocationEntry *entry,
+                                                                const char        *tooltip);
+
+void            ephy_location_entry_set_add_bookmark_popover   (EphyLocationEntry *entry,
+                                                                GtkPopover        *popover);
+
+GtkPopover     *ephy_location_entry_get_add_bookmark_popover   (EphyLocationEntry *entry);
 
 G_END_DECLS
diff --git a/src/Makefile.am b/src/Makefile.am
index ab94b11..4a982af 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -22,6 +22,8 @@ libephymain_la_SOURCES = \
        cookies-dialog.h                        \
        ephy-action-helper.c                    \
        ephy-action-helper.h                    \
+       ephy-add-bookmark-popover.c             \
+       ephy-add-bookmark-popover.h             \
        ephy-bookmark.c                         \
        ephy-bookmark.h                         \
        ephy-bookmark-properties-grid.c         \
diff --git a/src/ephy-add-bookmark-popover.c b/src/ephy-add-bookmark-popover.c
new file mode 100644
index 0000000..ec1f1d8
--- /dev/null
+++ b/src/ephy-add-bookmark-popover.c
@@ -0,0 +1,205 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ *  Copyright © 2016 Iulian-Gabriel Radu <iulian radu67 gmail com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "ephy-add-bookmark-popover.h"
+
+#include "ephy-bookmark-properties-grid.h"
+#include "ephy-bookmarks-manager.h"
+#include "ephy-embed-container.h"
+#include "ephy-location-entry.h"
+#include "ephy-shell.h"
+
+struct _EphyAddBookmarkPopover {
+  GtkPopover     parent_instance;
+
+  char          *address;
+
+  GtkWidget     *grid;
+
+  EphyHeaderBar *header_bar;
+};
+
+G_DEFINE_TYPE (EphyAddBookmarkPopover, ephy_add_bookmark_popover, GTK_TYPE_POPOVER)
+
+enum {
+  PROP_0,
+  PROP_HEADER_BAR,
+  LAST_PROP
+};
+
+static GParamSpec *obj_properties[LAST_PROP];
+
+static void
+ephy_bookmarks_popover_set_property (GObject      *object,
+                                     guint         prop_id,
+                                     const GValue *value,
+                                     GParamSpec   *pspec)
+{
+  EphyAddBookmarkPopover *self = EPHY_ADD_BOOKMARK_POPOVER (object);
+
+  switch (prop_id) {
+    case PROP_HEADER_BAR:
+      self->header_bar = g_value_get_object (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+  }
+}
+
+static void
+ephy_add_bookmark_popover_constructed (GObject *object)
+{
+  EphyAddBookmarkPopover *self = EPHY_ADD_BOOKMARK_POPOVER (object);
+  GtkWidget *location_entry;
+
+  location_entry = GTK_WIDGET (ephy_header_bar_get_title_widget (self->header_bar));
+  g_assert (EPHY_IS_LOCATION_ENTRY (location_entry));
+
+  gtk_popover_set_relative_to (GTK_POPOVER (self), location_entry);
+
+  G_OBJECT_CLASS (ephy_add_bookmark_popover_parent_class)->constructed (object);
+}
+
+static void
+ephy_add_bookmark_popover_class_init (EphyAddBookmarkPopoverClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->set_property = ephy_bookmarks_popover_set_property;
+
+  obj_properties[PROP_HEADER_BAR] =
+    g_param_spec_object ("header-bar",
+                         "An EphyHeaderBar object",
+                         "The popover's parent EphyHeaderBar",
+                         EPHY_TYPE_HEADER_BAR,
+                         G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
+
+  object_class->constructed = ephy_add_bookmark_popover_constructed;
+}
+
+static void
+ephy_add_bookmark_popover_init (EphyAddBookmarkPopover *self)
+{
+}
+
+GtkWidget *
+ephy_add_bookmark_popover_new (EphyHeaderBar *header_bar)
+{
+  g_return_val_if_fail (GTK_IS_WIDGET (header_bar), NULL);
+
+  return g_object_new (EPHY_TYPE_ADD_BOOKMARK_POPOVER,
+                       "header-bar", header_bar,
+                       NULL);
+}
+
+/**
+ * update_bookmarked_status_cb:
+ * @bookmark: an #EphyBookmark object
+ * @header_bar: an #EphyHeaderBar widget
+ *
+ * Remove bookmarked status if the @bookmark was removed.
+ *
+ **/
+static void
+ephy_add_bookmark_popover_update_bookmarked_status_cb (EphyAddBookmarkPopover *self,
+                                                       EphyBookmark           *bookmark,
+                                                       EphyBookmarksManager   *manager)
+{
+  GtkWidget *location_entry;
+  EphyWindow *window;
+  EphyEmbed *embed;
+  EphyWebView *view;
+  const char *address;
+
+  g_assert (EPHY_IS_ADD_BOOKMARK_POPOVER (self));
+  g_assert (EPHY_IS_BOOKMARK (bookmark));
+  g_assert (EPHY_IS_BOOKMARKS_MANAGER (manager));
+
+  location_entry = GTK_WIDGET (ephy_header_bar_get_title_widget (self->header_bar));
+  window = ephy_header_bar_get_window (self->header_bar);
+  embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
+  view = ephy_embed_get_web_view (embed);
+
+  address = ephy_web_view_get_address (view);
+
+  if (g_strcmp0 (ephy_bookmark_get_url (bookmark), address) == 0) {
+    ephy_location_entry_set_bookmarked_status (EPHY_LOCATION_ENTRY (location_entry),
+                                               FALSE);
+  }
+
+  ephy_bookmarks_manager_save_to_file_async (manager, NULL, NULL, NULL);
+
+  gtk_widget_hide (GTK_WIDGET (self));
+
+  g_clear_pointer (&self->address, g_free);
+  g_clear_pointer (&self->grid, gtk_widget_destroy);
+}
+
+void
+ephy_add_bookmark_popover_show (EphyAddBookmarkPopover *self)
+{
+  EphyBookmarksManager *manager;
+  GtkWidget *location_entry;
+  EphyWindow *window;
+  EphyEmbed *embed;
+  EphyBookmark *bookmark;
+  const char *address;
+
+  manager = ephy_shell_get_bookmarks_manager (ephy_shell_get_default ());
+  location_entry = GTK_WIDGET (ephy_header_bar_get_title_widget (self->header_bar));
+  window = ephy_header_bar_get_window (self->header_bar);
+  embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
+
+  address = ephy_web_view_get_address (ephy_embed_get_web_view (embed));
+
+  bookmark = ephy_bookmarks_manager_get_bookmark_by_url (manager, address);
+  if (!bookmark) {
+    bookmark = ephy_bookmark_new (g_strdup (address),
+                                  g_strdup (ephy_embed_get_title (embed)),
+                                  g_sequence_new (g_free));
+
+    ephy_bookmarks_manager_add_bookmark (manager, bookmark);
+    ephy_location_entry_set_bookmarked_status (EPHY_LOCATION_ENTRY (location_entry), TRUE);
+  }
+
+  g_signal_connect_object (manager, "bookmark-removed",
+                         G_CALLBACK (ephy_add_bookmark_popover_update_bookmarked_status_cb),
+                         self,
+                         G_CONNECT_SWAPPED);
+
+  if (!self->address || g_strcmp0 (address, self->address) != 0) {
+    if (self->grid)
+      gtk_widget_destroy (self->grid);
+
+    self->grid = ephy_bookmark_properties_grid_new (bookmark,
+                                                    EPHY_BOOKMARK_PROPERTIES_GRID_TYPE_POPOVER,
+                                                    GTK_WIDGET (self));
+    gtk_container_add (GTK_CONTAINER (self), self->grid);
+    gtk_popover_set_default_widget (GTK_POPOVER (self),
+                                    ephy_bookmark_properties_grid_get_add_tag_button 
(EPHY_BOOKMARK_PROPERTIES_GRID (self->grid)));
+
+    g_free (self->address);
+    self->address = g_strdup (address);
+  }
+
+  gtk_widget_show (GTK_WIDGET (self));
+}
diff --git a/src/ephy-add-bookmark-popover.h b/src/ephy-add-bookmark-popover.h
new file mode 100644
index 0000000..9a68fe6
--- /dev/null
+++ b/src/ephy-add-bookmark-popover.h
@@ -0,0 +1,38 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ *  Copyright © 2016 Iulian-Gabriel Radu <iulian radu67 gmail com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _EPHY_ADD_BOOKMARK_POPOVER_H
+#define _EPHY_ADD_BOOKMARK_POPOVER_H
+
+#include "ephy-header-bar.h"
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_ADD_BOOKMARK_POPOVER (ephy_add_bookmark_popover_get_type ())
+
+G_DECLARE_FINAL_TYPE (EphyAddBookmarkPopover, ephy_add_bookmark_popover, EPHY, ADD_BOOKMARK_POPOVER, 
GtkPopover)
+
+GtkWidget       *ephy_add_bookmark_popover_new      (EphyHeaderBar *header_bar);
+
+void             ephy_add_bookmark_popover_show     (EphyAddBookmarkPopover *self);
+
+G_END_DECLS
+
+#endif /* _EPHY_ADD_BOOKMARK_POPOVER_H */
diff --git a/src/ephy-bookmark-properties-grid.c b/src/ephy-bookmark-properties-grid.c
index 7c9ab76..0df011c 100644
--- a/src/ephy-bookmark-properties-grid.c
+++ b/src/ephy-bookmark-properties-grid.c
@@ -242,7 +242,8 @@ ephy_bookmarks_properties_grid_actions_remove_bookmark (GSimpleAction *action,
 
   ephy_bookmarks_manager_remove_bookmark (self->manager,  self->bookmark);
 
-  gtk_widget_destroy (self->parent);
+  if (self->type == EPHY_BOOKMARK_PROPERTIES_GRID_TYPE_DIALOG)
+    gtk_widget_destroy (self->parent);
 }
 
 static void
diff --git a/src/ephy-header-bar.c b/src/ephy-header-bar.c
index 4ca39a7..1292ef3 100644
--- a/src/ephy-header-bar.c
+++ b/src/ephy-header-bar.c
@@ -22,6 +22,7 @@
 #include "ephy-header-bar.h"
 
 #include "ephy-action-helper.h"
+#include "ephy-add-bookmark-popover.h"
 #include "ephy-bookmarks-popover.h"
 #include "ephy-bookmark-properties-grid.h"
 #include "ephy-downloads-popover.h"
@@ -548,97 +549,18 @@ ephy_header_bar_change_combined_stop_reload_state (GSimpleAction *action,
                         image);
 }
 
-/**
- * update_bookmarked_status_cb:
- * @bookmark: an #EphyBookmark object
- * @header_bar: an #EphyHeaderBar widget
- *
- * Remove bookmarked status if the @bookmark was removed.
- *
- **/
-static void
-update_bookmarked_status_cb (EphyBookmarksManager   *manager,
-                             EphyBookmark           *bookmark,
-                             EphyHeaderBar          *header_bar)
-{
-  EphyEmbed *embed;
-  EphyWebView *view;
-  const char *address;
-
-  g_assert (EPHY_IS_BOOKMARKS_MANAGER (manager));
-  g_assert (EPHY_IS_BOOKMARK (bookmark));
-  g_assert (EPHY_IS_HEADER_BAR (header_bar));
-
-  embed = ephy_embed_container_get_active_child
-            (EPHY_EMBED_CONTAINER (header_bar->window));
-  view = ephy_embed_get_web_view (embed);
-
-  address = ephy_web_view_get_address (view);
-
-  if (g_strcmp0 (ephy_bookmark_get_url (bookmark), address) == 0) {
-    ephy_location_entry_set_bookmarked_status (EPHY_LOCATION_ENTRY (header_bar->entry),
-                                               FALSE);
-  }
-}
-
-static void
-popover_closed_cb (GtkPopover  *popover,
-                   EphyBookmarksManager *manager)
-{
-  ephy_bookmarks_manager_save_to_file_async (manager, NULL, NULL, NULL);
-}
-
 static void
 add_bookmark_button_clicked_cb (EphyLocationEntry *entry,
                                 gpointer          *user_data)
 {
-  EphyBookmarksManager *manager = ephy_shell_get_bookmarks_manager (ephy_shell_get_default ());
   EphyHeaderBar *header_bar = EPHY_HEADER_BAR (user_data);
-  EphyEmbed *embed;
-  GtkWidget *popover;
-  GtkWidget *grid;
-  GdkRectangle rectangle;
-  EphyBookmark *bookmark;
-  const char *location;
-
-  embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (header_bar->window));
-
-  location = ephy_web_view_get_address (ephy_embed_get_web_view (embed));
-  bookmark = ephy_bookmarks_manager_get_bookmark_by_url (manager, location);
-  if (!bookmark) {
-    bookmark = ephy_bookmark_new (g_strdup (location),
-                                  g_strdup (ephy_embed_get_title (embed)),
-                                  g_sequence_new (g_free));
-
-    g_signal_connect_object (manager, "bookmark-removed",
-                             G_CALLBACK (update_bookmarked_status_cb),
-                             header_bar, 0);
-    ephy_bookmarks_manager_add_bookmark (manager, bookmark);
-    ephy_location_entry_set_bookmarked_status (entry, TRUE);
-  }
-
-  popover = gtk_popover_new (GTK_WIDGET (entry));
-  gtk_entry_get_icon_area (GTK_ENTRY (entry),
-                           GTK_ENTRY_ICON_SECONDARY,
-                           &rectangle);
-
-  /* FIXME: GTK+ sets "margin-left: 6px" for the icon. Add 3px to the
-   * rectangle so the popover is centered on the star.
-   */
-  rectangle.x = rectangle.x + 3;
+  GActionGroup *action_group;
+  GAction *action;
 
-  gtk_popover_set_pointing_to (GTK_POPOVER (popover), &rectangle);
-  grid = ephy_bookmark_properties_grid_new (bookmark,
-                                            EPHY_BOOKMARK_PROPERTIES_GRID_TYPE_POPOVER,
-                                            popover);
-  gtk_container_add (GTK_CONTAINER (popover), grid);
-  gtk_popover_set_default_widget (GTK_POPOVER (popover),
-                                  ephy_bookmark_properties_grid_get_add_tag_button 
(EPHY_BOOKMARK_PROPERTIES_GRID (grid)));
+  action_group = gtk_widget_get_action_group (GTK_WIDGET (header_bar->window), "win");
+  action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "bookmark-page");
 
-  g_signal_connect_object (popover, "closed",
-                           G_CALLBACK (popover_closed_cb),
-                           manager, 0);
-  gtk_widget_show (popover);
+  g_action_activate (action, NULL);
 }
 
 static void
@@ -736,6 +658,9 @@ ephy_header_bar_constructed (GObject *object)
   gtk_widget_show (GTK_WIDGET (header_bar->title_widget));
 
   if (EPHY_IS_LOCATION_ENTRY (header_bar->title_widget)) {
+    ephy_location_entry_set_add_bookmark_popover (EPHY_LOCATION_ENTRY (header_bar->title_widget),
+                                                  GTK_POPOVER (ephy_add_bookmark_popover_new (header_bar)));
+
     g_signal_connect_object (header_bar->title_widget,
                              "bookmark-clicked",
                              G_CALLBACK (add_bookmark_button_clicked_cb),
@@ -879,3 +804,9 @@ ephy_header_bar_get_new_tab_button (EphyHeaderBar *header_bar)
 {
   return header_bar->new_tab_button;
 }
+
+EphyWindow *
+ephy_header_bar_get_window (EphyHeaderBar *header_bar)
+{
+  return header_bar->window;
+}
diff --git a/src/ephy-header-bar.h b/src/ephy-header-bar.h
index 5cd4e75..910526a 100644
--- a/src/ephy-header-bar.h
+++ b/src/ephy-header-bar.h
@@ -38,5 +38,6 @@ void             ephy_header_bar_change_combined_stop_reload_state (GSimpleActio
 EphyTitleWidget *ephy_header_bar_get_title_widget                  (EphyHeaderBar *header_bar);
 GtkWidget       *ephy_header_bar_get_page_menu_button              (EphyHeaderBar *header_bar);
 GtkWidget       *ephy_header_bar_get_new_tab_button                (EphyHeaderBar *header_bar);
+EphyWindow      *ephy_header_bar_get_window                        (EphyHeaderBar *header_bar);
 
 G_END_DECLS
diff --git a/src/ephy-window.c b/src/ephy-window.c
index a76eb54..3e6e09a 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -2782,32 +2782,6 @@ title_widget_lock_clicked_cb (EphyTitleWidget *title_widget,
   gtk_widget_show (security_popover);
 }
 
-<<<<<<< 1e82cb5ec66b886ceb75c078fbd20f2fd7d5f89f
-=======
-static void
-location_controller_lock_clicked_cb (EphyLocationController *controller,
-                                     gpointer                user_data)
-{
-  EphyWindow *window = EPHY_WINDOW (user_data);
-  GtkWidget *location_entry;
-  GdkRectangle lock_position;
-
-  location_entry = ephy_header_bar_get_location_entry (EPHY_HEADER_BAR (window->header_bar));
-  gtk_entry_get_icon_area (GTK_ENTRY (location_entry), GTK_ENTRY_ICON_PRIMARY, &lock_position);
-  open_security_popover (window, location_entry, &lock_position);
-}
-
-static void
-title_box_lock_clicked_cb (EphyTitleBox *title_box,
-                           GdkRectangle *lock_position,
-                           gpointer      user_data)
-{
-  EphyWindow *window = EPHY_WINDOW (user_data);
-
-  open_security_popover (window, GTK_WIDGET (title_box), lock_position);
-}
-
->>>>>>> bookmarks-popover: Update all stacks accordingly when a bookmark/tag is added/modified/removed
 static GtkWidget *
 setup_header_bar (EphyWindow *window)
 {
diff --git a/src/window-commands.c b/src/window-commands.c
index 0fdb5de..9d92e6e 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -20,8 +20,10 @@
  */
 
 #include "config.h"
+
 #include "window-commands.h"
 
+#include "ephy-add-bookmark-popover.h"
 #include "ephy-bookmarks-editor.h"
 #include "ephy-bookmarks-ui.h"
 #include "ephy-debug.h"
@@ -36,6 +38,7 @@
 #include "ephy-file-helpers.h"
 #include "ephy-find-toolbar.h"
 #include "ephy-gui.h"
+#include "ephy-header-bar.h"
 #include "ephy-history-window.h"
 #include "ephy-link.h"
 #include "ephy-location-entry.h"
@@ -1313,15 +1316,17 @@ window_cmd_bookmark_page (GSimpleAction *action,
                           GVariant      *parameter,
                           gpointer       user_data)
 {
-  EphyEmbed *embed;
+  EphyWindow *window = EPHY_WINDOW (user_data);
+  EphyHeaderBar *header_bar;
+  EphyTitleWidget *title_widget;
+  GtkPopover *popover;
 
-  embed = ephy_embed_container_get_active_child
-            (EPHY_EMBED_CONTAINER (user_data));
-  g_return_if_fail (embed != NULL);
+  header_bar = EPHY_HEADER_BAR (ephy_window_get_header_bar (window));
+  title_widget = ephy_header_bar_get_title_widget (header_bar);
+  g_assert (EPHY_IS_LOCATION_ENTRY (title_widget));
+  popover = ephy_location_entry_get_add_bookmark_popover (EPHY_LOCATION_ENTRY (title_widget));
 
-  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));
+  ephy_add_bookmark_popover_show (EPHY_ADD_BOOKMARK_POPOVER (popover));
 }
 
 void


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