From 2eedb967d2a3f8026163bd182e973106e6846a13 Mon Sep 17 00:00:00 2001 From: "jsc@umbraculum.org" Date: Fri, 26 Apr 2013 15:22:49 +0200 Subject: Setting directory to previous selected directory when selecting new file. --- plugingui/directory.cc | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'plugingui/directory.cc') diff --git a/plugingui/directory.cc b/plugingui/directory.cc index be5fad9..d25a367 100644 --- a/plugingui/directory.cc +++ b/plugingui/directory.cc @@ -92,22 +92,7 @@ std::string Directory::cleanPath(std::string path) { WARN(directory, "Cleaning path '%s'\n", path.c_str()); Directory::Path pathlst = parsePath(path); - - std::string cleaned_path; - DEBUG(directory, "Number of directories in path %d\n", pathlst.size()); - - for(Directory::Path::iterator it = pathlst.begin(); - it != pathlst.end(); it++) { - std::string dir = *it; - DEBUG(directory, "\tDir '%s'\n", dir.c_str()); - cleaned_path += "/" + dir; - } - - DEBUG(directory, "Cleaned path '%s'\n", cleaned_path.c_str()); - - if(cleaned_path.empty()) cleaned_path = "/"; - - return cleaned_path; + return Directory::pathToStr(pathlst); } Directory::EntryList Directory::listFiles(std::string path) { @@ -234,6 +219,33 @@ Directory::Path Directory::parsePath(std::string path_str) { return path; } +std::string Directory::pathToStr(Directory::Path& path) { + std::string cleaned_path; + DEBUG(directory, "Number of directories in path %d\n", path.size()); + + for(Directory::Path::iterator it = path.begin(); + it != path.end(); it++) { + std::string dir = *it; + DEBUG(directory, "\tDir '%s'\n", dir.c_str()); + cleaned_path += "/" + dir; + } + + DEBUG(directory, "Cleaned path '%s'\n", cleaned_path.c_str()); + + if(cleaned_path.empty()) cleaned_path = "/"; + + return cleaned_path; +} + +std::string Directory::pathDirectory(std::string filepath) { + if(Directory::isDir(filepath)) return filepath; + + Directory::Path path = parsePath(filepath); + if(path.size() > 0) path.pop_back(); + + return Directory::pathToStr(path); +} + #ifdef TEST_DIRECTORY //Additional dependency files //deps: -- cgit v1.2.3