places view: Stop using ::button-press-event

Instead, use a multi-press gesture in the row widget,
and emit ::popup-menu from there.
This commit is contained in:
Matthias Clasen 2018-01-07 20:40:11 -05:00
parent 270b6d3a84
commit 1818e7bed2
2 changed files with 19 additions and 28 deletions

View File

@ -99,9 +99,6 @@ struct _GtkPlacesViewPrivate
static void mount_volume (GtkPlacesView *view,
GVolume *volume);
static gboolean on_button_press_event (GtkPlacesViewRow *row,
GdkEventButton *event);
static void on_eject_button_clicked (GtkWidget *widget,
GtkPlacesViewRow *row);
@ -662,15 +659,7 @@ insert_row (GtkPlacesView *view,
g_object_set_data (G_OBJECT (row), "is-network", GINT_TO_POINTER (is_network));
g_signal_connect_swapped (GTK_PLACES_VIEW_ROW (row),
"button-press-event",
G_CALLBACK (on_button_press_event),
row);
g_signal_connect (row,
"popup-menu",
G_CALLBACK (on_row_popup_menu),
row);
g_signal_connect (row, "popup-menu", G_CALLBACK (on_row_popup_menu), row);
g_signal_connect (gtk_places_view_row_get_eject_button (GTK_PLACES_VIEW_ROW (row)),
"clicked",
@ -1697,22 +1686,6 @@ on_row_popup_menu (GtkPlacesViewRow *row)
return TRUE;
}
static gboolean
on_button_press_event (GtkPlacesViewRow *row,
GdkEventButton *event)
{
if (row &&
gdk_event_triggers_context_menu ((GdkEvent*) event) &&
gdk_event_get_event_type ((GdkEvent *)event) == GDK_BUTTON_PRESS)
{
popup_menu (row, event);
return TRUE;
}
return FALSE;
}
static gboolean
on_key_press_event (GtkWidget *widget,
GdkEventKey *event,

View File

@ -34,6 +34,7 @@
#include "gtkspinner.h"
#include "gtkstack.h"
#include "gtktypebuiltins.h"
#include "gtkgesturemultipress.h"
#else
#include <gtk/gtk.h>
#endif
@ -55,6 +56,8 @@ struct _GtkPlacesViewRow
GMount *mount;
GFile *file;
GtkGesture *gesture;
GCancellable *cancellable;
gint is_network : 1;
@ -192,6 +195,16 @@ measure_available_space (GtkPlacesViewRow *row)
}
}
static void
pressed_cb (GtkGesture *gesture,
int n_pressed,
double x,
double y,
GtkPlacesViewRow *row)
{
g_signal_emit_by_name (row, "popup-menu", 0);
}
static void
gtk_places_view_row_finalize (GObject *object)
{
@ -203,6 +216,7 @@ gtk_places_view_row_finalize (GObject *object)
g_clear_object (&self->mount);
g_clear_object (&self->file);
g_clear_object (&self->cancellable);
g_clear_object (&self->gesture);
G_OBJECT_CLASS (gtk_places_view_row_parent_class)->finalize (object);
}
@ -384,6 +398,10 @@ static void
gtk_places_view_row_init (GtkPlacesViewRow *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
self->gesture = gtk_gesture_multi_press_new (GTK_WIDGET (self));
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (self->gesture), GDK_BUTTON_SECONDARY);
g_signal_connect (self->gesture, "pressed", G_CALLBACK (pressed_cb), self);
}
GtkWidget*