[nautilus/wip/antoniof/gtk4-preparation-step-event-controllers: 21/22] rename-file-popover-controller: Use controller for key events
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/gtk4-preparation-step-event-controllers: 21/22] rename-file-popover-controller: Use controller for key events
- Date: Wed, 11 Aug 2021 00:21:35 +0000 (UTC)
commit ea667e752c0be13cb649db43bcbb36965a598f64
Author: Ernestas Kulik <ernestask gnome org>
Date: Mon Aug 6 12:14:07 2018 +0300
rename-file-popover-controller: Use controller for key events
Rebased and ammended by António Fernandes <antoniof gnome org>
src/nautilus-rename-file-popover-controller.c | 40 ++++++++++++---------------
1 file changed, 17 insertions(+), 23 deletions(-)
---
diff --git a/src/nautilus-rename-file-popover-controller.c b/src/nautilus-rename-file-popover-controller.c
index 8cc76c7fe..d9f879c62 100644
--- a/src/nautilus-rename-file-popover-controller.c
+++ b/src/nautilus-rename-file-popover-controller.c
@@ -44,6 +44,8 @@ struct _NautilusRenameFilePopoverController
gulong closed_handler_id;
gulong file_changed_handler_id;
gulong key_press_event_handler_id;
+
+ GtkEventController *key_controller;
};
G_DEFINE_TYPE (NautilusRenameFilePopoverController, nautilus_rename_file_popover_controller,
NAUTILUS_TYPE_FILE_NAME_WIDGET_CONTROLLER)
@@ -231,30 +233,18 @@ name_entry_on_undo (GtkWidget *widget,
}
static gboolean
-name_entry_on_event (GtkWidget *widget,
- GdkEvent *event,
- gpointer user_data)
+on_event_controller_key_key_pressed (GtkEventControllerKey *controller,
+ guint keyval,
+ guint keycode,
+ GdkModifierType state,
+ gpointer user_data)
{
+ GtkWidget *widget;
NautilusRenameFilePopoverController *self;
- guint keyval;
- GdkModifierType state;
-
- if (gdk_event_get_event_type (event) != GDK_KEY_PRESS)
- {
- return GDK_EVENT_PROPAGATE;
- }
+ widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (controller));
self = NAUTILUS_RENAME_FILE_POPOVER_CONTROLLER (user_data);
- if (G_UNLIKELY (!gdk_event_get_keyval (event, &keyval)))
- {
- g_return_val_if_reached (GDK_EVENT_PROPAGATE);
- }
- if (G_UNLIKELY (!gdk_event_get_state (event, &state)))
- {
- g_return_val_if_reached (GDK_EVENT_PROPAGATE);
- }
-
if (keyval == GDK_KEY_F2)
{
return name_entry_on_f2_pressed (widget, self);
@@ -336,6 +326,7 @@ nautilus_rename_file_popover_controller_show_for_file (NautilusRenameFilePopov
g_autoptr (NautilusDirectory) containing_directory = NULL;
g_autofree gchar *edit_name = NULL;
gint n_chars;
+ GtkEventController *controller;
g_assert (NAUTILUS_IS_RENAME_FILE_POPOVER_CONTROLLER (self));
g_assert (NAUTILUS_IS_FILE (target_file));
@@ -371,10 +362,11 @@ nautilus_rename_file_popover_controller_show_for_file (NautilusRenameFilePopov
G_CALLBACK (target_file_on_changed),
self);
- self->key_press_event_handler_id = g_signal_connect (self->name_entry,
- "event",
- G_CALLBACK (name_entry_on_event),
- self);
+ self->key_controller = gtk_event_controller_key_new (self->name_entry);
+ g_signal_connect (self->key_controller,
+ "key-pressed",
+ G_CALLBACK (on_event_controller_key_key_pressed),
+ self);
gtk_label_set_text (GTK_LABEL (self->name_label),
self->target_is_folder ? _("Folder name") :
@@ -435,6 +427,8 @@ nautilus_rename_file_popover_controller_finalize (GObject *object)
gtk_widget_destroy (self->rename_file_popover);
g_clear_object (&self->rename_file_popover);
+ g_clear_object (&self->key_controller);
+
G_OBJECT_CLASS (nautilus_rename_file_popover_controller_parent_class)->finalize (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]