search: use a separate view setting for search

So we can select what type of view do we want for search independently
of what we normally use.

This is needed since we default to switch to list view for search, but
we would like to allow users to select a different view. However,
instead of adding a preference in the preference dialog, we can do it
more straightforward and change the setting when we are in search.

On the way, rework all the enums and views id for a saner code...
parent b1392c7a
......@@ -192,10 +192,10 @@
<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 type="b" name="list-view-on-search">
<default>true</default>
<summary>Whether to switch to the list view on search</summary>
<description>If this is set to true, view mode will be switched to the list view while searching. However, if the user changes the mode manually, this will be disabled.</description>
<key name="search-view" enum="org.gnome.nautilus.FolderView">
<default>'icon-view'</default>
<summary>What viewer should be used when searching</summary>
<description>When searching Nautilus will switch to the type of view in this setting.</description>
</key>
<key type="ay" name="bulk-rename-tool">
<default>[]</default>
......
......@@ -45,27 +45,6 @@ GSettings *gnome_background_preferences;
GSettings *gnome_interface_preferences;
GSettings *gnome_privacy_preferences;
/*
* Public functions
*/
char *
nautilus_global_preferences_get_default_folder_viewer_preference_as_iid (void)
{
int preference_value;
const char *viewer_iid;
preference_value =
g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_DEFAULT_FOLDER_VIEWER);
if (preference_value == NAUTILUS_DEFAULT_FOLDER_VIEWER_LIST_VIEW) {
viewer_iid = NAUTILUS_LIST_VIEW_ID;
} else {
viewer_iid = NAUTILUS_CANVAS_VIEW_ID;
}
return g_strdup (viewer_iid);
}
void
nautilus_global_preferences_init (void)
{
......
......@@ -78,13 +78,6 @@ typedef enum
/* The default folder viewer - one of the two enums below */
#define NAUTILUS_PREFERENCES_DEFAULT_FOLDER_VIEWER "default-folder-viewer"
enum
{
NAUTILUS_DEFAULT_FOLDER_VIEWER_ICON_VIEW,
NAUTILUS_DEFAULT_FOLDER_VIEWER_LIST_VIEW,
NAUTILUS_DEFAULT_FOLDER_VIEWER_OTHER
};
/* Icon View */
#define NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_ZOOM_LEVEL "default-zoom-level"
......@@ -159,8 +152,8 @@ 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"
/* Default view when searching */
#define NAUTILUS_PREFERENCES_SEARCH_VIEW "search-view"
/* Search behaviour */
#define NAUTILUS_PREFERENCES_LOCAL_RECURSIVE_SEARCH "local-recursive-search"
......@@ -171,7 +164,6 @@ typedef enum
#define NAUTILUS_PREFERENCES_SHOW_CREATE_LINK "show-create-link"
void nautilus_global_preferences_init (void);
char *nautilus_global_preferences_get_default_folder_viewer_preference_as_iid (void);
extern GSettings *nautilus_preferences;
extern GSettings *nautilus_icon_view_preferences;
......
......@@ -1811,10 +1811,10 @@ canvas_view_scroll_to_file (NautilusFilesView *view,
}
}
static const char *
static guint
nautilus_canvas_view_get_id (NautilusFilesView *view)
{
return NAUTILUS_CANVAS_VIEW_ID;
return NAUTILUS_VIEW_GRID_ID;
}
static void
......
......@@ -216,10 +216,10 @@ desktop_canvas_view_property_filter (GdkXEvent *gdk_xevent,
return GDK_FILTER_CONTINUE;
}
static const char *
static guint
real_get_id (NautilusFilesView *view)
{
return NAUTILUS_DESKTOP_VIEW_ID;
return NAUTILUS_VIEW_DESKTOP_ID;
}
static void
......
......@@ -223,10 +223,10 @@ nautilus_empty_view_sort_directories_first_changed (NautilusFilesView *view)
{
}
static const char *
static guint
nautilus_empty_view_get_id (NautilusFilesView *view)
{
return NAUTILUS_EMPTY_VIEW_ID;
return NAUTILUS_VIEW_EMPTY_ID;
}
static GIcon*
......
......@@ -876,7 +876,7 @@ nautilus_files_view_is_searching (NautilusView *view)
return NAUTILUS_IS_SEARCH_DIRECTORY (files_view->details->model);
}
const char *
guint
nautilus_files_view_get_view_id (NautilusFilesView *view)
{
return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->get_view_id (view);
......@@ -8290,26 +8290,30 @@ nautilus_files_view_init (NautilusFilesView *view)
}
NautilusFilesView *
nautilus_files_view_new (const gchar *id,
nautilus_files_view_new (guint id,
NautilusWindowSlot *slot)
{
NautilusFilesView *view = NULL;
if (g_strcmp0 (id, NAUTILUS_CANVAS_VIEW_ID) == 0) {
switch (id) {
case NAUTILUS_VIEW_GRID_ID:
view = nautilus_canvas_view_new (slot);
} else if (g_strcmp0 (id, NAUTILUS_LIST_VIEW_ID) == 0) {
break;
case NAUTILUS_VIEW_LIST_ID:
view = nautilus_list_view_new (slot);
} else if (g_strcmp0 (id, NAUTILUS_DESKTOP_VIEW_ID) == 0) {
break;
case NAUTILUS_VIEW_DESKTOP_ID:
view = nautilus_desktop_canvas_view_new (slot);
}
break;
#if ENABLE_EMPTY_VIEW
else if (g_strcmp0 (id, NAUTILUS_EMPTY_VIEW_ID) == 0) {
case NAUTILUS_VIEW_EMPTY_ID:
view = nautilus_empty_view_new (slot);
}
break;
#endif
}
if (view == NULL) {
g_critical ("Unknown view type ID: %s", id);
g_critical ("Unknown view type ID: %d", id);
} else if (g_object_is_floating (view)) {
g_object_ref_sink (view);
}
......
......@@ -39,13 +39,13 @@ typedef struct NautilusFilesViewClass NautilusFilesViewClass;
#include "nautilus-window.h"
#include "nautilus-window-slot.h"
#if ENABLE_EMPTY_VIEW
#define NAUTILUS_EMPTY_VIEW_ID "empty"
#endif
#define NAUTILUS_CANVAS_VIEW_ID "grid"
#define NAUTILUS_DESKTOP_VIEW_ID "desktop"
#define NAUTILUS_LIST_VIEW_ID "list"
enum {
NAUTILUS_VIEW_GRID_ID,
NAUTILUS_VIEW_LIST_ID,
NAUTILUS_VIEW_DESKTOP_ID,
NAUTILUS_VIEW_EMPTY_ID,
NAUTILUS_VIEW_INVALID_ID,
};
#define NAUTILUS_TYPE_FILES_VIEW nautilus_files_view_get_type()
#define NAUTILUS_FILES_VIEW(obj)\
......@@ -265,8 +265,8 @@ struct NautilusFilesViewClass {
void (* click_policy_changed) (NautilusFilesView *view);
void (* sort_directories_first_changed) (NautilusFilesView *view);
/* Get the id string for this view. Its a constant string, not memory managed */
const char * (* get_view_id) (NautilusFilesView *view);
/* Get the id for this view. Its a guint*/
guint (* get_view_id) (NautilusFilesView *view);
/* Return the uri of the first visible file */
char * (* get_first_visible_file) (NautilusFilesView *view);
......@@ -285,7 +285,7 @@ struct NautilusFilesViewClass {
/* GObject support */
GType nautilus_files_view_get_type (void);
NautilusFilesView * nautilus_files_view_new (const gchar *id,
NautilusFilesView * nautilus_files_view_new (guint id,
NautilusWindowSlot *slot);
/* Functions callable from the user interface and elsewhere. */
......@@ -339,7 +339,7 @@ gboolean nautilus_files_view_is_editable (NautilusFilesV
NautilusWindow * nautilus_files_view_get_window (NautilusFilesView *view);
/* NautilusFilesView methods */
const char * nautilus_files_view_get_view_id (NautilusFilesView *view);
guint nautilus_files_view_get_view_id (NautilusFilesView *view);
/* file operations */
char * nautilus_files_view_get_backing_uri (NautilusFilesView *view);
......
......@@ -3061,10 +3061,10 @@ nautilus_list_view_end_loading (NautilusFilesView *view,
list_view_notify_clipboard_info (monitor, info, NAUTILUS_LIST_VIEW (view));
}
static const char *
static guint
nautilus_list_view_get_id (NautilusFilesView *view)
{
return NAUTILUS_LIST_VIEW_ID;
return NAUTILUS_VIEW_LIST_ID;
}
static GdkRectangle*
......
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
nautilus-window-slot.c: Nautilus window slot
......@@ -122,8 +122,8 @@ struct NautilusWindowSlotDetails {
GCancellable *mount_cancellable;
GError *mount_error;
gboolean tried_mount;
gchar *view_mode_before_search;
gchar *view_mode_before_places;
gint view_mode_before_search;
gint view_mode_before_places;
};
static guint signals[LAST_SIGNAL] = { 0 };
......@@ -135,9 +135,9 @@ static void hide_query_editor (NautilusWindowSlot *slot);
static void nautilus_window_slot_sync_actions (NautilusWindowSlot *slot);
static void nautilus_window_slot_connect_new_content_view (NautilusWindowSlot *slot);
static void nautilus_window_slot_disconnect_content_view (NautilusWindowSlot *slot);
static gboolean nautilus_window_slot_content_view_matches (NautilusWindowSlot *slot, const char *iid);
static gboolean nautilus_window_slot_content_view_matches (NautilusWindowSlot *slot, guint id);
static NautilusView* nautilus_window_slot_get_view_for_location (NautilusWindowSlot *slot, GFile *location);
static void nautilus_window_slot_set_content_view (NautilusWindowSlot *slot, const char *id);
static void nautilus_window_slot_set_content_view (NautilusWindowSlot *slot, guint id);
static void nautilus_window_slot_set_loading (NautilusWindowSlot *slot, gboolean loading);
char * nautilus_window_slot_get_location_uri (NautilusWindowSlot *slot);
static void nautilus_window_slot_set_search_visible (NautilusWindowSlot *slot,
......@@ -163,56 +163,47 @@ nautilus_window_slot_get_view_for_location (NautilusWindowSlot *slot,
* for the desktop window.
*/
if (NAUTILUS_IS_DESKTOP_WINDOW (window)) {
view = NAUTILUS_VIEW (nautilus_files_view_new (NAUTILUS_DESKTOP_VIEW_ID, slot));
view = NAUTILUS_VIEW (nautilus_files_view_new (NAUTILUS_VIEW_DESKTOP_ID, slot));
} else if (nautilus_file_is_other_locations (file)) {
view = NAUTILUS_VIEW (nautilus_places_view_new ());
/* Save the current view, so we can go back after places view */
if (slot->details->content_view && NAUTILUS_IS_FILES_VIEW (slot->details->content_view)) {
g_clear_pointer (&slot->details->view_mode_before_places, g_free);
slot->details->view_mode_before_places = g_strdup (nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW (slot->details->content_view)));
slot->details->view_mode_before_places = nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW (slot->details->content_view));
}
} else {
gchar *view_id;
guint view_id;
view_id = NULL;
view_id = NAUTILUS_VIEW_INVALID_ID;
/* 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 we are in search, try to use by default list view. */
if (nautilus_file_is_in_search (file)) {
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_files_view_get_view_id (NAUTILUS_FILES_VIEW (slot->details->content_view)));
}
view_id = g_strdup (NAUTILUS_LIST_VIEW_ID);
} else {
g_free (slot->details->view_mode_before_search);
slot->details->view_mode_before_search = NULL;
/* 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 == NAUTILUS_VIEW_INVALID_ID) {
slot->details->view_mode_before_search = nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW (slot->details->content_view));
}
}
/* 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_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_SEARCH_VIEW);
} else if (slot->details->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 (slot->details->view_mode_before_search != NAUTILUS_VIEW_INVALID_ID) {
view_id = slot->details->view_mode_before_search;
slot->details->view_mode_before_search = NULL;
slot->details->view_mode_before_search = NAUTILUS_VIEW_INVALID_ID;
} else if (NAUTILUS_IS_PLACES_VIEW (slot->details->content_view)) {
view_id = slot->details->view_mode_before_places;
slot->details->view_mode_before_places = NULL;
slot->details->view_mode_before_places = NAUTILUS_VIEW_INVALID_ID;
} else {
view_id = g_strdup (nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW (slot->details->content_view)));
view_id = nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW (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 ();
if (view_id == NAUTILUS_VIEW_INVALID_ID) {
view_id = g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_DEFAULT_FOLDER_VIEWER);
}
/* Try to reuse the current view */
......@@ -221,8 +212,6 @@ nautilus_window_slot_get_view_for_location (NautilusWindowSlot *slot,
} else {
view = NAUTILUS_VIEW (nautilus_files_view_new (view_id, slot));
}
g_free (view_id);
}
nautilus_file_unref (file);
......@@ -232,16 +221,16 @@ nautilus_window_slot_get_view_for_location (NautilusWindowSlot *slot,
static gboolean
nautilus_window_slot_content_view_matches (NautilusWindowSlot *slot,
const char *iid)
guint id)
{
if (slot->details->content_view == NULL) {
return FALSE;
}
if (!iid && NAUTILUS_IS_PLACES_VIEW (slot->details->content_view)) {
if (id == NAUTILUS_VIEW_INVALID_ID && NAUTILUS_IS_PLACES_VIEW (slot->details->content_view)) {
return TRUE;
} else if (iid && NAUTILUS_IS_FILES_VIEW (slot->details->content_view)){
return g_strcmp0 (nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW (slot->details->content_view)), iid) == 0;
} else if (id != NAUTILUS_VIEW_INVALID_ID && NAUTILUS_IS_FILES_VIEW (slot->details->content_view)){
return nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW (slot->details->content_view)) == id;
} else {
return FALSE;
}
......@@ -304,7 +293,7 @@ nautilus_window_slot_sync_actions (NautilusWindowSlot *slot)
action = g_action_map_lookup_action (G_ACTION_MAP (slot->details->slot_action_group), "files-view-mode");
if (NAUTILUS_IS_FILES_VIEW (nautilus_window_slot_get_current_view (slot)) &&
!NAUTILUS_IS_DESKTOP_CANVAS_VIEW (nautilus_window_slot_get_current_view (slot))) {
variant = g_variant_new_string (nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW (nautilus_window_slot_get_current_view (slot))));
variant = g_variant_new_uint32 (nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW (nautilus_window_slot_get_current_view (slot))));
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
g_action_change_state (action, variant);
} else {
......@@ -667,45 +656,29 @@ action_files_view_mode (GSimpleAction *action,
GVariant *value,
gpointer user_data)
{
const gchar *name;
NautilusWindowSlot *slot;
const gchar *preferences_key;
guint view_id;
name = g_variant_get_string (value, NULL);
view_id = g_variant_get_uint32 (value);
slot = NAUTILUS_WINDOW_SLOT (user_data);
if (!NAUTILUS_IS_FILES_VIEW (nautilus_window_slot_get_current_view (slot)))
return;
nautilus_window_slot_set_content_view (slot, name);
if (g_strcmp0 (name, "list") == 0) {
/* If this change is caused because of the automatic list view
* switch for search, don't set as default list view */
if (!(nautilus_view_is_searching (nautilus_window_slot_get_current_view (slot)) &&
g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_LIST_VIEW_ON_SEARCH))) {
g_settings_set_enum (nautilus_preferences,
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 to grid, disable the automatic
* switch to list view on search */
if (nautilus_view_is_searching (nautilus_window_slot_get_current_view (slot))) {
g_settings_set_boolean (nautilus_preferences,
NAUTILUS_PREFERENCES_LIST_VIEW_ON_SEARCH,
FALSE);
}
g_settings_set_enum (nautilus_preferences,
NAUTILUS_PREFERENCES_DEFAULT_FOLDER_VIEWER,
NAUTILUS_DEFAULT_FOLDER_VIEWER_ICON_VIEW);
} else {
g_assert_not_reached ();
}
return;
nautilus_window_slot_set_content_view (slot, view_id);
preferences_key = nautilus_view_is_searching (nautilus_window_slot_get_current_view (slot)) ?
NAUTILUS_PREFERENCES_SEARCH_VIEW :
NAUTILUS_PREFERENCES_DEFAULT_FOLDER_VIEWER;
g_settings_set_enum (nautilus_preferences, preferences_key, view_id);
g_simple_action_set_state (action, value);
}
const GActionEntry slot_entries[] = {
{ "files-view-mode", NULL, "s", "''", action_files_view_mode },
/* 4 is NAUTILUS_VIEW_INVALID_ID */
{ "files-view-mode", NULL, "u", "uint32 4", action_files_view_mode },
{ "search-visible", NULL, NULL, "false", action_search_visible },
};
......@@ -727,8 +700,8 @@ nautilus_window_slot_init (NautilusWindowSlot *slot)
gtk_widget_insert_action_group (GTK_WIDGET (slot),
"slot",
G_ACTION_GROUP (slot->details->slot_action_group));
nautilus_application_add_accelerator (app, "slot.files-view-mode('list')", "<control>1");
nautilus_application_add_accelerator (app, "slot.files-view-mode('grid')", "<control>2");
nautilus_application_add_accelerator (app, "slot.files-view-mode(1)", "<control>1");
nautilus_application_add_accelerator (app, "slot.files-view-mode(0)", "<control>2");
nautilus_application_add_accelerator (app, "slot.search-visible", "<control>f");
}
......@@ -1544,19 +1517,18 @@ free_location_change (NautilusWindowSlot *slot)
}
}
void
static void
nautilus_window_slot_set_content_view (NautilusWindowSlot *slot,
const char *id)
guint id)
{
NautilusFilesView *view;
GList *selection;
char *uri;
g_assert (slot != NULL);
g_assert (id != NULL);
uri = nautilus_window_slot_get_location_uri (slot);
DEBUG ("Change view of window %s to %s", uri, id);
DEBUG ("Change view of window %s to %d", uri, id);
g_free (uri);
if (nautilus_window_slot_content_view_matches (slot, id)) {
......@@ -2248,11 +2220,6 @@ nautilus_window_slot_dispose (GObject *object)
g_clear_object (&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;
}
nautilus_file_list_free (slot->details->pending_selection);
slot->details->pending_selection = NULL;
......
......@@ -21,7 +21,7 @@
<property name="visible">True</property>
<property name="text">Grid</property>
<property name="action-name">slot.files-view-mode</property>
<property name="action-target">'grid'</property>
<property name="action-target">uint32 0</property>
<property name="iconic">True</property>
<property name="centered">True</property>
<property name="icon">icon_grid</property>
......@@ -37,7 +37,7 @@
<property name="visible">True</property>
<property name="text">List</property>
<property name="action-name">slot.files-view-mode</property>
<property name="action-target">'list'</property>
<property name="action-target">uint32 1</property>
<property name="iconic">True</property>
<property name="centered">True</property>
<property name="icon">icon_list</property>
......
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