[nautilus/wip/antoniof/search-list-redesign: 1/3] file: Add trailing slash to parent path
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/search-list-redesign: 1/3] file: Add trailing slash to parent path
- Date: Thu, 4 Aug 2022 22:12:15 +0000 (UTC)
commit 38d3d014f953e8fd27f66704c67f8db7f7022fa1
Author: António Fernandes <antoniof gnome org>
Date: Wed Aug 3 10:00:46 2022 +0100
file: Add trailing slash to parent path
This makes it easier to tell it is a folder path.
In a special case, for recursive search, where we omit the common
prefix, this is especially important because direct subfolders would
be a single basename without any slash.
src/nautilus-file.c | 18 ++++++++++++++----
src/nautilus-name-cell.c | 17 ++++++++++++++---
2 files changed, 28 insertions(+), 7 deletions(-)
---
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index e03d78f90..7be6151c6 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -993,13 +993,14 @@ nautilus_file_unref (NautilusFile *file)
* @file: The file in question.
*
* Return value: A string representing the parent's location,
- * formatted for user display (including stripping "file://").
+ * formatted for user display (including stripping "file://"
+ * and adding trailing slash).
* If the parent is NULL, returns the empty string.
*/
char *
nautilus_file_get_parent_uri_for_display (NautilusFile *file)
{
- GFile *parent;
+ g_autoptr (GFile) parent = NULL;
char *result;
g_assert (NAUTILUS_IS_FILE (file));
@@ -1007,8 +1008,17 @@ nautilus_file_get_parent_uri_for_display (NautilusFile *file)
parent = nautilus_file_get_parent_location (file);
if (parent)
{
- result = g_file_get_parse_name (parent);
- g_object_unref (parent);
+ g_autofree gchar *parse_name = g_file_get_parse_name (parent);
+
+ /* Ensure a trailing slash to emphasize it is a directory */
+ if (g_str_has_suffix (parse_name, G_DIR_SEPARATOR_S))
+ {
+ result = g_steal_pointer (&parse_name);
+ }
+ else
+ {
+ result = g_strconcat (parse_name, G_DIR_SEPARATOR_S, NULL);
+ }
}
else
{
diff --git a/src/nautilus-name-cell.c b/src/nautilus-name-cell.c
index 1a0720ea6..71c845257 100644
--- a/src/nautilus-name-cell.c
+++ b/src/nautilus-name-cell.c
@@ -36,6 +36,7 @@ get_path_text (NautilusFile *file,
g_autofree gchar *path = NULL;
g_autoptr (GFile) dir_location = NULL;
g_autoptr (GFile) home_location = g_file_new_for_path (g_get_home_dir ());
+ g_autoptr (GFile) root_location = g_file_new_for_path ("/");
GFile *relative_location_base;
if (path_attribute_q == 0)
@@ -66,15 +67,25 @@ get_path_text (NautilusFile *file,
relative_location_base = home_location;
}
- if (g_file_has_prefix (dir_location, relative_location_base))
+ if (relative_location_base != root_location &&
+ g_file_has_prefix (dir_location, relative_location_base))
{
g_autofree gchar *relative_path = NULL;
+ g_autofree gchar *display_name = NULL;
relative_path = g_file_get_relative_path (relative_location_base, dir_location);
- return g_filename_display_name (relative_path);
+ display_name = g_filename_display_name (relative_path);
+
+ /* Ensure a trailing slash to emphasize it is a directory */
+ if (g_str_has_suffix (display_name, G_DIR_SEPARATOR_S))
+ {
+ return g_steal_pointer (&display_name);
+ }
+
+ return g_strconcat (display_name, G_DIR_SEPARATOR_S, NULL);
}
- return g_file_get_path (dir_location);
+ return g_steal_pointer (&path);
}
static gchar *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]