diff options
author | Iulian Radu <iulian.radu67@gmail.com> | 2016-06-28 00:11:27 +0300 |
---|---|---|
committer | Iulian Radu <iulian.radu67@gmail.com> | 2016-07-11 19:17:05 +0300 |
commit | 5dca593964665fa973698f99cb12e998b2b9221f (patch) | |
tree | f49a4cedc8cbcbeaa20a62ea4b476ad375815f1f | |
parent | ad4ba63e40d13c2c13c2c76817355572d5c5928c (diff) | |
download | epiphany-5dca593964665fa973698f99cb12e998b2b9221f.tar.gz |
Use GAction for the combined stop/reload button
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/ephy-combined-stop-reload-action.c | 150 | ||||
-rw-r--r-- | src/ephy-combined-stop-reload-action.h | 60 | ||||
-rw-r--r-- | src/ephy-toolbar.c | 42 | ||||
-rw-r--r-- | src/ephy-toolbar.h | 16 | ||||
-rw-r--r-- | src/ephy-window.c | 108 | ||||
-rw-r--r-- | src/ephy-window.h | 2 | ||||
-rw-r--r-- | src/resources/epiphany-ui.xml | 2 | ||||
-rw-r--r-- | src/window-commands.c | 138 | ||||
-rw-r--r-- | src/window-commands.h | 13 |
10 files changed, 183 insertions, 350 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index ce61ce2b7..095c85db7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -32,8 +32,6 @@ libephymain_la_SOURCES = \ ephy-action-helper.h \ ephy-completion-model.c \ ephy-completion-model.h \ - ephy-combined-stop-reload-action.c \ - ephy-combined-stop-reload-action.h \ ephy-encoding-dialog.c \ ephy-encoding-dialog.h \ ephy-encoding-row.c \ diff --git a/src/ephy-combined-stop-reload-action.c b/src/ephy-combined-stop-reload-action.c deleted file mode 100644 index 012e09e38..000000000 --- a/src/ephy-combined-stop-reload-action.c +++ /dev/null @@ -1,150 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set sw=2 ts=2 sts=2 et: */ -/* - * Copyright © 2011 Igalia S.L. - * - * 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-combined-stop-reload-action.h" - -#include "window-commands.h" - -#include <glib/gi18n.h> - -G_DEFINE_TYPE (EphyCombinedStopReloadAction, ephy_combined_stop_reload_action, EPHY_TYPE_WINDOW_ACTION) - -#define COMBINED_STOP_RELOAD_ACTION_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), EPHY_TYPE_COMBINED_STOP_RELOAD_ACTION, EphyCombinedStopReloadActionPrivate)) - -struct _EphyCombinedStopReloadActionPrivate { - gboolean loading; - gulong action_handler_id; -}; - -GtkActionEntry combined_stop_reload_action_entries [] = { - { NULL, "process-stop-symbolic", N_("Stop"), NULL, - N_("Stop current data transfer"), - G_CALLBACK (window_cmd_view_stop) }, - { NULL, "view-refresh-symbolic", N_("_Reload"), NULL, - N_("Display the latest content of the current page"), - G_CALLBACK (window_cmd_view_reload) } -}; - -typedef enum { - EPHY_COMBINED_STOP_RELOAD_ACTION_STOP, - EPHY_COMBINED_STOP_RELOAD_ACTION_REFRESH -} EphyCombinedStopReloadActionEnum; - -enum { - PROP_0, - PROP_LOADING, - LAST_PROP -}; - -static GParamSpec *obj_properties[LAST_PROP]; - -void -ephy_combined_stop_reload_action_set_loading (EphyCombinedStopReloadAction *action, - gboolean loading) -{ - EphyCombinedStopReloadActionEnum action_enum; - EphyCombinedStopReloadActionPrivate *priv; - - g_return_if_fail (EPHY_IS_COMBINED_STOP_RELOAD_ACTION (action)); - - priv = action->priv; - - if (priv->loading == loading && priv->action_handler_id) - return; - - action_enum = loading ? - EPHY_COMBINED_STOP_RELOAD_ACTION_STOP : EPHY_COMBINED_STOP_RELOAD_ACTION_REFRESH; - - g_object_set (action, - "icon-name", combined_stop_reload_action_entries[action_enum].stock_id, - "tooltip", combined_stop_reload_action_entries[action_enum].tooltip, - NULL); - - if (priv->action_handler_id) - g_signal_handler_disconnect (action, priv->action_handler_id); - - priv->action_handler_id = g_signal_connect (action, "activate", - combined_stop_reload_action_entries[action_enum].callback, - ephy_window_action_get_window (EPHY_WINDOW_ACTION (action))); - - priv->loading = loading; -} - -static void -ephy_combined_stop_reload_action_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - EphyCombinedStopReloadAction *action = EPHY_COMBINED_STOP_RELOAD_ACTION (object); - - switch (property_id) { - case PROP_LOADING: - g_value_set_boolean (value, action->priv->loading); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -ephy_combined_stop_reload_action_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - EphyCombinedStopReloadAction *action = EPHY_COMBINED_STOP_RELOAD_ACTION (object); - - switch (property_id) { - case PROP_LOADING: - ephy_combined_stop_reload_action_set_loading (action, - g_value_get_boolean (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -ephy_combined_stop_reload_action_class_init (EphyCombinedStopReloadActionClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (EphyCombinedStopReloadActionPrivate)); - - object_class->get_property = ephy_combined_stop_reload_action_get_property; - object_class->set_property = ephy_combined_stop_reload_action_set_property; - - obj_properties[PROP_LOADING] = - g_param_spec_boolean ("loading", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties (object_class, LAST_PROP, obj_properties); -} - -static void -ephy_combined_stop_reload_action_init (EphyCombinedStopReloadAction *self) -{ - self->priv = COMBINED_STOP_RELOAD_ACTION_PRIVATE (self); -} diff --git a/src/ephy-combined-stop-reload-action.h b/src/ephy-combined-stop-reload-action.h deleted file mode 100644 index b6f465e01..000000000 --- a/src/ephy-combined-stop-reload-action.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set sw=2 ts=2 sts=2 et: */ -/* - * Copyright © 2011 Igalia S.L. - * - * 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_COMBINED_STOP_RELOAD_ACTION_H -#define _EPHY_COMBINED_STOP_RELOAD_ACTION_H - -#include <gtk/gtk.h> - -#include "ephy-window-action.h" - -G_BEGIN_DECLS - -#define EPHY_TYPE_COMBINED_STOP_RELOAD_ACTION (ephy_combined_stop_reload_action_get_type()) -#define EPHY_COMBINED_STOP_RELOAD_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EPHY_TYPE_COMBINED_STOP_RELOAD_ACTION, EphyCombinedStopReloadAction)) -#define EPHY_COMBINED_STOP_RELOAD_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EPHY_TYPE_COMBINED_STOP_RELOAD_ACTION, EphyCombinedStopReloadActionClass)) -#define EPHY_IS_COMBINED_STOP_RELOAD_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EPHY_TYPE_COMBINED_STOP_RELOAD_ACTION)) -#define EPHY_IS_COMBINED_STOP_RELOAD_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EPHY_TYPE_COMBINED_STOP_RELOAD_ACTION)) -#define EPHY_COMBINED_STOP_RELOAD_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EPHY_TYPE_COMBINED_STOP_RELOAD_ACTION, EphyCombinedStopReloadActionClass)) - -typedef struct _EphyCombinedStopReloadAction EphyCombinedStopReloadAction; -typedef struct _EphyCombinedStopReloadActionClass EphyCombinedStopReloadActionClass; -typedef struct _EphyCombinedStopReloadActionPrivate EphyCombinedStopReloadActionPrivate; - -struct _EphyCombinedStopReloadAction -{ - EphyWindowAction parent; - - /*< private >*/ - EphyCombinedStopReloadActionPrivate *priv; -}; - -struct _EphyCombinedStopReloadActionClass -{ - EphyWindowActionClass parent_class; -}; - -GType ephy_combined_stop_reload_action_get_type (void) G_GNUC_CONST; - -void ephy_combined_stop_reload_action_set_loading (EphyCombinedStopReloadAction *action, - gboolean loading); - -G_END_DECLS - -#endif /* _EPHY_COMBINED_STOP_RELOAD_ACTION_H */ diff --git a/src/ephy-toolbar.c b/src/ephy-toolbar.c index 7eb1b4c72..f19b31248 100644 --- a/src/ephy-toolbar.c +++ b/src/ephy-toolbar.c @@ -35,6 +35,7 @@ #include "ephy-private.h" #include "ephy-shell.h" +#include <glib/gi18n.h> #include <webkit2/webkit2.h> enum { @@ -55,8 +56,9 @@ struct _EphyToolbar { EphyTitleBox *title_box; GtkWidget *entry; GtkWidget *navigation_box; - GtkWidget *page_menu_button; GtkWidget *new_tab_button; + GtkWidget *combined_stop_reload_button; + GtkWidget *page_menu_button; GtkWidget *downloads_revealer; GtkWidget *downloads_button; GtkWidget *downloads_popover; @@ -545,12 +547,31 @@ navigation_leave_notify_event_cb (GtkButton *button, return G_SOURCE_REMOVE; } +void +ephy_toolbar_change_combined_stop_reload_state (GSimpleAction *action, + GVariant *loading, + gpointer user_data) +{ + EphyWindow *window = EPHY_WINDOW (user_data); + EphyToolbar *toolbar; + GtkWidget *image; + + if (g_variant_get_boolean (loading)) + image = gtk_image_new_from_icon_name ("process-stop-symbolic", + GTK_ICON_SIZE_BUTTON); + else + image = gtk_image_new_from_icon_name ("view-refresh-symbolic", + GTK_ICON_SIZE_BUTTON); + + toolbar = EPHY_TOOLBAR (ephy_window_get_toolbar (window)); + gtk_button_set_image (GTK_BUTTON (toolbar->combined_stop_reload_button), + image); +} + static void ephy_toolbar_constructed (GObject *object) { EphyToolbar *toolbar = EPHY_TOOLBAR (object); - GtkActionGroup *action_group; - GtkAction *action; GtkWidget *box, *button; GtkMenu *menu; EphyDownloadsManager *downloads_manager; @@ -616,16 +637,14 @@ ephy_toolbar_constructed (GObject *object) gtk_header_bar_pack_start (GTK_HEADER_BAR (toolbar), box); /* Reload/Stop */ - action_group = ephy_window_get_toolbar_action_group (toolbar->window); - button = gtk_button_new (); - /* FIXME: apparently we need an image inside the button for the action - * icon to appear. */ - gtk_button_set_image (GTK_BUTTON (button), gtk_image_new ()); + toolbar->combined_stop_reload_button = button; + gtk_button_set_image (GTK_BUTTON (button), + gtk_image_new_from_icon_name ("view-refresh-symbolic", GTK_ICON_SIZE_BUTTON)); gtk_widget_set_valign (button, GTK_ALIGN_CENTER); - action = gtk_action_group_get_action (action_group, "ViewCombinedStopReload"); - gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), - action); + gtk_actionable_set_action_name (GTK_ACTIONABLE (button), + "toolbar.combined-stop-reload"); + gtk_widget_show (GTK_WIDGET (button)); gtk_header_bar_pack_start (GTK_HEADER_BAR (toolbar), button); /* New Tab */ @@ -638,7 +657,6 @@ ephy_toolbar_constructed (GObject *object) gtk_button_set_label (GTK_BUTTON (button), NULL); gtk_header_bar_pack_start (GTK_HEADER_BAR (toolbar), button); - /* Location bar + Title */ toolbar->title_box = ephy_title_box_new (toolbar->window); toolbar->entry = ephy_title_box_get_location_entry (toolbar->title_box); diff --git a/src/ephy-toolbar.h b/src/ephy-toolbar.h index 6f3a23544..53434aa73 100644 --- a/src/ephy-toolbar.h +++ b/src/ephy-toolbar.h @@ -30,13 +30,17 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (EphyToolbar, ephy_toolbar, EPHY, TOOLBAR, GtkHeaderBar) -GtkWidget *ephy_toolbar_new (EphyWindow *window); +GtkWidget *ephy_toolbar_new (EphyWindow *window); -GtkWidget *ephy_toolbar_get_location_entry (EphyToolbar *toolbar); -EphyTitleBox *ephy_toolbar_get_title_box (EphyToolbar *toolbar); -GMenu *ephy_toolbar_get_page_menu (EphyToolbar *toolbar); -GtkWidget * ephy_toolbar_get_page_menu_button (EphyToolbar *toolbar); -GtkWidget * ephy_toolbar_get_new_tab_button (EphyToolbar *toolbar); +void ephy_toolbar_change_combined_stop_reload_state (GSimpleAction *action, + GVariant *state, + gpointer user_data); + +GtkWidget *ephy_toolbar_get_location_entry (EphyToolbar *toolbar); +EphyTitleBox *ephy_toolbar_get_title_box (EphyToolbar *toolbar); +GMenu *ephy_toolbar_get_page_menu (EphyToolbar *toolbar); +GtkWidget *ephy_toolbar_get_page_menu_button (EphyToolbar *toolbar); +GtkWidget *ephy_toolbar_get_new_tab_button (EphyToolbar *toolbar); G_END_DECLS diff --git a/src/ephy-window.c b/src/ephy-window.c index 5123362ef..79c7fe126 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -23,7 +23,6 @@ #include "ephy-action-helper.h" #include "ephy-bookmarks-ui.h" -#include "ephy-combined-stop-reload-action.h" #include "ephy-debug.h" #include "ephy-embed-container.h" #include "ephy-embed-prefs.h" @@ -94,15 +93,6 @@ static const GtkActionEntry ephy_menu_entries [] = { { "EditPreferences", NULL, N_("Pr_eferences"), "<control>e", NULL, G_CALLBACK (window_cmd_edit_preferences) }, - /* View actions. */ - - { "ViewStop", NULL, N_("_Stop"), "Escape", NULL, - G_CALLBACK (window_cmd_view_stop) }, - { "ViewAlwaysStop", NULL, N_("_Stop"), "Escape", - NULL, G_CALLBACK (window_cmd_view_stop) }, - { "ViewReload", NULL, N_("_Reload"), "<control>R", NULL, - G_CALLBACK (window_cmd_view_reload) }, - /* Bookmarks actions. */ { "FileBookmarkPage", NULL, N_("_Add Bookmark…"), "<control>D", NULL, @@ -214,11 +204,6 @@ static const struct { /* FIXME: these are not in any menu for now, so add them here. */ { GDK_KEY_F11, 0, "ViewFullscreen", FALSE }, - { GDK_KEY_r, GDK_CONTROL_MASK, "ViewReload", FALSE }, - { GDK_KEY_R, GDK_CONTROL_MASK, "ViewReload", FALSE }, - { GDK_KEY_R, GDK_CONTROL_MASK | - GDK_SHIFT_MASK, "ViewReload", FALSE }, - /* Tab navigation */ { GDK_KEY_Page_Up, GDK_CONTROL_MASK, "TabsPrevious", FALSE }, { GDK_KEY_Page_Down, GDK_CONTROL_MASK, "TabsNext", FALSE }, @@ -230,11 +215,6 @@ static const struct { { GDK_KEY_l, GDK_CONTROL_MASK, "GoLocation", FALSE }, { GDK_KEY_F6, 0, "GoLocation", FALSE }, /* Support all the MSIE tricks as well ;) */ - { GDK_KEY_F5, 0, "ViewReload", FALSE }, - { GDK_KEY_F5, GDK_CONTROL_MASK, "ViewReload", FALSE }, - { GDK_KEY_F5, GDK_SHIFT_MASK, "ViewReload", FALSE }, - { GDK_KEY_F5, GDK_CONTROL_MASK | - GDK_SHIFT_MASK, "ViewReload", FALSE }, /* These keys are a bit strange: when pressed with no modifiers, they emit * KP_PageUp/Down Control; when pressed with Control+Shift they are KP_9/3, * when NumLock is on they are KP_9/3 and with NumLock and Control+Shift @@ -252,19 +232,16 @@ static const struct { { XF86XK_Go, 0, "GoLocation", FALSE }, { XF86XK_OpenURL, 0, "GoLocation", FALSE }, { XF86XK_AddFavorite, 0, "FileBookmarkPage", FALSE }, - { XF86XK_Refresh, 0, "ViewReload", FALSE }, - { XF86XK_Reload, 0, "ViewReload", FALSE }, { XF86XK_Send, 0, "FileSendTo", FALSE }, - { XF86XK_Stop, 0, "ViewStop", FALSE }, /* FIXME: what about ScrollUp, ScrollDown, Menu*, Option, LogOff, Save,.. any others? */ #endif /* HAVE_X11_XF86KEYSYM_H */ }; const struct { const gchar *action_and_target; - const gchar *accelerators[5]; + const gchar *accelerators[9]; } accels [] = { - /* Window accels */ + /* Page Menu accels */ { "win.new-tab", { "<Primary>T", NULL } }, { "win.open", { "<Primary>O", NULL } }, { "win.save-as", { "<shift><Primary>S", "<Primary>S", NULL } }, @@ -274,7 +251,6 @@ const struct { { "win.copy", { "<Primary>C", NULL } }, { "win.cut", { "<Primary>X", NULL } }, { "win.paste", { "<Primary>V", NULL } }, - { "win.select-all", { "<Primary>A", NULL } }, { "win.zoom-in", { "<Primary>plus", "<Primary>KP_Add", "<Primary>equal", "ZoomIn", NULL } }, { "win.zoom-out", { "<Primary>minus", "<Primary>KP_Subtract", "ZoomOut", NULL } }, { "win.zoom-normal", { "<Primary>0", "<Primary>KP_0", NULL } }, @@ -286,6 +262,13 @@ const struct { { "win.page-source", { "<Primary>U", NULL } }, { "win.toggle-inspector", { "<shift><Primary>I", "F12", NULL } }, { "win.close", { "<Primary>W", NULL } }, + + { "win.select-all", { "<Primary>A", NULL } }, + + /* Navigation */ + { "toolbar.stop", { "Escape", "Stop", NULL } }, + { "toolbar.reload", { "<Primary>R", "<shift><Primary>R", "F5", "<Primary>F5", "<shift>F5", "<shift><Primary>F5", "Refresh", "Reload", NULL } }, + { "toolbar.combined-stop-reload", { NULL } } }, accels_navigation_ltr [] = { { "toolbar.navigation-back", { "<alt>Left", "<alt>KP_Left", "KP_4", "Back", NULL } }, { "toolbar.navigation-forward", { "<alt>Right", "<alt>KP_Right", "KP_6", "Forward", NULL } } @@ -627,31 +610,31 @@ sync_tab_load_status (EphyWebView *view, WebKitLoadEvent load_event, EphyWindow *window) { - GtkActionGroup *action_group = window->action_group; - GtkAction *action; - GActionGroup *new_action_group; - GAction *new_action; + GActionGroup *action_group; + GAction *action; gboolean loading; if (window->closing) return; loading = ephy_web_view_is_loading (view); - new_action_group = gtk_widget_get_action_group (GTK_WIDGET (window), - "win"); - - action = gtk_action_group_get_action (action_group, "ViewStop"); - gtk_action_set_sensitive (action, loading); + action_group = gtk_widget_get_action_group (GTK_WIDGET (window), "win"); /* disable print while loading, see bug #116344 */ - new_action = g_action_map_lookup_action (G_ACTION_MAP (new_action_group), + action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "print"); - new_ephy_action_change_sensitivity_flags (G_SIMPLE_ACTION (new_action), SENS_FLAG_LOADING, loading); + new_ephy_action_change_sensitivity_flags (G_SIMPLE_ACTION (action), + SENS_FLAG_LOADING, loading); - action = gtk_action_group_get_action (window->toolbar_action_group, - "ViewCombinedStopReload"); - ephy_combined_stop_reload_action_set_loading (EPHY_COMBINED_STOP_RELOAD_ACTION (action), - loading); + action_group = gtk_widget_get_action_group (GTK_WIDGET (window), "toolbar"); + + action = g_action_map_lookup_action (G_ACTION_MAP (action_group), + "stop"); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), loading); + + action = g_action_map_lookup_action (G_ACTION_MAP (action_group), + "combined-stop-reload"); + g_action_change_state (action, g_variant_new_boolean (loading)); } static void @@ -1038,7 +1021,12 @@ static const GActionEntry ephy_toolbar_entries [] = { { "navigation-back", window_cmd_navigation, "s" }, { "navigation-back-new-tab", window_cmd_navigation_new_tab, "s" }, { "navigation-forward", window_cmd_navigation, "s" }, - { "navigation-forward-new-tab", window_cmd_navigation_new_tab, "s" } + { "navigation-forward-new-tab", window_cmd_navigation_new_tab, "s" }, + + { "stop", window_cmd_view_stop }, + { "reload", window_cmd_view_reload }, + { "always-stop", window_cmd_view_stop }, + { "combined-stop-reload", window_cmd_combined_stop_reload, NULL, "false", ephy_toolbar_change_combined_stop_reload_state } }; static void @@ -1096,14 +1084,6 @@ setup_ui_manager (EphyWindow *window) G_CALLBACK (ephy_link_open), window); g_object_unref (action); - action = g_object_new (EPHY_TYPE_COMBINED_STOP_RELOAD_ACTION, - "name", "ViewCombinedStopReload", - "loading", FALSE, - "window", window, - NULL); - gtk_action_group_add_action (action_group, action); - g_object_unref (action); - gtk_action_group_set_accel_group (action_group, accel_group); gtk_ui_manager_insert_action_group (manager, action_group, 0); window->toolbar_action_group = action_group; @@ -1173,9 +1153,10 @@ _ephy_window_set_default_actions_sensitive (EphyWindow *window, flags, set); /* Toolbar */ - action = gtk_action_group_get_action (window->toolbar_action_group, - "ViewCombinedStopReload"); - ephy_action_change_sensitivity_flags (action, + new_action_group = gtk_widget_get_action_group (GTK_WIDGET (window), "toolbar"); + new_action = g_action_map_lookup_action (G_ACTION_MAP (new_action_group), + "combined-stop-reload"); + new_ephy_action_change_sensitivity_flags (G_SIMPLE_ACTION (new_action), flags, set); } @@ -1806,8 +1787,8 @@ populate_context_menu (WebKitWebView *web_view, "navigation-back", window->toolbar); new_add_action_to_context_menu (context_menu, toolbar_action_group, "navigation-forward", window->toolbar); - add_action_to_context_menu (context_menu, - window->action_group, "ViewReload"); + new_add_action_to_context_menu (context_menu, toolbar_action_group, + "reload", window->toolbar); webkit_context_menu_append (context_menu, webkit_context_menu_item_new_separator ()); } @@ -3086,13 +3067,11 @@ ephy_window_constructor (GType type, { GObject *object; EphyWindow *window; - EphyToolbar *toolbar; GtkSettings *settings; GtkAction *action; GAction *new_action; GActionGroup *new_action_group; GSimpleActionGroup *new_simple_action_group; - GtkActionGroup *toolbar_action_group; GError *error = NULL; guint settings_connection; GtkCssProvider *css_provider; @@ -3213,7 +3192,6 @@ ephy_window_constructor (GType type, "win"); /* Disable actions not needed for popup mode. */ - toolbar_action_group = window->toolbar_action_group; new_action = g_action_map_lookup_action (G_ACTION_MAP (new_action_group), "new-tab"); new_ephy_action_change_sensitivity_flags (G_SIMPLE_ACTION (new_action), SENS_FLAG_CHROME, @@ -3577,6 +3555,20 @@ ephy_window_get_location_controller (EphyWindow *window) return window->location_controller; } +/** + * ephy_window_get_toolbar: + * @window: an #EphyWindow + * + * Returns the @window #EphyToolbar + * + * Returns: (transfer none): the @window #EphyToolbar + **/ +GtkWidget * +ephy_window_get_toolbar (EphyWindow *window) +{ + return window->toolbar; +} + typedef struct { EphyWindow *window; GCancellable *cancellable; diff --git a/src/ephy-window.h b/src/ephy-window.h index 8eb28dc4d..0279cec8c 100644 --- a/src/ephy-window.h +++ b/src/ephy-window.h @@ -52,6 +52,8 @@ void ephy_window_set_zoom (EphyWindow *window, void ephy_window_activate_location (EphyWindow *window); const char *ephy_window_get_location (EphyWindow *window); +GtkWidget *ephy_window_get_toolbar (EphyWindow *window); + gboolean ephy_window_close (EphyWindow *window); EphyWindowChrome ephy_window_get_chrome (EphyWindow *window); diff --git a/src/resources/epiphany-ui.xml b/src/resources/epiphany-ui.xml index 18b7dc643..134165165 100644 --- a/src/resources/epiphany-ui.xml +++ b/src/resources/epiphany-ui.xml @@ -16,7 +16,5 @@ </menu> </popup> - <accelerator name="AlwaysStopAccel" action="ViewAlwaysStop"/> <accelerator name="BrowseWithCaretAccel" action="BrowseWithCaret"/> - </ui> diff --git a/src/window-commands.c b/src/window-commands.c index 4047d682b..dd9f0989c 100644 --- a/src/window-commands.c +++ b/src/window-commands.c @@ -140,51 +140,20 @@ window_cmd_navigation_new_tab (GSimpleAction *action, } void -window_cmd_undo_close_tab (GtkAction *action, - EphyWindow *window) -{ - ephy_session_undo_close_tab (ephy_shell_get_session (ephy_shell_get_default ())); -} - -void -window_cmd_file_send_to (GtkAction *action, - EphyWindow *window) +window_cmd_view_stop (GSimpleAction *action, + GVariant *value, + gpointer user_data) { + EphyWindow *window = EPHY_WINDOW (user_data); EphyEmbed *embed; - char *command, *subject, *body; - const char *location, *title; - GdkScreen *screen; - GError *error = NULL; embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window)); g_return_if_fail (embed != NULL); - location = ephy_web_view_get_address (ephy_embed_get_web_view (embed)); - title = ephy_embed_get_title (embed); - - subject = g_uri_escape_string (title, NULL, TRUE); - body = g_uri_escape_string (location, NULL, TRUE); - - command = g_strconcat ("mailto:", - "?Subject=", subject, - "&Body=", body, NULL); - - g_free (subject); - g_free (body); - - if (window) { - screen = gtk_widget_get_screen (GTK_WIDGET (window)); - } else { - screen = gdk_screen_get_default (); - } - - if (!gtk_show_uri (screen, command, gtk_get_current_event_time (), &error)) { - g_warning ("Unable to send link by email: %s\n", error->message); - g_error_free (error); - } + gtk_widget_grab_focus (GTK_WIDGET (embed)); - g_free (command); + webkit_web_view_stop_loading (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed)); } static gboolean @@ -211,17 +180,13 @@ event_with_shift (void) } void -window_cmd_go_location (GtkAction *action, - EphyWindow *window) -{ - ephy_window_activate_location (window); -} - -void -window_cmd_view_stop (GtkAction *action, - EphyWindow *window) +window_cmd_view_reload (GSimpleAction *action, + GVariant *value, + gpointer user_data) { + EphyWindow *window = EPHY_WINDOW (user_data); EphyEmbed *embed; + WebKitWebView *view; embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window)); @@ -229,27 +194,88 @@ window_cmd_view_stop (GtkAction *action, gtk_widget_grab_focus (GTK_WIDGET (embed)); - webkit_web_view_stop_loading (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed)); + view = EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed); + if (event_with_shift ()) + webkit_web_view_reload_bypass_cache (view); + else + webkit_web_view_reload (view); +} + +void window_cmd_combined_stop_reload (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + GActionGroup *action_group; + GAction *gaction; + GVariant *state; + + action_group = gtk_widget_get_action_group (GTK_WIDGET (user_data), "toolbar"); + + state = g_action_get_state (G_ACTION (action)); + /* If loading */ + if (g_variant_get_boolean (state)) + gaction = g_action_map_lookup_action (G_ACTION_MAP (action_group), "stop"); + else + gaction = g_action_map_lookup_action (G_ACTION_MAP (action_group), "reload"); + + g_action_activate (gaction, NULL); + + g_variant_unref (state); } void -window_cmd_view_reload (GtkAction *action, - EphyWindow *window) +window_cmd_undo_close_tab (GtkAction *action, + EphyWindow *window) +{ + ephy_session_undo_close_tab (ephy_shell_get_session (ephy_shell_get_default ())); +} + +void +window_cmd_file_send_to (GtkAction *action, + EphyWindow *window) { EphyEmbed *embed; - WebKitWebView *view; + char *command, *subject, *body; + const char *location, *title; + GdkScreen *screen; + GError *error = NULL; embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window)); g_return_if_fail (embed != NULL); - gtk_widget_grab_focus (GTK_WIDGET (embed)); + location = ephy_web_view_get_address (ephy_embed_get_web_view (embed)); + title = ephy_embed_get_title (embed); - view = EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed); - if (event_with_shift ()) - webkit_web_view_reload_bypass_cache (view); - else - webkit_web_view_reload (view); + subject = g_uri_escape_string (title, NULL, TRUE); + body = g_uri_escape_string (location, NULL, TRUE); + + command = g_strconcat ("mailto:", + "?Subject=", subject, + "&Body=", body, NULL); + + g_free (subject); + g_free (body); + + if (window) { + screen = gtk_widget_get_screen (GTK_WIDGET (window)); + } else { + screen = gdk_screen_get_default (); + } + + if (!gtk_show_uri (screen, command, gtk_get_current_event_time (), &error)) { + g_warning ("Unable to send link by email: %s\n", error->message); + g_error_free (error); + } + + g_free (command); +} + +void +window_cmd_go_location (GtkAction *action, + EphyWindow *window) +{ + ephy_window_activate_location (window); } void diff --git a/src/window-commands.h b/src/window-commands.h index 463306f91..d3c811ccf 100644 --- a/src/window-commands.h +++ b/src/window-commands.h @@ -30,12 +30,17 @@ void window_cmd_navigation (GSimpleAction *action, void window_cmd_navigation_new_tab (GSimpleAction *action, GVariant *value, gpointer user_data); -void window_cmd_view_stop (GtkAction *action, - EphyWindow *window); +void window_cmd_view_stop (GSimpleAction *action, + GVariant *value, + gpointer user_data); +void window_cmd_view_reload (GSimpleAction *action, + GVariant *value, + gpointer user_data); +void window_cmd_combined_stop_reload (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); void window_cmd_go_location (GtkAction *action, EphyWindow *window); -void window_cmd_view_reload (GtkAction *action, - EphyWindow *window); void window_cmd_file_bookmark_page (GtkAction *action, EphyWindow *window); void window_cmd_undo_close_tab (GtkAction *action, |