From d28efb55435ff9859d6fa8bc2d5316816f85c160 Mon Sep 17 00:00:00 2001 From: John Levon Date: Tue, 8 Apr 2003 00:06:52 +0000 Subject: [PATCH] bug 993 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6734 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/support/ChangeLog | 5 ++++ src/support/filetools.C | 61 ++++++++++++++++------------------------- 2 files changed, 28 insertions(+), 38 deletions(-) diff --git a/src/support/ChangeLog b/src/support/ChangeLog index b5bb83aa88..75fb3debed 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,8 @@ +2003-04-08 John Levon + + * filetools.C: fix MakeDisplayPath() to not + lie (bug 993) + 2003-03-30 John Levon * Makefile.am: diff --git a/src/support/filetools.C b/src/support/filetools.C index 51ac03f9d0..575338bef7 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -1121,54 +1121,39 @@ string const unzipFile(string const & zipped_file) } -// Creates a nice compact path for displaying -string const -MakeDisplayPath (string const & path, unsigned int threshold) +string const MakeDisplayPath(string const & path, unsigned int threshold) { - string::size_type const l1 = path.length(); + string str = path; - // First, we try a relative path compared to home string const home(GetEnvPath("HOME")); - string relhome = MakeRelPath(path, home); - - string::size_type l2 = relhome.length(); - string prefix; + // replace /home/blah with ~/ + if (prefixIs(str, home)) + str = subst(str, home, "~"); - // If we backup from home or don't have a relative path, - // this try is no good - if (prefixIs(relhome, "../") || os::is_absolute_path(relhome)) { - // relative path was no good, just use the original path - relhome = path; - l2 = l1; - } else { - prefix = "~/"; - } + if (str.length() <= threshold) + return str; - // Is the path too long? - if (l2 > threshold) { - // Yes, shortend it - prefix += ".../"; + string const prefix = ".../"; + string temp; - string temp; + while (str.length() > threshold) + str = split(str, temp, '/'); - while (relhome.length() > threshold) - relhome = split(relhome, temp, '/'); + // Did we shorten everything away? + if (str.empty()) { + // Yes, filename itself is too long. + // Pick the start and the end of the filename. + str = OnlyFilename(path); + string const head = str.substr(0, threshold / 2 - 3); - // Did we shortend everything away? - if (relhome.empty()) { - // Yes, filename in itself is too long. - // Pick the start and the end of the filename. - relhome = OnlyFilename(path); - string const head = relhome.substr(0, threshold/2 - 3); - - l2 = relhome.length(); - string const tail = - relhome.substr(l2 - threshold/2 - 2, l2 - 1); - relhome = head + "..." + tail; - } + string::size_type len = str.length(); + string const tail = + str.substr(len - threshold / 2 - 2, len - 1); + str = head + "..." + tail; } - return prefix + relhome; + + return prefix + str; } -- 2.39.2