Add timer to autocomplete in FileSelector

This commit is contained in:
David Capello 2014-09-10 00:58:25 -03:00
parent 7af2882fb8
commit 03ac41e05d

View File

@ -104,7 +104,11 @@ static void on_exit_delete_navigation_history()
class CustomFileNameEntry : public Entry
{
public:
CustomFileNameEntry() : Entry(256, ""), m_fileList(NULL) {
CustomFileNameEntry() :
Entry(256, ""),
m_fileList(NULL),
m_timer(250, this) {
m_timer.Tick.connect(&CustomFileNameEntry::onTick, this);
}
void setAssociatedFileList(FileList* fileList) {
@ -113,12 +117,28 @@ public:
protected:
virtual bool onProcessMessage(Message* msg) override {
if (msg->type() == kKeyUpMessage &&
static_cast<KeyMessage*>(msg)->unicodeChar() >= 32) {
switch (msg->type()) {
case kKeyDownMessage:
m_timer.stop();
break;
case kKeyUpMessage:
if (static_cast<KeyMessage*>(msg)->unicodeChar() >= 32)
m_timer.start();
break;
}
return Entry::onProcessMessage(msg);
}
void onTick() {
m_timer.stop();
// String to be autocompleted
std::string left_part = getText();
if (left_part.empty())
return false;
return;
const FileItemList& children = m_fileList->getFileList();
@ -137,15 +157,14 @@ protected:
if (it2 == left_part.end()) {
setText(left_part + child_name.substr(left_part.size()));
selectText(child_name.size(), left_part.size());
return true;
return;
}
}
}
return Entry::onProcessMessage(msg);
}
private:
FileList* m_fileList;
Timer m_timer;
};
// Class to create CustomFileNameEntries.