[epiphany] Stop using GtkUIManager to create the toolbar
- From: Xan Lopez <xan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Stop using GtkUIManager to create the toolbar
- Date: Mon, 16 Jan 2012 17:52:05 +0000 (UTC)
commit 64d06cecbf24c4731acc5f6c0b6dde60a5938027
Author: Xan Lopez <xan igalia com>
Date: Mon Jan 16 17:35:36 2012 +0100
Stop using GtkUIManager to create the toolbar
Otherwise it's difficult to get the right layout for theming.
data/ui/epiphany-ui.xml | 8 --
po/POTFILES.in | 1 +
src/Makefile.am | 2 +
src/ephy-combined-stop-reload-action.c | 1 -
src/ephy-page-menu-action.c | 6 +-
src/ephy-toolbar.c | 199 ++++++++++++++++++++++++++++++++
src/ephy-toolbar.h | 62 ++++++++++
src/ephy-window.c | 30 +++--
src/ephy-window.h | 2 +
9 files changed, 290 insertions(+), 21 deletions(-)
---
diff --git a/data/ui/epiphany-ui.xml b/data/ui/epiphany-ui.xml
index 69d8536..b3c184d 100644
--- a/data/ui/epiphany-ui.xml
+++ b/data/ui/epiphany-ui.xml
@@ -81,14 +81,6 @@
<!-- <menuitem name="TabDetachENP" action="TabsDetach"/> -->
</popup>
- <toolbar name="DefaultToolbar">
- <toolitem action="NavigationBack"/>
- <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"/>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 2e24860..bee72dd 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -56,6 +56,7 @@ src/ephy-main.c
src/ephy-notebook.c
src/ephy-session.c
src/ephy-shell.c
+src/ephy-toolbar.c
src/ephy-window.c
src/pdm-dialog.c
src/popup-commands.c
diff --git a/src/Makefile.am b/src/Makefile.am
index d916499..f89a021 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -29,6 +29,7 @@ NOINST_H_FILES = \
ephy-navigation-history-action.h \
ephy-page-menu-action.h \
ephy-password-info.h \
+ ephy-toolbar.h \
languages.h \
pdm-dialog.h \
popup-commands.h \
@@ -70,6 +71,7 @@ libephymain_la_SOURCES = \
ephy-password-info.c \
ephy-session.c \
ephy-shell.c \
+ ephy-toolbar.c \
ephy-window.c \
pdm-dialog.c \
popup-commands.c \
diff --git a/src/ephy-combined-stop-reload-action.c b/src/ephy-combined-stop-reload-action.c
index 0b43d8f..0789a28 100644
--- a/src/ephy-combined-stop-reload-action.c
+++ b/src/ephy-combined-stop-reload-action.c
@@ -77,7 +77,6 @@ ephy_combined_stop_reload_action_set_loading (EphyCombinedStopReloadAction *acti
EPHY_COMBINED_STOP_RELOAD_ACTION_STOP : EPHY_COMBINED_STOP_RELOAD_ACTION_REFRESH;
g_object_set (action,
- "label", combined_stop_reload_action_entries[action_enum].label,
"icon-name", combined_stop_reload_action_entries[action_enum].stock_id,
"tooltip", combined_stop_reload_action_entries[action_enum].tooltip,
NULL);
diff --git a/src/ephy-page-menu-action.c b/src/ephy-page-menu-action.c
index 308d6c1..0a7c83d 100644
--- a/src/ephy-page-menu-action.c
+++ b/src/ephy-page-menu-action.c
@@ -28,7 +28,7 @@ menu_position_func (GtkMenu *menu,
int *x,
int *y,
gboolean *push_in,
- GtkMenuToolButton *button)
+ GtkToolButton *button)
{
GtkAllocation allocation;
GtkWidget *widget = GTK_WIDGET (button);
@@ -68,12 +68,14 @@ ephy_page_menu_action_activate (GtkAction *action)
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");
+ menu = gtk_ui_manager_get_widget (manager, "/ui/PagePopup");
list = gtk_action_get_proxies (action);
if (GTK_IS_TOOL_BUTTON (list->data))
button = GTK_WIDGET (list->data);
+ g_return_if_fail (GTK_IS_TOOL_BUTTON (button));
+
event = gtk_get_current_event ();
if (event && event->type == GDK_BUTTON_PRESS) {
activate_button = event->button.button;
diff --git a/src/ephy-toolbar.c b/src/ephy-toolbar.c
new file mode 100644
index 0000000..d3d8c3f
--- /dev/null
+++ b/src/ephy-toolbar.c
@@ -0,0 +1,199 @@
+/* -*- 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-toolbar.h"
+
+G_DEFINE_TYPE (EphyToolbar, ephy_toolbar, GTK_TYPE_TOOLBAR)
+
+#define EPHY_TOOLBAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), EPHY_TYPE_TOOLBAR, EphyToolbarPrivate))
+
+enum {
+ PROP_0,
+ PROP_WINDOW,
+ N_PROPERTIES
+};
+
+static GParamSpec *object_properties[N_PROPERTIES] = { NULL, };
+
+struct _EphyToolbarPrivate {
+ EphyWindow *window;
+};
+
+static void
+ephy_toolbar_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EphyToolbarPrivate *priv = EPHY_TOOLBAR (object)->priv;
+
+ switch (property_id) {
+ case PROP_WINDOW:
+ priv->window = EPHY_WINDOW (g_value_get_object (value));
+ g_object_notify_by_pspec (object, object_properties[PROP_WINDOW]);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+ephy_toolbar_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EphyToolbarPrivate *priv = EPHY_TOOLBAR (object)->priv;
+
+ switch (property_id) {
+ case PROP_WINDOW:
+ g_value_set_object (value, priv->window);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static gboolean
+create_menu_proxy_cb (GtkToolItem *item, gpointer user_data)
+{
+ return TRUE;
+}
+
+static void
+ephy_toolbar_constructed (GObject *object)
+{
+ EphyToolbarPrivate *priv = EPHY_TOOLBAR (object)->priv;
+ GtkActionGroup *action_group;
+ GtkAction *action;
+ GtkToolItem *tool_button, *back_forward, *location_stop_reload;
+ GtkWidget *box, *location, *toolbar;
+
+ G_OBJECT_CLASS (ephy_toolbar_parent_class)->constructed (object);
+
+ toolbar = GTK_WIDGET (object);
+
+ /* Back and Forward */
+ back_forward = gtk_tool_item_new ();
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+
+ /* Back */
+ tool_button = gtk_tool_button_new (NULL, NULL);
+ action_group = ephy_window_get_toolbar_action_group (priv->window);
+ action = gtk_action_group_get_action (action_group, "NavigationBack");
+ gtk_activatable_set_related_action (GTK_ACTIVATABLE (tool_button),
+ action);
+ gtk_container_add (GTK_CONTAINER (box), GTK_WIDGET (tool_button));
+
+ /* Forward */
+ tool_button = gtk_tool_button_new (NULL, NULL);
+ action = gtk_action_group_get_action (action_group, "NavigationForward");
+ gtk_activatable_set_related_action (GTK_ACTIVATABLE (tool_button),
+ action);
+ gtk_container_add (GTK_CONTAINER (box), GTK_WIDGET (tool_button));
+
+ gtk_style_context_add_class (gtk_widget_get_style_context (box),
+ "raised");
+ gtk_style_context_add_class (gtk_widget_get_style_context (box),
+ "linked");
+
+ gtk_container_add (GTK_CONTAINER (back_forward), box);
+ gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET (back_forward));
+ gtk_widget_show_all (GTK_WIDGET (back_forward));
+ gtk_widget_set_margin_right (GTK_WIDGET (back_forward), 12);
+
+ /* Location and Reload/Stop */
+ location_stop_reload = gtk_tool_item_new ();
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+
+ /* Location */
+ action = gtk_action_group_get_action (action_group, "Location");
+ location = gtk_action_create_tool_item (action);
+ gtk_box_pack_start (GTK_BOX (box), location,
+ TRUE, TRUE, 0);
+
+ /* Reload/Stop */
+ tool_button = gtk_tool_button_new (NULL, NULL);
+ action = gtk_action_group_get_action (action_group, "ViewCombinedStopReload");
+ gtk_activatable_set_related_action (GTK_ACTIVATABLE (tool_button),
+ action);
+ gtk_container_add (GTK_CONTAINER (box), GTK_WIDGET (tool_button));
+
+ gtk_container_add (GTK_CONTAINER (location_stop_reload), box);
+ gtk_container_child_set (GTK_CONTAINER (toolbar),
+ GTK_WIDGET (location_stop_reload),
+ "expand", TRUE,
+ NULL);
+
+ gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET (location_stop_reload));
+ gtk_widget_set_margin_right (GTK_WIDGET (location_stop_reload), 12);
+ gtk_widget_show_all (GTK_WIDGET (location_stop_reload));
+
+ /* Page Menu */
+ tool_button = gtk_tool_button_new (NULL, NULL);
+ action = gtk_action_group_get_action (action_group, "PageMenu");
+ gtk_activatable_set_related_action (GTK_ACTIVATABLE (tool_button),
+ action);
+ gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET (tool_button));
+ /* FIXME: why is this needed?! GTK+ wants to create an overflow menu
+ * for this, no idea why. Connect to the signal to cancel it. */
+ g_signal_connect (tool_button, "create-menu-proxy",
+ G_CALLBACK (create_menu_proxy_cb), NULL);
+}
+
+static void
+ephy_toolbar_class_init (EphyToolbarClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->set_property = ephy_toolbar_set_property;
+ gobject_class->get_property = ephy_toolbar_get_property;
+ gobject_class->constructed = ephy_toolbar_constructed;
+
+ object_properties[PROP_WINDOW] =
+ g_param_spec_object ("window",
+ "Window",
+ "The toolbar's EphyWindow",
+ EPHY_TYPE_WINDOW,
+ G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_CONSTRUCT_ONLY);
+
+ g_object_class_install_properties (gobject_class,
+ N_PROPERTIES,
+ object_properties);
+
+ g_type_class_add_private (klass, sizeof (EphyToolbarPrivate));
+}
+
+static void
+ephy_toolbar_init (EphyToolbar *toolbar)
+{
+ toolbar->priv = EPHY_TOOLBAR_GET_PRIVATE (toolbar);
+}
+
+GtkWidget*
+ephy_toolbar_new (EphyWindow *window)
+{
+ g_return_val_if_fail (EPHY_IS_WINDOW (window), NULL);
+
+ return GTK_WIDGET (g_object_new (EPHY_TYPE_TOOLBAR,
+ "window", window,
+ NULL));
+}
diff --git a/src/ephy-toolbar.h b/src/ephy-toolbar.h
new file mode 100644
index 0000000..2ecc97f
--- /dev/null
+++ b/src/ephy-toolbar.h
@@ -0,0 +1,62 @@
+/* -*- 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.
+ *
+ */
+
+#if !defined (__EPHY_EPIPHANY_H_INSIDE__) && !defined (EPIPHANY_COMPILATION)
+#error "Only <epiphany/epiphany.h> can be included directly."
+#endif
+
+#ifndef EPHY_TOOLBAR_H
+#define EPHY_TOOLBAR_H
+
+#include <gtk/gtk.h>
+
+#include "ephy-window.h"
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_TOOLBAR (ephy_toolbar_get_type())
+#define EPHY_TOOLBAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EPHY_TYPE_TOOLBAR, EphyToolbar))
+#define EPHY_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EPHY_TYPE_TOOLBAR, EphyToolbarClass))
+#define EPHY_IS_TOOLBAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EPHY_TYPE_TOOLBAR))
+#define EPHY_IS_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EPHY_TYPE_TOOLBAR))
+#define EPHY_TOOLBAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EPHY_TYPE_TOOLBAR, EphyToolbarClass))
+
+typedef struct _EphyToolbar EphyToolbar;
+typedef struct _EphyToolbarClass EphyToolbarClass;
+typedef struct _EphyToolbarPrivate EphyToolbarPrivate;
+
+struct _EphyToolbar {
+ GtkToolbar parent;
+
+ /*< private >*/
+ EphyToolbarPrivate *priv;
+};
+
+struct _EphyToolbarClass {
+ GtkToolbarClass parent_class;
+};
+
+GType ephy_toolbar_get_type (void) G_GNUC_CONST;
+
+GtkWidget *ephy_toolbar_new (EphyWindow *window);
+
+G_END_DECLS
+
+#endif /* EPHY_TOOLBAR_H */
diff --git a/src/ephy-window.c b/src/ephy-window.c
index ea63589..f8e7031 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -55,6 +55,7 @@
#include "ephy-state.h"
#include "ephy-stock-icons.h"
#include "ephy-topic-action.h"
+#include "ephy-toolbar.h"
#include "ephy-type-builtins.h"
#include "ephy-web-view.h"
#include "ephy-zoom-action.h"
@@ -1480,7 +1481,6 @@ setup_ui_manager (EphyWindow *window)
action =
g_object_new (EPHY_TYPE_NAVIGATION_HISTORY_ACTION,
"name", "NavigationBack",
- "label", _("_Back"),
"icon-name", "go-previous-symbolic",
"tooltip", _("Go to the previous visited page"),
"window", window,
@@ -1493,7 +1493,6 @@ setup_ui_manager (EphyWindow *window)
action =
g_object_new (EPHY_TYPE_NAVIGATION_HISTORY_ACTION,
"name", "NavigationForward",
- "label", _("_Forward"),
"icon-name", "go-next-symbolic",
"tooltip", _("Go to the next visited page"),
"window", window,
@@ -3560,13 +3559,12 @@ static GtkWidget *
setup_toolbar (EphyWindow *window)
{
GtkWidget *toolbar;
- GtkUIManager *manager;
GtkAction *action;
EphyWindowPrivate *priv = window->priv;
- manager = GTK_UI_MANAGER (ephy_window_get_ui_manager (window));
-
- toolbar = gtk_ui_manager_get_widget (manager, "/DefaultToolbar");
+ toolbar = ephy_toolbar_new (window);
+ gtk_box_pack_start (GTK_BOX (priv->menu_dock),
+ toolbar, FALSE, FALSE, 0);
action = gtk_action_group_get_action (priv->toolbar_action_group,
"NavigationBack");
@@ -3657,7 +3655,14 @@ ephy_window_constructor (GType type,
/* Setup the UI manager and connect verbs */
setup_ui_manager (window);
+ /* Create the notebook. */
+ /* FIXME: the notebook needs to exist before the toolbar,
+ * because EphyLocationEntry uses it... */
priv->notebook = setup_notebook (window);
+
+ /* Setup the toolbar. */
+ priv->toolbar = setup_toolbar (window);
+
g_signal_connect_swapped (priv->notebook, "open-link",
G_CALLBACK (ephy_link_open), window);
gtk_box_pack_start (GTK_BOX (priv->main_vbox),
@@ -3713,9 +3718,6 @@ ephy_window_constructor (GType type,
g_object_unref (css_provider);
g_object_unref (css_file);
- /* Setup the toolbar. */
- priv->toolbar = setup_toolbar (window);
-
/* Initialize the menus */
priv->enc_menu = ephy_encoding_menu_new (window);
@@ -3769,7 +3771,7 @@ ephy_window_constructor (GType type,
ephy_action_change_sensitivity_flags (action, SENS_FLAG_CHROME, TRUE);
}
}
-
+
/* ensure the UI is updated */
gtk_ui_manager_ensure_update (priv->manager);
@@ -4259,3 +4261,11 @@ ephy_window_set_location (EphyWindow *window,
ephy_location_action_set_address (EPHY_LOCATION_ACTION (action), address);
priv->updating_address = FALSE;
}
+
+GtkActionGroup *
+ephy_window_get_toolbar_action_group (EphyWindow *window)
+{
+ g_return_val_if_fail (EPHY_IS_WINDOW (window), NULL);
+
+ return window->priv->toolbar_action_group;
+}
diff --git a/src/ephy-window.h b/src/ephy-window.h
index c0f6747..e9b443f 100644
--- a/src/ephy-window.h
+++ b/src/ephy-window.h
@@ -85,6 +85,8 @@ EphyEmbedEvent *ephy_window_get_context_event (EphyWindow *window);
void ephy_window_set_downloads_box_visibility (EphyWindow *window,
gboolean show);
+GtkActionGroup *ephy_window_get_toolbar_action_group (EphyWindow *window);
+
G_END_DECLS
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]