Merge pull request #5577 from vnen/improve-quickopen-listing

Improve quick open sorting
This commit is contained in:
Rémi Verschelde 2016-07-07 07:47:10 +02:00 committed by GitHub
commit 779bf6eca3
2 changed files with 25 additions and 14 deletions

View file

@ -109,6 +109,17 @@ void EditorQuickOpen::_sbox_input(const InputEvent& p_ie) {
}
float EditorQuickOpen::_path_cmp(String search, String path) const {
if (search == path) {
return 1.2f;
}
if (path.findn(search) != -1) {
return 1.1f;
}
return path.to_lower().similarity(search.to_lower());
}
void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd, Vector< Pair< String, Ref<Texture> > > &list) {
if (!add_directories) {
@ -130,17 +141,18 @@ void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd, Vector< Pair< S
Pair< String, Ref<Texture> > pair;
pair.first = path;
pair.second = get_icon("folder", "FileDialog");
if (list.size() > 0) {
float this_sim = search_text.to_lower().similarity(path.to_lower());
float other_sim = search_text.to_lower().similarity(list[0].first.to_lower());
if (search_text != String() && list.size() > 0) {
float this_sim = _path_cmp(search_text, path);
float other_sim = _path_cmp(list[0].first, path);
int pos = 1;
while (pos < list.size() && this_sim < other_sim) {
other_sim = search_text.to_lower().similarity(list[pos++].first.to_lower());
while (pos < list.size() && this_sim <= other_sim) {
other_sim = _path_cmp(list[pos++].first, path);
}
pos = this_sim > other_sim ? pos - 1 : pos;
pos = this_sim >= other_sim ? pos - 1 : pos;
list.insert(pos, pair);
} else {
@ -159,17 +171,17 @@ void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd, Vector< Pair< S
pair.first = file;
pair.second = get_icon((has_icon(efsd->get_file_type(i), ei) ? efsd->get_file_type(i) : ot), ei);
if (list.size() > 0) {
if (search_text != String() && list.size() > 0) {
float this_sim = search_text.to_lower().similarity(file.to_lower());
float other_sim = search_text.to_lower().similarity(list[0].first.to_lower());
float this_sim = _path_cmp(search_text, file);
float other_sim = _path_cmp(list[0].first, file);
int pos = 1;
while (pos < list.size() && this_sim < other_sim) {
other_sim = search_text.to_lower().similarity(list[pos++].first.to_lower());
while (pos < list.size() && this_sim <= other_sim) {
other_sim = _path_cmp(list[pos++].first, file);
}
pos = this_sim > other_sim ? pos - 1 : pos;
pos = this_sim >= other_sim ? pos - 1 : pos;
list.insert(pos, pair);
} else {
@ -198,8 +210,6 @@ void EditorQuickOpen::_update_search() {
_parse_fs(efsd, list);
//String best_match = list[0];
for (int i = 0; i < list.size(); i++) {
TreeItem *ti = search_options->create_item(root);
ti->set_text(0, list[i].first);

View file

@ -49,6 +49,7 @@ class EditorQuickOpen : public ConfirmationDialog {
void _sbox_input(const InputEvent& p_ie);
void _parse_fs(EditorFileSystemDirectory *efsd, Vector< Pair< String,Ref <Texture> > > &list);
float _path_cmp(String search, String path) const;
void _confirmed();