diff options
Diffstat (limited to 'editor/editor_help.cpp')
-rw-r--r-- | editor/editor_help.cpp | 230 |
1 files changed, 117 insertions, 113 deletions
diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 198a52fef2..f3be02a8c7 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -81,162 +81,147 @@ void EditorHelpSearch::_sbox_input(const Ref<InputEvent> &p_ie) { } } -class EditorHelpSearch::IncrementalSearch : public Reference { - String term; - TreeItem *root; +void EditorHelpSearch::IncrementalSearch::phase1(Map<String, DocData::ClassDoc>::Element *E) { - EditorHelpSearch *search; - Tree *search_options; + if (E->key().findn(term) != -1) { - DocData *doc; - Ref<Texture> def_icon; - - int phase; - Map<String, DocData::ClassDoc>::Element *iterator; - - 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 (search->has_icon(E->key(), "EditorIcons")) - item->set_icon(0, search->get_icon(E->key(), "EditorIcons")); - else - item->set_icon(0, def_icon); - } + TreeItem *item = search_options->create_item(root); + item->set_metadata(0, "class_name:" + E->key()); + item->set_text(0, E->key() + " (Class)"); + if (search->has_icon(E->key(), "EditorIcons")) + item->set_icon(0, search->get_icon(E->key(), "EditorIcons")); + else + item->set_icon(0, def_icon); } +} - void phase2(Map<String, DocData::ClassDoc>::Element *E) { +void EditorHelpSearch::IncrementalSearch::phase2(Map<String, DocData::ClassDoc>::Element *E) { - DocData::ClassDoc &c = E->get(); + DocData::ClassDoc &c = E->get(); - Ref<Texture> cicon; - if (search->has_icon(E->key(), "EditorIcons")) - cicon = search->get_icon(E->key(), "EditorIcons"); - else - cicon = def_icon; + Ref<Texture> cicon; + if (search->has_icon(E->key(), "EditorIcons")) + cicon = search->get_icon(E->key(), "EditorIcons"); + else + cicon = def_icon; - for (int i = 0; i < c.methods.size(); i++) { - if ((term.begins_with(".") && c.methods[i].name.begins_with(term.right(1))) || (term.ends_with("(") && c.methods[i].name.ends_with(term.left(term.length() - 1).strip_edges())) || (term.begins_with(".") && term.ends_with("(") && c.methods[i].name == term.substr(1, term.length() - 2).strip_edges()) || c.methods[i].name.findn(term) != -1) { + for (int i = 0; i < c.methods.size(); i++) { + if ((term.begins_with(".") && c.methods[i].name.begins_with(term.right(1))) || (term.ends_with("(") && c.methods[i].name.ends_with(term.left(term.length() - 1).strip_edges())) || (term.begins_with(".") && term.ends_with("(") && c.methods[i].name == term.substr(1, term.length() - 2).strip_edges()) || c.methods[i].name.findn(term) != -1) { - TreeItem *item = search_options->create_item(root); - item->set_metadata(0, "class_method:" + E->key() + ":" + c.methods[i].name); - item->set_text(0, E->key() + "." + c.methods[i].name + " (Method)"); - item->set_icon(0, cicon); - } + TreeItem *item = search_options->create_item(root); + item->set_metadata(0, "class_method:" + E->key() + ":" + c.methods[i].name); + item->set_text(0, E->key() + "." + c.methods[i].name + " (Method)"); + item->set_icon(0, cicon); } + } - for (int i = 0; i < c.signals.size(); i++) { + for (int i = 0; i < c.signals.size(); i++) { - if (c.signals[i].name.findn(term) != -1) { + if (c.signals[i].name.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)"); - item->set_icon(0, cicon); - } + 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)"); + item->set_icon(0, cicon); } + } - for (int i = 0; i < c.constants.size(); i++) { + for (int i = 0; i < c.constants.size(); i++) { - if (c.constants[i].name.findn(term) != -1) { + if (c.constants[i].name.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)"); - item->set_icon(0, cicon); - } + 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)"); + item->set_icon(0, cicon); } + } - for (int i = 0; i < c.properties.size(); i++) { + for (int i = 0; i < c.properties.size(); i++) { - if (c.properties[i].name.findn(term) != -1) { + if (c.properties[i].name.findn(term) != -1) { - TreeItem *item = search_options->create_item(root); - item->set_metadata(0, "class_property:" + E->key() + ":" + c.properties[i].name); - item->set_text(0, E->key() + "." + c.properties[i].name + " (Property)"); - item->set_icon(0, cicon); - } + TreeItem *item = search_options->create_item(root); + item->set_metadata(0, "class_property:" + E->key() + ":" + c.properties[i].name); + item->set_text(0, E->key() + "." + c.properties[i].name + " (Property)"); + item->set_icon(0, cicon); } + } - for (int i = 0; i < c.theme_properties.size(); i++) { + for (int i = 0; i < c.theme_properties.size(); i++) { - if (c.theme_properties[i].name.findn(term) != -1) { + if (c.theme_properties[i].name.findn(term) != -1) { - TreeItem *item = search_options->create_item(root); - item->set_metadata(0, "class_theme_item:" + E->key() + ":" + c.theme_properties[i].name); - item->set_text(0, E->key() + "." + c.theme_properties[i].name + " (Theme Item)"); - item->set_icon(0, cicon); - } + TreeItem *item = search_options->create_item(root); + item->set_metadata(0, "class_theme_item:" + E->key() + ":" + c.theme_properties[i].name); + item->set_text(0, E->key() + "." + c.theme_properties[i].name + " (Theme Item)"); + item->set_icon(0, cicon); } } +} - bool slice() { +bool EditorHelpSearch::IncrementalSearch::slice() { - if (phase > 2) - return true; + if (phase > 2) + return true; - if (iterator) { + if (iterator) { - switch (phase) { + switch (phase) { - case 1: { - phase1(iterator); - } break; - case 2: { - phase2(iterator); - } break; - default: { - WARN_PRINT("illegal phase in IncrementalSearch"); - return true; - } + case 1: { + phase1(iterator); + } break; + case 2: { + phase2(iterator); + } break; + default: { + WARN_PRINT("illegal phase in IncrementalSearch"); + return true; } - - iterator = iterator->next(); - } else { - - phase += 1; - iterator = doc->class_list.front(); } - return false; + iterator = iterator->next(); + } else { + + phase += 1; + iterator = doc->class_list.front(); } -public: - IncrementalSearch(EditorHelpSearch *p_search, Tree *p_search_options, const String &p_term) : - search(p_search), - search_options(p_search_options) { + return false; +} - def_icon = search->get_icon("Node", "EditorIcons"); - doc = EditorHelp::get_doc_data(); +EditorHelpSearch::IncrementalSearch::IncrementalSearch(EditorHelpSearch *p_search, Tree *p_search_options, const String &p_term) : + search(p_search), + search_options(p_search_options) { - term = p_term; + def_icon = search->get_icon("Node", "EditorIcons"); + doc = EditorHelp::get_doc_data(); - root = search_options->create_item(); - phase = 0; - iterator = 0; - } + term = p_term; - bool empty() const { + root = search_options->create_item(); + phase = 0; + iterator = 0; +} - return root->get_children() == NULL; - } +bool EditorHelpSearch::IncrementalSearch::empty() const { - bool work(uint64_t slot = 1000000 / 10) { + return root->get_children() == NULL; +} - const uint64_t until = OS::get_singleton()->get_ticks_usec() + slot; +bool EditorHelpSearch::IncrementalSearch::work(uint64_t slot) { - while (!slice()) { + const uint64_t until = OS::get_singleton()->get_ticks_usec() + slot; - if (OS::get_singleton()->get_ticks_usec() > until) - return false; - } + while (!slice()) { - return true; + if (OS::get_singleton()->get_ticks_usec() > until) + return false; } -}; + + return true; +} void EditorHelpSearch::_update_search() { search_options->clear(); @@ -1187,7 +1172,12 @@ Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) { class_desc->push_indent(1); Vector<DocData::ConstantDoc> enum_list = E->get(); + Map<String, int> enumValuesContainer; + int enumStartingLine = enum_line[E->key()]; + for (int i = 0; i < enum_list.size(); i++) { + if (cd.name == "@GlobalScope") + enumValuesContainer[enum_list[i].name] = enumStartingLine; class_desc->push_font(doc_code_font); class_desc->push_color(headline_color); @@ -1215,6 +1205,9 @@ Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) { class_desc->add_newline(); } + if (cd.name == "@GlobalScope") + enum_values_line[E->key()] = enumValuesContainer; + class_desc->pop(); class_desc->add_newline(); @@ -1500,21 +1493,32 @@ void EditorHelp::_help_callback(const String &p_topic) { if (method_line.has(name)) line = method_line[name]; } else if (what == "class_property") { - if (property_line.has(name)) line = property_line[name]; } else if (what == "class_enum") { - if (enum_line.has(name)) line = enum_line[name]; } else if (what == "class_theme_item") { - if (theme_property_line.has(name)) line = theme_property_line[name]; } else if (what == "class_constant") { - if (constant_line.has(name)) line = constant_line[name]; + } else if (what == "class_global") { + if (constant_line.has(name)) + line = constant_line[name]; + else { + Map<String, Map<String, int> >::Element *iter = enum_values_line.front(); + while (true) { + if (iter->value().has(name)) { + line = iter->value()[name]; + break; + } else if (iter == enum_values_line.back()) + break; + else + iter = iter->next(); + } + } } class_desc->call_deferred("scroll_to_line", line); |