Implement search for DirectoryList

This commit is contained in:
Simon Robertshaw 2012-07-28 22:14:38 +01:00
parent c14a008d46
commit df3b1e2a62
3 changed files with 25 additions and 5 deletions

View File

@ -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)

View File

@ -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;

View File

@ -20,6 +20,7 @@ class Textbox : public Label
{
friend class TextboxAction;
protected:
size_t limit;
bool mouseDown;
bool masked, border;
int cursor, cursorPositionX, cursorPositionY;