From 899960fd491389cb3b4bdcbd52837c55061453e2 Mon Sep 17 00:00:00 2001 From: Xan Lopez Date: Sun, 7 Oct 2012 10:37:57 -0400 Subject: Merge the app menu into the gear menu when we are not in the Shell Gets rid of the ugly menubar with a single menu. https://bugzilla.gnome.org/show_bug.cgi?id=673054 --- src/ephy-shell.c | 32 +++++----------------- src/ephy-window.c | 63 +++++++++++++++++++++++++++++++++++++++++++ src/resources/epiphany-ui.xml | 7 ++++- src/window-commands.c | 63 +++++++++++++++++++++++++++++++++++++++++++ src/window-commands.h | 12 +++++++++ 5 files changed, 150 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/ephy-shell.c b/src/ephy-shell.c index 6931a6bb8..763ceeb77 100644 --- a/src/ephy-shell.c +++ b/src/ephy-shell.c @@ -166,8 +166,7 @@ new_window (GSimpleAction *action, GVariant *parameter, gpointer user_data) { - ephy_shell_new_tab (ephy_shell, NULL, NULL, NULL, - EPHY_NEW_TAB_IN_NEW_WINDOW | EPHY_NEW_TAB_HOME_PAGE); + window_cmd_file_new_window (NULL, NULL); } static void @@ -175,10 +174,7 @@ show_bookmarks (GSimpleAction *action, GVariant *parameter, gpointer user_data) { - GtkWidget *bwindow; - - bwindow = ephy_shell_get_bookmarks_editor (ephy_shell); - gtk_window_present (GTK_WINDOW (bwindow)); + window_cmd_edit_bookmarks (NULL, NULL); } static void @@ -186,10 +182,7 @@ show_history (GSimpleAction *action, GVariant *parameter, gpointer user_data) { - GtkWidget *hwindow; - - hwindow = ephy_shell_get_history_window (ephy_shell); - gtk_window_present (GTK_WINDOW (hwindow)); + window_cmd_edit_history (NULL, NULL); } static void @@ -197,11 +190,7 @@ show_preferences (GSimpleAction *action, GVariant *parameter, gpointer user_data) { - EphyDialog *dialog; - - dialog = EPHY_DIALOG (ephy_shell_get_prefs_dialog (ephy_shell)); - - ephy_dialog_show (dialog); + window_cmd_edit_preferences (NULL, NULL); } static void @@ -209,15 +198,7 @@ show_pdm (GSimpleAction *action, GVariant *parameter, gpointer user_data) { - PdmDialog *dialog; - - dialog = EPHY_PDM_DIALOG (ephy_shell_get_pdm_dialog (ephy_shell)); - /* FIXME?: pdm_dialog_open is supposed to scroll to the host passed - * as second parameters in the cookies tab. Honestly I think this - * has been broken for a while. In any case it's probably not - * relevant here, although we could get the host of the last active - * ephy window, I guess. */ - pdm_dialog_open (dialog, NULL); + window_cmd_edit_personal_data (NULL, NULL); } static void @@ -239,8 +220,7 @@ quit_application (GSimpleAction *action, GVariant *parameter, gpointer user_data) { - if (ephy_session_close_all_windows (EPHY_SESSION (ephy_shell_get_session (ephy_shell)))) - g_application_quit (g_application_get_default ()); + window_cmd_file_quit (NULL, NULL); } static GActionEntry app_entries[] = { diff --git a/src/ephy-window.c b/src/ephy-window.c index d2afac0dd..ab8b405ec 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -98,6 +98,8 @@ static const GtkActionEntry ephy_menu_entries [] = { /* File actions. */ + { "FileNewWindow", NULL, N_("_New Window"), "N", NULL, + G_CALLBACK (window_cmd_file_new_window) }, { "FileOpen", NULL, N_("_Open…"), "O", NULL, G_CALLBACK (window_cmd_file_open) }, { "FileSaveAs", NULL, N_("Save _As…"), "S", NULL, @@ -110,6 +112,8 @@ static const GtkActionEntry ephy_menu_entries [] = { G_CALLBACK (window_cmd_file_send_to) }, { "FileCloseTab", NULL, N_("_Close"), "W", NULL, G_CALLBACK (window_cmd_file_close_window) }, + { "FileQuit", NULL, N_("_Quit"), "Q", NULL, + G_CALLBACK (window_cmd_file_quit) }, /* Edit actions. */ @@ -133,6 +137,14 @@ static const GtkActionEntry ephy_menu_entries [] = { G_CALLBACK (window_cmd_edit_find_next) }, { "EditFindPrev", NULL, N_("Find Pre_vious"), "G", NULL, G_CALLBACK (window_cmd_edit_find_prev) }, + { "EditBookmarks", NULL, N_("Edit _Bookmarks…"), "B", NULL, + G_CALLBACK (window_cmd_edit_bookmarks) }, + { "EditHistory", NULL, N_("Edit _History…"), "H", NULL, + G_CALLBACK (window_cmd_edit_history) }, + { "EditPreferences", NULL, N_("Preferences"), "e", NULL, + G_CALLBACK (window_cmd_edit_preferences) }, + { "EditPersonalData", NULL, N_("Personal Data"), "m", NULL, + G_CALLBACK (window_cmd_edit_personal_data) }, /* View actions. */ @@ -174,6 +186,11 @@ static const GtkActionEntry ephy_menu_entries [] = { G_CALLBACK (window_cmd_tabs_move_right) }, { "TabsDetach", NULL, N_("_Detach Tab"), NULL, NULL, G_CALLBACK (window_cmd_tabs_detach) }, + + /* Help. */ + + { "HelpAbout", NULL, N_("_About"), NULL, NULL, + G_CALLBACK (window_cmd_help_about) } }; static const GtkToggleActionEntry ephy_menu_toggle_entries [] = @@ -354,6 +371,7 @@ struct _EphyWindowPrivate EphyLocationController *location_controller; gulong set_focus_handler; + gulong app_menu_visibility_handler; guint closing : 1; guint has_size : 1; @@ -3355,6 +3373,10 @@ ephy_window_finalize (GObject *object) g_signal_handler_disconnect (window, priv->set_focus_handler); + if (priv->app_menu_visibility_handler != 0) + g_signal_handler_disconnect (gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window))), + priv->app_menu_visibility_handler); + G_OBJECT_CLASS (ephy_window_parent_class)->finalize (object); LOG ("EphyWindow finalised %p", object); @@ -3531,6 +3553,38 @@ _gtk_css_provider_load_from_resource (GtkCssProvider* provider, return res; } +static const gchar* app_actions[] = { + "FileNewWindow", + "EditPreferences", + "EditPersonalData", + "EditBookmarks", + "EditHistory", + "FileQuit", + "HelpAbout" +}; + +static void +ephy_window_toggle_visibility_for_app_menu (EphyWindow *window) +{ + const gchar *action_name; + gboolean shows_app_menu; + GtkSettings *settings; + GtkAction *action; + gint idx; + + settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window))); + g_object_get (settings, + "gtk-shell-shows-app-menu", &shows_app_menu, + NULL); + + for (idx = 0; idx < G_N_ELEMENTS (app_actions); idx++) { + action_name = app_actions[idx]; + action = gtk_action_group_get_action (window->priv->action_group, action_name); + + gtk_action_set_visible (action, !shows_app_menu); + } +} + static GObject * ephy_window_constructor (GType type, guint n_construct_properties, @@ -3712,6 +3766,15 @@ ephy_window_constructor (GType type, } } + /* We never want the menubar shown, we merge the app menu into + * our super menu manually when running outside the Shell. */ + gtk_application_window_set_show_menubar (GTK_APPLICATION_WINDOW (window), FALSE); + + ephy_window_toggle_visibility_for_app_menu (window); + priv->app_menu_visibility_handler = g_signal_connect_swapped (gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window))), + "notify::gtk-shell-shows-app-menu", + G_CALLBACK (ephy_window_toggle_visibility_for_app_menu), window); + /* ensure the UI is updated */ gtk_ui_manager_ensure_update (priv->manager); diff --git a/src/resources/epiphany-ui.xml b/src/resources/epiphany-ui.xml index c4789036f..5a2446c6c 100644 --- a/src/resources/epiphany-ui.xml +++ b/src/resources/epiphany-ui.xml @@ -68,6 +68,7 @@ + @@ -79,9 +80,11 @@ - + + + @@ -93,7 +96,9 @@ + + diff --git a/src/window-commands.c b/src/window-commands.c index 4b4fcb23a..81ba0f0bb 100644 --- a/src/window-commands.c +++ b/src/window-commands.c @@ -43,6 +43,7 @@ #include "ephy-notebook.h" #include "ephy-prefs.h" #include "ephy-private.h" +#include "ephy-session.h" #include "ephy-settings.h" #include "ephy-shell.h" #include "ephy-state.h" @@ -717,6 +718,22 @@ window_cmd_file_close_window (GtkAction *action, g_signal_emit_by_name (notebook, "tab-close-request", embed); } +void +window_cmd_file_quit (GtkAction *action, + EphyWindow *window) +{ + if (ephy_session_close_all_windows (EPHY_SESSION (ephy_shell_get_session (ephy_shell)))) + g_application_quit (g_application_get_default ()); +} + +void +window_cmd_file_new_window (GtkAction *action, + EphyWindow *window) +{ + ephy_shell_new_tab (ephy_shell, NULL, NULL, NULL, + EPHY_NEW_TAB_IN_NEW_WINDOW | EPHY_NEW_TAB_HOME_PAGE); +} + void window_cmd_edit_undo (GtkAction *action, EphyWindow *window) @@ -929,6 +946,52 @@ window_cmd_edit_find_prev (GtkAction *action, ephy_find_toolbar_find_previous (toolbar); } +void +window_cmd_edit_bookmarks (GtkAction *action, + EphyWindow *window) +{ + GtkWidget *bwindow; + + bwindow = ephy_shell_get_bookmarks_editor (ephy_shell); + gtk_window_present (GTK_WINDOW (bwindow)); +} + +void +window_cmd_edit_history (GtkAction *action, + EphyWindow *window) +{ + GtkWidget *hwindow; + + hwindow = ephy_shell_get_history_window (ephy_shell); + gtk_window_present (GTK_WINDOW (hwindow)); +} + +void +window_cmd_edit_preferences (GtkAction *action, + EphyWindow *window) +{ + EphyDialog *dialog; + + dialog = EPHY_DIALOG (ephy_shell_get_prefs_dialog (ephy_shell)); + + ephy_dialog_show (dialog); +} + +void +window_cmd_edit_personal_data (GtkAction *action, + EphyWindow *window) +{ + PdmDialog *dialog; + + dialog = EPHY_PDM_DIALOG (ephy_shell_get_pdm_dialog (ephy_shell)); + /* FIXME?: pdm_dialog_open is supposed to scroll to the host passed + * as second parameters in the cookies tab. Honestly I think this + * has been broken for a while. In any case it's probably not + * relevant here, although we could get the host of the last active + * ephy window, I guess. */ + pdm_dialog_open (dialog, NULL); +} + void window_cmd_view_fullscreen (GtkAction *action, EphyWindow *window) diff --git a/src/window-commands.h b/src/window-commands.h index 8c1840ba1..b689bb4c0 100644 --- a/src/window-commands.h +++ b/src/window-commands.h @@ -100,6 +100,18 @@ void window_cmd_load_location (GtkAction *action, EphyWindow *window); void window_cmd_browse_with_caret (GtkAction *action, EphyWindow *window); +void window_cmd_file_quit (GtkAction *action, + EphyWindow *window); +void window_cmd_edit_bookmarks (GtkAction *action, + EphyWindow *window); +void window_cmd_edit_history (GtkAction *action, + EphyWindow *window); +void window_cmd_file_new_window (GtkAction *action, + EphyWindow *window); +void window_cmd_edit_preferences (GtkAction *action, + EphyWindow *window); +void window_cmd_edit_personal_data (GtkAction *action, + EphyWindow *window); G_END_DECLS -- cgit v1.2.3