[nautilus: 1/2] view-icon-controller: Add longpress gesture to open context menu
- From: Carlos Soriano <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus: 1/2] view-icon-controller: Add longpress gesture to open context menu
- Date: Wed, 14 Mar 2018 15:22:05 +0000 (UTC)
commit b431c5920ce8c427f8a45244b739eaa60423eec0
Author: Jan-Michael Brummer <jan brummer tabos org>
Date: Wed Jan 24 18:55:30 2018 +0100
view-icon-controller: Add longpress gesture to open context menu
Touch screen devices currently do not have a possibility to open the context menu
within the new experimental views.
This patch adds a long press gesture to within view icon controller to open the context menu.
Close: https://gitlab.gnome.org/GNOME/nautilus/issues/221
src/nautilus-view-icon-controller.c | 66 +++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
---
diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c
index 353f48572..33c795f9a 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -687,6 +687,61 @@ on_button_press_event (GtkWidget *widget,
return GDK_EVENT_STOP;
}
+static void
+on_longpress_gesture_pressed_callback (GtkGestureLongPress *gesture,
+ gdouble x,
+ gdouble y,
+ gpointer user_data)
+{
+ NautilusViewIconController *self;
+ g_autoptr (GList) selection = NULL;
+ GtkWidget *child_at_pos;
+ GdkEventButton *event_button;
+ GdkEventSequence *event_sequence;
+ GdkEvent *event;
+
+ event_sequence = gtk_gesture_get_last_updated_sequence (GTK_GESTURE (gesture));
+ event = (GdkEvent *) gtk_gesture_get_last_event (GTK_GESTURE (gesture), event_sequence);
+
+ self = NAUTILUS_VIEW_ICON_CONTROLLER (user_data);
+ event_button = (GdkEventButton *) event;
+
+ /* Need to update the selection so the popup has the right actions enabled */
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (self));
+ child_at_pos = GTK_WIDGET (gtk_flow_box_get_child_at_pos (GTK_FLOW_BOX (self->view_ui),
+ event_button->x, event_button->y));
+ if (child_at_pos != NULL)
+ {
+ NautilusFile *selected_file;
+ NautilusViewItemModel *item_model;
+
+ item_model = nautilus_view_icon_item_ui_get_model (NAUTILUS_VIEW_ICON_ITEM_UI (child_at_pos));
+ selected_file = nautilus_view_item_model_get_file (item_model);
+ if (g_list_find (selection, selected_file) == NULL)
+ {
+ g_list_foreach (selection, (GFunc) g_object_unref, NULL);
+ selection = g_list_append (NULL, g_object_ref (selected_file));
+ }
+ else
+ {
+ selection = g_list_prepend (selection, g_object_ref (selected_file));
+ }
+
+ nautilus_view_set_selection (NAUTILUS_VIEW (self), selection);
+
+ nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (self),
+ event);
+ }
+ else
+ {
+ nautilus_view_set_selection (NAUTILUS_VIEW (self), NULL);
+ nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (self),
+ event);
+ }
+
+ g_list_foreach (selection, (GFunc) g_object_unref, NULL);
+}
+
static int
real_compare_files (NautilusFilesView *files_view,
NautilusFile *file1,
@@ -842,6 +897,7 @@ constructed (GObject *object)
NautilusViewIconController *self = NAUTILUS_VIEW_ICON_CONTROLLER (object);
GtkWidget *content_widget;
GActionGroup *view_action_group;
+ GtkGesture *longpress_gesture;
self->model = nautilus_view_model_new ();
self->view_ui = nautilus_view_icon_ui_new (self);
@@ -853,6 +909,16 @@ constructed (GObject *object)
g_signal_connect (GTK_WIDGET (self->event_box), "button-press-event",
(GCallback) on_button_press_event, self);
+ longpress_gesture = gtk_gesture_long_press_new (GTK_WIDGET (self->event_box));
+ gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (longpress_gesture),
+ GTK_PHASE_CAPTURE);
+ gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (longpress_gesture),
+ TRUE);
+ g_signal_connect (longpress_gesture, "pressed",
+ (GCallback) on_longpress_gesture_pressed_callback,
+ self);
+
+
content_widget = nautilus_files_view_get_content_widget (NAUTILUS_FILES_VIEW (self));
gtk_container_add (GTK_CONTAINER (content_widget), GTK_WIDGET (self->event_box));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]