mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-05 00:39:50 +00:00
Add timer to autocomplete in FileSelector
This commit is contained in:
parent
7af2882fb8
commit
03ac41e05d
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user