window-slot: switch to list view on search

When searching, list view is a better view given that we can see
more attributes of the files, for instance, the location is
a important part for discerning files in the current folder or
in nested folders.

For that, switch to list view while searching, and disable this behavior
if the user changes the view mode while searching.
parent 8f2f9025
......@@ -161,6 +161,9 @@ typedef enum
/* Move to trash shorcut changed dialog */
#define NAUTILUS_PREFERENCES_SHOW_MOVE_TO_TRASH_SHORTCUT_CHANGED_DIALOG "show-move-to-trash-shortcut-changed-dialog"
/* Switch to list view while searching */
#define NAUTILUS_PREFERENCES_LIST_VIEW_ON_SEARCH "list-view-on-search"
void nautilus_global_preferences_init (void);
char *nautilus_global_preferences_get_default_folder_viewer_preference_as_iid (void);
......
......@@ -166,6 +166,11 @@
<_summary>Whether to show hidden files</_summary>
<_description>This key is deprecated and ignored. The "show-hidden" key from "org.gtk.Settings.FileChooser" is now used instead.</_description>
</key>
<key name="list-view-on-search" type="b">
<default>true</default>
<_summary>Wheter to swtich to list view on Search</_summary>
<_description>If this is set to true, while searching view mode will switch to list view. However if the user change the mode manually, this will be disabled</_description>
</key>
<key name="bulk-rename-tool" type="ay">
<default>[]</default>
<_summary>Bulk rename utility</_summary>
......
......@@ -124,6 +124,7 @@ struct NautilusWindowSlotDetails {
gboolean tried_mount;
NautilusWindowGoToCallback open_callback;
gpointer open_callback_user_data;
gchar *view_mode_before_search;
};
static guint signals[LAST_SIGNAL] = { 0 };
......@@ -1245,11 +1246,38 @@ got_file_info_for_view_selection_callback (NautilusFile *file,
(error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_SUPPORTED)) {
/* We got the information we need, now pick what view to use: */
/* Otherwise, use default */
if (slot->details->content_view != NULL) {
view_id = g_strdup (nautilus_view_get_view_id (slot->details->content_view));
/* If we are in search, try to use by default list view. This will be deactivated
* if the user manually switch to a diferent view mode */
if (nautilus_file_is_in_search (nautilus_file_get (location))) {
if (g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_LIST_VIEW_ON_SEARCH)) {
/* 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 (slot->details->view_mode_before_search == NULL) {
slot->details->view_mode_before_search = g_strdup (nautilus_view_get_view_id (slot->details->content_view));
}
view_id = g_strdup (NAUTILUS_LIST_VIEW_IID);
} else {
g_free (slot->details->view_mode_before_search);
slot->details->view_mode_before_search = 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 (slot->details->content_view != NULL && view_id == NULL) {
if (slot->details->view_mode_before_search != NULL) {
view_id = g_strdup (slot->details->view_mode_before_search);
g_free (slot->details->view_mode_before_search);
slot->details->view_mode_before_search = NULL;
} else {
view_id = g_strdup (nautilus_view_get_view_id (slot->details->content_view));
}
}
/* If there is not previous view in this slot, use the default view mode
* from preferences */
if (view_id == NULL) {
view_id = nautilus_global_preferences_get_default_folder_viewer_preference_as_iid ();
}
......@@ -2440,6 +2468,11 @@ nautilus_window_slot_dispose (GObject *object)
g_object_ref (slot->details->location);
}
if (slot->details->view_mode_before_search) {
g_free (slot->details->view_mode_before_search);
slot->details->view_mode_before_search = NULL;
}
g_list_free_full (slot->details->pending_selection, g_object_unref);
slot->details->pending_selection = NULL;
......
......@@ -439,6 +439,19 @@ action_toggle_state_action_button (GSimpleAction *action,
g_variant_unref (current_state);
}
static void
check_use_list_view_on_search (NautilusWindowSlot *slot)
{
GFile *location;
location = nautilus_window_slot_get_location (slot);
if (nautilus_file_is_in_search (nautilus_file_get (location))) {
g_settings_set_boolean (nautilus_preferences,
NAUTILUS_PREFERENCES_LIST_VIEW_ON_SEARCH,
FALSE);
}
}
static void
action_view_mode (GSimpleAction *action,
GVariant *value,
......@@ -456,6 +469,9 @@ action_view_mode (GSimpleAction *action,
NAUTILUS_PREFERENCES_DEFAULT_FOLDER_VIEWER,
NAUTILUS_DEFAULT_FOLDER_VIEWER_LIST_VIEW);
} else if (g_strcmp0 (name, "grid") == 0) {
/* If the user manually changed the view mode, disable the automatic
* switch to list view on search */
check_use_list_view_on_search (slot);
nautilus_window_slot_set_content_view (slot, NAUTILUS_CANVAS_VIEW_ID);
g_settings_set_enum (nautilus_preferences,
NAUTILUS_PREFERENCES_DEFAULT_FOLDER_VIEWER,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment