From c4096987fead49ca4aee7350bceb0562817c4273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Fernandes?= Date: Tue, 23 May 2023 19:19:30 +0100 Subject: [PATCH 1/4] window-slot: Don't switch view mode when searching When searching from grid view, we switch to list view by default. While good intentioned (list view provides more space to display the location of recursive search results), it's disruptive and ignores that the user might have chosen grid view because it's more suited to the content being searched. This effectively reverts the features introduced by these commits: * 46d18fecc33d5a9a85f90ca2aa58d5017f3415de * a88310dd2143476bf34d2d892807d0457d2f7d85 Fixes https://gitlab.gnome.org/GNOME/nautilus/-/issues/2969 --- data/org.gnome.nautilus.gschema.xml | 5 ---- src/nautilus-global-preferences.h | 3 --- src/nautilus-window-slot.c | 38 ++++------------------------- src/nautilus-window-slot.h | 1 - 4 files changed, 5 insertions(+), 42 deletions(-) diff --git a/data/org.gnome.nautilus.gschema.xml b/data/org.gnome.nautilus.gschema.xml index 6613b97ae4..94b17208d1 100644 --- a/data/org.gnome.nautilus.gschema.xml +++ b/data/org.gnome.nautilus.gschema.xml @@ -173,11 +173,6 @@ Whether GTK 4 settings migration happened Whether settings shared with GtkFileChooser have been migrated from their GTK 3 keys to the GTK 4 ones. - - 'list-view' - What viewer should be used when searching - When searching Nautilus will switch to the type of view in this setting. - true Whether to open the hovered folder after a timeout when drag and drop operation diff --git a/src/nautilus-global-preferences.h b/src/nautilus-global-preferences.h index 5a73717b30..9d39bbc03a 100644 --- a/src/nautilus-global-preferences.h +++ b/src/nautilus-global-preferences.h @@ -114,9 +114,6 @@ typedef enum /* Recent files */ #define NAUTILUS_PREFERENCES_RECENT_FILES_ENABLED "remember-recent-files" -/* Default view when searching */ -#define NAUTILUS_PREFERENCES_SEARCH_VIEW "search-view" - /* Search behaviour */ #define NAUTILUS_PREFERENCES_RECURSIVE_SEARCH "recursive-search" diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c index 48aa61f553..629350321d 100644 --- a/src/nautilus-window-slot.c +++ b/src/nautilus-window-slot.c @@ -131,7 +131,6 @@ struct _NautilusWindowSlot GCancellable *mount_cancellable; GError *mount_error; gboolean tried_mount; - gint view_mode_before_search; gint view_mode_before_places; /* Menus */ @@ -199,8 +198,6 @@ nautilus_window_slot_restore_navigation_state (NautilusWindowSlot *self, self->forward_list = g_steal_pointer (&data->forward_list); - self->view_mode_before_search = data->view_before_search; - g_set_object (&self->current_location_bookmark, data->current_location_bookmark); self->location_change_type = NAUTILUS_LOCATION_CHANGE_RELOAD; @@ -234,7 +231,6 @@ nautilus_window_slot_get_navigation_state (NautilusWindowSlot *self) data->back_list = back_list; data->forward_list = forward_list; data->file = nautilus_file_get (self->location); - data->view_before_search = self->view_mode_before_search; g_set_object (&data->current_location_bookmark, self->current_location_bookmark); return data; @@ -265,30 +261,12 @@ nautilus_window_slot_get_view_for_location (NautilusWindowSlot *self, return view; } - /* If we are in search, try to use by default list view. */ - if (nautilus_file_is_in_search (file)) - { - /* If it's already set, is because we already made the change to search mode, - * so the view mode of the current view will be the one search is using, - * which is not the one we are interested in */ - if (self->view_mode_before_search == NAUTILUS_VIEW_INVALID_ID && - NAUTILUS_IS_FILES_VIEW (self->content_view)) - { - self->view_mode_before_search = nautilus_view_get_view_id (self->content_view); - } - view_id = g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_SEARCH_VIEW); - } - else if (self->content_view != NULL) + if (self->content_view != NULL) { /* If there is already a view, just use the view mode that it's currently using, or - * if we were on search before, use what we were using before entering - * search mode */ - if (self->view_mode_before_search != NAUTILUS_VIEW_INVALID_ID) - { - view_id = self->view_mode_before_search; - self->view_mode_before_search = NAUTILUS_VIEW_INVALID_ID; - } - else if (NAUTILUS_IS_PLACES_VIEW (self->content_view)) + * if we were on "Other Locations" before, use what we were using before entering + * it. */ + if (NAUTILUS_IS_PLACES_VIEW (self->content_view)) { view_id = self->view_mode_before_places; self->view_mode_before_places = NAUTILUS_VIEW_INVALID_ID; @@ -972,17 +950,12 @@ static void change_files_view_mode (NautilusWindowSlot *self, guint view_id) { - const gchar *preferences_key; - if (!nautilus_window_slot_content_view_matches (self, view_id)) { nautilus_window_slot_set_content_view (self, view_id); } - preferences_key = nautilus_view_is_searching (nautilus_window_slot_get_current_view (self)) ? - NAUTILUS_PREFERENCES_SEARCH_VIEW : - NAUTILUS_PREFERENCES_DEFAULT_FOLDER_VIEWER; - g_settings_set_enum (nautilus_preferences, preferences_key, view_id); + g_settings_set_enum (nautilus_preferences, NAUTILUS_PREFERENCES_DEFAULT_FOLDER_VIEWER, view_id); } static void @@ -1167,7 +1140,6 @@ nautilus_window_slot_init (NautilusWindowSlot *self) "2"); nautilus_application_set_accelerators (app, "slot.focus-search", search_visible_accels); - self->view_mode_before_search = NAUTILUS_VIEW_INVALID_ID; self->view_mode_before_places = NAUTILUS_VIEW_INVALID_ID; } diff --git a/src/nautilus-window-slot.h b/src/nautilus-window-slot.h index 847bbecabf..0be67097d7 100644 --- a/src/nautilus-window-slot.h +++ b/src/nautilus-window-slot.h @@ -40,7 +40,6 @@ G_DECLARE_FINAL_TYPE (NautilusWindowSlot, nautilus_window_slot, NAUTILUS, WINDOW typedef struct { NautilusFile *file; - gint view_before_search; GList *back_list; GList *forward_list; NautilusBookmark *current_location_bookmark; -- GitLab From d06b4d6a81d52dc085fba33a6c91d479841228c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Fernandes?= Date: Tue, 23 May 2023 19:04:19 +0100 Subject: [PATCH 2/4] window-slot: Don't add search to history We've been treating search as a location that can be "opened" and even navigated back or forward to. Yet, the results of navigating back or forward to a search directory are inconsistent and even unpredictable. Furthermore, from a design point of view, search should be treated as filtering the current location, not as navigating to another location. If that were not enough, treating searching as opening a location triggers a cascade of code which ends up reloading it twice. This means search engines are restarted twice: START-STOP-START-STOP-START. Starting engines 3 times for every keystroke is not only wasteful, it multiplies any performance bottlenecks when starting and stopping search engines. In short: an unpredictable feature that reflects implementation details rather than UX design and amplifies search performance issues. In order to perform a search without causing a navigation event, let's slot location directly without triggering any navigation logic. Fixes https://gitlab.gnome.org/GNOME/nautilus/-/issues/2686 --- src/nautilus-window-slot.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c index 629350321d..a0cb713aea 100644 --- a/src/nautilus-window-slot.c +++ b/src/nautilus-window-slot.c @@ -434,7 +434,7 @@ query_editor_changed_callback (NautilusQueryEditor *editor, view = nautilus_window_slot_get_current_view (self); nautilus_view_set_search_query (view, query); - nautilus_window_slot_open_location_full (self, nautilus_view_get_location (view), 0, NULL); + nautilus_window_slot_set_location (self, nautilus_view_get_location (view)); } static void @@ -455,13 +455,15 @@ hide_query_editor (NautilusWindowSlot *self) { g_autolist (NautilusFile) selection = NULL; + /* Save current selection to restore it after leaving search results. + * This allows finding a file from current folder using search, then + * press [Esc], and have the selected search result still selected and + * revealed in the unfiltered folder view. */ selection = nautilus_view_get_selection (view); nautilus_view_set_search_query (view, NULL); - nautilus_window_slot_open_location_full (self, - nautilus_view_get_location (view), - 0, - selection); + nautilus_window_slot_set_location (self, nautilus_view_get_location (view)); + nautilus_view_set_selection (view, selection); } if (nautilus_window_slot_get_active (self)) -- GitLab From 570e5c59c372058b4af4c754ad954832f2a5bbfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Fernandes?= Date: Wed, 24 May 2023 00:03:19 +0100 Subject: [PATCH 3/4] files-view: Remove "search from history" complexity Now that we never "go back" to a search directory, the added complexity to accomodate for that can be reverted. This effectively reverts logic introduced by the following commits: * 63d0425a9b9a6dc21123ef620eeee441e0b40cdb * f24fd6934d03361899e2626c6dbd8bc01eb252c7 --- src/nautilus-files-view.c | 78 +++++++-------------------------------- 1 file changed, 13 insertions(+), 65 deletions(-) diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c index 9fab47e863..887466dbfd 100644 --- a/src/nautilus-files-view.c +++ b/src/nautilus-files-view.c @@ -340,10 +340,6 @@ static gboolean nautilus_files_view_is_searching (NautilusView *view); static void nautilus_files_view_iface_init (NautilusViewInterface *view); -static void set_search_query_internal (NautilusFilesView *files_view, - NautilusQuery *query, - NautilusDirectory *base_model); - static gboolean nautilus_files_view_is_read_only (NautilusFilesView *view); static void nautilus_files_view_set_selection (NautilusView *nautilus_files_view, GList *selection); @@ -3695,32 +3691,11 @@ nautilus_files_view_set_location (NautilusView *view, GFile *location) { NautilusDirectory *directory; - NautilusFilesView *files_view; nautilus_profile_start (NULL); - files_view = NAUTILUS_FILES_VIEW (view); directory = nautilus_directory_get (location); - nautilus_files_view_stop_loading (files_view); - /* In case we want to load a previous search we need to extract the real - * location and the search location, and load the directory when everything - * is ready. That's why we cannot use the nautilus_view_set_query, because - * to set a query we need a previous location loaded, but to load a search - * location we need to know the real location behind it. */ - if (NAUTILUS_IS_SEARCH_DIRECTORY (directory)) - { - NautilusQuery *previous_query; - NautilusDirectory *base_model; - - base_model = nautilus_search_directory_get_base_model (NAUTILUS_SEARCH_DIRECTORY (directory)); - previous_query = nautilus_search_directory_get_query (NAUTILUS_SEARCH_DIRECTORY (directory)); - set_search_query_internal (files_view, previous_query, base_model); - g_object_unref (previous_query); - } - else - { - load_directory (NAUTILUS_FILES_VIEW (view), directory); - } + load_directory (NAUTILUS_FILES_VIEW (view), directory); nautilus_directory_unref (directory); nautilus_profile_end (NULL); } @@ -9393,10 +9368,10 @@ nautilus_files_view_get_search_query (NautilusView *view) } static void -set_search_query_internal (NautilusFilesView *files_view, - NautilusQuery *query, - NautilusDirectory *base_model) +nautilus_files_view_set_search_query (NautilusView *view, + NautilusQuery *query) { + NautilusFilesView *files_view = NAUTILUS_FILES_VIEW (view); GFile *location; NautilusFilesViewPrivate *priv; @@ -9404,23 +9379,16 @@ set_search_query_internal (NautilusFilesView *files_view, priv = nautilus_files_view_get_instance_private (files_view); g_set_object (&priv->search_query, query); - g_object_notify (G_OBJECT (files_view), "search-query"); + g_object_notify (G_OBJECT (view), "search-query"); if (!nautilus_query_is_empty (query)) { - if (nautilus_view_is_searching (NAUTILUS_VIEW (files_view))) + if (nautilus_view_is_searching (view)) { /* * Reuse the search directory and reload it. */ nautilus_search_directory_set_query (NAUTILUS_SEARCH_DIRECTORY (priv->model), query); - /* It's important to use load_directory instead of set_location, - * since the location is already correct, however we need - * to reload the directory with the new query set. But - * set_location has a check for wheter the location is a - * search directory, so setting the location to a search - * directory when is already serching will enter a loop. - */ load_directory (files_view, priv->model); } else @@ -9433,12 +9401,12 @@ set_search_query_internal (NautilusFilesView *files_view, directory = nautilus_directory_get (location); g_assert (NAUTILUS_IS_SEARCH_DIRECTORY (directory)); - nautilus_search_directory_set_base_model (NAUTILUS_SEARCH_DIRECTORY (directory), base_model); + nautilus_search_directory_set_base_model (NAUTILUS_SEARCH_DIRECTORY (directory), priv->model); nautilus_search_directory_set_query (NAUTILUS_SEARCH_DIRECTORY (directory), query); load_directory (files_view, directory); - g_object_notify (G_OBJECT (files_view), "searching"); + g_object_notify (G_OBJECT (view), "searching"); nautilus_directory_unref (directory); g_free (uri); @@ -9446,39 +9414,19 @@ set_search_query_internal (NautilusFilesView *files_view, } else { - if (nautilus_view_is_searching (NAUTILUS_VIEW (files_view))) + if (nautilus_view_is_searching (view)) { + NautilusDirectory *base_model; + + base_model = nautilus_search_directory_get_base_model (NAUTILUS_SEARCH_DIRECTORY (priv->model)); location = nautilus_directory_get_location (base_model); - nautilus_view_set_location (NAUTILUS_VIEW (files_view), location); + nautilus_view_set_location (view, location); } } g_clear_object (&location); } -static void -nautilus_files_view_set_search_query (NautilusView *view, - NautilusQuery *query) -{ - NautilusDirectory *base_model; - NautilusFilesView *files_view; - NautilusFilesViewPrivate *priv; - - files_view = NAUTILUS_FILES_VIEW (view); - priv = nautilus_files_view_get_instance_private (files_view); - - if (nautilus_view_is_searching (view)) - { - base_model = nautilus_search_directory_get_base_model (NAUTILUS_SEARCH_DIRECTORY (priv->model)); - } - else - { - base_model = priv->model; - } - - set_search_query_internal (NAUTILUS_FILES_VIEW (view), query, base_model); -} - static GFile * nautilus_files_view_get_location (NautilusView *view) { -- GitLab From 466dcd40e9dc8d8ebded58659633e37182cb7b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Fernandes?= Date: Thu, 8 Jun 2023 21:32:55 +0100 Subject: [PATCH 4/4] window-slot: Make "back" leave search first Quoting Allan: On the one hand, search is treated as a filter on the current location, so conceptually I would expect it to be independent of navigation controls. On the other hand, I'm not sure if there's anything better for forward and back to do in this context. Having them actually take you to another location does seem like it would be surprising. --- src/nautilus-window-slot.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c index a0cb713aea..5d22912afa 100644 --- a/src/nautilus-window-slot.c +++ b/src/nautilus-window-slot.c @@ -2171,6 +2171,17 @@ nautilus_window_slot_back_or_forward (NautilusWindowSlot *self, GFile *old_location; g_autofree char *scroll_pos = NULL; + if (back) + { + /* While searching, maybe the user means to go "back" to no search. */ + NautilusView *view = nautilus_window_slot_get_current_view (self); + if (nautilus_view_is_searching (view)) + { + nautilus_window_slot_set_search_visible (self, FALSE); + return; + } + } + list = back ? self->back_list : self->forward_list; len = g_list_length (list); -- GitLab