diff options
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/bookmarks/Makefile.am | 2 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-menu.c | 239 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-menu.h | 32 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-ui.c | 178 | ||||
-rw-r--r-- | src/bookmarks/ephy-topic-action.c | 1 | ||||
-rw-r--r-- | src/ephy-header-bar.c | 14 | ||||
-rw-r--r-- | src/ephy-window.c | 71 | ||||
-rw-r--r-- | src/epiphany.gresource.xml | 1 | ||||
-rw-r--r-- | src/resources/gtk/menus.ui | 96 | ||||
-rw-r--r-- | src/resources/gtk/page-menu-popover.ui | 199 |
11 files changed, 248 insertions, 586 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 16edae7ac..d392db721 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -117,6 +117,7 @@ RESOURCE_FILES = \ resources/epiphany.css \ resources/error.html \ resources/gtk/menus.ui \ + resources/gtk/page-menu-popover.ui \ resources/history-dialog.ui \ resources/incognito.png \ resources/missing-thumbnail.png \ diff --git a/src/bookmarks/Makefile.am b/src/bookmarks/Makefile.am index bc8661d59..c695db215 100644 --- a/src/bookmarks/Makefile.am +++ b/src/bookmarks/Makefile.am @@ -16,8 +16,6 @@ libephybookmarks_la_SOURCES = \ ephy-bookmarks-import.h \ ephy-bookmarks-ui.c \ ephy-bookmarks-ui.h \ - ephy-bookmarks-menu.c \ - ephy-bookmarks-menu.h \ ephy-bookmark-properties.c \ ephy-bookmark-properties.h \ ephy-link-action.c \ diff --git a/src/bookmarks/ephy-bookmarks-menu.c b/src/bookmarks/ephy-bookmarks-menu.c deleted file mode 100644 index 1ef812b1d..000000000 --- a/src/bookmarks/ephy-bookmarks-menu.c +++ /dev/null @@ -1,239 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * Copyright © 2003, 2004 Marco Pesenti Gritti - * Copyright © 2003, 2004 Christian Persch - * Copyright © 2004 Peter Harvey - * - * 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-bookmarks-menu.h" -#include "ephy-bookmarks-ui.h" -#include "ephy-bookmark-action.h" -#include "ephy-open-tabs-action.h" -#include "ephy-topic-action.h" -#include "ephy-nodes-cover.h" -#include "ephy-node-common.h" -#include "ephy-link.h" -#include "ephy-shell.h" -#include "ephy-string.h" -#include "ephy-gui.h" -#include "ephy-debug.h" - -#include <string.h> - -#define MIN_MENU_SIZE 3 -#define MAX_MENU_SIZE 21 - -enum { - BUILD_SUBDIVIS = 1 << 0, - BUILD_SUBMENUS = 1 << 1, - BUILD_CHILD_SUBDIVIS = 1 << 2, - BUILD_CHILD_SUBMENUS = 1 << 3 -}; - -/* 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 (GMenu *menu, - const GPtrArray *bookmarks) -{ - EphyNode *child; - const gchar *action_name; - GVariant *location; - - long i; - - for (i = 0; i < bookmarks->len; i++) { - child = g_ptr_array_index (bookmarks, i); - - location = g_variant_new_string (ephy_node_get_property_string (child, EPHY_NODE_BMK_PROP_LOCATION)); - action_name = g_action_print_detailed_name ("win.open-bookmark", location); - g_variant_unref (location); - - 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 (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; - - if (use_subdivis || use_submenus) { - GPtrArray *subset, *covering, *subdivisions, *submenus, *unused; - GArray *sizes = 0; - EphyNode *topic; - gint size, total; - gboolean separate = FALSE; - const gchar *name; - - /* Get the subtopics, uncovered bookmarks, and subtopic sizes. */ - sizes = g_array_sized_new (FALSE, FALSE, sizeof (int), topics->len); - uncovered = g_ptr_array_sized_new (bookmarks->len); - covering = ephy_nodes_get_covering (topics, bookmarks, 0, uncovered, sizes); - - /* Preallocate arrays for submenus, subdivisions, and bookmark subsets. */ - subdivisions = g_ptr_array_sized_new (topics->len); - submenus = g_ptr_array_sized_new (topics->len); - subset = g_ptr_array_sized_new (bookmarks->len); - unused = g_ptr_array_sized_new (bookmarks->len); - - /* Get the total number of items in the menu. */ - total = uncovered->len; - for (i = 0; i < covering->len; i++) - total += g_array_index (sizes, int, i); - - /* Seperate covering into list of submenus and subdivisions */ - for (i = 0; i < covering->len; i++) { - topic = g_ptr_array_index (covering, i); - size = g_array_index (sizes, int, i); - - if (!use_submenus || (use_subdivis && (size < MIN_MENU_SIZE || total < MAX_MENU_SIZE))) { - g_ptr_array_add (subdivisions, topic); - } else { - g_ptr_array_add (submenus, topic); - total = total - size + 1; - } - } - - /* Sort the list of submenus and subdivisions. */ - g_ptr_array_sort (submenus, ephy_bookmarks_compare_topic_pointers); - g_ptr_array_sort (subdivisions, ephy_bookmarks_compare_topic_pointers); - - if (flags & BUILD_CHILD_SUBDIVIS) flags |= BUILD_SUBDIVIS; - if (flags & BUILD_CHILD_SUBMENUS) flags |= BUILD_SUBMENUS; - - /* Create each of the submenus. */ - for (i = 0; i < submenus->len; i++) { - topic = g_ptr_array_index (submenus, i); - ephy_nodes_get_covered (topic, bookmarks, subset); - - 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); - - separate = TRUE; - } - - /* Build a list of bookmarks which don't appear in any subdivision yet. */ - for (i = 0; i < bookmarks->len; i++) { - g_ptr_array_add (unused, g_ptr_array_index (bookmarks, i)); - } - - /* Create each of the subdivisions. */ - for (i = 0; i < subdivisions->len; i++) { - topic = g_ptr_array_index (subdivisions, i); - ephy_nodes_get_covered (topic, unused, subset); - g_ptr_array_sort (subset, ephy_bookmarks_compare_bookmark_pointers); - - 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. */ - for (j = 0; j < subset->len; j++) { - g_ptr_array_remove_fast (unused, g_ptr_array_index (subset, j)); - } - } - - g_array_free (sizes, TRUE); - g_ptr_array_free (covering, TRUE); - g_ptr_array_free (subdivisions, TRUE); - g_ptr_array_free (submenus, TRUE); - g_ptr_array_free (subset, TRUE); - g_ptr_array_free (unused, TRUE); - } else { - uncovered = g_ptr_array_sized_new (bookmarks->len); - for (i = 0; i < bookmarks->len; i++) - g_ptr_array_add (uncovered, g_ptr_array_index (bookmarks, i)); - g_ptr_array_sort (uncovered, ephy_bookmarks_compare_bookmark_pointers); - } - - /* Create the final subdivision (uncovered bookmarks). */ - g_ptr_array_sort (uncovered, ephy_bookmarks_compare_bookmark_pointers); - append_bookmarks (menu, uncovered); - g_ptr_array_free (uncovered, TRUE); -} - -void -ephy_bookmarks_menu_build (GMenu *menu, EphyNode *parent) -{ - GPtrArray *children, *topics; - EphyBookmarks *eb; - EphyNode *node; - gint priority; - guint flags, id, i; - - eb = ephy_shell_get_bookmarks (ephy_shell_get_default ()); - - children = ephy_node_get_children (ephy_bookmarks_get_keywords (eb)); - topics = g_ptr_array_sized_new (children->len); - for (i = 0; i < children->len; i++) { - node = g_ptr_array_index (children, i); - priority = ephy_node_get_property_int (node, EPHY_NODE_KEYWORD_PROP_PRIORITY); - if (priority == EPHY_NODE_NORMAL_PRIORITY) - g_ptr_array_add (topics, node); - } - - /* If no parent was supplied, use the default 'All' */ - node = parent ? parent : ephy_bookmarks_get_bookmarks (eb); - children = ephy_node_get_children (node); - - /* Determine what kind of menu we want. */ - id = ephy_node_get_id (node); - switch (id) { - case FAVORITES_NODE_ID: - flags = 0; - break; - case BOOKMARKS_NODE_ID: - flags = BUILD_SUBMENUS | BUILD_CHILD_SUBDIVIS; - break; - default: - flags = BUILD_SUBMENUS | BUILD_SUBDIVIS | BUILD_CHILD_SUBDIVIS; - /* flags = BUILD_SUBDIVIS; */ - break; - } - - /* If this menu is the 'All' menu, be sure to include the 'local' topic. */ - if (id == BOOKMARKS_NODE_ID) { - EphyNode *local_node; - - local_node = ephy_bookmarks_get_local (eb); - if (local_node != NULL) { - g_ptr_array_add (topics, ephy_bookmarks_get_local (eb)); - } - - append_menu (menu, topics, children, flags); - g_ptr_array_free (topics, TRUE); - } -} diff --git a/src/bookmarks/ephy-bookmarks-menu.h b/src/bookmarks/ephy-bookmarks-menu.h deleted file mode 100644 index a76a17e92..000000000 --- a/src/bookmarks/ephy-bookmarks-menu.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * Copyright © 2002 Ricardo Fernández Pascual - * Copyright © 2003, 2004 Marco Pesenti Gritti - * Copyright © 2003, 2004 Christian Persch - * - * 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/>. - */ - -#pragma once - -#include "ephy-window.h" -#include "ephy-node.h" - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -void ephy_bookmarks_menu_build (GMenu *menu, EphyNode *parent); - -G_END_DECLS diff --git a/src/bookmarks/ephy-bookmarks-ui.c b/src/bookmarks/ephy-bookmarks-ui.c index f9e239b81..5e61d178b 100644 --- a/src/bookmarks/ephy-bookmarks-ui.c +++ b/src/bookmarks/ephy-bookmarks-ui.c @@ -23,7 +23,6 @@ #include "ephy-bookmark-action-group.h" #include "ephy-bookmark-action.h" #include "ephy-bookmark-properties.h" -#include "ephy-bookmarks-menu.h" #include "ephy-bookmarks.h" #include "ephy-debug.h" #include "ephy-dnd.h" @@ -48,7 +47,6 @@ #define BM_WINDOW_DATA_KEY "bookmarks-window-data" typedef struct { - GMenu *bookmarks_menu; guint toolbar_menu; } BookmarksWindowData; @@ -59,114 +57,6 @@ enum { static GHashTable *properties_dialogs = 0; -static GMenu * -find_bookmarks_menu (EphyWindow *window) -{ - GtkWidget *page_menu_button; - GMenuModel *page_menu; - gint n_items, i; - - /* Page menu */ - page_menu_button = ephy_header_bar_get_page_menu_button (EPHY_HEADER_BAR (ephy_window_get_header_bar (window))); - page_menu = gtk_menu_button_get_menu_model (GTK_MENU_BUTTON (page_menu_button)); - - /* Number of sections in the model */ - n_items = g_menu_model_get_n_items (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 (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; - GMenuModel *bookmarks_menu_model; - - /* Bookmarks section should contain the bookmarks menu */ - bookmarks_section_model = g_menu_model_get_item_link (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); - - if (event->type != GDK_BUTTON_PRESS) - return G_SOURCE_REMOVE; - - 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; - - data = g_object_get_data (G_OBJECT (window), BM_WINDOW_DATA_KEY); - - if (data != NULL && data->bookmarks_menu != NULL) { - g_menu_remove_all (data->bookmarks_menu); - g_clear_object (&data->bookmarks_menu); - } -} - -static void -tree_changed_cb (EphyBookmarks *bookmarks, - EphyWindow *window) -{ - erase_bookmarks_menu (window); -} - -static void -node_added_cb (EphyNode *parent, - EphyNode *child, - EphyWindow *window) -{ - erase_bookmarks_menu (window); -} - -static void -node_changed_cb (EphyNode *parent, - EphyNode *child, - guint property_id, - EphyWindow *window) -{ - if (property_id == EPHY_NODE_KEYWORD_PROP_NAME || - property_id == EPHY_NODE_BMK_PROP_TITLE) { - erase_bookmarks_menu (window); - } -} - -static void -node_removed_cb (EphyNode *parent, - EphyNode *child, - guint index, - EphyWindow *window) -{ - erase_bookmarks_menu (window); -} - void ephy_bookmarks_ui_attach_window (EphyWindow *window) { @@ -176,7 +66,6 @@ ephy_bookmarks_ui_attach_window (EphyWindow *window) BookmarksWindowData *data; GtkUIManager *manager; GtkActionGroup *actions; - GtkWidget *page_menu_button; eb = ephy_shell_get_bookmarks (ephy_shell_get_default ()); bookmarks = ephy_bookmarks_get_bookmarks (eb); @@ -207,83 +96,16 @@ ephy_bookmarks_ui_attach_window (EphyWindow *window) G_CALLBACK (ephy_link_open), G_OBJECT (window), G_CONNECT_SWAPPED | G_CONNECT_AFTER); g_object_unref (actions); - - /* Add signal handlers for the bookmark database */ - ephy_node_signal_connect_object (bookmarks, EPHY_NODE_CHILD_ADDED, - (EphyNodeCallback)node_added_cb, - G_OBJECT (window)); - ephy_node_signal_connect_object (topics, EPHY_NODE_CHILD_ADDED, - (EphyNodeCallback)node_added_cb, - G_OBJECT (window)); - - ephy_node_signal_connect_object (bookmarks, EPHY_NODE_CHILD_REMOVED, - (EphyNodeCallback)node_removed_cb, - G_OBJECT (window)); - ephy_node_signal_connect_object (topics, EPHY_NODE_CHILD_REMOVED, - (EphyNodeCallback)node_removed_cb, - G_OBJECT (window)); - - ephy_node_signal_connect_object (bookmarks, EPHY_NODE_CHILD_CHANGED, - (EphyNodeCallback)node_changed_cb, - G_OBJECT (window)); - ephy_node_signal_connect_object (topics, EPHY_NODE_CHILD_CHANGED, - (EphyNodeCallback)node_changed_cb, - G_OBJECT (window)); - - g_signal_connect_object (eb, "tree_changed", - G_CALLBACK (tree_changed_cb), - G_OBJECT (window), 0); - - page_menu_button = ephy_header_bar_get_page_menu_button (EPHY_HEADER_BAR (ephy_window_get_header_bar (window))); - g_signal_connect (GTK_WIDGET (page_menu_button), "button-press-event", G_CALLBACK (activate_bookmarks_menu), window); } void ephy_bookmarks_ui_detach_window (EphyWindow *window) { - EphyBookmarks *eb = ephy_shell_get_bookmarks (ephy_shell_get_default ()); - EphyNode *bookmarks = ephy_bookmarks_get_bookmarks (eb); - EphyNode *topics = ephy_bookmarks_get_keywords (eb); - BookmarksWindowData *data = g_object_get_data (G_OBJECT (window), BM_WINDOW_DATA_KEY); - GtkWidget *page_menu_button; g_return_if_fail (data != 0); - 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); - - ephy_node_signal_disconnect_object (bookmarks, EPHY_NODE_CHILD_ADDED, - (EphyNodeCallback)node_added_cb, - G_OBJECT (window)); - ephy_node_signal_disconnect_object (topics, EPHY_NODE_CHILD_ADDED, - (EphyNodeCallback)node_added_cb, - G_OBJECT (window)); - - ephy_node_signal_disconnect_object (bookmarks, EPHY_NODE_CHILD_REMOVED, - (EphyNodeCallback)node_removed_cb, - G_OBJECT (window)); - ephy_node_signal_disconnect_object (topics, EPHY_NODE_CHILD_REMOVED, - (EphyNodeCallback)node_removed_cb, - G_OBJECT (window)); - - ephy_node_signal_disconnect_object (bookmarks, EPHY_NODE_CHILD_CHANGED, - (EphyNodeCallback)node_changed_cb, - G_OBJECT (window)); - ephy_node_signal_disconnect_object (topics, EPHY_NODE_CHILD_CHANGED, - (EphyNodeCallback)node_changed_cb, - G_OBJECT (window)); - - g_signal_handlers_disconnect_by_func - (G_OBJECT (eb), G_CALLBACK (tree_changed_cb), G_OBJECT (window)); - - page_menu_button = ephy_header_bar_get_page_menu_button (EPHY_HEADER_BAR (ephy_window_get_header_bar (window))); - g_signal_handlers_disconnect_by_func (GTK_WIDGET (page_menu_button), G_CALLBACK (activate_bookmarks_menu), window); } static void diff --git a/src/bookmarks/ephy-topic-action.c b/src/bookmarks/ephy-topic-action.c index 077bf005a..cde615c3f 100644 --- a/src/bookmarks/ephy-topic-action.c +++ b/src/bookmarks/ephy-topic-action.c @@ -25,7 +25,6 @@ #include "ephy-nodes-cover.h" #include "ephy-bookmarks.h" #include "ephy-bookmarks-ui.h" -#include "ephy-bookmarks-menu.h" #include "ephy-shell.h" #include "ephy-gui.h" #include "ephy-debug.h" diff --git a/src/ephy-header-bar.c b/src/ephy-header-bar.c index 17c8516d9..5d0bcde76 100644 --- a/src/ephy-header-bar.c +++ b/src/ephy-header-bar.c @@ -548,8 +548,7 @@ ephy_header_bar_constructed (GObject *object) { EphyHeaderBar *header_bar = EPHY_HEADER_BAR (object); GtkWidget *box, *button; - GtkMenu *menu; - GMenu *page_menu; + GtkWidget *page_menu_popover; EphyDownloadsManager *downloads_manager; GtkBuilder *builder; EphyHistoryService *history_service; @@ -644,15 +643,12 @@ ephy_header_bar_constructed (GObject *object) gtk_button_set_image (GTK_BUTTON (button), gtk_image_new_from_icon_name ("open-menu-symbolic", GTK_ICON_SIZE_BUTTON)); gtk_widget_set_valign (button, GTK_ALIGN_CENTER); - builder = gtk_builder_new_from_resource ("/org/gnome/epiphany/gtk/menus.ui"); - page_menu = G_MENU (gtk_builder_get_object (builder, "page-menu")); - gtk_menu_button_set_use_popover (GTK_MENU_BUTTON (button), FALSE); - gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), - G_MENU_MODEL (page_menu)); + g_type_ensure (G_TYPE_THEMED_ICON); + builder = gtk_builder_new_from_resource ("/org/gnome/epiphany/gtk/page-menu-popover.ui"); + page_menu_popover = GTK_WIDGET (gtk_builder_get_object (builder, "page-menu-popover")); + gtk_menu_button_set_popover (GTK_MENU_BUTTON (button), page_menu_popover); g_object_unref (builder); - menu = gtk_menu_button_get_popup (GTK_MENU_BUTTON (button)); - gtk_widget_set_halign (GTK_WIDGET (menu), GTK_ALIGN_END); gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), button); /* Downloads */ diff --git a/src/ephy-window.c b/src/ephy-window.c index 2ee233766..3d226565e 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -772,27 +772,6 @@ enable_edit_actions_sensitivity (EphyWindow *window) g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE); } -static void -edit_menu_toggle_cb (GtkWidget *menu, - EphyWindow *window) -{ - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (menu))) - update_edit_actions_sensitivity (window, FALSE); - else - enable_edit_actions_sensitivity (window); -} - -static void -init_menu_updaters (EphyWindow *window) -{ - GtkWidget *page_menu; - - page_menu = ephy_header_bar_get_page_menu_button (EPHY_HEADER_BAR (window->header_bar)); - - g_signal_connect (page_menu, "toggled", - G_CALLBACK (edit_menu_toggle_cb), window); -} - static const GActionEntry window_entries [] = { { "new-tab", window_cmd_new_tab }, @@ -942,7 +921,10 @@ const struct { { "copy-audio-location", N_("_Copy Audio Address") }, /* Selection */ - { "search-selection", NULL } + { "search-selection", NULL }, + + { "save-as", N_("Save Pa_ge As…") }, + { "page-source", N_("_Page Source") } }; static char * @@ -1030,12 +1012,40 @@ sync_tab_zoom (WebKitWebView *web_view, GParamSpec *pspec, EphyWindow *window) GAction *action; gboolean can_zoom_in = TRUE, can_zoom_out = TRUE, can_zoom_normal = FALSE; double zoom; + GtkWidget *page_menu_button; + GtkPopover *page_menu_popover; + GtkWidget *widget; + GtkWidget *zoom_level_entry; + GList *children; + char *zoom_level_text; if (window->closing) return; zoom = webkit_web_view_get_zoom_level (web_view); + /* Update the zoom level entry in the page menu popover: + * - obtain the popover from the page menu button + * - obtain the box (the first child of the popover) + * - obtain the "zoom box" (the first child of the box above) + * - obtain the GtkEntry which is the second child of the zoom box + */ + page_menu_button = ephy_header_bar_get_page_menu_button (EPHY_HEADER_BAR (window->header_bar)); + page_menu_popover = gtk_menu_button_get_popover (GTK_MENU_BUTTON (page_menu_button)); + children = gtk_container_get_children (GTK_CONTAINER (page_menu_popover)); + widget = g_list_nth_data (children, 0); + g_assert (GTK_IS_BOX (widget)); + children = gtk_container_get_children (GTK_CONTAINER (widget)); + widget = g_list_nth_data (children, 0); + g_assert (GTK_IS_BOX (widget)); + children = gtk_container_get_children (GTK_CONTAINER (widget)); + zoom_level_entry = g_list_nth_data (children, 1); + g_assert (GTK_IS_ENTRY (zoom_level_entry)); + + zoom_level_text = g_strdup_printf ("%.0lf%%", zoom * 100); + gtk_entry_set_text (GTK_ENTRY (zoom_level_entry), zoom_level_text); + g_free (zoom_level_text); + if (zoom >= ZOOM_MAXIMAL) { can_zoom_in = FALSE; } @@ -1671,6 +1681,13 @@ populate_context_menu (WebKitWebView *web_view, webkit_context_menu_append (context_menu, webkit_context_menu_item_new_separator ()); + add_action_to_context_menu (context_menu, window_action_group, + "save-as", window); + + webkit_context_menu_append (context_menu, + webkit_context_menu_item_new_separator ()); + add_action_to_context_menu (context_menu, window_action_group, + "page-source", window); webkit_context_menu_append (context_menu, webkit_context_menu_item_new_from_stock_action (WEBKIT_CONTEXT_MENU_ACTION_INSPECT_ELEMENT)); @@ -3024,8 +3041,6 @@ ephy_window_constructed (GObject *object) chrome &= ~(EPHY_WINDOW_CHROME_LOCATION | EPHY_WINDOW_CHROME_MENU | EPHY_WINDOW_CHROME_TABSBAR); } - init_menu_updaters (window); - ephy_window_set_chrome (window, chrome); } @@ -3207,15 +3222,13 @@ ephy_window_set_zoom (EphyWindow *window, current_zoom = webkit_web_view_get_zoom_level (web_view); - if (zoom == ZOOM_IN) { + if (zoom == ZOOM_IN) zoom = ephy_zoom_get_changed_zoom_level (current_zoom, 1); - } else if (zoom == ZOOM_OUT) { + else if (zoom == ZOOM_OUT) zoom = ephy_zoom_get_changed_zoom_level (current_zoom, -1); - } - if (zoom != current_zoom) { + if (zoom != current_zoom) webkit_web_view_set_zoom_level (web_view, zoom); - } } static void diff --git a/src/epiphany.gresource.xml b/src/epiphany.gresource.xml index dbf2afbc7..0391977dd 100644 --- a/src/epiphany.gresource.xml +++ b/src/epiphany.gresource.xml @@ -13,6 +13,7 @@ <file preprocess="xml-stripblanks" compressed="true">passwords-dialog.ui</file> <file preprocess="xml-stripblanks" compressed="true">shortcuts-dialog.ui</file> <file preprocess="xml-stripblanks" compressed="true">gtk/menus.ui</file> + <file preprocess="xml-stripblanks" compressed="true">gtk/page-menu-popover.ui</file> <file preprocess="xml-stripblanks">epiphany-application-menu.ui</file> <file preprocess="xml-stripblanks">epiphany-bookmark-editor-ui.xml</file> <file>epiphany.css</file> diff --git a/src/resources/gtk/menus.ui b/src/resources/gtk/menus.ui index e66f2cceb..7c46b35c7 100644 --- a/src/resources/gtk/menus.ui +++ b/src/resources/gtk/menus.ui @@ -1,102 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <interface> <!-- interface-requires gtk+ 3.0 --> - <menu id="page-menu"> - <section> - <item> - <attribute name="label" translatable="yes">New Tab</attribute> - <attribute name="action">win.new-tab</attribute> - </item> - <item> - <attribute name="label" translatable="yes">_Open…</attribute> - <attribute name="action">win.open</attribute> - </item> - </section> - <section> - <item> - <attribute name="label" translatable="yes">Save _As…</attribute> - <attribute name="action">win.save-as</attribute> - </item> - <item> - <attribute name="label" translatable="yes">Save As _Web Application…</attribute> - <attribute name="action">win.save-as-application</attribute> - </item> - </section> - <section> - <item> - <attribute name="label" translatable="yes">_Undo</attribute> - <attribute name="action">win.undo</attribute> - </item> - <item> - <attribute name="label" translatable="yes">Re_do</attribute> - <attribute name="action">win.redo</attribute> - </item> - </section> - <section> - <item> - <attribute name="label" translatable="yes">Cu_t</attribute> - <attribute name="action">win.cut</attribute> - </item> - <item> - <attribute name="label" translatable="yes">_Copy</attribute> - <attribute name="action">win.copy</attribute> - </item> - <item> - <attribute name="label" translatable="yes">_Paste</attribute> - <attribute name="action">win.paste</attribute> - </item> - </section> - <section> - <item> - <attribute name="label" translatable="yes">Zoom _In</attribute> - <attribute name="action">win.zoom-in</attribute> - </item> - <item> - <attribute name="label" translatable="yes">Zoom _Out</attribute> - <attribute name="action">win.zoom-out</attribute> - </item> - </section> - <section> - <item> - <attribute name="label" translatable="yes">Print…</attribute> - <attribute name="action">win.print</attribute> - </item> - <item> - <attribute name="label" translatable="yes">_Find…</attribute> - <attribute name="action">win.find</attribute> - </item> - </section> - <section id="bookmarks-section"> - <attribute name="id">bookmarks-section</attribute> - <submenu id="bookmarks-menu"> - <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> - <item> - <attribute name="label" translatable="yes">Text _Encoding</attribute> - <attribute name="action">win.encoding</attribute> - </item> - <item> - <attribute name="label" translatable="yes">_Page Source</attribute> - <attribute name="action">win.page-source</attribute> - </item> - </section> - <section> - <item> - <attribute name="label" translatable="yes">_Close</attribute> - <attribute name="action">tab.close</attribute> - </item> - </section> - </menu> <menu id="notebook-menu"> <section> <item> diff --git a/src/resources/gtk/page-menu-popover.ui b/src/resources/gtk/page-menu-popover.ui new file mode 100644 index 000000000..9dc6d9492 --- /dev/null +++ b/src/resources/gtk/page-menu-popover.ui @@ -0,0 +1,199 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <object class="GtkPopoverMenu" id="page-menu-popover"> + <child> + <object class="GtkBox"> + <property name="can_focus">False</property> + <property name="border_width">12</property> + <property name="orientation">vertical</property> + <property name="visible">True</property> + <child> + <object class="GtkBox" id="zoom-box"> + <property name="visible">True</property> + <property name="orientation">horizontal</property> + <property name="homogeneous">True</property> + <property name="margin-bottom">6</property> + <style> + <class name="linked"/> + </style> + <child> + <object class="GtkModelButton"> + <property name="text">Zoom Out</property> + <property name="action-name">win.zoom-out</property> + <property name="iconic">True</property> + <property name="centered">True</property> + <property name="icon">zoom_out</property> + <property name="visible">True</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkEntry" id="zoom-level"> + <property name="xalign">0.5</property> + <property name="sensitive">False</property> + <property name="visible">True</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkModelButton"> + <property name="text">Zoom In</property> + <property name="action-name">win.zoom-in</property> + <property name="iconic">True</property> + <property name="centered">True</property> + <property name="icon">zoom_in</property> + <property name="visible">True</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> + </object> + </child> + <child> + <object class="GtkBox"> + <property name="visible">True</property> + <property name="orientation">horizontal</property> + <property name="spacing">6</property> + <property name="homogeneous">True</property> + <property name="margin-bottom">6</property> + <child> + <object class="GtkModelButton"> + <property name="text">Zoom Out</property> + <property name="action-name">win.print</property> + <property name="iconic">True</property> + <property name="centered">True</property> + <property name="icon">print</property> + <property name="visible">True</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkModelButton"> + <property name="text">Zoom Out</property> + <property name="action-name">win.find</property> + <property name="iconic">True</property> + <property name="centered">True</property> + <property name="icon">find</property> + <property name="visible">True</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkModelButton"> + <property name="text">Zoom In</property> + <property name="action-name">win.fullscreen</property> + <property name="iconic">True</property> + <property name="centered">True</property> + <property name="icon">fullscreen</property> + <property name="visible">True</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> + </object> + </child> + <child> + <object class="GtkSeparator"> + <property name="orientation">horizontal</property> + <property name="margin-top">6</property> + <property name="margin-bottom">6</property> + <property name="visible">True</property> + </object> + </child> + <child> + <object class="GtkModelButton"> + <property name="can_focus">True</property> + <property name="text" translatable="yes">_New Tab</property> + <property name="action-name">win.new-tab</property> + <property name="visible">True</property> + </object> + </child> + <child> + <object class="GtkModelButton"> + <property name="can_focus">True</property> + <property name="text" translatable="yes">New _Window</property> + <property name="action-name">app.new-window</property> + <property name="visible">True</property> + </object> + </child> + <child> + <object class="GtkModelButton"> + <property name="can_focus">True</property> + <property name="text" translatable="yes">New _Incognito Window</property> + <property name="action-name">app.new-incognito</property> + <property name="visible">True</property> + </object> + </child> + <child> + <object class="GtkSeparator"> + <property name="orientation">horizontal</property> + <property name="margin-top">6</property> + <property name="margin-bottom">6</property> + <property name="visible">True</property> + </object> + </child> + <child> + <object class="GtkModelButton"> + <property name="can_focus">True</property> + <property name="text" translatable="yes">Text _Encoding</property> + <property name="action-name">win.encoding</property> + <property name="visible">True</property> + </object> + </child> + <child> + <object class="GtkSeparator"> + <property name="orientation">horizontal</property> + <property name="margin-top">6</property> + <property name="margin-bottom">6</property> + <property name="visible">True</property> + </object> + </child> + <child> + <object class="GtkModelButton"> + <property name="can_focus">True</property> + <property name="text" translatable="yes">Install Site as Web _Application…</property> + <property name="action-name">win.save-as-application</property> + <property name="visible">True</property> + </object> + </child> + </object> + </child> + </object> + <object class="GThemedIcon" id="zoom_out"> + <property name="name">zoom-out-symbolic</property> + </object> + <object class="GThemedIcon" id="zoom_in"> + <property name="name">zoom-in-symbolic</property> + </object> + <object class="GThemedIcon" id="print"> + <property name="name">document-print-symbolic</property> + </object> + <object class="GThemedIcon" id="find"> + <property name="name">system-search-symbolic</property> + </object> + <object class="GThemedIcon" id="fullscreen"> + <property name="name">view-fullscreen-symbolic</property> + </object> +</interface> |