diff options
Diffstat (limited to 'editor/quick_open.cpp')
-rw-r--r-- | editor/quick_open.cpp | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/editor/quick_open.cpp b/editor/quick_open.cpp index 95277e72d7..b872bc3dd4 100644 --- a/editor/quick_open.cpp +++ b/editor/quick_open.cpp @@ -113,12 +113,18 @@ void EditorQuickOpen::_sbox_input(const Ref<InputEvent> &p_ie) { float EditorQuickOpen::_path_cmp(String search, String path) const { + // Exact match. if (search == path) { return 1.2f; } - if (path.findn(search) != -1) { - return 1.1f; + + // Substring match, with positive bias for matches close to the end of the path. + int pos = path.rfindn(search); + if (pos != -1) { + return 1.1f + 0.09 / (path.length() - pos + 1); } + + // Similarity. return path.to_lower().similarity(search.to_lower()); } @@ -142,7 +148,7 @@ void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd, Vector<Pair<Str if (search_text.is_subsequence_ofi(path)) { Pair<String, Ref<Texture2D>> pair; pair.first = path; - pair.second = get_icon("folder", "FileDialog"); + pair.second = search_options->get_theme_icon("folder", "FileDialog"); if (search_text != String() && list.size() > 0) { @@ -171,7 +177,7 @@ void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd, Vector<Pair<Str if (ClassDB::is_parent_class(efsd->get_file_type(i), base_type) && (search_text.is_subsequence_ofi(file))) { Pair<String, Ref<Texture2D>> pair; pair.first = file; - pair.second = get_icon((has_icon(efsd->get_file_type(i), ei) ? efsd->get_file_type(i) : ot), ei); + pair.second = search_options->get_theme_icon((search_options->has_theme_icon(efsd->get_file_type(i), ei) ? efsd->get_file_type(i) : ot), ei); list.push_back(pair); } } @@ -241,7 +247,7 @@ void EditorQuickOpen::_update_search() { ti->set_as_cursor(0); } - get_ok()->set_disabled(root->get_children() == NULL); + get_ok()->set_disabled(root->get_children() == nullptr); } void EditorQuickOpen::_confirmed() { @@ -253,6 +259,11 @@ void EditorQuickOpen::_confirmed() { hide(); } +void EditorQuickOpen::_theme_changed() { + + search_box->set_right_icon(search_options->get_theme_icon("Search", "EditorIcons")); +} + void EditorQuickOpen::_notification(int p_what) { switch (p_what) { @@ -260,10 +271,6 @@ void EditorQuickOpen::_notification(int p_what) { connect("confirmed", callable_mp(this, &EditorQuickOpen::_confirmed)); search_box->set_clear_button_enabled(true); - [[fallthrough]]; - } - case NOTIFICATION_THEME_CHANGED: { - search_box->set_right_icon(get_icon("Search", "EditorIcons")); } break; case NOTIFICATION_EXIT_TREE: { disconnect("confirmed", callable_mp(this, &EditorQuickOpen::_confirmed)); @@ -284,6 +291,8 @@ void EditorQuickOpen::_bind_methods() { EditorQuickOpen::EditorQuickOpen() { VBoxContainer *vbc = memnew(VBoxContainer); + vbc->connect("theme_changed", callable_mp(this, &EditorQuickOpen::_theme_changed)); + add_child(vbc); search_box = memnew(LineEdit); vbc->add_margin_child(TTR("Search:"), search_box); @@ -298,7 +307,7 @@ EditorQuickOpen::EditorQuickOpen() { search_options->connect("item_activated", callable_mp(this, &EditorQuickOpen::_confirmed)); search_options->set_hide_root(true); search_options->set_hide_folding(true); - search_options->add_constant_override("draw_guides", 1); + search_options->add_theme_constant_override("draw_guides", 1); ei = "EditorIcons"; ot = "Object"; add_directories = false; |