diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-12-07 00:23:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-07 00:23:23 +0100 |
commit | c0fd111e71bf12df346793a71229cb6d983c09bd (patch) | |
tree | 9aab45e5771b13b92dc5d7e292668dd9a20f7689 | |
parent | a88543c88173a5cbdd2566d9d09acc13e38a7922 (diff) | |
parent | ef49edc3873f050a8fdea18f683f216742661e74 (diff) |
Merge pull request #14002 from poke1024/fixhelpspeed
Make "Search Help" more responsive
-rw-r--r-- | editor/editor_help.cpp | 154 | ||||
-rw-r--r-- | editor/editor_help.h | 3 |
2 files changed, 86 insertions, 71 deletions
diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 5fc27c2e3c..8f427582ae 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -78,50 +78,40 @@ void EditorHelpSearch::_sbox_input(const Ref<InputEvent> &p_ie) { } } -void EditorHelpSearch::_update_search() { +class EditorHelpSearch::IncrementalSearch : public Reference { + String term; + TreeItem *root; - search_options->clear(); - search_options->set_hide_root(true); + EditorHelpSearch *search; + Tree *search_options; - /* - TreeItem *root = search_options->create_item(); - _parse_fs(EditorFileSystem::get_singleton()->get_filesystem()); -*/ + DocData *doc; + Ref<Texture> def_icon; - List<StringName> type_list; - ClassDB::get_class_list(&type_list); + int phase; + Map<String, DocData::ClassDoc>::Element *iterator; - DocData *doc = EditorHelp::get_doc_data(); - String term = search_box->get_text(); - if (term.length() < 2) - return; - - TreeItem *root = search_options->create_item(); - - Ref<Texture> def_icon = get_icon("Node", "EditorIcons"); - //classes first - for (Map<String, DocData::ClassDoc>::Element *E = doc->class_list.front(); E; E = E->next()) { + void phase1(Map<String, DocData::ClassDoc>::Element *E) { if (E->key().findn(term) != -1) { TreeItem *item = search_options->create_item(root); item->set_metadata(0, "class_name:" + E->key()); item->set_text(0, E->key() + " (Class)"); - if (has_icon(E->key(), "EditorIcons")) - item->set_icon(0, get_icon(E->key(), "EditorIcons")); + if (search->has_icon(E->key(), "EditorIcons")) + item->set_icon(0, search->get_icon(E->key(), "EditorIcons")); else item->set_icon(0, def_icon); } } - //class methods, etc second - for (Map<String, DocData::ClassDoc>::Element *E = doc->class_list.front(); E; E = E->next()) { + void phase2(Map<String, DocData::ClassDoc>::Element *E) { DocData::ClassDoc &c = E->get(); Ref<Texture> cicon; - if (has_icon(E->key(), "EditorIcons")) - cicon = get_icon(E->key(), "EditorIcons"); + if (search->has_icon(E->key(), "EditorIcons")) + cicon = search->get_icon(E->key(), "EditorIcons"); else cicon = def_icon; @@ -180,72 +170,80 @@ void EditorHelpSearch::_update_search() { } } - //same but descriptions + bool slice() { - for (Map<String, DocData::ClassDoc>::Element *E = doc->class_list.front(); E; E = E->next()) { + if (phase > 2) + return true; - DocData::ClassDoc &c = E->get(); + if (iterator) { - Ref<Texture> cicon; - if (has_icon(E->key(), "EditorIcons")) - cicon = get_icon(E->key(), "EditorIcons"); - else - cicon = def_icon; + switch (phase) { + + case 1: { + phase1(iterator); + } break; + case 2: { + phase2(iterator); + } break; + default: { + WARN_PRINT("illegal phase in IncrementalSearch"); + return true; + } + } - if (c.description.findn(term) != -1) { + iterator = iterator->next(); + } else { - TreeItem *item = search_options->create_item(root); - item->set_metadata(0, "class_desc:" + E->key()); - item->set_text(0, E->key() + " (Class Description)"); - item->set_icon(0, cicon); + phase += 1; + iterator = doc->class_list.front(); } - for (int i = 0; i < c.methods.size(); i++) { + return false; + } - if (c.methods[i].description.findn(term) != -1) { +public: + IncrementalSearch(EditorHelpSearch *p_search, Tree *p_search_options, const String &p_term) + : search(p_search), search_options(p_search_options) { - TreeItem *item = search_options->create_item(root); - item->set_metadata(0, "class_method_desc:" + E->key() + ":" + c.methods[i].name); - item->set_text(0, E->key() + "." + c.methods[i].name + " (Method Description)"); - item->set_icon(0, cicon); - } - } - - for (int i = 0; i < c.signals.size(); i++) { + def_icon = search->get_icon("Node", "EditorIcons"); + doc = EditorHelp::get_doc_data(); - if (c.signals[i].description.findn(term) != -1) { + term = p_term; - TreeItem *item = search_options->create_item(root); - item->set_metadata(0, "class_signal:" + E->key() + ":" + c.signals[i].name); - item->set_text(0, E->key() + "." + c.signals[i].name + " (Signal Description)"); - item->set_icon(0, cicon); - } - } + root = search_options->create_item(); + phase = 0; + iterator = 0; + } - for (int i = 0; i < c.constants.size(); i++) { + bool empty() const { - if (c.constants[i].description.findn(term) != -1) { + return root->get_children() == NULL; + } - TreeItem *item = search_options->create_item(root); - item->set_metadata(0, "class_constant:" + E->key() + ":" + c.constants[i].name); - item->set_text(0, E->key() + "." + c.constants[i].name + " (Constant Description)"); - item->set_icon(0, cicon); - } - } + bool work(uint64_t slot = 1000000 / 10) { - for (int i = 0; i < c.properties.size(); i++) { + const uint64_t until = OS::get_singleton()->get_ticks_usec() + slot; - if (c.properties[i].description.findn(term) != -1) { + while (!slice()) { - TreeItem *item = search_options->create_item(root); - item->set_metadata(0, "class_property_desc:" + E->key() + ":" + c.properties[i].name); - item->set_text(0, E->key() + "." + c.properties[i].name + " (Property Description)"); - item->set_icon(0, cicon); - } + if (OS::get_singleton()->get_ticks_usec() > until) + return false; } + + return true; } +}; - get_ok()->set_disabled(root->get_children() == NULL); +void EditorHelpSearch::_update_search() { + search_options->clear(); + search_options->set_hide_root(true); + + String term = search_box->get_text(); + if (term.length() < 2) + return; + + search = Ref<IncrementalSearch>(memnew(IncrementalSearch(this, search_options, term))); + set_process(true); } void EditorHelpSearch::_confirmed() { @@ -281,6 +279,20 @@ void EditorHelpSearch::_notification(int p_what) { //_update_icons search_box->add_icon_override("right_icon", get_icon("Search", "EditorIcons")); + } else if (p_what == NOTIFICATION_PROCESS) { + + if (search.is_valid()) { + + if (search->work()) { + + get_ok()->set_disabled(search->empty()); + search = Ref<IncrementalSearch>(); + set_process(false); + } + } else { + + set_process(false); + } } } diff --git a/editor/editor_help.h b/editor/editor_help.h index 92c0e2f4d1..a224c7f8ee 100644 --- a/editor/editor_help.h +++ b/editor/editor_help.h @@ -53,6 +53,9 @@ class EditorHelpSearch : public ConfirmationDialog { Tree *search_options; String base_type; + class IncrementalSearch; + Ref<IncrementalSearch> search; + void _update_search(); void _sbox_input(const Ref<InputEvent> &p_ie); |