[nautilus/search-events-on-view: 2/2] window-slot: Focus view widget on search up or down arrow pressed
- From: Carlos Soriano <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/search-events-on-view: 2/2] window-slot: Focus view widget on search up or down arrow pressed
- Date: Tue, 2 Oct 2018 12:45:46 +0000 (UTC)
commit dae54e0c72e92a3129c4e8754bd9f3025e487c72
Author: Carlos Soriano <csoriano redhat com>
Date: Tue Oct 2 14:38:38 2018 +0200
window-slot: Focus view widget on search up or down arrow pressed
This is a regression from 3.28, where the file items where being
selected while searching if the user clicked either up or the down
arrows.
Since 3.30 we moved the query editor to the header bar, this automatic
handling was lost.
To fix it, do something similar as we do when activating the search,
which is emitting a signal to inform the window slot and the views to
perform an explicit action. In this case, we focus the views so further
key events are handled by the views themselves and not by the query.
Closes: https://gitlab.gnome.org/GNOME/nautilus/issues/610
src/nautilus-query-editor.c | 32 ++++++++++++++++++++++++++++++++
src/nautilus-window-slot.c | 25 +++++++++++++++++++++++++
src/nautilus-window.c | 5 +++--
3 files changed, 60 insertions(+), 2 deletions(-)
---
diff --git a/src/nautilus-query-editor.c b/src/nautilus-query-editor.c
index b95dbe5c8..a1dc0a63e 100644
--- a/src/nautilus-query-editor.c
+++ b/src/nautilus-query-editor.c
@@ -58,6 +58,7 @@ struct _NautilusQueryEditor
enum
{
ACTIVATED,
+ FOCUS_VIEW,
CHANGED,
CANCEL,
LAST_SIGNAL
@@ -271,6 +272,15 @@ nautilus_query_editor_class_init (NautilusQueryEditorClass *class)
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+ signals[FOCUS_VIEW] =
+ g_signal_new ("focus-view",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
/**
* NautilusQueryEditor::location:
*
@@ -727,8 +737,30 @@ gboolean
nautilus_query_editor_handle_event (NautilusQueryEditor *self,
GdkEvent *event)
{
+ guint keyval;
+ GdkModifierType state;
+
g_return_val_if_fail (NAUTILUS_IS_QUERY_EDITOR (self), GDK_EVENT_PROPAGATE);
g_return_val_if_fail (event != NULL, GDK_EVENT_PROPAGATE);
+ if (G_UNLIKELY (!gdk_event_get_keyval (event, &keyval)))
+ {
+ g_return_val_if_reached (GDK_EVENT_PROPAGATE);
+ }
+
+ gdk_event_get_state (event, &state);
+
+ /* In the case of key up/down we want to move the focus to the view, since
+ * the user is probably trying to navigate the files
+ */
+ if (gtk_widget_has_focus (GTK_WIDGET (self->entry)))
+ {
+ if (keyval == GDK_KEY_Down || keyval == GDK_KEY_Up)
+ {
+ g_signal_emit (self, signals[FOCUS_VIEW], 0);
+ return GDK_EVENT_STOP;
+ }
+ }
+
return gtk_search_entry_handle_event (GTK_SEARCH_ENTRY (self->entry), event);
}
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index b3a7bc211..169f1fb6e 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -102,6 +102,7 @@ typedef struct
gulong qe_changed_id;
gulong qe_cancel_id;
gulong qe_activated_id;
+ gulong qe_focus_view_id;
GtkLabel *search_info_label;
GtkRevealer *search_info_label_revealer;
@@ -438,6 +439,19 @@ query_editor_activated_callback (NautilusQueryEditor *editor,
}
}
+static void
+query_editor_focus_view_callback (NautilusQueryEditor *editor,
+ NautilusWindowSlot *self)
+{
+ NautilusWindowSlotPrivate *priv;
+
+ priv = nautilus_window_slot_get_instance_private (self);
+ if (priv->content_view != NULL)
+ {
+ gtk_widget_grab_focus (priv->content_view);
+ }
+}
+
static void
query_editor_changed_callback (NautilusQueryEditor *editor,
NautilusQuery *query,
@@ -476,6 +490,11 @@ hide_query_editor (NautilusWindowSlot *self)
g_signal_handler_disconnect (priv->query_editor, priv->qe_activated_id);
priv->qe_activated_id = 0;
}
+ if (priv->qe_focus_view_id > 0)
+ {
+ g_signal_handler_disconnect (priv->query_editor, priv->qe_focus_view_id);
+ priv->qe_focus_view_id = 0;
+ }
nautilus_query_editor_set_query (priv->query_editor, NULL);
@@ -562,6 +581,12 @@ show_query_editor (NautilusWindowSlot *self)
g_signal_connect (priv->query_editor, "activated",
G_CALLBACK (query_editor_activated_callback), self);
}
+ if (priv->qe_focus_view_id == 0)
+ {
+ priv->qe_focus_view_id =
+ g_signal_connect (priv->query_editor, "focus-view",
+ G_CALLBACK (query_editor_focus_view_callback), self);
+ }
}
static void
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 0d1234f15..9b3380de6 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -2494,12 +2494,13 @@ nautilus_window_key_press_event (GtkWidget *widget,
}
}
- if (GTK_WIDGET_CLASS (nautilus_window_parent_class)->key_press_event (widget, event))
+ if (nautilus_window_slot_handle_event (window->active_slot, (GdkEvent *) event))
{
return GDK_EVENT_STOP;
}
- if (nautilus_window_slot_handle_event (window->active_slot, (GdkEvent *) event))
+
+ if (GTK_WIDGET_CLASS (nautilus_window_parent_class)->key_press_event (widget, event))
{
return GDK_EVENT_STOP;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]