mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-27 06:35:16 +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
|
class CustomFileNameEntry : public Entry
|
||||||
{
|
{
|
||||||
public:
|
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) {
|
void setAssociatedFileList(FileList* fileList) {
|
||||||
@ -113,39 +117,54 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool onProcessMessage(Message* msg) override {
|
virtual bool onProcessMessage(Message* msg) override {
|
||||||
if (msg->type() == kKeyUpMessage &&
|
switch (msg->type()) {
|
||||||
static_cast<KeyMessage*>(msg)->unicodeChar() >= 32) {
|
|
||||||
// String to be autocompleted
|
|
||||||
std::string left_part = getText();
|
|
||||||
if (left_part.empty())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const FileItemList& children = m_fileList->getFileList();
|
case kKeyDownMessage:
|
||||||
|
m_timer.stop();
|
||||||
|
break;
|
||||||
|
|
||||||
for (IFileItem* child : children) {
|
case kKeyUpMessage:
|
||||||
std::string child_name = child->getDisplayName();
|
if (static_cast<KeyMessage*>(msg)->unicodeChar() >= 32)
|
||||||
std::string::iterator it1, it2;
|
m_timer.start();
|
||||||
|
break;
|
||||||
|
|
||||||
for (it1 = child_name.begin(), it2 = left_part.begin();
|
|
||||||
it1 != child_name.end() && it2 != left_part.end();
|
|
||||||
++it1, ++it2) {
|
|
||||||
if (std::tolower(*it1) != std::tolower(*it2))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Is the pattern (left_part) in the child_name's beginning?
|
|
||||||
if (it2 == left_part.end()) {
|
|
||||||
setText(left_part + child_name.substr(left_part.size()));
|
|
||||||
selectText(child_name.size(), left_part.size());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return Entry::onProcessMessage(msg);
|
return Entry::onProcessMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onTick() {
|
||||||
|
m_timer.stop();
|
||||||
|
|
||||||
|
// String to be autocompleted
|
||||||
|
std::string left_part = getText();
|
||||||
|
if (left_part.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
const FileItemList& children = m_fileList->getFileList();
|
||||||
|
|
||||||
|
for (IFileItem* child : children) {
|
||||||
|
std::string child_name = child->getDisplayName();
|
||||||
|
std::string::iterator it1, it2;
|
||||||
|
|
||||||
|
for (it1 = child_name.begin(), it2 = left_part.begin();
|
||||||
|
it1 != child_name.end() && it2 != left_part.end();
|
||||||
|
++it1, ++it2) {
|
||||||
|
if (std::tolower(*it1) != std::tolower(*it2))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Is the pattern (left_part) in the child_name's beginning?
|
||||||
|
if (it2 == left_part.end()) {
|
||||||
|
setText(left_part + child_name.substr(left_part.size()));
|
||||||
|
selectText(child_name.size(), left_part.size());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FileList* m_fileList;
|
FileList* m_fileList;
|
||||||
|
Timer m_timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Class to create CustomFileNameEntries.
|
// Class to create CustomFileNameEntries.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user