summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2022-10-22 00:36:26 +0000
committerMatthias Clasen <mclasen@redhat.com>2022-10-22 00:36:26 +0000
commit86f7c19b910f4c0e8c3df9f8e5f3e504a8b38662 (patch)
tree6e7cdcf759f0ead4d3f37e8cfdadf20f37aa17be
parentc09ba28b061cd285dc9882a7da03db3ae6fbcaf3 (diff)
parente5cea4e39da3f21d6b6193823ad9f00da41229a2 (diff)
downloadgtk+-86f7c19b910f4c0e8c3df9f8e5f3e504a8b38662.tar.gz
Merge branch 'wip/corey/file-chooser-popup' into 'main'
filechooserwidget: Fix popup issues See merge request GNOME/gtk!5161
-rw-r--r--gtk/gtkfilechoosercell.c7
-rw-r--r--gtk/gtkfilechooserwidget.c60
2 files changed, 61 insertions, 6 deletions
diff --git a/gtk/gtkfilechoosercell.c b/gtk/gtkfilechoosercell.c
index 655f54c46f..c14ae0a021 100644
--- a/gtk/gtkfilechoosercell.c
+++ b/gtk/gtkfilechoosercell.c
@@ -67,11 +67,15 @@ popup_menu (GtkFileChooserCell *self,
double y)
{
GtkWidget *widget = GTK_WIDGET (self);
+ GtkSelectionModel *model;
GtkWidget *impl;
double xx, yy;
impl = gtk_widget_get_ancestor (widget, GTK_TYPE_FILE_CHOOSER_WIDGET);
+ model = gtk_file_chooser_widget_get_selection_model (GTK_FILE_CHOOSER_WIDGET (impl));
+ gtk_selection_model_select_item (model, self->position, TRUE);
+
gtk_widget_translate_coordinates (widget, GTK_WIDGET (impl),
x, y, &xx, &yy);
@@ -88,6 +92,7 @@ file_chooser_cell_clicked (GtkEventController *controller,
GtkWidget *widget = gtk_event_controller_get_widget (controller);
GtkFileChooserCell *self = GTK_FILE_CHOOSER_CELL (widget);
+ gtk_gesture_set_state (GTK_GESTURE (controller), GTK_EVENT_SEQUENCE_CLAIMED);
popup_menu (self, x, y);
}
@@ -99,6 +104,7 @@ file_chooser_cell_long_pressed (GtkEventController *controller,
GtkWidget *widget = gtk_event_controller_get_widget (controller);
GtkFileChooserCell *self = GTK_FILE_CHOOSER_CELL (widget);
+ gtk_gesture_set_state (GTK_GESTURE (controller), GTK_EVENT_SEQUENCE_CLAIMED);
popup_menu (self, x, y);
}
@@ -171,6 +177,7 @@ gtk_file_chooser_cell_init (GtkFileChooserCell *self)
gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (gesture));
gesture = gtk_gesture_long_press_new ();
+ gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), TRUE);
g_signal_connect (gesture, "pressed", G_CALLBACK (file_chooser_cell_long_pressed), NULL);
drag_source = gtk_drag_source_new ();
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index 7d18ea03df..024cfb2ee1 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -38,6 +38,8 @@
#include "gtkfilechooser.h"
#include "gtkfilesystemmodel.h"
#include "gtkfilethumbnail.h"
+#include "gtkgestureclick.h"
+#include "gtkgesturelongpress.h"
#include "gtkgrid.h"
#include "gtklabel.h"
#include "gtklistitem.h"
@@ -1662,22 +1664,23 @@ check_file_list_popover_sensitivity (GtkFileChooserWidget *impl)
GSimpleAction *delete_action, *trash_action;
info = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), impl->browse_files_popover_item);
- is_folder = _gtk_file_info_consider_as_directory (info);
+ is_folder = info && _gtk_file_info_consider_as_directory (info);
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "copy-location");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), info != NULL);
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "add-shortcut");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), is_folder);
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "visit");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), info != NULL);
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "open");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), is_folder);
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "rename");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ info &&
g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME));
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "delete");
@@ -1686,12 +1689,12 @@ check_file_list_popover_sensitivity (GtkFileChooserWidget *impl)
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "trash");
trash_action = G_SIMPLE_ACTION (action);
- if (g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH))
+ if (info && g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH))
{
g_simple_action_set_enabled (trash_action, TRUE);
g_simple_action_set_enabled (delete_action, FALSE);
}
- else if (g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE))
+ else if (info && g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE))
{
g_simple_action_set_enabled (delete_action, TRUE);
g_simple_action_set_enabled (trash_action, FALSE);
@@ -1828,7 +1831,8 @@ file_list_update_popover (GtkFileChooserWidget *impl)
* bookmarks_check_add_sensitivity()
*/
state = impl->action == GTK_FILE_CHOOSER_ACTION_SAVE &&
- impl->operation_mode == OPERATION_MODE_BROWSE;
+ impl->operation_mode == OPERATION_MODE_BROWSE &&
+ impl->browse_files_popover_item != G_MAXUINT;
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "rename");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), state);
@@ -7174,9 +7178,44 @@ setup_sorting (GtkFileChooserWidget *impl)
}
static void
+popup_menu (GtkWidget *widget,
+ double x,
+ double y)
+{
+ gtk_widget_activate_action (widget, "item.popup-file-list-menu",
+ "(udd)", G_MAXUINT, x, y);
+}
+
+static void
+file_chooser_widget_clicked (GtkEventController *controller,
+ int n_press,
+ double x,
+ double y,
+ gpointer user_data)
+{
+ GtkWidget *widget = user_data;
+
+ gtk_gesture_set_state (GTK_GESTURE (controller), GTK_EVENT_SEQUENCE_CLAIMED);
+ popup_menu (widget, x, y);
+}
+
+static void
+file_chooser_widget_long_pressed (GtkEventController *controller,
+ double x,
+ double y,
+ gpointer user_data)
+{
+ GtkWidget *widget = user_data;
+
+ gtk_gesture_set_state (GTK_GESTURE (controller), GTK_EVENT_SEQUENCE_CLAIMED);
+ popup_menu (widget, x, y);
+}
+
+static void
gtk_file_chooser_widget_init (GtkFileChooserWidget *impl)
{
GtkExpression *expression;
+ GtkGesture *gesture;
/* Ensure private types used by the template
* definition before calling gtk_widget_init_template()
@@ -7235,6 +7274,15 @@ gtk_file_chooser_widget_init (GtkFileChooserWidget *impl)
gtk_drop_down_set_expression (GTK_DROP_DOWN (impl->filter_combo), expression);
gtk_expression_unref (expression);
+ gesture = gtk_gesture_click_new ();
+ gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_SECONDARY);
+ g_signal_connect (gesture, "pressed", G_CALLBACK (file_chooser_widget_clicked), impl);
+ gtk_widget_add_controller (GTK_WIDGET (impl), GTK_EVENT_CONTROLLER (gesture));
+
+ gesture = gtk_gesture_long_press_new ();
+ gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), TRUE);
+ g_signal_connect (gesture, "pressed", G_CALLBACK (file_chooser_widget_long_pressed), impl);
+
/* Setup various attributes and callbacks in the UI
* which cannot be done with GtkBuilder
*/