diff options
author | Carlos Soriano <csoriano@redhat.com> | 2018-10-02 14:38:38 +0200 |
---|---|---|
committer | Carlos Soriano <csoriano1618@gmail.com> | 2018-10-02 12:45:30 +0000 |
commit | dae54e0c72e92a3129c4e8754bd9f3025e487c72 (patch) | |
tree | 914363a08614c97b99487ed9502b8a7dc3e4cffd /src | |
parent | 461d1c1cd9ed3ba0df05f748b5beaf0269a751f5 (diff) | |
download | nautilus-dae54e0c72e92a3129c4e8754bd9f3025e487c72.tar.gz |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/nautilus-query-editor.c | 32 | ||||
-rw-r--r-- | src/nautilus-window-slot.c | 25 | ||||
-rw-r--r-- | 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; @@ -439,6 +440,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, gboolean reload, @@ -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; } |