From f86deb0a03e741b614961a8f718dc1f51e47a988 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Thu, 17 Jun 2010 12:03:00 +0000 Subject: [PATCH] Replace /home/user with ~ in the documents list (patch by Jon Strait, thanks). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5028 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 7 +++++++ src/sidebar.c | 18 +++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 3edb3d56..ed9a9f08 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-06-17 Nick Treleaven + + * src/sidebar.c: + Replace /home/user with ~ in the documents list (patch by Jon + Strait, thanks). + + 2010-06-16 Nick Treleaven * src/notebook.c: diff --git a/src/sidebar.c b/src/sidebar.c index 69e0c238..20859e3b 100644 --- a/src/sidebar.c +++ b/src/sidebar.c @@ -345,8 +345,10 @@ static GtkTreeIter *get_doc_parent(GeanyDocument *doc) gchar *tmp_dirname; gchar *project_base_path; gchar *dirname = NULL; + const gchar *home_dir = g_get_home_dir(); static GtkTreeIter parent; GtkTreeModel *model = GTK_TREE_MODEL(store_openfiles); + const gchar *rest; if (!documents_show_paths) return NULL; @@ -357,7 +359,6 @@ static GtkTreeIter *get_doc_parent(GeanyDocument *doc) if (project_base_path != NULL) { gsize len = strlen(project_base_path); - const gchar *rest; if (project_base_path[len-1] == G_DIR_SEPARATOR) project_base_path[len-1] = '\0'; @@ -367,12 +368,27 @@ static GtkTreeIter *get_doc_parent(GeanyDocument *doc) { rest = tmp_dirname + len; if (*rest == G_DIR_SEPARATOR || *rest == '\0') + { dirname = g_strdup_printf("%s%s", app->project->name, rest); + } } g_free(project_base_path); } if (dirname == NULL) + { dirname = tmp_dirname; + + /* If matches home dir, replace with tilde */ + if (home_dir && *home_dir != 0 && g_str_has_prefix(dirname, home_dir)) + { + rest = dirname + strlen(home_dir); + if (*rest == G_DIR_SEPARATOR || *rest == '\0') + { + dirname = g_strdup_printf("~%s", rest); + g_free(tmp_dirname); + } + } + } else g_free(tmp_dirname);