From df3b1e2a6210b45df8bcace1db81a0a0881efbab Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sat, 28 Jul 2012 22:14:38 +0100 Subject: [PATCH] Implement search for DirectoryList --- src/client/Client.cpp | 26 ++++++++++++++++++++++---- src/interface/Textbox.cpp | 3 ++- 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 a9661ca7e..f5ea91d70 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -132,8 +132,6 @@ std::vector Client::DirectorySearch(std::string directory, std::str std::vector Client::DirectorySearch(std::string directory, std::string search, std::vector extensions) { - std::vector results; - //Get full file listing std::vector directoryList; #if defined(WIN32) && !defined(__GNUC__) @@ -173,9 +171,29 @@ std::vector Client::DirectorySearch(std::string directory, std::str closedir(directoryHandle); #endif + std::vector searchResults; + for(std::vector::iterator iter = directoryList.begin(), end = directoryList.end(); iter != end; ++iter) + { + std::string filename = *iter; + bool extensionMatch = !extensions.size(); + for(std::vector::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 Client::ReadFile(std::string filename) diff --git a/src/interface/Textbox.cpp b/src/interface/Textbox.cpp index 54c6e7551..ad5597fe2 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 95588cb38..f975bd7f2 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;