diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-07-28 21:14:38 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-07-28 21:14:38 (GMT) |
| commit | df3b1e2a6210b45df8bcace1db81a0a0881efbab (patch) | |
| tree | 520f92934157c28b9887fa3107ec9c4a82c73f99 /src | |
| parent | c14a008d463dab4e6e2168fa28afb26384432b36 (diff) | |
| download | powder-df3b1e2a6210b45df8bcace1db81a0a0881efbab.zip powder-df3b1e2a6210b45df8bcace1db81a0a0881efbab.tar.gz | |
Implement search for DirectoryList
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/Client.cpp | 26 | ||||
| -rw-r--r-- | src/interface/Textbox.cpp | 3 | ||||
| -rw-r--r-- | src/interface/Textbox.h | 1 |
3 files changed, 25 insertions, 5 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp index a9661ca..f5ea91d 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -132,8 +132,6 @@ std::vector<std::string> Client::DirectorySearch(std::string directory, std::str std::vector<std::string> Client::DirectorySearch(std::string directory, std::string search, std::vector<std::string> extensions) { - std::vector<std::string> results; - //Get full file listing std::vector<std::string> directoryList; #if defined(WIN32) && !defined(__GNUC__) @@ -173,9 +171,29 @@ std::vector<std::string> Client::DirectorySearch(std::string directory, std::str closedir(directoryHandle); #endif + std::vector<std::string> searchResults; + for(std::vector<std::string>::iterator iter = directoryList.begin(), end = directoryList.end(); iter != end; ++iter) + { + std::string filename = *iter; + bool extensionMatch = !extensions.size(); + for(std::vector<std::string>::iterator extIter = extensions.begin(), extEnd = extensions.end(); extIter != extEnd; ++extIter) + { + if(filename.find(*extIter)==filename.length()-(*extIter).length()) + { + extensionMatch = true; + break; + } + } + bool searchMatch = !search.size(); + if(search.size() && filename.find(search)!=std::string::npos) + searchMatch = true; + + if(searchMatch && extensionMatch) + searchResults.push_back(filename); + } + //Filter results - return directoryList; - return results; + return searchResults; } std::vector<unsigned char> Client::ReadFile(std::string filename) diff --git a/src/interface/Textbox.cpp b/src/interface/Textbox.cpp index 54c6e75..ad5597f 100644 --- a/src/interface/Textbox.cpp +++ b/src/interface/Textbox.cpp @@ -14,7 +14,8 @@ Textbox::Textbox(Point position, Point size, std::string textboxText, std::strin actionCallback(NULL), masked(false), border(true), - mouseDown(false) + mouseDown(false), + limit(0) { placeHolder = textboxPlaceholder; diff --git a/src/interface/Textbox.h b/src/interface/Textbox.h index 95588cb..f975bd7 100644 --- a/src/interface/Textbox.h +++ b/src/interface/Textbox.h @@ -20,6 +20,7 @@ class Textbox : public Label { friend class TextboxAction; protected: + size_t limit; bool mouseDown; bool masked, border; int cursor, cursorPositionX, cursorPositionY; |
