summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Soriano <csoriano@gnome.org>2015-07-20 17:56:30 +0200
committerCarlos Soriano <csoriano@gnome.org>2015-07-20 18:41:48 +0200
commit46d18fecc33d5a9a85f90ca2aa58d5017f3415de (patch)
tree65a38c923494db157e7824d53369fccd1c076ed8
parent8f2f9025939b5bbac75deee4bc2c448e22bed60c (diff)
downloadnautilus-46d18fecc33d5a9a85f90ca2aa58d5017f3415de.tar.gz
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.
-rw-r--r--libnautilus-private/nautilus-global-preferences.h3
-rw-r--r--libnautilus-private/org.gnome.nautilus.gschema.xml.in5
-rw-r--r--src/nautilus-window-slot.c39
-rw-r--r--src/nautilus-window.c16
4 files changed, 60 insertions, 3 deletions
diff --git a/libnautilus-private/nautilus-global-preferences.h b/libnautilus-private/nautilus-global-preferences.h
index c33cef534..ef9dfbfc3 100644
--- a/libnautilus-private/nautilus-global-preferences.h
+++ b/libnautilus-private/nautilus-global-preferences.h
@@ -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);
diff --git a/libnautilus-private/org.gnome.nautilus.gschema.xml.in b/libnautilus-private/org.gnome.nautilus.gschema.xml.in
index 657190458..a6bb3d265 100644
--- a/libnautilus-private/org.gnome.nautilus.gschema.xml.in
+++ b/libnautilus-private/org.gnome.nautilus.gschema.xml.in
@@ -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>
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index cb42c1d76..4590006d2 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -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;
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 30fb9ecd8..f77a73e76 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -440,6 +440,19 @@ action_toggle_state_action_button (GSimpleAction *action,
}
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,
gpointer user_data)
@@ -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,