[epiphany] Drop menubar and create an actions menu button in the toolbar



commit 042f09bcf84db2ade9aa18f881ac5064aacbf116
Author: Xan Lopez <xan igalia com>
Date:   Wed Jan 11 19:21:23 2012 +0100

    Drop menubar and create an actions menu button in the toolbar
    
    Similar to Chrome's wrench menu, but used only (in the future) for
    page-related actions. For now we have mechanically moved most stuff
    there, now we need to start removing them one by one when appropriate.

 data/ui/epiphany-ui.xml           |   94 +++++++++++++-----------------------
 src/Makefile.am                   |    2 +
 src/bookmarks/ephy-bookmarks-ui.c |    4 +-
 src/ephy-encoding-menu.c          |    4 +-
 src/ephy-page-menu-action.c       |   90 +++++++++++++++++++++++++++++++++++
 src/ephy-page-menu-action.h       |   52 ++++++++++++++++++++
 src/ephy-window.c                 |   72 +++++++++-------------------
 7 files changed, 204 insertions(+), 114 deletions(-)
---
diff --git a/data/ui/epiphany-ui.xml b/data/ui/epiphany-ui.xml
index 30ea176..69d8536 100644
--- a/data/ui/epiphany-ui.xml
+++ b/data/ui/epiphany-ui.xml
@@ -1,64 +1,4 @@
 <ui>
-	<menubar>
-		<menu name="FileMenu" action="File">  
-			<menuitem name="FileNewTabMenu" action="FileNewTab"/>
-			<menuitem name="FileOpenMenu" action="FileOpen"/>
-			<separator name="FileSep1"/>	
-			<menuitem name="FileSaveAsMenu" action="FileSaveAs"/>
-			<menuitem name="FileSaveAsApplicationMenu" action="FileSaveAsApplication"/>
-			<separator name="FileSep2"/>
-			<menuitem name="FilePrintSetupMenu" action="FilePrintSetup"/>
-			<menuitem name="FilePrintPreviewMenu" action="FilePrintPreview"/>
-			<menuitem name="FilePrintMenu" action="FilePrint"/>
-			<menuitem name="FileSendToMenu" action="FileSendTo"/>
-			<separator name="FileSep3"/>
-			<menuitem name="FileWorkOfflineItem" action="FileWorkOffline"/>
-			<menuitem name="FileCloseWindowMenu" action="FileCloseTab"/>
-		</menu>
-
-		<menu name="EditMenu" action="Edit">
-			<menuitem name="EditUndoMenu" action="EditUndo"/>
-			<menuitem name="EditRedoMenu" action="EditRedo"/>
-			<separator name="EditSep0"/>
-			<menuitem name="EditCutMenu" action="EditCut"/>
-			<menuitem name="EditCopyMenu" action="EditCopy"/>
-			<menuitem name="EditPasteMenu" action="EditPaste"/>
-			<separator name="EditSep1"/> 
-			<menuitem name="EditSelectAllMenu" action="EditSelectAll"/>
-			<separator name="EditSep2"/>
-			<menuitem name="EditFindMenu" action="EditFind"/>
-			<menuitem name="EditFindNextMenu" action="EditFindNext"/> 
-			<menuitem name="EditFindPrevMenu" action="EditFindPrev"/>
-		</menu>
-
-		<menu name="ViewMenu" action="View">
-			<menuitem name="ViewDownloadsBar" action="ViewDownloadsBar"/>
-			<separator name="ViewSep1"/>
-			<menuitem name="ViewPopupsMenu" action="ViewPopupWindows"/>
-			<menuitem name="ViewFullscreenMenu" action="ViewFullscreen"/>
-			<separator name="ViewSep2"/>
-			<menuitem name="ViewZoomInMenu" action="ViewZoomIn"/>
-			<menuitem name="ViewZoomOutMenu" action="ViewZoomOut"/>
-			<menuitem name="ViewZoomNormalMenu" action="ViewZoomNormal"/>
-			<separator name="ViewSep3"/>
-			<menu name="ViewEncodingMenu" action="ViewEncoding">
-				<placeholder name="ViewEncodingPlaceholder"/>
-			</menu>
-			<menuitem name="ViewPageSourceMenu" action="ViewPageSource"/>
-			<menuitem action="ViewPageSecurityInfo"/>
-			<separator name="ViewSep4"/>
-			<menuitem name="ViewStopMenu" action="ViewStop"/> 
-			<menuitem name="ViewReloadMenu" action="ViewReload"/>
-		</menu>
-
-		<menu name="BookmarksMenu" action="Bookmarks">
-			<menuitem name="BookmarksAddBookmarkMenu" action="FileBookmarkPage"/>
-			<separator name="BookmarksSep1"/>
-		</menu>
-
-		<menu name="ToolsMenu" action="Tools"/>
-	</menubar>
-
 	<popup name="EphyInputPopup" action="PopupAction">
 		<menuitem name="SpellingSuggestion0" action="ReplaceWithSpellingSuggestion0"/>
 		<menuitem name="SpellingSuggestion1" action="ReplaceWithSpellingSuggestion1"/>
@@ -146,8 +86,42 @@
                 <toolitem action="NavigationForward"/>
                 <toolitem action="ViewCombinedStopReload"/>
                 <toolitem action="Location"/>
+                <toolitem action="PageMenu"/>
         </toolbar>
 
+	<popup name="PagePopup" action="PagePopupAction">
+                <menuitem name="FileNewTabMenu" action="FileNewTab"/>
+                <menuitem name="FileOpenMenu" action="FileOpen"/>
+                <separator name="FileSep1"/>	
+                <menuitem name="FileSaveAsMenu" action="FileSaveAs"/>
+                <menuitem name="FileSaveAsApplicationMenu" action="FileSaveAsApplication"/>
+                <separator name="FileSep2"/>
+                <menuitem name="EditCutMenu" action="EditCut"/>
+                <menuitem name="EditCopyMenu" action="EditCopy"/>
+                <menuitem name="EditPasteMenu" action="EditPaste"/>
+                <separator name="EditSep3"/> 
+                <menuitem name="FilePrintSetupMenu" action="FilePrintSetup"/>
+                <menuitem name="FilePrintPreviewMenu" action="FilePrintPreview"/>
+                <menuitem name="FilePrintMenu" action="FilePrint"/>
+                <menuitem name="FileSendToMenu" action="FileSendTo"/>
+                <separator name="FileSep4"/>
+                <menuitem name="EditFindMenu" action="EditFind"/>
+                <menuitem name="EditFindNextMenu" action="EditFindNext"/> 
+                <menuitem name="EditFindPrevMenu" action="EditFindPrev"/>
+                <separator name="FileSep5"/>
+		<menu name="BookmarksMenu" action="Bookmarks">
+			<menuitem name="BookmarksAddBookmarkMenu" action="FileBookmarkPage"/>
+			<separator name="BookmarksSep1"/>
+		</menu>
+                <separator name="FileSep6"/>
+                <menu name="ViewEncodingMenu" action="ViewEncoding">
+                  <placeholder name="ViewEncodingPlaceholder"/>
+                </menu>
+                <menuitem name="ViewPageSourceMenu" action="ViewPageSource"/>
+                <separator name="FileSep7"/>
+                <menuitem name="FileCloseWindowMenu" action="FileCloseTab"/>
+	</popup>
+
 	<accelerator name="AlwaysStopAccel" action="ViewAlwaysStop"/>
 	<accelerator name="BrowseWithCaretAccel" action="BrowseWithCaret"/>
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 57267d8..d916499 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -27,6 +27,7 @@ NOINST_H_FILES = \
 	ephy-location-action.h			\
 	ephy-navigation-action.h		\
 	ephy-navigation-history-action.h	\
+	ephy-page-menu-action.h			\
 	ephy-password-info.h			\
 	languages.h				\
 	pdm-dialog.h				\
@@ -65,6 +66,7 @@ libephymain_la_SOURCES = \
 	ephy-navigation-action.c		\
 	ephy-navigation-history-action.c	\
 	ephy-notebook.c				\
+	ephy-page-menu-action.c			\
 	ephy-password-info.c	        	\
 	ephy-session.c				\
 	ephy-shell.c				\
diff --git a/src/bookmarks/ephy-bookmarks-ui.c b/src/bookmarks/ephy-bookmarks-ui.c
index 66d675d..994b322 100644
--- a/src/bookmarks/ephy-bookmarks-ui.c
+++ b/src/bookmarks/ephy-bookmarks-ui.c
@@ -93,9 +93,9 @@ activate_bookmarks_menu (GtkAction *action, EphyWindow *window)
 		if (!bookmarks_menu_string->len)
 		{
 			g_string_append (bookmarks_menu_string,
-					 "<ui><menubar><menu name=\"BookmarksMenu\" action=\"Bookmarks\">");
+					 "<ui><popup name=\"PagePopup\" action=\"PopupAction\"><menu name=\"BookmarksMenu\" action=\"Bookmarks\">");
 			ephy_bookmarks_menu_build (bookmarks_menu_string, 0);
-			g_string_append (bookmarks_menu_string, "</menu></menubar></ui>");
+			g_string_append (bookmarks_menu_string, "</menu></popup></ui>");
 		}
 
 		data->bookmarks_menu = gtk_ui_manager_add_ui_from_string
diff --git a/src/ephy-encoding-menu.c b/src/ephy-encoding-menu.c
index 7811842..4fa7abe 100644
--- a/src/ephy-encoding-menu.c
+++ b/src/ephy-encoding-menu.c
@@ -51,7 +51,7 @@ struct _EphyEncodingMenuPrivate
 	EphyEncodingDialog *dialog;
 };
 
-#define ENCODING_PLACEHOLDER_PATH	"/menubar/ViewMenu/ViewEncodingMenu/ViewEncodingPlaceholder"
+#define ENCODING_PLACEHOLDER_PATH	"/ui/PagePopup/ViewEncodingMenu/ViewEncodingPlaceholder"
 
 static void	ephy_encoding_menu_class_init	  (EphyEncodingMenuClass *klass);
 static void	ephy_encoding_menu_init		  (EphyEncodingMenu *menu);
@@ -387,7 +387,7 @@ ephy_encoding_menu_set_window (EphyEncodingMenu *menu, EphyWindow *window)
 	g_object_unref (action_group);
 
 	action = gtk_ui_manager_get_action (menu->priv->manager,
-					    "/menubar/ViewMenu");
+					    "/ui/PagePopup/ViewEncodingMenu");
 	g_signal_connect_object (action, "activate",
 				 G_CALLBACK (update_encoding_menu_cb),
 				 menu, 0);
diff --git a/src/ephy-page-menu-action.c b/src/ephy-page-menu-action.c
new file mode 100644
index 0000000..d5c6592
--- /dev/null
+++ b/src/ephy-page-menu-action.c
@@ -0,0 +1,90 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ *  Copyright  2012 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, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+#include "ephy-page-menu-action.h"
+
+G_DEFINE_TYPE (EphyPageMenuAction, ephy_page_menu_action, EPHY_TYPE_NAVIGATION_ACTION);
+
+static void
+menu_position_func (GtkMenu           *menu,
+                    int               *x,
+                    int               *y,
+                    gboolean          *push_in,
+                    GtkMenuToolButton *button)
+{
+  GtkAllocation allocation;
+  GtkWidget *widget = GTK_WIDGET (button);
+  GtkRequisition menu_req;
+  GtkTextDirection direction;
+  GdkWindow *window;
+
+  gtk_widget_get_preferred_size (GTK_WIDGET (menu),
+                                 &menu_req, NULL);
+
+  direction = gtk_widget_get_direction (widget);
+  window = gtk_widget_get_window (widget);
+
+  gtk_widget_get_allocation (widget, &allocation);
+
+  gdk_window_get_origin (window, x, y);
+  *x += allocation.x;
+  *y += allocation.y + allocation.height;
+
+  if (direction == GTK_TEXT_DIR_LTR)
+      *x += allocation.width - menu_req.width;
+
+  *push_in = FALSE;
+}
+
+static void
+ephy_page_menu_action_activate (GtkAction *action)
+{
+    GtkWidget *menu;
+    EphyWindow *window;
+    GtkUIManager *manager;
+    GSList *list;
+    GtkWidget *button;
+
+    window = _ephy_navigation_action_get_window (EPHY_NAVIGATION_ACTION (action));
+    manager = GTK_UI_MANAGER (ephy_window_get_ui_manager (window));
+    menu = gtk_ui_manager_get_widget (manager, "/PagePopup");
+
+    list = gtk_action_get_proxies (action);
+    if (GTK_IS_TOOL_BUTTON (list->data))
+        button = GTK_WIDGET (list->data);
+
+    gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
+                    (GtkMenuPositionFunc)menu_position_func, button,
+                    1, 0);
+}
+
+static void
+ephy_page_menu_action_class_init (EphyPageMenuActionClass *klass)
+{
+    GtkActionClass *action_class = GTK_ACTION_CLASS (klass);
+
+    action_class->activate = ephy_page_menu_action_activate;
+}
+
+static void
+ephy_page_menu_action_init (EphyPageMenuAction *self)
+{
+}
diff --git a/src/ephy-page-menu-action.h b/src/ephy-page-menu-action.h
new file mode 100644
index 0000000..c7239b6
--- /dev/null
+++ b/src/ephy-page-menu-action.h
@@ -0,0 +1,52 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ *  Copyright  2012 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, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef __EPHY_PAGE_MENU_ACTION_H__
+#define __EPHY_PAGE_MENU_ACTION_H__
+
+#include "ephy-navigation-action.h"
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_PAGE_MENU_ACTION (ephy_page_menu_action_get_type())
+#define EPHY_PAGE_MENU_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EPHY_TYPE_PAGE_MENU_ACTION, EphyPageMenuAction))
+#define EPHY_PAGE_MENU_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EPHY_TYPE_PAGE_MENU_ACTION, EphyPageMenuActionClass))
+#define EPHY_IS_PAGE_MENU_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EPHY_TYPE_PAGE_MENU_ACTION))
+#define EPHY_IS_PAGE_MENU_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EPHY_TYPE_PAGE_MENU_ACTION))
+#define EPHY_PAGE_MENU_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EPHY_TYPE_PAGE_MENU_ACTION, EphyPageMenuActionClass))
+
+typedef struct _EphyPageMenuAction      EphyPageMenuAction;
+typedef struct _EphyPageMenuActionClass EphyPageMenuActionClass;
+
+struct _EphyPageMenuActionClass {
+    EphyNavigationActionClass parent_class;
+};
+
+struct _EphyPageMenuAction {
+    EphyNavigationAction parent_instance;
+};
+
+GType ephy_page_menu_action_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* __EPHY_PAGE_MENU_ACTION_H__ */
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 0b0005f..fe27a9b 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -48,6 +48,7 @@
 #include "ephy-navigation-action.h"
 #include "ephy-navigation-history-action.h"
 #include "ephy-notebook.h"
+#include "ephy-page-menu-action.h"
 #include "ephy-prefs.h"
 #include "ephy-settings.h"
 #include "ephy-shell.h"
@@ -111,6 +112,7 @@ static const GtkActionEntry ephy_menu_entries [] = {
 	{ "Tools", NULL, N_("T_ools") },
 	{ "Toolbar", NULL, N_("_Toolbars") },
 	{ "PopupAction", NULL, "" },
+	{ "PagePopupAction", NULL, "" },
 	{ "NotebookPopupAction", NULL, "" },
 
 	/* File menu */
@@ -774,7 +776,6 @@ static void
 sync_chromes_visibility (EphyWindow *window)
 {
 	EphyWindowPrivate *priv = window->priv;
-	GtkWidget *menubar;
 	gboolean show_menubar, show_toolbar, show_tabsbar;
 
 	if (priv->closing) return;
@@ -783,10 +784,6 @@ sync_chromes_visibility (EphyWindow *window)
 				&show_toolbar,
 				&show_tabsbar);
 
-	menubar = gtk_ui_manager_get_widget (window->priv->manager, "/menubar");
-	g_assert (menubar != NULL);
-
-	g_object_set (menubar, "visible", show_menubar, NULL);
 	g_object_set (priv->toolbar, "visible", show_toolbar, NULL);
 
 	ephy_notebook_set_show_tabs (EPHY_NOTEBOOK (priv->notebook), show_tabsbar);
@@ -860,18 +857,6 @@ ephy_window_unfullscreen (EphyWindow *window)
 	sync_chromes_visibility (window);
 }
 
-static void
-menubar_deactivate_cb (GtkWidget *menubar,
-		       EphyWindow *window)
-{
-	g_signal_handlers_disconnect_by_func
-		(menubar, G_CALLBACK (menubar_deactivate_cb), window);
-
-	gtk_menu_shell_deselect (GTK_MENU_SHELL (menubar));
-
-	sync_chromes_visibility (window);
-}
-
 static gboolean 
 scroll_event_cb (GtkWidget *widget,
 		 GdkEventScroll *event,
@@ -896,7 +881,7 @@ ephy_window_key_press_event (GtkWidget *widget,
 {
 	EphyWindow *window = EPHY_WINDOW (widget);
 	EphyWindowPrivate *priv = window->priv;
-	GtkWidget *menubar, *focus_widget;
+	GtkWidget *focus_widget;
 	gboolean shortcircuit = FALSE, force_chain = FALSE, handled = FALSE;
 	guint modifier = event->state & gtk_accelerator_get_default_mod_mask ();
 	guint i;
@@ -978,26 +963,6 @@ ephy_window_key_press_event (GtkWidget *widget,
 		return GTK_WIDGET_CLASS (ephy_window_parent_class)->key_press_event (widget, event);
 	}
 
-	/* Show and activate the menubar, if it isn't visible */
-	if (priv->menubar_accel_keyval != 0 &&
-	    event->keyval == priv->menubar_accel_keyval &&
-            modifier == priv->menubar_accel_modifier)
-	{
-		menubar = gtk_ui_manager_get_widget (window->priv->manager, "/menubar");
-		g_return_val_if_fail (menubar != NULL , FALSE);
-
-		if (!gtk_widget_get_visible (menubar))
-		{
-			g_signal_connect (menubar, "deactivate",
-					  G_CALLBACK (menubar_deactivate_cb), window);
-
-			gtk_widget_show (menubar);
-			gtk_menu_shell_select_first (GTK_MENU_SHELL (menubar), FALSE);
-
-			return TRUE;
-		}
-	}
-
 	return GTK_WIDGET_CLASS (ephy_window_parent_class)->key_press_event (widget, event);
 }
 
@@ -1290,31 +1255,30 @@ enable_edit_actions_sensitivity (EphyWindow *window)
 
 static void
 edit_menu_show_cb (GtkWidget *menu,
-		   EphyWindow *window)
+                  EphyWindow *window)
 {
-	update_edit_actions_sensitivity (window, FALSE);
+       update_edit_actions_sensitivity (window, FALSE);
 }
 
 static void
 edit_menu_hide_cb (GtkWidget *menu,
-		   EphyWindow *window)
+                  EphyWindow *window)
 {
-	enable_edit_actions_sensitivity (window);
+       enable_edit_actions_sensitivity (window);
 }
 
 static void
 init_menu_updaters (EphyWindow *window)
 {
-	GtkWidget *edit_menu_item, *edit_menu;
+       GtkWidget *edit_menu;
 
-	edit_menu_item = gtk_ui_manager_get_widget
-		(window->priv->manager, "/menubar/EditMenu");
-	edit_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (edit_menu_item));
+       edit_menu = gtk_ui_manager_get_widget
+               (window->priv->manager, "/ui/PagePopup");
 
-	g_signal_connect (edit_menu, "show",
-			  G_CALLBACK (edit_menu_show_cb), window);
-	g_signal_connect (edit_menu, "hide",
-			  G_CALLBACK (edit_menu_hide_cb), window);
+       g_signal_connect (edit_menu, "show",
+                         G_CALLBACK (edit_menu_show_cb), window);
+       g_signal_connect (edit_menu, "hide",
+                         G_CALLBACK (edit_menu_hide_cb), window);
 }
 
 static EphyWebView*
@@ -1627,6 +1591,14 @@ setup_ui_manager (EphyWindow *window)
 	gtk_action_group_add_action (action_group, action);
 	g_object_unref (action);
 
+	action = g_object_new (EPHY_TYPE_PAGE_MENU_ACTION,
+			       "name", "PageMenu",
+			       "icon-name", "send-to-symbolic",
+			       "window", window,
+			       NULL);
+	gtk_action_group_add_action_with_accel (action_group, action, "<alt>E");
+	g_object_unref (action);
+
 	gtk_ui_manager_insert_action_group (manager, action_group, 0);
 	window->priv->toolbar_action_group = action_group;
 	g_object_unref (action_group);



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