[gtk+/wip/matthiasc/kill-event-signals] file chooser: Use a multipress gesture
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/matthiasc/kill-event-signals] file chooser: Use a multipress gesture
- Date: Mon, 8 Jan 2018 03:37:06 +0000 (UTC)
commit 00701b4ef10cd5cead26fdd11af38816a7990097
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Jan 7 19:33:27 2018 -0500
file chooser: Use a multipress gesture
This replaces the use of ::button-press-event. There's two
issues with this commit:
1) We don't have a good way to do the equivalent of
gdk_event_triggers_context_menu with gestures
2) We have to defer to and idle to avoid ordering
issues with the treeviews own gestures
gtk/gtkfilechooserwidget.c | 51 +++++++++++++++++++++++++--------------
gtk/ui/gtkfilechooserwidget.ui | 1 -
2 files changed, 33 insertions(+), 19 deletions(-)
---
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index d50dd7e..621c0ad 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -78,6 +78,7 @@
#include "gtkseparator.h"
#include "gtkmodelbutton.h"
#include "gtkgesturelongpress.h"
+#include "gtkgesturemultipress.h"
#include "gtkdebug.h"
#include "gtkfilechoosererrorstackprivate.h"
@@ -251,6 +252,7 @@ struct _GtkFileChooserWidgetPrivate {
GFile *rename_file_source_file;
GtkGesture *long_press_gesture;
+ GtkGesture *multipress_gesture;
GtkFileSystemModel *browse_files_model;
char *browse_files_last_selected_name;
@@ -2302,31 +2304,39 @@ list_popup_menu_cb (GtkWidget *widget,
/* Callback used when a button is pressed on the file list. We trap button 3 to
* bring up a popup menu.
*/
-static gboolean
-list_button_press_event_cb (GtkWidget *widget,
- GdkEventButton *event,
- GtkFileChooserWidget *impl)
-{
- GtkFileChooserWidgetPrivate *priv = impl->priv;
- static gboolean in_press = FALSE;
+
+typedef struct {
+ GtkFileChooserWidget *impl;
double x;
double y;
+} PopoverData;
- if (in_press)
- return FALSE;
+static gboolean
+file_list_show_popover_in_idle (gpointer data)
+{
+ PopoverData *pd = data;
- if (!gdk_event_triggers_context_menu ((GdkEvent *) event))
- return FALSE;
+ file_list_show_popover (pd->impl, pd->x, pd->y);
+ g_free (data);
- in_press = TRUE;
- gtk_widget_event (priv->browse_files_tree_view, (GdkEvent *) event);
- in_press = FALSE;
+ return G_SOURCE_REMOVE;
+}
- gdk_event_get_coords ((GdkEvent *)event, &x, &y);
+static void
+multi_press_cb (GtkGesture *gesture,
+ int n_press,
+ double x,
+ double y,
+ GtkFileChooserWidget *impl)
+{
+ PopoverData *pd;
- file_list_show_popover (impl, x, y);
+ pd = g_new (PopoverData, 1);
+ pd->impl = impl;
+ pd->x = x;
+ pd->y = y;
- return TRUE;
+ g_idle_add (file_list_show_popover_in_idle, pd);
}
static void
@@ -3538,6 +3548,7 @@ gtk_file_chooser_widget_dispose (GObject *object)
}
g_clear_object (&priv->long_press_gesture);
+ g_clear_object (&priv->multipress_gesture);
G_OBJECT_CLASS (gtk_file_chooser_widget_parent_class)->dispose (object);
}
@@ -8382,7 +8393,6 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
gtk_widget_class_bind_template_callback (widget_class, file_list_drag_data_received_cb);
gtk_widget_class_bind_template_callback (widget_class, list_popup_menu_cb);
gtk_widget_class_bind_template_callback (widget_class, file_list_query_tooltip_cb);
- gtk_widget_class_bind_template_callback (widget_class, list_button_press_event_cb);
gtk_widget_class_bind_template_callback (widget_class, list_row_activated);
gtk_widget_class_bind_template_callback (widget_class, file_list_drag_begin_cb);
gtk_widget_class_bind_template_callback (widget_class, file_list_drag_motion_cb);
@@ -8542,6 +8552,11 @@ gtk_file_chooser_widget_init (GtkFileChooserWidget *impl)
g_signal_connect (priv->long_press_gesture, "pressed",
G_CALLBACK (long_press_cb), impl);
+ priv->multipress_gesture = gtk_gesture_multi_press_new (priv->browse_files_tree_view);
+ gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->multipress_gesture), GDK_BUTTON_SECONDARY);
+ g_signal_connect (priv->multipress_gesture, "pressed",
+ G_CALLBACK (multi_press_cb), impl);
+
/* Setup various attributes and callbacks in the UI
* which cannot be done with GtkBuilder.
*/
diff --git a/gtk/ui/gtkfilechooserwidget.ui b/gtk/ui/gtkfilechooserwidget.ui
index f178927..5186a72 100644
--- a/gtk/ui/gtkfilechooserwidget.ui
+++ b/gtk/ui/gtkfilechooserwidget.ui
@@ -143,7 +143,6 @@
<property name="AtkObject::accessible-name"
translatable="yes">Files</property>
</object>
</child>
- <signal name="button-press-event"
handler="list_button_press_event_cb" swapped="no"/>
<signal name="drag-data-received"
handler="file_list_drag_data_received_cb" swapped="no"/>
<signal name="drag-drop" handler="file_list_drag_drop_cb"
swapped="no"/>
<signal name="drag-begin" handler="file_list_drag_begin_cb"
swapped="no"/>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]