[nautilus/antonioffix-menus-and-popovers: 12/14] files-view: Open context menu on longpress
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/antonioffix-menus-and-popovers: 12/14] files-view: Open context menu on longpress
- Date: Mon, 29 Jan 2018 23:03:13 +0000 (UTC)
commit fce822dddfa3990db4211b93807ace3fbd0851df
Author: Jan-Michael Brummer <jan brummer tabos org>
Date: Sun Dec 17 13:07:04 2017 +0100
files-view: Open context menu on longpress
An important portion of file management functionality
is exclusively available through context menus.
Currently, when using a touchscreen, there is no way
to open a context menu.
Fix this adding a longpress gesture to popup context
menus on canvas view and list view.
Closes: https://gitlab.gnome.org/GNOME/nautilus/issues/178
src/nautilus-canvas-container.c | 6 ++---
src/nautilus-canvas-view.c | 45 ++++++++++++++++++++++++++++++----
src/nautilus-files-view.c | 4 ++--
src/nautilus-files-view.h | 4 ++--
src/nautilus-list-view.c | 48 +++++++++++++++++++++++++++++++++++--
src/nautilus-pathbar.c | 4 ++--
src/nautilus-ui-utilities.c | 8 +++----
src/nautilus-ui-utilities.h | 6 ++---
src/nautilus-view-icon-controller.c | 4 ++--
9 files changed, 105 insertions(+), 24 deletions(-)
---
diff --git a/src/nautilus-canvas-container.c b/src/nautilus-canvas-container.c
index 5372df654..e12ef6d7c 100644
--- a/src/nautilus-canvas-container.c
+++ b/src/nautilus-canvas-container.c
@@ -3621,13 +3621,13 @@ nautilus_canvas_container_get_icon_text (NautilusCanvasContainer *container,
static gboolean
handle_popups (NautilusCanvasContainer *container,
- GdkEventKey *event,
+ GdkEvent *event,
const char *signal)
{
/* ensure we clear the drag state before showing the menu */
clear_drag_state (container);
- g_signal_emit_by_name (container, signal, NULL);
+ g_signal_emit_by_name (container, signal, event);
return TRUE;
}
@@ -3723,7 +3723,7 @@ key_press_event (GtkWidget *widget,
*/
if (event->state & GDK_CONTROL_MASK)
{
- handled = handle_popups (container, event,
+ handled = handle_popups (container, (GdkEvent *) event,
"context_click_background");
}
}
diff --git a/src/nautilus-canvas-view.c b/src/nautilus-canvas-view.c
index f384eed7f..bac5f6d46 100644
--- a/src/nautilus-canvas-view.c
+++ b/src/nautilus-canvas-view.c
@@ -1184,24 +1184,26 @@ selection_changed_callback (NautilusCanvasContainer *container,
static void
canvas_container_context_click_selection_callback (NautilusCanvasContainer *container,
- GdkEventButton *event,
+ const GdkEvent *event,
NautilusCanvasView *canvas_view)
{
g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
- nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (canvas_view), event);
+ nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (canvas_view),
+ (GdkEvent *) event);
}
static void
canvas_container_context_click_background_callback (NautilusCanvasContainer *container,
- GdkEventButton *event,
+ const GdkEvent *event,
NautilusCanvasView *canvas_view)
{
g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
- nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (canvas_view), event);
+ nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (canvas_view),
+ (GdkEvent *) event);
}
static char *
@@ -1345,17 +1347,52 @@ nautilus_canvas_view_update_click_mode (NautilusCanvasView *canvas_view)
click_mode == NAUTILUS_CLICK_POLICY_SINGLE);
}
+static void
+canvas_container_longpress_gesture_pressed_callback (GtkGestureLongPress *gesture,
+ gdouble x,
+ gdouble y,
+ gpointer user_data)
+{
+ GdkEventSequence *event_sequence;
+ GdkEvent *event;
+ NautilusCanvasView *view = NAUTILUS_CANVAS_VIEW (user_data);
+
+ event_sequence = gtk_gesture_get_last_updated_sequence (GTK_GESTURE (gesture));
+ event = (GdkEvent *) gtk_gesture_get_last_event (GTK_GESTURE (gesture), event_sequence);
+
+ if (nautilus_view_get_selection (NAUTILUS_VIEW (view)))
+ {
+ nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (view),
+ event);
+ }
+ else
+ {
+ nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (view),
+ (GdkEvent *) event);
+ }
+}
+
static void
initialize_canvas_container (NautilusCanvasView *canvas_view,
NautilusCanvasContainer *canvas_container)
{
GtkWidget *content_widget;
+ GtkGesture *longpress_gesture;
content_widget = nautilus_files_view_get_content_widget (NAUTILUS_FILES_VIEW (canvas_view));
canvas_view->canvas_container = GTK_WIDGET (canvas_container);
g_object_add_weak_pointer (G_OBJECT (canvas_container),
(gpointer *) &canvas_view->canvas_container);
+ longpress_gesture = gtk_gesture_long_press_new (GTK_WIDGET (content_widget));
+ 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) canvas_container_longpress_gesture_pressed_callback,
+ canvas_view);
+
gtk_widget_set_can_focus (GTK_WIDGET (canvas_container), TRUE);
g_signal_connect_object (canvas_container, "activate",
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 639fd000f..59f625e16 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -8122,7 +8122,7 @@ nautilus_files_view_reveal_for_selection_context_menu (NautilusFilesView *view)
**/
void
nautilus_files_view_pop_up_selection_context_menu (NautilusFilesView *view,
- GdkEventButton *event)
+ GdkEvent *event)
{
NautilusFilesViewPrivate *priv;
@@ -8172,7 +8172,7 @@ nautilus_files_view_pop_up_selection_context_menu (NautilusFilesView *view,
**/
void
nautilus_files_view_pop_up_background_context_menu (NautilusFilesView *view,
- GdkEventButton *event)
+ GdkEvent *event)
{
NautilusFilesViewPrivate *priv;
diff --git a/src/nautilus-files-view.h b/src/nautilus-files-view.h
index c4c1d19d7..e7c317f74 100644
--- a/src/nautilus-files-view.h
+++ b/src/nautilus-files-view.h
@@ -274,9 +274,9 @@ void nautilus_files_view_notify_selection_changed (Nautil
NautilusDirectory *nautilus_files_view_get_model (NautilusFilesView *view);
NautilusFile *nautilus_files_view_get_directory_as_file (NautilusFilesView *view);
void nautilus_files_view_pop_up_background_context_menu (NautilusFilesView *view,
- GdkEventButton *event);
+ GdkEvent *event);
void nautilus_files_view_pop_up_selection_context_menu (NautilusFilesView *view,
- GdkEventButton *event);
+ GdkEvent *event);
gboolean nautilus_files_view_should_show_file (NautilusFilesView *view,
NautilusFile *file);
gboolean nautilus_files_view_should_sort_directories_first (NautilusFilesView *view);
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index dce2bb756..09364f813 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -584,7 +584,8 @@ button_press_callback (GtkWidget *widget,
if (event->button == 3)
{
- nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (view), event);
+ nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (view),
+ (GdkEvent *) event);
}
return TRUE;
@@ -740,7 +741,8 @@ button_press_callback (GtkWidget *widget,
if (event->button == 3)
{
- nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (view), event);
+ nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (view),
+ (GdkEvent *) event);
}
}
@@ -1937,6 +1939,37 @@ get_icon_scale_callback (NautilusListModel *model,
return gtk_widget_get_scale_factor (GTK_WIDGET (view->details->tree_view));
}
+static void
+on_longpress_gesture_pressed_event (GtkGestureLongPress *gesture,
+ gdouble x,
+ gdouble y,
+ gpointer user_data)
+{
+ GdkEventSequence *event_sequence;
+ GdkEvent *event;
+ NautilusListView *view = user_data;
+ GList *selection;
+
+ event_sequence = gtk_gesture_get_last_updated_sequence (GTK_GESTURE (gesture));
+ if (event_sequence == NULL)
+ {
+ return;
+ }
+
+ event = (GdkEvent *) gtk_gesture_get_last_event (GTK_GESTURE (gesture), event_sequence);
+
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ if (selection != NULL)
+ {
+ nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (view), event);
+ }
+ else
+ {
+ nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (view), event);
+ }
+ nautilus_file_list_free (selection);
+}
+
static void
create_and_set_up_tree_view (NautilusListView *view)
{
@@ -1950,6 +1983,7 @@ create_and_set_up_tree_view (NautilusListView *view)
NautilusDirectory *directory = NULL;
NautilusQuery *query = NULL;
NautilusQuerySearchContent content;
+ GtkGesture *longpress_gesture;
content_widget = nautilus_files_view_get_content_widget (NAUTILUS_FILES_VIEW (view));
view->details->tree_view = GTK_TREE_VIEW (gtk_tree_view_new ());
@@ -2025,6 +2059,16 @@ create_and_set_up_tree_view (NautilusListView *view)
g_signal_connect_object (view->details->model, "get-icon-scale",
G_CALLBACK (get_icon_scale_callback), view, 0);
+ longpress_gesture = gtk_gesture_long_press_new (GTK_WIDGET (content_widget));
+ 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_event,
+ view);
+
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (view->details->tree_view),
GTK_SELECTION_MULTIPLE);
g_settings_bind (nautilus_list_view_preferences, NAUTILUS_PREFERENCES_LIST_VIEW_USE_TREE,
diff --git a/src/nautilus-pathbar.c b/src/nautilus-pathbar.c
index 8466e31de..ae6706a20 100644
--- a/src/nautilus-pathbar.c
+++ b/src/nautilus-pathbar.c
@@ -102,7 +102,7 @@ typedef struct
GMenu *context_menu;
NautilusFile *context_menu_file;
- GdkEventButton *context_menu_event;
+ GdkEvent *context_menu_event;
} NautilusPathBarPrivate;
@@ -1680,7 +1680,7 @@ schedule_pop_up_context_menu (NautilusPathBar *self,
{
gdk_event_free ((GdkEvent *) priv->context_menu_event);
}
- priv->context_menu_event = (GdkEventButton *) gdk_event_copy ((GdkEvent *) event);
+ priv->context_menu_event = gdk_event_copy ((GdkEvent *) event);
if (file == priv->context_menu_file)
{
diff --git a/src/nautilus-ui-utilities.c b/src/nautilus-ui-utilities.c
index ad77d22ee..022a71d6b 100644
--- a/src/nautilus-ui-utilities.c
+++ b/src/nautilus-ui-utilities.c
@@ -175,9 +175,9 @@ nautilus_gmenu_add_item_in_submodel (GMenu *menu,
* the current even will be assumed by gtk_menu_popup_at_pointer().
*/
void
-nautilus_pop_up_context_menu_at_pointer (GtkWidget *parent,
- GMenu *menu,
- const GdkEventButton *button_event)
+nautilus_pop_up_context_menu_at_pointer (GtkWidget *parent,
+ GMenu *menu,
+ const GdkEvent *event)
{
g_autoptr (GtkWidget) gtk_menu = NULL;
@@ -187,7 +187,7 @@ nautilus_pop_up_context_menu_at_pointer (GtkWidget *parent,
gtk_menu = gtk_menu_new_from_model (G_MENU_MODEL (menu));
gtk_menu_attach_to_widget (GTK_MENU (gtk_menu), parent, NULL);
- gtk_menu_popup_at_pointer (GTK_MENU (gtk_menu), (GdkEvent *) button_event);
+ gtk_menu_popup_at_pointer (GTK_MENU (gtk_menu), (GdkEvent *) event);
g_object_ref_sink (gtk_menu);
}
diff --git a/src/nautilus-ui-utilities.h b/src/nautilus-ui-utilities.h
index f6cac6ea8..ce949483f 100644
--- a/src/nautilus-ui-utilities.h
+++ b/src/nautilus-ui-utilities.h
@@ -34,9 +34,9 @@ void nautilus_gmenu_merge (GMenu *original,
GMenu *gmenu_to_merge,
const gchar *submodel_name,
gboolean prepend);
-void nautilus_pop_up_context_menu_at_pointer (GtkWidget *parent,
- GMenu *menu,
- const GdkEventButton *button_event);
+void nautilus_pop_up_context_menu_at_pointer (GtkWidget *parent,
+ GMenu *menu,
+ const GdkEvent *event);
void nautilus_ui_frame_image (GdkPixbuf **pixbuf);
void nautilus_ui_frame_video (GdkPixbuf **pixbuf);
diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c
index 4cd37e552..c6db5b506 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -734,7 +734,7 @@ on_button_press_event (GtkWidget *widget,
if (event_button->button == GDK_BUTTON_SECONDARY)
{
nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (self),
- event_button);
+ event);
}
}
else
@@ -743,7 +743,7 @@ on_button_press_event (GtkWidget *widget,
if (event_button->button == GDK_BUTTON_SECONDARY)
{
nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (self),
- event_button);
+ event);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]