aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ephy-page-menu-action.c77
-rw-r--r--src/ephy-page-menu-action.h11
-rw-r--r--src/ephy-window-action.c2
3 files changed, 61 insertions, 29 deletions
diff --git a/src/ephy-page-menu-action.c b/src/ephy-page-menu-action.c
index da2f49973..b97c6e23b 100644
--- a/src/ephy-page-menu-action.c
+++ b/src/ephy-page-menu-action.c
@@ -23,6 +23,12 @@
G_DEFINE_TYPE (EphyPageMenuAction, ephy_page_menu_action, EPHY_TYPE_WINDOW_ACTION);
+#define EPHY_PAGE_MENU_ACTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), EPHY_TYPE_PAGE_MENU_ACTION, EphyPageMenuActionPrivate))
+
+struct _EphyPageMenuActionPrivate {
+ GtkWidget *menu;
+};
+
static void
menu_position_func (GtkMenu *menu,
int *x,
@@ -55,40 +61,60 @@ menu_position_func (GtkMenu *menu,
}
static void
-button_press_cb (GtkWidget *button, GdkEventButton *event, GtkAction *action)
+visible_cb (GtkWidget *menu, GParamSpec *pspec, gpointer user_data)
{
- GtkWidget *menu;
- EphyWindow *window;
- GtkUIManager *manager;
- guint event_button = 1;
- guint32 event_time = 0;
+ if (gtk_widget_get_visible (menu))
+ gtk_style_context_add_class (gtk_widget_get_style_context (menu),
+ "active-menu");
+ else
+ gtk_style_context_remove_class (gtk_widget_get_style_context (menu),
+ "active-menu");
+}
+static void
+button_press_cb (GtkWidget *button, GdkEventButton *event, EphyPageMenuAction *action)
+{
+ GtkWidget *menu;
+ EphyWindow *window;
+ GtkUIManager *manager;
+ guint event_button = 1;
+ guint32 event_time = 0;
+
+ if (!action->priv->menu) {
window = ephy_window_action_get_window (EPHY_WINDOW_ACTION (action));
manager = GTK_UI_MANAGER (ephy_window_get_ui_manager (window));
menu = gtk_ui_manager_get_widget (manager, "/ui/PagePopup");
- if (!button) {
- GSList *l = gtk_action_get_proxies (action);
- if (GTK_IS_BUTTON (l->data))
- button = GTK_WIDGET (l->data);
- }
+ g_signal_connect (menu, "notify::visible",
+ G_CALLBACK (visible_cb), NULL);
+
+ action->priv->menu = menu;
+ }
+
- g_return_if_fail (GTK_IS_BUTTON (button));
+ if (!button) {
+ GSList *l = gtk_action_get_proxies (GTK_ACTION (action));
+ if (GTK_IS_BUTTON (l->data))
+ button = GTK_WIDGET (l->data);
+ }
- if (event) {
- event_button = event->button;
- event_time = event->time;
- }
+ g_return_if_fail (GTK_IS_BUTTON (button));
- gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
- (GtkMenuPositionFunc)menu_position_func, button,
- event_button, event_time);
+ if (event) {
+ event_button = event->button;
+ event_time = event->time;
+ }
+
+ gtk_menu_popup (GTK_MENU (action->priv->menu),
+ NULL, NULL,
+ (GtkMenuPositionFunc)menu_position_func, button,
+ event_button, event_time);
}
static void
ephy_page_menu_action_activate (GtkAction *action)
{
- button_press_cb (NULL, NULL, action);
+ button_press_cb (NULL, NULL, EPHY_PAGE_MENU_ACTION (action));
}
static void
@@ -115,14 +141,17 @@ ephy_page_menu_action_disconnect_proxy (GtkAction *action,
static void
ephy_page_menu_action_class_init (EphyPageMenuActionClass *klass)
{
- GtkActionClass *action_class = GTK_ACTION_CLASS (klass);
+ GtkActionClass *action_class = GTK_ACTION_CLASS (klass);
+
+ action_class->activate = ephy_page_menu_action_activate;
+ action_class->connect_proxy = ephy_page_menu_action_connect_proxy;
+ action_class->disconnect_proxy = ephy_page_menu_action_disconnect_proxy;
- action_class->activate = ephy_page_menu_action_activate;
- action_class->connect_proxy = ephy_page_menu_action_connect_proxy;
- action_class->disconnect_proxy = ephy_page_menu_action_disconnect_proxy;
+ g_type_class_add_private (klass, sizeof (EphyPageMenuActionPrivate));
}
static void
ephy_page_menu_action_init (EphyPageMenuAction *self)
{
+ self->priv = EPHY_PAGE_MENU_ACTION_GET_PRIVATE (self);
}
diff --git a/src/ephy-page-menu-action.h b/src/ephy-page-menu-action.h
index c510f944b..ca96d73c3 100644
--- a/src/ephy-page-menu-action.h
+++ b/src/ephy-page-menu-action.h
@@ -34,15 +34,18 @@ G_BEGIN_DECLS
#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;
+typedef struct _EphyPageMenuAction EphyPageMenuAction;
+typedef struct _EphyPageMenuActionClass EphyPageMenuActionClass;
+typedef struct _EphyPageMenuActionPrivate EphyPageMenuActionPrivate;
struct _EphyPageMenuActionClass {
- EphyWindowActionClass parent_class;
+ EphyWindowActionClass parent_class;
};
struct _EphyPageMenuAction {
- EphyWindowAction parent_instance;
+ EphyWindowAction parent_instance;
+
+ EphyPageMenuActionPrivate *priv;
};
GType ephy_page_menu_action_get_type (void) G_GNUC_CONST;
diff --git a/src/ephy-window-action.c b/src/ephy-window-action.c
index f04d7e5a3..22634ed99 100644
--- a/src/ephy-window-action.c
+++ b/src/ephy-window-action.c
@@ -88,7 +88,7 @@ ephy_window_action_class_init (EphyWindowActionClass *class)
PROP_WINDOW,
g_param_spec_object ("window", NULL, NULL,
G_TYPE_OBJECT,
- G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+ G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_CONSTRUCT));
g_type_class_add_private (object_class, sizeof (EphyWindowActionPrivate));
}