diff options
author | Claudio Saavedra <csaavedra@igalia.com> | 2012-03-08 17:59:03 +0800 |
---|---|---|
committer | Claudio Saavedra <csaavedra@igalia.com> | 2012-03-13 16:14:03 +0800 |
commit | 12c233832347dddfe64ac842998e043692ecb2be (patch) | |
tree | c1518fc04e54e28f10e932ed9574e679ddf49a83 | |
parent | 63cbd77dc4f5bad34b6ebfae18416e5c73886984 (diff) | |
download | gsoc2013-epiphany-12c233832347dddfe64ac842998e043692ecb2be.tar gsoc2013-epiphany-12c233832347dddfe64ac842998e043692ecb2be.tar.gz gsoc2013-epiphany-12c233832347dddfe64ac842998e043692ecb2be.tar.bz2 gsoc2013-epiphany-12c233832347dddfe64ac842998e043692ecb2be.tar.lz gsoc2013-epiphany-12c233832347dddfe64ac842998e043692ecb2be.tar.xz gsoc2013-epiphany-12c233832347dddfe64ac842998e043692ecb2be.tar.zst gsoc2013-epiphany-12c233832347dddfe64ac842998e043692ecb2be.zip |
ephy-history-view: add row-middle-clicked signal
https://bugzilla.gnome.org/show_bug.cgi?id=671635
-rw-r--r-- | lib/widgets/ephy-history-view.c | 69 | ||||
-rw-r--r-- | lib/widgets/ephy-history-view.h | 5 |
2 files changed, 74 insertions, 0 deletions
diff --git a/lib/widgets/ephy-history-view.c b/lib/widgets/ephy-history-view.c index 461d308a2..27d45aead 100644 --- a/lib/widgets/ephy-history-view.c +++ b/lib/widgets/ephy-history-view.c @@ -27,8 +27,21 @@ #include <glib/gi18n.h> #include <gtk/gtk.h> +#define EPHY_HISTORY_VIEW_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_HISTORY_VIEW, EphyHistoryViewPrivate)) + +struct _EphyHistoryViewPrivate +{ + GtkTreePath *pressed_path; +}; + G_DEFINE_TYPE (EphyHistoryView, ephy_history_view, GTK_TYPE_TREE_VIEW) +enum { + ROW_MIDDLE_CLICKED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL]; static gboolean button_event_modifies_selection (GdkEventButton *event) @@ -40,6 +53,7 @@ static gboolean ephy_history_view_button_press (GtkWidget *treeview, GdkEventButton *event) { + EphyHistoryView *view; GtkTreeSelection *selection; GtkTreePath *path = NULL; gboolean path_is_selected, call_parent = TRUE; @@ -73,6 +87,11 @@ ephy_history_view_button_press (GtkWidget *treeview, gboolean retval; g_signal_emit_by_name (treeview, "popup_menu", &retval); + } else if (event->button == 2) { + view = EPHY_HISTORY_VIEW (treeview); + if (view->priv->pressed_path) + gtk_tree_path_free (view->priv->pressed_path); + view->priv->pressed_path = gtk_tree_path_copy (path); } gtk_tree_path_free (path); } @@ -80,12 +99,60 @@ ephy_history_view_button_press (GtkWidget *treeview, return FALSE; } +static gboolean +ephy_history_view_button_release (GtkWidget *treeview, + GdkEventButton *event) +{ + EphyHistoryView *view; + GtkTreePath *path; + + view = EPHY_HISTORY_VIEW (treeview); + + if (view->priv->pressed_path && event->button == 2 && + gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (treeview), + event->x, + event->y, + &path, + NULL, NULL, NULL)) { + if (gtk_tree_path_compare (view->priv->pressed_path, path) == 0) + g_signal_emit (view, signals[ROW_MIDDLE_CLICKED], 0, path); + gtk_tree_path_free (path); + } + + return FALSE; +} + +static void +ephy_history_view_finalize (GObject *object) +{ + EphyHistoryView *view = EPHY_HISTORY_VIEW (object); + + if (view->priv->pressed_path) + gtk_tree_path_free (view->priv->pressed_path); + + G_OBJECT_CLASS (ephy_history_view_parent_class)->finalize (object); +} + static void ephy_history_view_class_init (EphyHistoryViewClass *klass) { + GObjectClass *object_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + object_class->finalize = ephy_history_view_finalize; widget_class->button_press_event = ephy_history_view_button_press; + widget_class->button_release_event = ephy_history_view_button_release; + + signals[ROW_MIDDLE_CLICKED] = g_signal_new ("row-middle-clicked", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EphyHistoryViewClass, row_middle_clicked), + NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, + 1, + G_TYPE_POINTER); + g_type_class_add_private (object_class, sizeof (EphyHistoryViewPrivate)); } static void @@ -93,6 +160,8 @@ ephy_history_view_init (EphyHistoryView *self) { GtkTreeSelection *selection; + self->priv = EPHY_HISTORY_VIEW_GET_PRIVATE (self); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self)); gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE); } diff --git a/lib/widgets/ephy-history-view.h b/lib/widgets/ephy-history-view.h index d6c2d0656..3a502edb2 100644 --- a/lib/widgets/ephy-history-view.h +++ b/lib/widgets/ephy-history-view.h @@ -40,10 +40,15 @@ typedef struct _EphyHistoryViewPrivate EphyHistoryViewPrivate; struct _EphyHistoryView { GtkTreeView parent; + + /*< private >*/ + EphyHistoryViewPrivate *priv; }; struct _EphyHistoryViewClass { GtkTreeViewClass parent_class; + + void (* row_middle_clicked) (EphyHistoryView *view, GtkTreePath *path); }; GType ephy_history_view_get_type (void) G_GNUC_CONST; |