Merge pull request #14002 from poke1024/fixhelpspeed

Make "Search Help" more responsive
This commit is contained in:
Rémi Verschelde 2017-12-07 00:23:23 +01:00 committed by GitHub
commit c0fd111e71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 97 additions and 82 deletions

View file

@ -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(); EditorHelpSearch *search;
search_options->set_hide_root(true); Tree *search_options;
/* DocData *doc;
TreeItem *root = search_options->create_item(); Ref<Texture> def_icon;
_parse_fs(EditorFileSystem::get_singleton()->get_filesystem());
*/
List<StringName> type_list; int phase;
ClassDB::get_class_list(&type_list); Map<String, DocData::ClassDoc>::Element *iterator;
DocData *doc = EditorHelp::get_doc_data(); void phase1(Map<String, DocData::ClassDoc>::Element *E) {
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()) {
if (E->key().findn(term) != -1) { if (E->key().findn(term) != -1) {
TreeItem *item = search_options->create_item(root); TreeItem *item = search_options->create_item(root);
item->set_metadata(0, "class_name:" + E->key()); item->set_metadata(0, "class_name:" + E->key());
item->set_text(0, E->key() + " (Class)"); item->set_text(0, E->key() + " (Class)");
if (has_icon(E->key(), "EditorIcons")) if (search->has_icon(E->key(), "EditorIcons"))
item->set_icon(0, get_icon(E->key(), "EditorIcons")); item->set_icon(0, search->get_icon(E->key(), "EditorIcons"));
else else
item->set_icon(0, def_icon); item->set_icon(0, def_icon);
} }
} }
//class methods, etc second void phase2(Map<String, DocData::ClassDoc>::Element *E) {
for (Map<String, DocData::ClassDoc>::Element *E = doc->class_list.front(); E; E = E->next()) {
DocData::ClassDoc &c = E->get(); DocData::ClassDoc &c = E->get();
Ref<Texture> cicon; Ref<Texture> cicon;
if (has_icon(E->key(), "EditorIcons")) if (search->has_icon(E->key(), "EditorIcons"))
cicon = get_icon(E->key(), "EditorIcons"); cicon = search->get_icon(E->key(), "EditorIcons");
else else
cicon = def_icon; 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; switch (phase) {
if (has_icon(E->key(), "EditorIcons"))
cicon = get_icon(E->key(), "EditorIcons");
else
cicon = def_icon;
if (c.description.findn(term) != -1) { case 1: {
phase1(iterator);
TreeItem *item = search_options->create_item(root); } break;
item->set_metadata(0, "class_desc:" + E->key()); case 2: {
item->set_text(0, E->key() + " (Class Description)"); phase2(iterator);
item->set_icon(0, cicon); } break;
} default: {
WARN_PRINT("illegal phase in IncrementalSearch");
for (int i = 0; i < c.methods.size(); i++) { return true;
}
if (c.methods[i].description.findn(term) != -1) {
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);
} }
iterator = iterator->next();
} else {
phase += 1;
iterator = doc->class_list.front();
} }
for (int i = 0; i < c.signals.size(); i++) { return false;
if (c.signals[i].description.findn(term) != -1) {
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);
}
}
for (int i = 0; i < c.constants.size(); i++) {
if (c.constants[i].description.findn(term) != -1) {
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);
}
}
for (int i = 0; i < c.properties.size(); i++) {
if (c.properties[i].description.findn(term) != -1) {
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);
}
}
} }
get_ok()->set_disabled(root->get_children() == NULL); public:
IncrementalSearch(EditorHelpSearch *p_search, Tree *p_search_options, const String &p_term)
: search(p_search), search_options(p_search_options) {
def_icon = search->get_icon("Node", "EditorIcons");
doc = EditorHelp::get_doc_data();
term = p_term;
root = search_options->create_item();
phase = 0;
iterator = 0;
}
bool empty() const {
return root->get_children() == NULL;
}
bool work(uint64_t slot = 1000000 / 10) {
const uint64_t until = OS::get_singleton()->get_ticks_usec() + slot;
while (!slice()) {
if (OS::get_singleton()->get_ticks_usec() > until)
return false;
}
return true;
}
};
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() { void EditorHelpSearch::_confirmed() {
@ -281,6 +279,20 @@ void EditorHelpSearch::_notification(int p_what) {
//_update_icons //_update_icons
search_box->add_icon_override("right_icon", get_icon("Search", "EditorIcons")); 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);
}
} }
} }

View file

@ -53,6 +53,9 @@ class EditorHelpSearch : public ConfirmationDialog {
Tree *search_options; Tree *search_options;
String base_type; String base_type;
class IncrementalSearch;
Ref<IncrementalSearch> search;
void _update_search(); void _update_search();
void _sbox_input(const Ref<InputEvent> &p_ie); void _sbox_input(const Ref<InputEvent> &p_ie);