1
0
mirror of https://gitlab.gnome.org/GNOME/nautilus synced 2024-06-30 23:46:35 +00:00

placessidebar: Reorganize places

The sidebar has got too many unremovable places at the top, which leave
little space for other potentially more relevant places before they
overflow out of view by scrolling.

A set of special user directories (DOCUMENTS, MUSIC, PICTURES, VIDEOS,
and DOWNLOAD) are found near the top, and cannot be removed, even if
people don't need quick access to all of them.

Bookmarks (i.e. custom locations added to the sidebar by the users) are
always at the bottom, which means they are the first to go out of view.
This is made worse by internal storage units being back to the sidebar.

To fix these issues, let's reorganize the places:

  - reduce the number of default sidebar locations by turning the
special user directories into regular bookmarks[0] that people can
reorder or remove from the sidebar.
  - show bookmarks before mounts; this allows special user locations to
remain close to their previous position, keep important bookmarks from
being scrolled out of view, and instead overflow excess mounts/devices.

While at it, reposition the Home to the first place, as it is the first
location shown when launching the app.

Part of: https://gitlab.gnome.org/GNOME/nautilus/-/issues/3012

[0] This assumes a default set of bookmarks including these directories
    is created by xdg-user-dirs-update-gtk on first login. Ensuring it
    is installed, running on startup, and working correctly is a system
    integration and quality assurance task for vendors/administrators.
This commit is contained in:
António Fernandes 2024-01-31 11:53:36 +00:00
parent f5cacef579
commit 5c2f55663a
5 changed files with 16 additions and 107 deletions

View File

@ -479,69 +479,6 @@ path_is_home_dir (const char *path)
return res;
}
static void
add_special_dirs (NautilusGtkPlacesSidebar *sidebar)
{
GList *dirs;
int index;
dirs = NULL;
for (index = 0; index < G_USER_N_DIRECTORIES; index++)
{
const char *path;
GFile *root;
GIcon *start_icon;
char *name;
char *mount_uri;
char *tooltip;
NautilusBookmark *bookmark;
if (index == G_USER_DIRECTORY_DESKTOP ||
index == G_USER_DIRECTORY_TEMPLATES ||
index == G_USER_DIRECTORY_PUBLIC_SHARE)
continue;
path = g_get_user_special_dir (index);
/* XDG resets special dirs to the home directory in case
* it's not finiding what it expects. We don't want the home
* to be added multiple times in that weird configuration.
*/
if (path == NULL ||
path_is_home_dir (path) ||
g_list_find_custom (dirs, path, (GCompareFunc) g_strcmp0) != NULL)
continue;
root = g_file_new_for_path (path);
bookmark = nautilus_bookmark_list_item_with_location (sidebar->bookmark_list, root, NULL);
if (bookmark)
name = g_strdup (nautilus_bookmark_get_name (bookmark));
else
name = g_file_get_basename (root);
start_icon = nautilus_special_directory_get_symbolic_icon (index);
mount_uri = g_file_get_uri (root);
tooltip = g_file_get_parse_name (root);
add_place (sidebar, NAUTILUS_GTK_PLACES_XDG_DIR,
NAUTILUS_GTK_PLACES_SECTION_COMPUTER,
name, start_icon, NULL, mount_uri,
NULL, NULL, NULL, NULL, 0,
tooltip);
g_free (name);
g_object_unref (root);
g_object_unref (start_icon);
g_free (mount_uri);
g_free (tooltip);
dirs = g_list_prepend (dirs, (char *)path);
}
g_list_free (dirs);
}
static char *
get_home_directory_uri (void)
{
@ -742,6 +679,18 @@ update_places (NautilusGtkPlacesSidebar *sidebar)
network_mounts = network_volumes = NULL;
/* add built-in places */
/* home folder */
home_uri = get_home_directory_uri ();
start_icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_HOME);
add_place (sidebar, NAUTILUS_GTK_PLACES_BUILT_IN,
NAUTILUS_GTK_PLACES_SECTION_COMPUTER,
_("Home"), start_icon, NULL, home_uri,
NULL, NULL, NULL, NULL, 0,
_("Open Personal Folder"));
g_object_unref (start_icon);
g_free (home_uri);
if (should_show_recent (sidebar))
{
start_icon = g_themed_icon_new_with_default_fallbacks ("document-open-recent-symbolic");
@ -761,17 +710,6 @@ update_places (NautilusGtkPlacesSidebar *sidebar)
_("Starred Files"));
g_object_unref (start_icon);
/* home folder */
home_uri = get_home_directory_uri ();
start_icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_HOME);
add_place (sidebar, NAUTILUS_GTK_PLACES_BUILT_IN,
NAUTILUS_GTK_PLACES_SECTION_COMPUTER,
_("Home"), start_icon, NULL, home_uri,
NULL, NULL, NULL, NULL, 0,
_("Open Personal Folder"));
g_object_unref (start_icon);
g_free (home_uri);
/* desktop */
if (sidebar->show_desktop)
{
@ -789,9 +727,6 @@ update_places (NautilusGtkPlacesSidebar *sidebar)
}
}
/* XDG directories */
add_special_dirs (sidebar);
/* Network view */
start_icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_NETWORK_VIEW);
add_place (sidebar, NAUTILUS_GTK_PLACES_BUILT_IN,
@ -1074,9 +1009,6 @@ update_places (NautilusGtkPlacesSidebar *sidebar)
{
GtkWidget *row;
if (nautilus_bookmark_get_is_builtin (l->data))
continue;
g_autoptr (GFile) location = nautilus_bookmark_get_location (l->data);
g_autofree char *mount_uri = nautilus_bookmark_get_uri (l->data);

View File

@ -89,9 +89,9 @@ void nautilus_gtk_places_sidebar_set_drop_targets_visible (Nauti
typedef enum {
NAUTILUS_GTK_PLACES_SECTION_INVALID,
NAUTILUS_GTK_PLACES_SECTION_COMPUTER,
NAUTILUS_GTK_PLACES_SECTION_MOUNTS,
NAUTILUS_GTK_PLACES_SECTION_CLOUD,
NAUTILUS_GTK_PLACES_SECTION_BOOKMARKS,
NAUTILUS_GTK_PLACES_SECTION_CLOUD,
NAUTILUS_GTK_PLACES_SECTION_MOUNTS,
NAUTILUS_GTK_PLACES_N_SECTIONS
} NautilusGtkPlacesSectionType;

View File

@ -770,8 +770,6 @@ gboolean
nautilus_bookmark_list_can_bookmark_location (NautilusBookmarkList *list,
GFile *location)
{
g_autoptr (NautilusBookmark) bookmark = NULL;
if (nautilus_bookmark_list_item_with_location (list, location, NULL))
{
/* Already bookmarked */
@ -792,8 +790,7 @@ nautilus_bookmark_list_can_bookmark_location (NautilusBookmarkList *list,
return FALSE;
}
bookmark = nautilus_bookmark_new (location, NULL);
return !nautilus_bookmark_get_is_builtin (bookmark);
return TRUE;
}
/**

View File

@ -165,24 +165,7 @@ bookmark_file_changed_callback (NautilusFile *file,
}
}
gboolean
nautilus_bookmark_get_is_builtin (NautilusBookmark *bookmark)
{
GUserDirectory xdg_type;
/* if this is not an XDG dir, it's never builtin */
if (!nautilus_bookmark_get_xdg_type (bookmark, &xdg_type))
{
return FALSE;
}
/* exclude XDG locations which are not in our builtin list */
return (xdg_type != G_USER_DIRECTORY_DESKTOP) &&
(xdg_type != G_USER_DIRECTORY_TEMPLATES) &&
(xdg_type != G_USER_DIRECTORY_PUBLIC_SHARE);
}
gboolean
static gboolean
nautilus_bookmark_get_xdg_type (NautilusBookmark *bookmark,
GUserDirectory *directory)
{

View File

@ -40,9 +40,6 @@ GFile * nautilus_bookmark_get_location (NautilusBookmark
char * nautilus_bookmark_get_uri (NautilusBookmark *bookmark);
GIcon * nautilus_bookmark_get_icon (NautilusBookmark *bookmark);
GIcon * nautilus_bookmark_get_symbolic_icon (NautilusBookmark *bookmark);
gboolean nautilus_bookmark_get_xdg_type (NautilusBookmark *bookmark,
GUserDirectory *directory);
gboolean nautilus_bookmark_get_is_builtin (NautilusBookmark *bookmark);
gboolean nautilus_bookmark_get_has_custom_name (NautilusBookmark *bookmark);
int nautilus_bookmark_compare_with (gconstpointer a,
gconstpointer b);