[epiphany] Refactor GtkActions with attached EphyWindows



commit 52cdd6df6cb561a48032358b3eedce16cfa2c9fb
Author: Xan Lopez <xan igalia com>
Date:   Mon Jan 16 20:11:40 2012 +0100

    Refactor GtkActions with attached EphyWindows
    
    Make a GtkAction subclass that only holds an EphyWindow and nothing
    else, and use it throughout. Allows us to kill some duplicated code.

 src/Makefile.am                        |    4 +-
 src/ephy-combined-stop-reload-action.c |   23 +-----
 src/ephy-link-action.c                 |    3 +-
 src/ephy-link-action.h                 |    6 +-
 src/ephy-navigation-action.c           |  114 --------------------------------
 src/ephy-navigation-action.h           |   65 ------------------
 src/ephy-navigation-history-action.c   |    4 +-
 src/ephy-navigation-history-action.h   |    6 +-
 src/ephy-page-menu-action.c            |    4 +-
 src/ephy-page-menu-action.h            |    6 +-
 src/ephy-toolbar.c                     |    6 +-
 src/ephy-window-action.c               |  102 ++++++++++++++++++++++++++++
 src/ephy-window-action.h               |   62 +++++++++++++++++
 13 files changed, 190 insertions(+), 215 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index f89a021..24d47ae 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -25,11 +25,11 @@ NOINST_H_FILES = \
 	ephy-link-action.h			\
 	ephy-lockdown.h				\
 	ephy-location-action.h			\
-	ephy-navigation-action.h		\
 	ephy-navigation-history-action.h	\
 	ephy-page-menu-action.h			\
 	ephy-password-info.h			\
 	ephy-toolbar.h				\
+	ephy-window-action.h			\
 	languages.h				\
 	pdm-dialog.h				\
 	popup-commands.h			\
@@ -64,7 +64,6 @@ libephymain_la_SOURCES = \
 	ephy-link-action.c			\
 	ephy-location-action.c			\
 	ephy-lockdown.c				\
-	ephy-navigation-action.c		\
 	ephy-navigation-history-action.c	\
 	ephy-notebook.c				\
 	ephy-page-menu-action.c			\
@@ -73,6 +72,7 @@ libephymain_la_SOURCES = \
 	ephy-shell.c				\
 	ephy-toolbar.c				\
 	ephy-window.c				\
+	ephy-window-action.c			\
 	pdm-dialog.c				\
 	popup-commands.c			\
 	prefs-dialog.c				\
diff --git a/src/ephy-combined-stop-reload-action.c b/src/ephy-combined-stop-reload-action.c
index 0789a28..0e85cd1 100644
--- a/src/ephy-combined-stop-reload-action.c
+++ b/src/ephy-combined-stop-reload-action.c
@@ -22,12 +22,12 @@
 #include "config.h"
 #include "ephy-combined-stop-reload-action.h"
 
-#include "ephy-window.h"
+#include "ephy-window-action.h"
 #include "window-commands.h"
 
 #include <glib/gi18n.h>
 
-G_DEFINE_TYPE (EphyCombinedStopReloadAction, ephy_combined_stop_reload_action, GTK_TYPE_ACTION)
+G_DEFINE_TYPE (EphyCombinedStopReloadAction, ephy_combined_stop_reload_action, EPHY_TYPE_WINDOW_ACTION)
 
 #define COMBINED_STOP_RELOAD_ACTION_PRIVATE(o) \
   (G_TYPE_INSTANCE_GET_PRIVATE ((o), EPHY_TYPE_COMBINED_STOP_RELOAD_ACTION, EphyCombinedStopReloadActionPrivate))
@@ -35,7 +35,6 @@ G_DEFINE_TYPE (EphyCombinedStopReloadAction, ephy_combined_stop_reload_action, G
 struct _EphyCombinedStopReloadActionPrivate
 {
   gboolean loading;
-  EphyWindow *window;
   gulong action_handler_id;
 };
 
@@ -55,8 +54,7 @@ typedef enum {
 
 enum {
   PROP_0,
-  PROP_LOADING,
-  PROP_WINDOW
+  PROP_LOADING
 };
 
 void
@@ -86,7 +84,7 @@ ephy_combined_stop_reload_action_set_loading (EphyCombinedStopReloadAction *acti
 
   priv->action_handler_id = g_signal_connect (action, "activate",
                                               combined_stop_reload_action_entries[action_enum].callback,
-                                              priv->window);
+                                              ephy_window_action_get_window (EPHY_WINDOW_ACTION (action)));
 
   priv->loading = loading;
 }
@@ -104,9 +102,6 @@ ephy_combined_stop_reload_action_get_property (GObject    *object,
     case PROP_LOADING:
       g_value_set_boolean (value, action->priv->loading);
       break;
-    case PROP_WINDOW:
-      g_value_set_object (value, action->priv->window);
-      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -126,9 +121,6 @@ ephy_combined_stop_reload_action_set_property (GObject      *object,
     ephy_combined_stop_reload_action_set_loading (action,
                                       g_value_get_boolean (value));
     break;
-  case PROP_WINDOW:
-    action->priv->window = EPHY_WINDOW (g_value_get_object (value));
-    break;
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
   }
@@ -149,13 +141,6 @@ ephy_combined_stop_reload_action_class_init (EphyCombinedStopReloadActionClass *
                                    g_param_spec_boolean ("loading", NULL, NULL,
                                                          FALSE,
                                                          G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
-
-  g_object_class_install_property (object_class,
-                                   PROP_WINDOW,
-                                   g_param_spec_object ("window", NULL, NULL,
-                                                        EPHY_TYPE_WINDOW,
-                                                        G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
-
 }
 
 static void
diff --git a/src/ephy-link-action.c b/src/ephy-link-action.c
index 804aae7..665975a 100644
--- a/src/ephy-link-action.c
+++ b/src/ephy-link-action.c
@@ -25,10 +25,11 @@
 #include "ephy-debug.h"
 #include "ephy-gui.h"
 #include "ephy-link.h"
+#include "ephy-window-action.h"
 
 #include <gtk/gtk.h>
 
-G_DEFINE_TYPE_WITH_CODE (EphyLinkAction, ephy_link_action, GTK_TYPE_ACTION,
+G_DEFINE_TYPE_WITH_CODE (EphyLinkAction, ephy_link_action, EPHY_TYPE_WINDOW_ACTION,
 			 G_IMPLEMENT_INTERFACE (EPHY_TYPE_LINK,
 						NULL))
 
diff --git a/src/ephy-link-action.h b/src/ephy-link-action.h
index a6b4419..b2113bd 100644
--- a/src/ephy-link-action.h
+++ b/src/ephy-link-action.h
@@ -24,6 +24,8 @@
 #ifndef EPHY_LINK_ACTION_H
 #define EPHY_LINK_ACTION_H
 
+#include "ephy-window-action.h"
+
 #include <gtk/gtk.h>
 
 G_BEGIN_DECLS
@@ -51,14 +53,14 @@ typedef struct _EphyLinkActionGroupClass	EphyLinkActionGroupClass;
 
 struct _EphyLinkAction
 {
-	GtkAction parent_instance;
+	EphyWindowAction parent_instance;
 
 	EphyLinkActionPrivate *priv;
 };
 
 struct _EphyLinkActionClass
 {
-	GtkActionClass parent_class;
+	EphyWindowActionClass parent_class;
 };
 
 struct _EphyLinkActionGroup
diff --git a/src/ephy-navigation-history-action.c b/src/ephy-navigation-history-action.c
index cac0735..1fdf937 100644
--- a/src/ephy-navigation-history-action.c
+++ b/src/ephy-navigation-history-action.c
@@ -56,7 +56,7 @@ enum {
 static void ephy_navigation_history_action_init       (EphyNavigationHistoryAction *action);
 static void ephy_navigation_history_action_class_init (EphyNavigationHistoryActionClass *klass);
 
-G_DEFINE_TYPE (EphyNavigationHistoryAction, ephy_navigation_history_action, EPHY_TYPE_NAVIGATION_ACTION)
+G_DEFINE_TYPE (EphyNavigationHistoryAction, ephy_navigation_history_action, EPHY_TYPE_LINK_ACTION)
 
 static void
 ephy_history_cleared_cb (EphyHistory *history,
@@ -74,7 +74,7 @@ action_activate (GtkAction *action)
   WebKitWebView *web_view;
 
   history_action = EPHY_NAVIGATION_HISTORY_ACTION (action);
-  window = _ephy_navigation_action_get_window (EPHY_NAVIGATION_ACTION (action));
+  window = ephy_window_action_get_window (EPHY_WINDOW_ACTION (action));
   embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
   g_return_if_fail (embed != NULL);
 
diff --git a/src/ephy-navigation-history-action.h b/src/ephy-navigation-history-action.h
index 6388b4d..d455e86 100644
--- a/src/ephy-navigation-history-action.h
+++ b/src/ephy-navigation-history-action.h
@@ -26,7 +26,7 @@
 #ifndef EPHY_NAVIGATION_HISTORY_ACTION_H
 #define EPHY_NAVIGATION_HISTORY_ACTION_H
 
-#include "ephy-navigation-action.h"
+#include "ephy-link-action.h"
 
 G_BEGIN_DECLS
 
@@ -49,7 +49,7 @@ typedef struct _EphyNavigationHistoryActionClass	EphyNavigationHistoryActionClas
 
 struct _EphyNavigationHistoryAction
 {
-  EphyNavigationAction parent;
+  EphyLinkAction parent;
 
   /*< private >*/
   EphyNavigationHistoryActionPrivate *priv;
@@ -57,7 +57,7 @@ struct _EphyNavigationHistoryAction
 
 struct _EphyNavigationHistoryActionClass
 {
-  EphyNavigationActionClass parent_class;
+  EphyLinkActionClass parent_class;
 };
 
 GType ephy_navigation_history_action_get_type (void);
diff --git a/src/ephy-page-menu-action.c b/src/ephy-page-menu-action.c
index 2342512..dad11c4 100644
--- a/src/ephy-page-menu-action.c
+++ b/src/ephy-page-menu-action.c
@@ -21,7 +21,7 @@
 #include "config.h"
 #include "ephy-page-menu-action.h"
 
-G_DEFINE_TYPE (EphyPageMenuAction, ephy_page_menu_action, EPHY_TYPE_NAVIGATION_ACTION);
+G_DEFINE_TYPE (EphyPageMenuAction, ephy_page_menu_action, EPHY_TYPE_WINDOW_ACTION);
 
 static void
 menu_position_func (GtkMenu           *menu,
@@ -66,7 +66,7 @@ ephy_page_menu_action_activate (GtkAction *action)
     guint activate_button = 1;
     guint32 activate_time = 0;
 
-    window = _ephy_navigation_action_get_window (EPHY_NAVIGATION_ACTION (action));
+    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");
 
diff --git a/src/ephy-page-menu-action.h b/src/ephy-page-menu-action.h
index c7239b6..c510f94 100644
--- a/src/ephy-page-menu-action.h
+++ b/src/ephy-page-menu-action.h
@@ -21,7 +21,7 @@
 #ifndef __EPHY_PAGE_MENU_ACTION_H__
 #define __EPHY_PAGE_MENU_ACTION_H__
 
-#include "ephy-navigation-action.h"
+#include "ephy-window-action.h"
 
 #include <gtk/gtk.h>
 
@@ -38,11 +38,11 @@ typedef struct _EphyPageMenuAction      EphyPageMenuAction;
 typedef struct _EphyPageMenuActionClass EphyPageMenuActionClass;
 
 struct _EphyPageMenuActionClass {
-    EphyNavigationActionClass parent_class;
+    EphyWindowActionClass parent_class;
 };
 
 struct _EphyPageMenuAction {
-    EphyNavigationAction parent_instance;
+    EphyWindowAction parent_instance;
 };
 
 GType ephy_page_menu_action_get_type (void) G_GNUC_CONST;
diff --git a/src/ephy-toolbar.c b/src/ephy-toolbar.c
index b167f06..2e1b119 100644
--- a/src/ephy-toolbar.c
+++ b/src/ephy-toolbar.c
@@ -21,6 +21,8 @@
 #include "config.h"
 #include "ephy-toolbar.h"
 
+#include "ephy-middle-clickable-button.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))
@@ -90,7 +92,7 @@ ephy_toolbar_constructed (GObject *object)
   box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
 
   /* Back */
-  tool_button = gtk_button_new ();
+  tool_button = ephy_middle_clickable_button_new ();
   /* FIXME: apparently we need an image inside the button for the action
    * icon to appear. */
   gtk_button_set_image (GTK_BUTTON (tool_button), gtk_image_new ());
@@ -101,7 +103,7 @@ ephy_toolbar_constructed (GObject *object)
   gtk_container_add (GTK_CONTAINER (box), GTK_WIDGET (tool_button));
 
   /* Forward */
-  tool_button = gtk_button_new ();
+  tool_button = ephy_middle_clickable_button_new ();
   /* FIXME: apparently we need an image inside the button for the action
    * icon to appear. */
   gtk_button_set_image (GTK_BUTTON (tool_button), gtk_image_new ());
diff --git a/src/ephy-window-action.c b/src/ephy-window-action.c
new file mode 100644
index 0000000..f04d7e5
--- /dev/null
+++ b/src/ephy-window-action.c
@@ -0,0 +1,102 @@
+/* -*- 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-window-action.h"
+
+#include <gtk/gtk.h>
+
+#define EPHY_WINDOW_ACTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), EPHY_TYPE_WINDOW_ACTION, EphyWindowActionPrivate))
+
+struct _EphyWindowActionPrivate {
+    EphyWindow *window;
+};
+
+enum {
+    PROP_0,
+    PROP_WINDOW
+};
+
+G_DEFINE_TYPE (EphyWindowAction, ephy_window_action, GTK_TYPE_ACTION)
+
+static void
+ephy_window_action_init (EphyWindowAction *action)
+{
+    action->priv = EPHY_WINDOW_ACTION_GET_PRIVATE (action);
+}
+
+static void
+ephy_window_action_set_property (GObject *object,
+                                 guint property_id,
+                                 const GValue *value,
+                                 GParamSpec *pspec)
+{
+    EphyWindowAction *action = EPHY_WINDOW_ACTION (object);
+    
+    switch (property_id) {
+    case PROP_WINDOW:
+        action->priv->window = EPHY_WINDOW (g_value_get_object (value));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    }
+}
+
+static void
+ephy_window_action_get_property (GObject *object,
+                                 guint property_id,
+                                 GValue *value,
+                                 GParamSpec *pspec)
+{
+    EphyWindowAction *action = EPHY_WINDOW_ACTION (object);
+    
+    switch (property_id) {
+    case PROP_WINDOW:
+        g_value_set_object (value, action->priv->window);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    }
+}
+
+static void
+ephy_window_action_class_init (EphyWindowActionClass *class)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS (class);
+    
+    object_class->set_property = ephy_window_action_set_property;
+    object_class->get_property = ephy_window_action_get_property;
+    
+    g_object_class_install_property (object_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_type_class_add_private (object_class, sizeof (EphyWindowActionPrivate));
+}
+
+EphyWindow *
+ephy_window_action_get_window (EphyWindowAction *action)
+{
+    g_return_val_if_fail (EPHY_IS_WINDOW_ACTION (action), NULL);
+
+    return action->priv->window;
+}
diff --git a/src/ephy-window-action.h b/src/ephy-window-action.h
new file mode 100644
index 0000000..388bdfa
--- /dev/null
+++ b/src/ephy-window-action.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_WINDOW_ACTION_H
+#define EPHY_WINDOW_ACTION_H
+
+#include "ephy-window.h"
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_WINDOW_ACTION            (ephy_window_action_get_type ())
+#define EPHY_WINDOW_ACTION(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), EPHY_TYPE_WINDOW_ACTION, EphyWindowAction))
+#define EPHY_WINDOW_ACTION_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), EPHY_TYPE_WINDOW_ACTION, EphyWindowActionClass))
+#define EPHY_IS_WINDOW_ACTION(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EPHY_TYPE_WINDOW_ACTION))
+#define EPHY_IS_WINDOW_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), EPHY_TYPE_WINDOW_ACTION))
+#define EPHY_WINDOW_ACTION_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), EPHY_TYPE_WINDOW_ACTION, EphyWindowActionClass))
+
+typedef struct _EphyWindowAction                EphyWindowAction;
+typedef struct _EphyWindowActionPrivate EphyWindowActionPrivate;
+typedef struct _EphyWindowActionClass   EphyWindowActionClass;
+
+struct _EphyWindowAction {
+  GtkAction parent;
+
+  /*< private >*/
+  EphyWindowActionPrivate *priv;
+};
+
+struct _EphyWindowActionClass {
+  GtkActionClass parent_class;
+};
+
+GType ephy_window_action_get_type (void);
+
+EphyWindow     *ephy_window_action_get_window       (EphyWindowAction *action);
+
+G_END_DECLS
+
+#endif



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