[epiphany/wip/gtkaction-to-gaction] Use GActions for tab context menu
- From: Iulian Radu <iulianradu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/gtkaction-to-gaction] Use GActions for tab context menu
- Date: Wed, 29 Jun 2016 10:06:40 +0000 (UTC)
commit 7ef60cb754e2357cbb521fbaa933a9eccbd00504
Author: Iulian Radu <iulian radu67 gmail com>
Date: Wed Jun 29 13:06:27 2016 +0300
Use GActions for tab context menu
src/ephy-lockdown.c | 12 ++-
src/ephy-window.c | 176 +++++++++++++++--------------
src/resources/epiphany-ui.xml | 10 --
src/resources/gtk/menus.ui | 22 ++++-
src/window-commands.c | 248 +++++++++++++++++++++--------------------
src/window-commands.h | 37 ++++---
6 files changed, 271 insertions(+), 234 deletions(-)
---
diff --git a/src/ephy-lockdown.c b/src/ephy-lockdown.c
index 07103eb..85abc1f 100644
--- a/src/ephy-lockdown.c
+++ b/src/ephy-lockdown.c
@@ -104,7 +104,6 @@ static const BindAction window_actions[] = {
{ EPHY_PREFS_LOCKDOWN_ARBITRARY_URL, "GoLocation", "sensitive" },
{ EPHY_PREFS_LOCKDOWN_FULLSCREEN, "ViewFullscreen", "sensitive" },
- { EPHY_PREFS_LOCKDOWN_FULLSCREEN, "TabsDetach", "sensitive" },
};
static const BindAction app_actions[] = {
@@ -126,6 +125,10 @@ static const BindAction popup_actions[] = {
{ EPHY_PREFS_LOCKDOWN_FULLSCREEN, "OpenLinkInNewWindow", "sensitive" }
};
+static const BindAction tab_actions[] = {
+ EPHY_PREFS_LOCKDOWN_FULLSCREEN, "detach", "enabled"
+};
+
static const BindAction toolbar_actions[] = {
{ EPHY_PREFS_LOCKDOWN_HISTORY, "navigation-back", "enabled" },
{ EPHY_PREFS_LOCKDOWN_HISTORY, "navigation-forward", "enabled" }
@@ -312,6 +315,13 @@ window_added_cb (GtkApplication *application,
action, "sensitive", FALSE);
new_action_group = gtk_widget_get_action_group (GTK_WIDGET (window),
+ "tab");
+ new_bind_settings_and_actions (EPHY_SETTINGS_LOCKDOWN,
+ new_action_group,
+ tab_actions,
+ G_N_ELEMENTS (tab_actions));
+
+ new_action_group = gtk_widget_get_action_group (GTK_WIDGET (window),
"toolbar");
new_bind_settings_and_actions (EPHY_SETTINGS_LOCKDOWN,
new_action_group,
diff --git a/src/ephy-window.c b/src/ephy-window.c
index e464be4..29a4315 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -80,7 +80,6 @@ static const GtkActionEntry ephy_menu_entries [] = {
{ "Bookmarks", NULL, N_("_Bookmarks") },
{ "PopupAction", NULL, "" },
{ "PagePopupAction", NULL, "" },
- { "NotebookPopupAction", NULL, "" },
/* File actions. */
@@ -102,21 +101,6 @@ static const GtkActionEntry ephy_menu_entries [] = {
{ "GoLocation", NULL, N_("_Location…"), "<control>L", NULL,
G_CALLBACK (window_cmd_go_location) },
-
- /* Tabs actions. */
-
- { "TabsPrevious", NULL, N_("_Previous Tab"), "<control>Page_Up", NULL,
- G_CALLBACK (window_cmd_tabs_previous) },
- { "TabsNext", NULL, N_("_Next Tab"), "<control>Page_Down", NULL,
- G_CALLBACK (window_cmd_tabs_next) },
- { "TabsMoveLeft", NULL, N_("Move Tab _Left"), "<shift><control>Page_Up", NULL,
- G_CALLBACK (window_cmd_tabs_move_left) },
- { "TabsMoveRight", NULL, N_("Move Tab _Right"), "<shift><control>Page_Down", NULL,
- G_CALLBACK (window_cmd_tabs_move_right) },
- { "TabsDuplicate", NULL, N_("Du_plicate"), "<shift><control>D", NULL,
- G_CALLBACK (window_cmd_tabs_duplicate) },
- { "TabsDetach", NULL, N_("_Detach Tab"), NULL, NULL,
- G_CALLBACK (window_cmd_tabs_detach) },
};
static const GtkToggleActionEntry ephy_menu_toggle_entries [] =
@@ -202,30 +186,9 @@ static const struct {
/* FIXME: these are not in any menu for now, so add them here. */
{ GDK_KEY_F11, 0, "ViewFullscreen", FALSE },
- /* Tab navigation */
- { GDK_KEY_Page_Up, GDK_CONTROL_MASK, "TabsPrevious", FALSE },
- { GDK_KEY_Page_Down, GDK_CONTROL_MASK, "TabsNext", FALSE },
- { GDK_KEY_Page_Up, GDK_CONTROL_MASK |
- GDK_SHIFT_MASK, "TabsMoveLeft", FALSE },
- { GDK_KEY_Page_Down, GDK_CONTROL_MASK |
- GDK_SHIFT_MASK, "TabsMoveRight", FALSE },
/* Go */
{ GDK_KEY_l, GDK_CONTROL_MASK, "GoLocation", FALSE },
{ GDK_KEY_F6, 0, "GoLocation", FALSE },
- /* Support all the MSIE tricks as well ;) */
- /* 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
- * They're KP_PageUp/Down again!
- */
- { GDK_KEY_KP_Page_Up, GDK_CONTROL_MASK, "TabsPrevious", FALSE },
- { GDK_KEY_KP_9, GDK_CONTROL_MASK, "TabsPrevious", FALSE },
- { GDK_KEY_KP_Page_Down, GDK_CONTROL_MASK, "TabsNext", FALSE },
- { GDK_KEY_KP_3, GDK_CONTROL_MASK, "TabsNext", FALSE },
- { GDK_KEY_KP_Page_Up, GDK_SHIFT_MASK | GDK_CONTROL_MASK, "TabsMoveLeft", FALSE },
- { GDK_KEY_KP_9, GDK_SHIFT_MASK | GDK_CONTROL_MASK, "TabsMoveLeft", FALSE },
- { GDK_KEY_KP_Page_Down, GDK_SHIFT_MASK | GDK_CONTROL_MASK, "TabsMoveRight", FALSE },
- { GDK_KEY_KP_3, GDK_SHIFT_MASK | GDK_CONTROL_MASK, "TabsMoveRight", FALSE },
#ifdef HAVE_X11_XF86KEYSYM_H
{ XF86XK_Go, 0, "GoLocation", FALSE },
{ XF86XK_OpenURL, 0, "GoLocation", FALSE },
@@ -259,7 +222,6 @@ const struct {
{ "win.encoding", { NULL } },
{ "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 } },
@@ -268,7 +230,15 @@ const struct {
/* 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 } }
+ { "toolbar.combined-stop-reload", { NULL } },
+
+ /* Tabs */
+ { "tab.previous", { "<Primary>Page_Up", "<Primary>KP_9", NULL } },
+ { "tab.next", { "<Primary>Page_Down", "<Primary>KP_3", NULL } },
+ { "tab.move-left", { "<shift><Primary>Page_Up", "<shift><Primary>Page_Up", NULL } },
+ { "tab.move-right", { "<shift><Primary>Page_Down", "<shift><Primary>Page_Down", NULL } },
+ { "tab.duplicate", { "<shift><Primary>D", NULL } },
+ { "tab.close", { "<Primary>W", 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 } }
@@ -1016,13 +986,22 @@ static const GActionEntry window_entries [] =
{ "encoding", window_cmd_view_encoding },
{ "page-source", window_cmd_view_page_source },
{ "toggle-inspector", window_cmd_view_toggle_inspector },
- { "close-tab", window_cmd_file_close_window },
{ "select-all", window_cmd_edit_select_all },
{ "browse-with-caret", activate_toggle, NULL, "false", window_cmd_change_browse_with_caret }
};
+static const GActionEntry tab_entries [] = {
+ { "previous", window_cmd_tabs_previous },
+ { "next", window_cmd_tabs_next },
+ { "move-left", window_cmd_tabs_move_left },
+ { "move-right", window_cmd_tabs_move_right },
+ { "duplicate", window_cmd_tabs_duplicate },
+ { "detach", window_cmd_tabs_detach },
+ { "close", window_cmd_tabs_close }
+};
+
static const GActionEntry toolbar_entries [] = {
{ "navigation-back", window_cmd_navigation, "s" },
{ "navigation-back-new-tab", window_cmd_navigation_new_tab, "s" },
@@ -2417,34 +2396,44 @@ ephy_window_set_active_tab (EphyWindow *window, EphyEmbed *new_embed)
}
static void
-tab_accels_item_activate (GtkAction *action,
- EphyWindow *window)
+tab_accels_item_activate (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
- const char *name;
+ const gchar *action_name;
int tab_number;
- name = gtk_action_get_name (action);
- tab_number = atoi (name + strlen ("TabAccel"));
+ action_name = g_action_get_name (G_ACTION (action));
+
+ tab_number = atoi (action_name + strlen ("accel-"));
- gtk_notebook_set_current_page (window->notebook, tab_number);
+ gtk_notebook_set_current_page (EPHY_WINDOW (user_data)->notebook, tab_number);
+
+ g_free (action_name);
}
static void
tab_accels_update (EphyWindow *window)
{
- int pages, i = 0;
- GList *actions, *l;
+ gint n_pages, i = 0;
+ GActionGroup *action_group;
+ gchar **actions;
- actions = gtk_action_group_list_actions (window->tab_accels_action_group);
- pages = gtk_notebook_get_n_pages (window->notebook);
- for (l = actions; l != NULL; l = l->next) {
- GtkAction *action = GTK_ACTION (l->data);
+ action_group = gtk_widget_get_action_group (GTK_WIDGET (window), "tab");
+ actions = g_action_group_list_actions (action_group);
- gtk_action_set_sensitive (action, (i < pages));
+ n_pages = gtk_notebook_get_n_pages (window->notebook);
+ for (i = 0; actions[i] != NULL; i++) {
+ if (strstr (actions[i], "accel-") != NULL) {
+ GAction *action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
+ actions[i]);
+ int tab_number = atoi (actions[i] + strlen ("accel-"));
- i++;
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), (tab_number < n_pages));
+ }
}
- g_list_free (actions);
+
+ g_strfreev (actions);
}
#define TAB_ACCELS_N 10
@@ -2452,33 +2441,34 @@ tab_accels_update (EphyWindow *window)
static void
setup_tab_accels (EphyWindow *window)
{
- guint id;
- int i;
+ GActionGroup *action_group;
+ GApplication *app;
+ guint i;
- id = gtk_ui_manager_new_merge_id (window->manager);
+ action_group = gtk_widget_get_action_group (GTK_WIDGET (window), "tab");
+ app = g_application_get_default ();
for (i = 0; i < TAB_ACCELS_N; i++) {
- GtkAction *action;
- char *name;
+ GSimpleAction *simple_action;
+ char *action_name;
char *accel;
- name = g_strdup_printf ("TabAccel%d", i);
+ action_name = g_strdup_printf ("accel-%d", i);
accel = g_strdup_printf ("<alt>%d", (i + 1) % TAB_ACCELS_N);
- action = gtk_action_new (name, NULL, NULL, NULL);
- gtk_action_group_add_action_with_accel (window->tab_accels_action_group,
- action, accel);
+ simple_action = g_simple_action_new (action_name, NULL);
- g_signal_connect (action, "activate",
+ g_action_map_add_action (G_ACTION_MAP (action_group), G_ACTION (simple_action));
+ gtk_application_set_accels_for_action (GTK_APPLICATION (app),
+ g_strconcat ("tab.", action_name, NULL),
+ (const gchar*[]) {accel, NULL});
+
+ g_signal_connect (G_ACTION (simple_action), "activate",
G_CALLBACK (tab_accels_item_activate), window);
- gtk_ui_manager_add_ui (window->manager, id, "/",
- name, name,
- GTK_UI_MANAGER_ACCELERATOR,
- FALSE);
- g_object_unref (action);
+ g_object_unref (simple_action);
g_free (accel);
- g_free (name);
+ g_free (action_name);
}
}
@@ -2488,16 +2478,22 @@ show_notebook_popup_menu (GtkNotebook *notebook,
GdkEventButton *event)
{
GtkWidget *menu, *tab, *tab_label;
- GtkAction *action;
+ GMenu *menu_model;
+ GtkBuilder *builder;
+ GActionGroup *action_group;
+ GAction *action;
- menu = gtk_ui_manager_get_widget (window->manager, "/EphyNotebookPopup");
- g_return_val_if_fail (menu != NULL, FALSE);
+ builder = gtk_builder_new_from_resource ("/org/gnome/epiphany/gtk/menus.ui");
+ if (!builder) {
+ g_object_unref (builder);
+ return FALSE;
+ }
- /* allow extensions to sync when showing the popup */
- action = gtk_action_group_get_action (window->action_group,
- "NotebookPopupAction");
- g_return_val_if_fail (action != NULL, FALSE);
- gtk_action_activate (action);
+ menu_model = G_MENU (gtk_builder_get_object (builder, "notebook-menu"));
+ menu = gtk_menu_new_from_model (G_MENU_MODEL (menu_model));
+ gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (window), NULL);
+
+ action_group = gtk_widget_get_action_group (GTK_WIDGET (window), "tab");
if (event != NULL) {
gint n_pages, page_num;
@@ -2507,13 +2503,13 @@ show_notebook_popup_menu (GtkNotebook *notebook,
page_num = gtk_notebook_page_num (notebook, tab);
/* enable/disable move left/right items*/
- action = gtk_action_group_get_action (window->action_group,
- "TabsMoveLeft");
- gtk_action_set_sensitive (action, page_num > 0);
+ action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
+ "move-left");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), page_num > 0);
- action = gtk_action_group_get_action (window->action_group,
- "TabsMoveRight");
- gtk_action_set_sensitive (action, page_num < n_pages - 1);
+ action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
+ "move-right");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), page_num < n_pages - 1);
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
NULL, NULL,
@@ -2528,6 +2524,8 @@ show_notebook_popup_menu (GtkNotebook *notebook,
gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
}
+ g_object_unref (builder);
+
return TRUE;
}
@@ -3113,6 +3111,14 @@ ephy_window_constructor (GType type,
simple_action_group = g_simple_action_group_new ();
g_action_map_add_action_entries (G_ACTION_MAP (simple_action_group),
+ tab_entries,
+ G_N_ELEMENTS (tab_entries),
+ window);
+ gtk_widget_insert_action_group (GTK_WIDGET (window), "tab",
+ G_ACTION_GROUP (simple_action_group));
+
+ simple_action_group = g_simple_action_group_new ();
+ g_action_map_add_action_entries (G_ACTION_MAP (simple_action_group),
toolbar_entries,
G_N_ELEMENTS (toolbar_entries),
window);
diff --git a/src/resources/epiphany-ui.xml b/src/resources/epiphany-ui.xml
index fac73a4..2c99692 100644
--- a/src/resources/epiphany-ui.xml
+++ b/src/resources/epiphany-ui.xml
@@ -1,14 +1,4 @@
<ui>
- <popup name="EphyNotebookPopup" action="NotebookPopupAction">
- <placeholder name="TabsMoveGroupENP" position="top">
- <menuitem name="TabMoveLeftENP" action="TabsMoveLeft"/>
- <menuitem name="TabMoveRightENP" action="TabsMoveRight"/>
- </placeholder>
- <menuitem name="TabDuplicateENP" action="TabsDuplicate"/>
- <!-- <menuitem name="TabCloseENP" action="FileCloseTab"/> -->
- <!-- <menuitem name="TabDetachENP" action="TabsDetach"/> -->
- </popup>
-
<popup name="PagePopup" action="PagePopupAction" accelerators="true">
<menu name="BookmarksMenu" action="Bookmarks">
<menuitem name="BookmarksAddBookmarkMenu" action="FileBookmarkPage"/>
diff --git a/src/resources/gtk/menus.ui b/src/resources/gtk/menus.ui
index ac594c6..b13ff7c 100644
--- a/src/resources/gtk/menus.ui
+++ b/src/resources/gtk/menus.ui
@@ -91,7 +91,27 @@
<section>
<item>
<attribute name="label" translatable="yes">_Close</attribute>
- <attribute name="action">win.close-tab</attribute>
+ <attribute name="action">tab.close</attribute>
+ </item>
+ </section>
+ </menu>
+ <menu id="notebook-menu">
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">Move Tab _Left</attribute>
+ <attribute name="action">tab.move-left</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Move Tab _Right</attribute>
+ <attribute name="action">tab.move-right</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Du_plicate</attribute>
+ <attribute name="action">tab.duplicate</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Close</attribute>
+ <attribute name="action">tab.close</attribute>
</item>
</section>
</menu>
diff --git a/src/window-commands.c b/src/window-commands.c
index 3496b46..7971e64 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -1507,29 +1507,6 @@ window_cmd_view_toggle_inspector (GSimpleAction *action,
}
void
-window_cmd_file_close_window (GSimpleAction *action,
- GVariant *value,
- gpointer user_data)
-{
- EphyWindow *window = user_data;
- GtkWidget *notebook;
- EphyEmbed *embed;
-
- notebook = ephy_window_get_notebook (window);
-
- if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN,
- EPHY_PREFS_LOCKDOWN_QUIT) &&
- gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)) == 1) {
- return;
- }
-
- embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
- g_return_if_fail (embed != NULL);
-
- g_signal_emit_by_name (notebook, "tab-close-request", embed);
-}
-
-void
window_cmd_help_contents (GtkAction *action,
GtkWidget *window)
{
@@ -1652,38 +1629,127 @@ window_cmd_help_about (GtkAction *action,
}
void
-window_cmd_tabs_next (GtkAction *action,
- EphyWindow *window)
+window_cmd_load_location (GtkAction *action,
+ EphyWindow *window)
+{
+ const char *location;
+
+ location = ephy_window_get_location (window);
+
+ if (location) {
+ EphyBookmarks *bookmarks;
+ char *address;
+
+ bookmarks = ephy_shell_get_bookmarks (ephy_shell_get_default ());
+
+ address = ephy_bookmarks_resolve_address (bookmarks, location, NULL);
+ g_return_if_fail (address != NULL);
+
+ ephy_link_open (EPHY_LINK (window), address,
+ ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window)),
+ ephy_link_flags_from_current_event ());
+ }
+}
+
+void
+window_cmd_edit_select_all (GSimpleAction *action,
+ GVariant *value,
+ gpointer user_data)
+{
+ EphyWindow *window = user_data;
+
+ GtkWidget *widget = gtk_window_get_focus (GTK_WINDOW (window));
+
+ if (GTK_IS_EDITABLE (widget)) {
+ gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
+ } else {
+ EphyEmbed *embed;
+
+ embed = ephy_embed_container_get_active_child
+ (EPHY_EMBED_CONTAINER (window));
+ g_return_if_fail (embed != NULL);
+
+ webkit_web_view_execute_editing_command (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed), "SelectAll");
+ }
+}
+
+void
+window_cmd_change_browse_with_caret (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ EphyWindow *window = EPHY_WINDOW (user_data);
+ gboolean active;
+
+ active = g_variant_get_boolean (state);
+
+ if (active) {
+ GtkWidget *dialog;
+ int response;
+
+ dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_QUESTION, GTK_BUTTONS_CANCEL,
+ _("Enable caret browsing mode?"));
+
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ _("Pressing F7 turns caret browsing on or off. This feature "
+ "places a moveable cursor in web pages, allowing you to move
"
+ "around with your keyboard. Do you want to enable caret
browsing?"));
+ gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Enable"), GTK_RESPONSE_ACCEPT);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
+
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ gtk_widget_destroy (dialog);
+
+ if (response == GTK_RESPONSE_CANCEL) {
+ g_simple_action_set_state (action, g_variant_new_boolean (FALSE));
+ return;
+ }
+ }
+
+ g_simple_action_set_state (action, g_variant_new_boolean (active));
+ g_settings_set_boolean (EPHY_SETTINGS_MAIN,
+ EPHY_PREFS_ENABLE_CARET_BROWSING, active);
+}
+
+void
+window_cmd_tabs_previous (GSimpleAction *action,
+ GVariant *variant,
+ gpointer user_data)
{
GtkWidget *nb;
- nb = ephy_window_get_notebook (window);
+ nb = ephy_window_get_notebook (EPHY_WINDOW (user_data));
g_return_if_fail (nb != NULL);
- ephy_notebook_next_page (EPHY_NOTEBOOK (nb));
+ ephy_notebook_prev_page (EPHY_NOTEBOOK (nb));
}
void
-window_cmd_tabs_previous (GtkAction *action,
- EphyWindow *window)
+window_cmd_tabs_next (GSimpleAction *action,
+ GVariant *variant,
+ gpointer user_data)
{
GtkWidget *nb;
- nb = ephy_window_get_notebook (window);
+ nb = ephy_window_get_notebook (EPHY_WINDOW (user_data));
g_return_if_fail (nb != NULL);
- ephy_notebook_prev_page (EPHY_NOTEBOOK (nb));
+ ephy_notebook_next_page (EPHY_NOTEBOOK (nb));
}
void
-window_cmd_tabs_move_left (GtkAction *action,
- EphyWindow *window)
+window_cmd_tabs_move_left (GSimpleAction *action,
+ GVariant *variant,
+ gpointer user_data)
{
GtkWidget *child;
GtkNotebook *notebook;
int page;
- notebook = GTK_NOTEBOOK (ephy_window_get_notebook (window));
+ notebook = GTK_NOTEBOOK (ephy_window_get_notebook (EPHY_WINDOW (user_data)));
page = gtk_notebook_get_current_page (notebook);
if (page < 1) return;
@@ -1691,14 +1757,15 @@ window_cmd_tabs_move_left (GtkAction *action,
gtk_notebook_reorder_child (notebook, child, page - 1);
}
-void window_cmd_tabs_move_right (GtkAction *action,
- EphyWindow *window)
+void window_cmd_tabs_move_right (GSimpleAction *action,
+ GVariant *variant,
+ gpointer user_data)
{
GtkWidget *child;
GtkNotebook *notebook;
int page, n_pages;
- notebook = GTK_NOTEBOOK (ephy_window_get_notebook (window));
+ notebook = GTK_NOTEBOOK (ephy_window_get_notebook (EPHY_WINDOW (user_data)));
page = gtk_notebook_get_current_page (notebook);
n_pages = gtk_notebook_get_n_pages (notebook) - 1;
if (page > n_pages - 1) return;
@@ -1708,19 +1775,20 @@ void window_cmd_tabs_move_right (GtkAction *action,
}
void
-window_cmd_tabs_duplicate (GtkAction *action,
- EphyWindow *window)
+window_cmd_tabs_duplicate (GSimpleAction *action,
+ GVariant *variant,
+ gpointer user_data)
{
EphyEmbed *embed, *new_embed;
EphyWebView *view, *new_view;
WebKitWebViewSessionState *session_state;
- embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
+ embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (user_data));
view = ephy_embed_get_web_view (embed);
session_state = webkit_web_view_get_session_state (WEBKIT_WEB_VIEW (view));
new_embed = ephy_shell_new_tab (ephy_shell_get_default (),
- window,
+ EPHY_WINDOW (user_data),
embed,
EPHY_NEW_TAB_APPEND_AFTER | EPHY_NEW_TAB_JUMP);
@@ -1732,18 +1800,19 @@ window_cmd_tabs_duplicate (GtkAction *action,
}
void
-window_cmd_tabs_detach (GtkAction *action,
- EphyWindow *window)
+window_cmd_tabs_detach (GSimpleAction *action,
+ GVariant *variant,
+ gpointer user_data)
{
EphyEmbed *embed;
GtkNotebook *notebook;
EphyWindow *new_window;
- notebook = GTK_NOTEBOOK (ephy_window_get_notebook (window));
+ notebook = GTK_NOTEBOOK (ephy_window_get_notebook (EPHY_WINDOW (user_data)));
if (gtk_notebook_get_n_pages (notebook) <= 1)
return;
- embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
+ embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (user_data));
g_object_ref_sink (embed);
gtk_notebook_remove_page (notebook, gtk_notebook_page_num (notebook, GTK_WIDGET (embed)));
@@ -1756,87 +1825,24 @@ window_cmd_tabs_detach (GtkAction *action,
}
void
-window_cmd_load_location (GtkAction *action,
- EphyWindow *window)
-{
- const char *location;
-
- location = ephy_window_get_location (window);
-
- if (location) {
- EphyBookmarks *bookmarks;
- char *address;
-
- bookmarks = ephy_shell_get_bookmarks (ephy_shell_get_default ());
-
- address = ephy_bookmarks_resolve_address (bookmarks, location, NULL);
- g_return_if_fail (address != NULL);
-
- ephy_link_open (EPHY_LINK (window), address,
- ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window)),
- ephy_link_flags_from_current_event ());
- }
-}
-
-void
-window_cmd_edit_select_all (GSimpleAction *action,
- GVariant *value,
- gpointer user_data)
+window_cmd_tabs_close (GSimpleAction *action,
+ GVariant *value,
+ gpointer user_data)
{
EphyWindow *window = user_data;
+ GtkWidget *notebook;
+ EphyEmbed *embed;
- GtkWidget *widget = gtk_window_get_focus (GTK_WINDOW (window));
-
- if (GTK_IS_EDITABLE (widget)) {
- gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
- } else {
- EphyEmbed *embed;
-
- embed = ephy_embed_container_get_active_child
- (EPHY_EMBED_CONTAINER (window));
- g_return_if_fail (embed != NULL);
+ notebook = ephy_window_get_notebook (window);
- webkit_web_view_execute_editing_command (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed), "SelectAll");
+ if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN,
+ EPHY_PREFS_LOCKDOWN_QUIT) &&
+ gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)) == 1) {
+ return;
}
-}
-void
-window_cmd_change_browse_with_caret (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
-{
- EphyWindow *window = EPHY_WINDOW (user_data);
- gboolean active;
-
- active = g_variant_get_boolean (state);
-
- if (active) {
- GtkWidget *dialog;
- int response;
-
- dialog = gtk_message_dialog_new (GTK_WINDOW (window),
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_QUESTION, GTK_BUTTONS_CANCEL,
- _("Enable caret browsing mode?"));
-
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- _("Pressing F7 turns caret browsing on or off. This feature "
- "places a moveable cursor in web pages, allowing you to move
"
- "around with your keyboard. Do you want to enable caret
browsing?"));
- gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Enable"), GTK_RESPONSE_ACCEPT);
- gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
-
- response = gtk_dialog_run (GTK_DIALOG (dialog));
-
- gtk_widget_destroy (dialog);
-
- if (response == GTK_RESPONSE_CANCEL) {
- g_simple_action_set_state (action, g_variant_new_boolean (FALSE));
- return;
- }
- }
+ embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
+ g_return_if_fail (embed != NULL);
- g_simple_action_set_state (action, g_variant_new_boolean (active));
- g_settings_set_boolean (EPHY_SETTINGS_MAIN,
- EPHY_PREFS_ENABLE_CARET_BROWSING, active);
+ g_signal_emit_by_name (notebook, "tab-close-request", embed);
}
diff --git a/src/window-commands.h b/src/window-commands.h
index e998ca6..9f4a2b3 100644
--- a/src/window-commands.h
+++ b/src/window-commands.h
@@ -109,25 +109,10 @@ void window_cmd_view_page_source (GSimpleAction *action,
void window_cmd_view_toggle_inspector (GSimpleAction *action,
GVariant *value,
gpointer user_data);
-void window_cmd_file_close_window (GSimpleAction *action,
- GVariant *value,
- gpointer user_data);
void window_cmd_help_contents (GtkAction *action,
GtkWidget *window);
void window_cmd_help_about (GtkAction *action,
GtkWidget *window);
-void window_cmd_tabs_next (GtkAction *action,
- EphyWindow *window);
-void window_cmd_tabs_previous (GtkAction *action,
- EphyWindow *window);
-void window_cmd_tabs_move_left (GtkAction *action,
- EphyWindow *window);
-void window_cmd_tabs_move_right (GtkAction *action,
- EphyWindow *window);
-void window_cmd_tabs_duplicate (GtkAction *action,
- EphyWindow *window);
-void window_cmd_tabs_detach (GtkAction *action,
- EphyWindow *window);
void window_cmd_load_location (GtkAction *action,
EphyWindow *window);
void window_cmd_file_quit (GtkAction *action,
@@ -148,7 +133,27 @@ void window_cmd_edit_select_all (GSimpleAction *action,
void window_cmd_change_browse_with_caret (GSimpleAction *action,
GVariant *state,
gpointer user_data);
-
+void window_cmd_tabs_previous (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data);
+void window_cmd_tabs_next (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data);
+void window_cmd_tabs_move_left (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data);
+void window_cmd_tabs_move_right (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data);
+void window_cmd_tabs_duplicate (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data);
+void window_cmd_tabs_detach (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data);
+void window_cmd_tabs_close (GSimpleAction *action,
+ GVariant *value,
+ gpointer user_data);
G_END_DECLS
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]