summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsc@umbraculum.org <jsc@umbraculum.org>2013-04-26 15:22:49 +0200
committerjsc@umbraculum.org <jsc@umbraculum.org>2013-04-26 15:22:49 +0200
commit2eedb967d2a3f8026163bd182e973106e6846a13 (patch)
tree71922ee5a65fa5d3af2719b4c853466eae27d5c5
parentdda686a04556a4cbbed0d8acf68c7d017b613024 (diff)
Setting directory to previous selected directory when selecting new file.
-rw-r--r--plugingui/directory.cc44
-rw-r--r--plugingui/directory.h4
-rw-r--r--plugingui/filebrowser.cc13
3 files changed, 40 insertions, 21 deletions
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:
diff --git a/plugingui/directory.h b/plugingui/directory.h
index a85d0bb..391bf45 100644
--- a/plugingui/directory.h
+++ b/plugingui/directory.h
@@ -70,7 +70,8 @@ class Directory {
static bool isRoot(std::string path);
static Directory::DriveList drives();
static bool isDir(std::string path);
- static bool exists(std::string file);
+ static bool exists(std::string path);
+ static std::string pathDirectory(std::string filepath);
private:
std::string _path;
@@ -79,6 +80,7 @@ class Directory {
typedef std::list<std::string> Path;
static Path parsePath(std::string path);
+ static std::string pathToStr(Path &path);
};
#endif/*__DRUMGIZMO_DIRECTORY_H__*/
diff --git a/plugingui/filebrowser.cc b/plugingui/filebrowser.cc
index 39cb565..21e3cc8 100644
--- a/plugingui/filebrowser.cc
+++ b/plugingui/filebrowser.cc
@@ -72,6 +72,8 @@ static void changeDir(void *ptr) {
GUI::LineEdit *le = prv->lineedit;
std::string value = lb->selectedValue();
Directory* dir = prv->dir;
+
+ lb->clear();
INFO(filebrowser, "Changing path to '%s'\n", (dir->path() + "/" + value).c_str());
@@ -271,13 +273,16 @@ static bool isDir(std::string d)
void GUI::FileBrowser::setPath(std::string path)
{
- WARN(filebrowser, "Not implemented yet!");
+// WARN(filebrowser, "Not implemented yet!");
// TODO: Remove this check to directoy.cc
-// INFO(filebrowser, "Setting path to '%s'\n", path.c_str());
-// if(path.empty()) return;
+ INFO(filebrowser, "Setting path to '%s'\n", path.c_str());
+ if(path.empty()) path = Directory::cwd();
// TODO: Strip path to set path to a directory
-// prv->dir->setPath(path);
+ prv->dir->setPath(Directory::pathDirectory(path));
+ prv->listbox->clear();
+
+ changeDir(prv);
/*
std::string dir;
if(prv->dir->isDir()) {