From b61c55a43c21a95234d79f6afd9a64964f5fffec Mon Sep 17 00:00:00 2001 From: Jonas Suhr Christensen Date: Wed, 15 May 2013 16:35:01 +0200 Subject: Improved filebrowser functionality: * Directories listed first * Directories identified by "/" * Filtering out none drumkit files --- plugingui/directory.cc | 63 ++++++++++++++++++++++++++++++++++++++++++++--- plugingui/listboxbasic.cc | 3 +++ 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/plugingui/directory.cc b/plugingui/directory.cc index eefbd93..1069856 100644 --- a/plugingui/directory.cc +++ b/plugingui/directory.cc @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- M(de: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /*************************************************************************** * directory.cc * @@ -30,6 +30,8 @@ #include #include #include +#include +#include #ifdef WIN32 #include @@ -38,6 +40,8 @@ #include +#define DRUMKIT_SUFFIX ".xml" + // http://en.wikipedia.org/wiki/Path_(computing) #ifdef WIN32 #define SEP "\\" @@ -94,8 +98,7 @@ bool Directory::cdUp() std::string Directory::path() { - setPath(cleanPath(_path)); - return _path; + return cleanPath(_path); } Directory::EntryList Directory::entryList() @@ -131,22 +134,74 @@ Directory::EntryList Directory::listFiles(std::string path) return entries; } + std::vector directories; + std::vector files; + struct dirent *entry; while((entry = readdir(dir)) != NULL) { std::string name = entry->d_name; if(name == ".") continue; if(Directory::isRoot(path) && name == "..") continue; + + std::string entrypath = path; + entrypath += SEP; + entrypath += entry->d_name; + if(Directory::isDir(entrypath)) { + if(name == "..") directories.push_back(entry->d_name); + else directories.push_back(std::string("/") + entry->d_name); + } + else { + int drumkit_suffix_length = strlen(DRUMKIT_SUFFIX); + if(name.substr(name.length() - drumkit_suffix_length, + drumkit_suffix_length) != DRUMKIT_SUFFIX) { + continue; + } - entries.push_back(entry->d_name); + files.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 + // sort + for(int x = 0; x < (int)directories.size(); x++) { + for(int y = 0; y < (int)directories.size(); y++) { + if(directories[x] < directories[y]) { + + std::string tmp = directories[x]; + directories[x] = directories[y]; + directories[y] = tmp; + } + } + } + + for(int x = 0; x < (int)files.size(); x++) { + for(int y = 0; y < (int)files.size(); y++) { + if(files[x] < files[y]) { + + std::string tmp = files[x]; + files[x] = files[y]; + files[y] = tmp; + } + } + } + + + for(std::vector::iterator it = directories.begin(); it != directories.end(); it++) { + entries.push_back(*it); + } + + for(std::vector::iterator it = files.begin(); it != files.end(); it++) { + entries.push_back(*it); + } + + return entries; } diff --git a/plugingui/listboxbasic.cc b/plugingui/listboxbasic.cc index 9153907..f0699c7 100644 --- a/plugingui/listboxbasic.cc +++ b/plugingui/listboxbasic.cc @@ -92,6 +92,7 @@ void GUI::ListBoxBasic::addItems(std::vector &is) i++; } +/* // sort for(int x = 0; x < (int)items.size(); x++) { for(int y = 0; y < (int)items.size(); y++) { @@ -105,8 +106,10 @@ void GUI::ListBoxBasic::addItems(std::vector &is) } } } +*/ if(selected == -1) setSelection((int)items.size() - 1); + setSelection(0); int numitems = height() / (font.textHeight() + padding); scroll.setRange(numitems); -- cgit v1.2.3