From 4d86a47b8cf90beaf0fb90196a46d2d23eba43b7 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 5 May 2013 22:26:44 +0200 Subject: Dirty fixing win32 filebrowser. --- plugingui/directory.cc | 29 ++++++++++++++++++++++------- plugingui/filebrowser.cc | 27 +++++++++++++++------------ 2 files changed, 37 insertions(+), 19 deletions(-) (limited to 'plugingui') diff --git a/plugingui/directory.cc b/plugingui/directory.cc index 9a8fb38..6e4a414 100644 --- a/plugingui/directory.cc +++ b/plugingui/directory.cc @@ -127,26 +127,34 @@ Directory::EntryList Directory::listFiles(std::string path) { std::string name = entry->d_name; if(name == ".") continue; -#ifndef WIN32 - if(Directory::isRoot(path) && name == "..") continue; -#endif + if(Directory::isRoot(path) && name == "..") continue; entries.push_back(entry->d_name); } +#ifdef WIN32 + DEBUG(directory, "root is %s\n", Directory::root(path).c_str()); + DEBUG(directory, "current path %s is root? %d", path.c_str(), Directory::isRoot(path)); +if(Directory::isRoot(path)) entries.push_back(".."); +#endif + return entries; } bool Directory::isRoot(std::string path) { +// DEBUG(directory, "Is root %s\n", path.c_str()); #ifdef WIN32 std::transform(path.begin(), path.end(), path.begin(), ::tolower); + std::string root_str = Directory::root(path); + std::transform(root_str.begin(), root_str.end(), root_str.begin(), ::tolower); // TODO: This is not a correct root calculation, but works with partitions if(path.size() == 2) { - if(path == root()) return true; + if(path == root_str) return true; else return false; } else if (path.size() == 3) { - if(path == root() + SEP) return true; +// DEBUG(directory, "Comparing %s and %s\n", path.c_str(), (root_str + SEP).c_str()); + if(path == root_str + SEP) return true; return false; } else { @@ -165,7 +173,7 @@ std::string Directory::root() { // TODO: Handle windows root std::string Directory::root(std::string path) { #ifdef WIN32 - if(path.size() < 3) { + if(path.size() < 2) { return "c:"; // just something default when input is bad } else { @@ -289,7 +297,14 @@ std::string Directory::pathToStr(Directory::Path& path) { if(cleaned_path.empty()) { cleaned_path = Directory::root(); - } +#ifdef WIN32 + cleaned_path += SEP; +#endif +} + +#ifdef WIN32 + if(cleaned_path.size() == 2) cleaned_path += SEP; +#endif return cleaned_path; } diff --git a/plugingui/filebrowser.cc b/plugingui/filebrowser.cc index 6aaa6b7..d4acdd6 100644 --- a/plugingui/filebrowser.cc +++ b/plugingui/filebrowser.cc @@ -54,6 +54,7 @@ struct GUI::FileBrowser::private_data { Directory *dir; #ifdef WIN32 bool above_root; + bool in_root; #endif }; @@ -72,14 +73,15 @@ 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()); #ifdef WIN32 if(prv->above_root && !value.empty()) { - dir->setPath(value); +DEBUG(filebrowser, "AAAA"); + dir->setPath(value+"\\"); value.clear(); prv->above_root = false; } @@ -92,16 +94,7 @@ static void changeDir(void *ptr) { return; } - if(!value.empty() && !dir->cd(value)) { - DEBUG(filebrowser, "Error changing to '%s'\n", - (dir->path() + "/" + value).c_str()); - return; - } - - DEBUG(filebrowser, "Setting path of lineedit to %s\n", dir->path().c_str()); - le->setText(dir->path()); - lb->clear(); std::vector items; #ifdef WIN32 @@ -120,7 +113,17 @@ static void changeDir(void *ptr) { } else { #endif - Directory::EntryList entries = dir->entryList(); + + if(!value.empty() && !dir->cd(value)) { + DEBUG(filebrowser, "Error changing to '%s'\n", + (dir->path() + "/" + value).c_str()); + return; + } + + DEBUG(filebrowser, "Setting path of lineedit to %s\n", dir->path().c_str()); + le->setText(dir->path()); + +Directory::EntryList entries = dir->entryList(); for(Directory::EntryList::iterator it = entries.begin(); it != entries.end(); it++) { GUI::ListBoxBasic::Item item; -- cgit v1.2.3