2017-12-10 23:56:49 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* editor_help_search.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
#include "editor_help_search.h"
|
|
|
|
|
|
|
|
#include "core/os/keyboard.h"
|
2022-02-12 01:46:22 +00:00
|
|
|
#include "editor/editor_feature_profile.h"
|
2024-08-19 22:08:31 +00:00
|
|
|
#include "editor/editor_main_screen.h"
|
2022-02-12 01:46:22 +00:00
|
|
|
#include "editor/editor_node.h"
|
2022-07-31 18:14:15 +00:00
|
|
|
#include "editor/editor_settings.h"
|
2023-08-13 00:33:39 +00:00
|
|
|
#include "editor/editor_string_names.h"
|
2024-01-15 12:14:55 +00:00
|
|
|
#include "editor/themes/editor_scale.h"
|
2022-11-22 23:14:08 +00:00
|
|
|
#include "editor/themes/editor_theme_manager.h"
|
2017-12-10 23:56:49 +00:00
|
|
|
|
2023-10-22 11:29:56 +00:00
|
|
|
bool EditorHelpSearch::_all_terms_in_name(const Vector<String> &p_terms, const String &p_name) const {
|
|
|
|
for (int i = 0; i < p_terms.size(); i++) {
|
2024-05-06 08:26:10 +00:00
|
|
|
if (!p_name.containsn(p_terms[i])) {
|
2023-10-22 11:29:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorHelpSearch::_match_method_name_and_push_back(const String &p_term, const Vector<String> &p_terms, Vector<DocData::MethodDoc> &p_methods, const String &p_type, const String &p_metatype, const String &p_class_name, Dictionary &r_result) const {
|
|
|
|
// Constructors, Methods, Operators...
|
|
|
|
for (int i = 0; i < p_methods.size(); i++) {
|
|
|
|
String method_name = p_methods[i].name.to_lower();
|
|
|
|
if (_all_terms_in_name(p_terms, method_name) ||
|
|
|
|
(p_term.begins_with(".") && method_name.begins_with(p_term.substr(1))) ||
|
|
|
|
(p_term.ends_with("(") && method_name.ends_with(p_term.left(p_term.length() - 1).strip_edges())) ||
|
|
|
|
(p_term.begins_with(".") && p_term.ends_with("(") && method_name == p_term.substr(1, p_term.length() - 2).strip_edges())) {
|
|
|
|
r_result[vformat("class_%s:%s:%s", p_metatype, p_class_name, p_methods[i].name)] = vformat("%s > %s: %s", p_class_name, p_type, p_methods[i].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorHelpSearch::_match_const_name_and_push_back(const String &p_term, const Vector<String> &p_terms, Vector<DocData::ConstantDoc> &p_constants, const String &p_type, const String &p_metatype, const String &p_class_name, Dictionary &r_result) const {
|
|
|
|
for (int i = 0; i < p_constants.size(); i++) {
|
|
|
|
String method_name = p_constants[i].name.to_lower();
|
|
|
|
if (_all_terms_in_name(p_terms, method_name) ||
|
|
|
|
(p_term.begins_with(".") && method_name.begins_with(p_term.substr(1))) ||
|
|
|
|
(p_term.ends_with("(") && method_name.ends_with(p_term.left(p_term.length() - 1).strip_edges())) ||
|
|
|
|
(p_term.begins_with(".") && p_term.ends_with("(") && method_name == p_term.substr(1, p_term.length() - 2).strip_edges())) {
|
|
|
|
r_result[vformat("class_%s:%s:%s", p_metatype, p_class_name, p_constants[i].name)] = vformat("%s > %s: %s", p_class_name, p_type, p_constants[i].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorHelpSearch::_match_property_name_and_push_back(const String &p_term, const Vector<String> &p_terms, Vector<DocData::PropertyDoc> &p_properties, const String &p_type, const String &p_metatype, const String &p_class_name, Dictionary &r_result) const {
|
|
|
|
for (int i = 0; i < p_properties.size(); i++) {
|
|
|
|
String method_name = p_properties[i].name.to_lower();
|
|
|
|
if (_all_terms_in_name(p_terms, method_name) ||
|
|
|
|
(p_term.begins_with(".") && method_name.begins_with(p_term.substr(1))) ||
|
|
|
|
(p_term.ends_with("(") && method_name.ends_with(p_term.left(p_term.length() - 1).strip_edges())) ||
|
|
|
|
(p_term.begins_with(".") && p_term.ends_with("(") && method_name == p_term.substr(1, p_term.length() - 2).strip_edges())) {
|
|
|
|
r_result[vformat("class_%s:%s:%s", p_metatype, p_class_name, p_properties[i].name)] = vformat("%s > %s: %s", p_class_name, p_type, p_properties[i].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorHelpSearch::_match_theme_property_name_and_push_back(const String &p_term, const Vector<String> &p_terms, Vector<DocData::ThemeItemDoc> &p_properties, const String &p_type, const String &p_metatype, const String &p_class_name, Dictionary &r_result) const {
|
|
|
|
for (int i = 0; i < p_properties.size(); i++) {
|
|
|
|
String method_name = p_properties[i].name.to_lower();
|
|
|
|
if (_all_terms_in_name(p_terms, method_name) ||
|
|
|
|
(p_term.begins_with(".") && method_name.begins_with(p_term.substr(1))) ||
|
|
|
|
(p_term.ends_with("(") && method_name.ends_with(p_term.left(p_term.length() - 1).strip_edges())) ||
|
|
|
|
(p_term.begins_with(".") && p_term.ends_with("(") && method_name == p_term.substr(1, p_term.length() - 2).strip_edges())) {
|
|
|
|
r_result[vformat("class_%s:%s:%s", p_metatype, p_class_name, p_properties[i].name)] = vformat("%s > %s: %s", p_class_name, p_type, p_properties[i].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Dictionary EditorHelpSearch::_native_search_cb(const String &p_search_string, int p_result_limit) {
|
|
|
|
Dictionary ret;
|
|
|
|
const String &term = p_search_string.strip_edges().to_lower();
|
|
|
|
Vector<String> terms = term.split_spaces();
|
|
|
|
if (terms.is_empty()) {
|
|
|
|
terms.append(term);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (HashMap<String, DocData::ClassDoc>::Iterator iterator_doc = EditorHelp::get_doc_data()->class_list.begin(); iterator_doc; ++iterator_doc) {
|
|
|
|
DocData::ClassDoc &class_doc = iterator_doc->value;
|
|
|
|
if (class_doc.name.is_empty()) {
|
|
|
|
continue;
|
|
|
|
}
|
2024-05-06 08:26:10 +00:00
|
|
|
if (class_doc.name.containsn(term)) {
|
2023-10-22 11:29:56 +00:00
|
|
|
ret[vformat("class_name:%s", class_doc.name)] = class_doc.name;
|
|
|
|
}
|
|
|
|
if (term.length() > 1 || term == "@") {
|
|
|
|
_match_method_name_and_push_back(term, terms, class_doc.constructors, TTRC("Constructor"), "method", class_doc.name, ret);
|
|
|
|
_match_method_name_and_push_back(term, terms, class_doc.methods, TTRC("Method"), "method", class_doc.name, ret);
|
|
|
|
_match_method_name_and_push_back(term, terms, class_doc.operators, TTRC("Operator"), "method", class_doc.name, ret);
|
|
|
|
_match_method_name_and_push_back(term, terms, class_doc.signals, TTRC("Signal"), "signal", class_doc.name, ret);
|
|
|
|
_match_const_name_and_push_back(term, terms, class_doc.constants, TTRC("Constant"), "constant", class_doc.name, ret);
|
|
|
|
_match_property_name_and_push_back(term, terms, class_doc.properties, TTRC("Property"), "property", class_doc.name, ret);
|
|
|
|
_match_theme_property_name_and_push_back(term, terms, class_doc.theme_properties, TTRC("Theme Property"), "theme_item", class_doc.name, ret);
|
|
|
|
_match_method_name_and_push_back(term, terms, class_doc.annotations, TTRC("Annotation"), "annotation", class_doc.name, ret);
|
|
|
|
}
|
|
|
|
if (ret.size() > p_result_limit) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorHelpSearch::_native_action_cb(const String &p_item_string) {
|
|
|
|
emit_signal(SNAME("go_to_help"), p_item_string);
|
|
|
|
}
|
|
|
|
|
2017-12-10 23:56:49 +00:00
|
|
|
void EditorHelpSearch::_update_results() {
|
2023-12-07 14:51:40 +00:00
|
|
|
const String term = search_box->get_text().strip_edges();
|
2017-12-10 23:56:49 +00:00
|
|
|
|
|
|
|
int search_flags = filter_combo->get_selected_id();
|
|
|
|
|
2023-12-07 14:51:40 +00:00
|
|
|
// Process separately if term is not short, or is "@" for annotations.
|
|
|
|
if (term.length() > 1 || term == "@") {
|
|
|
|
case_sensitive_button->set_disabled(false);
|
|
|
|
hierarchy_button->set_disabled(false);
|
|
|
|
|
|
|
|
if (case_sensitive_button->is_pressed()) {
|
|
|
|
search_flags |= SEARCH_CASE_SENSITIVE;
|
|
|
|
}
|
|
|
|
if (hierarchy_button->is_pressed()) {
|
|
|
|
search_flags |= SEARCH_SHOW_HIERARCHY;
|
|
|
|
}
|
|
|
|
|
|
|
|
search = Ref<Runner>(memnew(Runner(results_tree, results_tree, &tree_cache, term, search_flags)));
|
|
|
|
|
|
|
|
// Clear old search flags to force rebuild on short term.
|
|
|
|
old_search_flags = 0;
|
|
|
|
set_process(true);
|
|
|
|
} else {
|
|
|
|
// Disable hierarchy and case sensitive options, not used for short searches.
|
|
|
|
case_sensitive_button->set_disabled(true);
|
|
|
|
hierarchy_button->set_disabled(true);
|
|
|
|
|
|
|
|
// Always show hierarchy for short searches.
|
|
|
|
search = Ref<Runner>(memnew(Runner(results_tree, results_tree, &tree_cache, term, search_flags | SEARCH_SHOW_HIERARCHY)));
|
|
|
|
|
|
|
|
old_search_flags = search_flags;
|
|
|
|
set_process(true);
|
|
|
|
}
|
2017-12-10 23:56:49 +00:00
|
|
|
}
|
|
|
|
|
2018-11-22 23:20:57 +00:00
|
|
|
void EditorHelpSearch::_search_box_gui_input(const Ref<InputEvent> &p_event) {
|
2024-08-31 17:23:34 +00:00
|
|
|
// Redirect navigational key events to the tree.
|
2018-11-22 23:20:57 +00:00
|
|
|
Ref<InputEventKey> key = p_event;
|
|
|
|
if (key.is_valid()) {
|
2024-08-31 17:23:34 +00:00
|
|
|
if (key->is_action("ui_up", true) || key->is_action("ui_down", true) || key->is_action("ui_page_up") || key->is_action("ui_page_down")) {
|
|
|
|
results_tree->gui_input(key);
|
|
|
|
search_box->accept_event();
|
2017-12-10 23:56:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorHelpSearch::_search_box_text_changed(const String &p_text) {
|
|
|
|
_update_results();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorHelpSearch::_filter_combo_item_selected(int p_option) {
|
|
|
|
_update_results();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorHelpSearch::_confirmed() {
|
2018-11-22 17:11:09 +00:00
|
|
|
TreeItem *item = results_tree->get_selected();
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!item) {
|
2018-11-22 17:11:09 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-11-22 17:11:09 +00:00
|
|
|
|
2017-12-10 23:56:49 +00:00
|
|
|
// Activate the script editor and emit the signal with the documentation link to display.
|
2024-08-19 22:08:31 +00:00
|
|
|
EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
|
2017-12-10 23:56:49 +00:00
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("go_to_help"), item->get_metadata(0));
|
2017-12-10 23:56:49 +00:00
|
|
|
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorHelpSearch::_notification(int p_what) {
|
|
|
|
switch (p_what) {
|
2023-10-22 11:29:56 +00:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
|
|
|
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_HELP)) {
|
|
|
|
DisplayServer::get_singleton()->help_set_search_callbacks(callable_mp(this, &EditorHelpSearch::_native_search_cb), callable_mp(this, &EditorHelpSearch::_native_action_cb));
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
|
|
|
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_HELP)) {
|
|
|
|
DisplayServer::get_singleton()->help_set_search_callbacks();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
2020-03-06 17:00:16 +00:00
|
|
|
case NOTIFICATION_VISIBILITY_CHANGED: {
|
|
|
|
if (!is_visible()) {
|
2023-12-02 12:44:40 +00:00
|
|
|
tree_cache.clear();
|
2023-12-07 14:51:40 +00:00
|
|
|
results_tree->get_vscroll_bar()->set_value(0);
|
|
|
|
search = Ref<Runner>();
|
2023-12-18 14:46:56 +00:00
|
|
|
callable_mp(results_tree, &Tree::clear).call_deferred(); // Wait for the Tree's mouse event propagation.
|
2020-12-14 18:37:30 +00:00
|
|
|
get_ok_button()->set_disabled(true);
|
2020-03-06 17:00:16 +00:00
|
|
|
EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "search_help", Rect2(get_position(), get_size()));
|
|
|
|
}
|
|
|
|
} break;
|
2022-02-15 23:52:32 +00:00
|
|
|
|
2022-11-02 14:23:25 +00:00
|
|
|
case NOTIFICATION_READY: {
|
2024-05-14 12:28:18 +00:00
|
|
|
connect(SceneStringName(confirmed), callable_mp(this, &EditorHelpSearch::_confirmed));
|
2022-11-02 14:23:25 +00:00
|
|
|
} break;
|
|
|
|
|
2022-11-22 23:14:08 +00:00
|
|
|
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
|
|
|
|
if (!EditorThemeManager::is_generated_theme_outdated()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
[[fallthrough]];
|
|
|
|
}
|
2022-11-02 14:23:25 +00:00
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
2023-10-26 15:56:09 +00:00
|
|
|
const int icon_width = get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor));
|
|
|
|
results_tree->add_theme_constant_override("icon_max_width", icon_width);
|
|
|
|
|
|
|
|
search_box->set_right_icon(get_editor_theme_icon(SNAME("Search")));
|
|
|
|
search_box->add_theme_icon_override("right_icon", get_editor_theme_icon(SNAME("Search")));
|
|
|
|
|
|
|
|
case_sensitive_button->set_icon(get_editor_theme_icon(SNAME("MatchCase")));
|
|
|
|
hierarchy_button->set_icon(get_editor_theme_icon(SNAME("ClassList")));
|
|
|
|
|
|
|
|
if (is_visible()) {
|
|
|
|
_update_results();
|
|
|
|
}
|
2017-12-10 23:56:49 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case NOTIFICATION_PROCESS: {
|
|
|
|
// Update background search.
|
|
|
|
if (search.is_valid()) {
|
|
|
|
if (search->work()) {
|
|
|
|
// Search done.
|
2018-11-26 15:38:39 +00:00
|
|
|
|
2021-03-19 21:49:21 +00:00
|
|
|
// Only point to the match if it's a new search, and not just reopening a old one.
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!old_search) {
|
2018-11-26 15:38:39 +00:00
|
|
|
results_tree->ensure_cursor_is_visible();
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2018-11-26 15:38:39 +00:00
|
|
|
old_search = false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-11-26 15:38:39 +00:00
|
|
|
|
2020-12-14 18:37:30 +00:00
|
|
|
get_ok_button()->set_disabled(!results_tree->get_selected());
|
2018-11-26 15:38:39 +00:00
|
|
|
|
2017-12-10 23:56:49 +00:00
|
|
|
search = Ref<Runner>();
|
|
|
|
set_process(false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
set_process(false);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorHelpSearch::_bind_methods() {
|
|
|
|
ADD_SIGNAL(MethodInfo("go_to_help"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorHelpSearch::popup_dialog() {
|
|
|
|
popup_dialog(search_box->get_text());
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorHelpSearch::popup_dialog(const String &p_term) {
|
|
|
|
// Restore valid window bounds or pop up at default size.
|
2018-12-04 15:52:56 +00:00
|
|
|
Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "search_help", Rect2());
|
2020-05-14 14:41:43 +00:00
|
|
|
if (saved_size != Rect2()) {
|
2018-12-04 15:52:56 +00:00
|
|
|
popup(saved_size);
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2017-12-10 23:56:49 +00:00
|
|
|
popup_centered_ratio(0.5F);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-12-10 23:56:49 +00:00
|
|
|
|
2023-12-07 14:51:40 +00:00
|
|
|
old_search_flags = 0;
|
2021-12-09 09:42:46 +00:00
|
|
|
if (p_term.is_empty()) {
|
2017-12-10 23:56:49 +00:00
|
|
|
search_box->clear();
|
|
|
|
} else {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (old_term == p_term) {
|
2019-11-25 15:23:35 +00:00
|
|
|
old_search = true;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2019-11-25 15:23:35 +00:00
|
|
|
old_term = p_term;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2019-11-25 15:23:35 +00:00
|
|
|
|
2017-12-10 23:56:49 +00:00
|
|
|
search_box->set_text(p_term);
|
|
|
|
search_box->select_all();
|
|
|
|
}
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_results();
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorHelpSearch::EditorHelpSearch() {
|
|
|
|
set_hide_on_ok(false);
|
2023-03-19 16:26:22 +00:00
|
|
|
set_clamp_to_embedder(true);
|
2020-03-06 17:00:16 +00:00
|
|
|
|
2017-12-10 23:56:49 +00:00
|
|
|
set_title(TTR("Search Help"));
|
|
|
|
|
2020-12-14 18:37:30 +00:00
|
|
|
get_ok_button()->set_disabled(true);
|
2022-07-08 00:31:19 +00:00
|
|
|
set_ok_button_text(TTR("Open"));
|
2017-12-10 23:56:49 +00:00
|
|
|
|
|
|
|
// Split search and results area.
|
|
|
|
VBoxContainer *vbox = memnew(VBoxContainer);
|
|
|
|
add_child(vbox);
|
|
|
|
|
|
|
|
// Create the search box and filter controls (at the top).
|
|
|
|
HBoxContainer *hbox = memnew(HBoxContainer);
|
|
|
|
vbox->add_child(hbox);
|
|
|
|
|
|
|
|
search_box = memnew(LineEdit);
|
2019-12-28 02:33:01 +00:00
|
|
|
search_box->set_custom_minimum_size(Size2(200, 0) * EDSCALE);
|
2020-03-06 17:00:16 +00:00
|
|
|
search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
2023-10-26 15:56:09 +00:00
|
|
|
search_box->set_clear_button_enabled(true);
|
2024-05-13 14:56:03 +00:00
|
|
|
search_box->connect(SceneStringName(gui_input), callable_mp(this, &EditorHelpSearch::_search_box_gui_input));
|
2024-05-14 09:42:00 +00:00
|
|
|
search_box->connect(SceneStringName(text_changed), callable_mp(this, &EditorHelpSearch::_search_box_text_changed));
|
2017-12-10 23:56:49 +00:00
|
|
|
register_text_enter(search_box);
|
|
|
|
hbox->add_child(search_box);
|
|
|
|
|
2020-06-19 18:49:04 +00:00
|
|
|
case_sensitive_button = memnew(Button);
|
2023-09-19 16:03:10 +00:00
|
|
|
case_sensitive_button->set_theme_type_variation("FlatButton");
|
2022-08-25 10:42:17 +00:00
|
|
|
case_sensitive_button->set_tooltip_text(TTR("Case Sensitive"));
|
2024-05-14 07:40:21 +00:00
|
|
|
case_sensitive_button->connect(SceneStringName(pressed), callable_mp(this, &EditorHelpSearch::_update_results));
|
2017-12-10 23:56:49 +00:00
|
|
|
case_sensitive_button->set_toggle_mode(true);
|
2020-03-06 17:00:16 +00:00
|
|
|
case_sensitive_button->set_focus_mode(Control::FOCUS_NONE);
|
2017-12-10 23:56:49 +00:00
|
|
|
hbox->add_child(case_sensitive_button);
|
|
|
|
|
2020-06-19 18:49:04 +00:00
|
|
|
hierarchy_button = memnew(Button);
|
2023-09-19 16:03:10 +00:00
|
|
|
hierarchy_button->set_theme_type_variation("FlatButton");
|
2022-08-25 10:42:17 +00:00
|
|
|
hierarchy_button->set_tooltip_text(TTR("Show Hierarchy"));
|
2024-05-14 07:40:21 +00:00
|
|
|
hierarchy_button->connect(SceneStringName(pressed), callable_mp(this, &EditorHelpSearch::_update_results));
|
2017-12-10 23:56:49 +00:00
|
|
|
hierarchy_button->set_toggle_mode(true);
|
|
|
|
hierarchy_button->set_pressed(true);
|
2020-03-06 17:00:16 +00:00
|
|
|
hierarchy_button->set_focus_mode(Control::FOCUS_NONE);
|
2017-12-10 23:56:49 +00:00
|
|
|
hbox->add_child(hierarchy_button);
|
|
|
|
|
|
|
|
filter_combo = memnew(OptionButton);
|
2019-12-28 02:33:01 +00:00
|
|
|
filter_combo->set_custom_minimum_size(Size2(200, 0) * EDSCALE);
|
2017-12-10 23:56:49 +00:00
|
|
|
filter_combo->set_stretch_ratio(0); // Fixed width.
|
|
|
|
filter_combo->add_item(TTR("Display All"), SEARCH_ALL);
|
|
|
|
filter_combo->add_separator();
|
|
|
|
filter_combo->add_item(TTR("Classes Only"), SEARCH_CLASSES);
|
2021-09-21 02:49:02 +00:00
|
|
|
filter_combo->add_item(TTR("Constructors Only"), SEARCH_CONSTRUCTORS);
|
2017-12-10 23:56:49 +00:00
|
|
|
filter_combo->add_item(TTR("Methods Only"), SEARCH_METHODS);
|
2021-09-21 02:49:02 +00:00
|
|
|
filter_combo->add_item(TTR("Operators Only"), SEARCH_OPERATORS);
|
2017-12-10 23:56:49 +00:00
|
|
|
filter_combo->add_item(TTR("Signals Only"), SEARCH_SIGNALS);
|
2022-09-01 16:11:19 +00:00
|
|
|
filter_combo->add_item(TTR("Annotations Only"), SEARCH_ANNOTATIONS);
|
2017-12-10 23:56:49 +00:00
|
|
|
filter_combo->add_item(TTR("Constants Only"), SEARCH_CONSTANTS);
|
|
|
|
filter_combo->add_item(TTR("Properties Only"), SEARCH_PROPERTIES);
|
|
|
|
filter_combo->add_item(TTR("Theme Properties Only"), SEARCH_THEME_ITEMS);
|
2024-05-14 12:21:31 +00:00
|
|
|
filter_combo->connect(SceneStringName(item_selected), callable_mp(this, &EditorHelpSearch::_filter_combo_item_selected));
|
2017-12-10 23:56:49 +00:00
|
|
|
hbox->add_child(filter_combo);
|
|
|
|
|
|
|
|
// Create the results tree.
|
|
|
|
results_tree = memnew(Tree);
|
2024-03-17 08:28:18 +00:00
|
|
|
results_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
|
2020-03-06 17:00:16 +00:00
|
|
|
results_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
2017-12-10 23:56:49 +00:00
|
|
|
results_tree->set_columns(2);
|
|
|
|
results_tree->set_column_title(0, TTR("Name"));
|
2021-07-04 03:13:28 +00:00
|
|
|
results_tree->set_column_clip_content(0, true);
|
2017-12-10 23:56:49 +00:00
|
|
|
results_tree->set_column_title(1, TTR("Member Type"));
|
|
|
|
results_tree->set_column_expand(1, false);
|
2021-06-28 13:40:56 +00:00
|
|
|
results_tree->set_column_custom_minimum_width(1, 150 * EDSCALE);
|
2021-07-04 03:13:28 +00:00
|
|
|
results_tree->set_column_clip_content(1, true);
|
2019-12-28 02:33:01 +00:00
|
|
|
results_tree->set_custom_minimum_size(Size2(0, 100) * EDSCALE);
|
2017-12-10 23:56:49 +00:00
|
|
|
results_tree->set_hide_root(true);
|
|
|
|
results_tree->set_select_mode(Tree::SELECT_ROW);
|
2020-02-21 17:28:45 +00:00
|
|
|
results_tree->connect("item_activated", callable_mp(this, &EditorHelpSearch::_confirmed));
|
2024-05-14 12:21:31 +00:00
|
|
|
results_tree->connect(SceneStringName(item_selected), callable_mp((BaseButton *)get_ok_button(), &BaseButton::set_disabled).bind(false));
|
2017-12-10 23:56:49 +00:00
|
|
|
vbox->add_child(results_tree, true);
|
|
|
|
}
|
|
|
|
|
2023-12-02 12:44:40 +00:00
|
|
|
void EditorHelpSearch::TreeCache::clear() {
|
|
|
|
for (const KeyValue<String, TreeItem *> &E : item_cache) {
|
|
|
|
memdelete(E.value);
|
|
|
|
}
|
|
|
|
item_cache.clear();
|
|
|
|
}
|
|
|
|
|
2019-06-07 01:04:25 +00:00
|
|
|
bool EditorHelpSearch::Runner::_is_class_disabled_by_feature_profile(const StringName &p_class) {
|
|
|
|
Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile();
|
|
|
|
if (profile.is_null()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringName class_name = p_class;
|
|
|
|
while (class_name != StringName()) {
|
2019-06-25 23:36:26 +00:00
|
|
|
if (!ClassDB::class_exists(class_name)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (profile->is_class_disabled(class_name)) {
|
2019-06-07 01:04:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
class_name = ClassDB::get_parent_class(class_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-12-07 14:51:40 +00:00
|
|
|
bool EditorHelpSearch::Runner::_fill() {
|
|
|
|
bool phase_done = false;
|
|
|
|
switch (phase) {
|
|
|
|
case PHASE_MATCH_CLASSES_INIT:
|
|
|
|
phase_done = _phase_fill_classes_init();
|
|
|
|
break;
|
|
|
|
case PHASE_MATCH_CLASSES:
|
|
|
|
phase_done = _phase_fill_classes();
|
|
|
|
break;
|
|
|
|
case PHASE_CLASS_ITEMS_INIT:
|
|
|
|
case PHASE_CLASS_ITEMS:
|
|
|
|
phase_done = true;
|
|
|
|
break;
|
|
|
|
case PHASE_MEMBER_ITEMS_INIT:
|
|
|
|
phase_done = _phase_fill_member_items_init();
|
|
|
|
break;
|
|
|
|
case PHASE_MEMBER_ITEMS:
|
|
|
|
phase_done = _phase_fill_member_items();
|
|
|
|
break;
|
|
|
|
case PHASE_SELECT_MATCH:
|
|
|
|
phase_done = _phase_select_match();
|
|
|
|
break;
|
|
|
|
case PHASE_MAX:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
WARN_PRINT("Invalid or unhandled phase in EditorHelpSearch::Runner, aborting search.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (phase_done) {
|
|
|
|
phase++;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorHelpSearch::Runner::_phase_fill_classes_init() {
|
|
|
|
// Initialize fill.
|
|
|
|
iterator_stack.clear();
|
|
|
|
matched_classes.clear();
|
|
|
|
matched_item = nullptr;
|
|
|
|
match_highest_score = 0;
|
|
|
|
|
|
|
|
// Initialize stack of iterators to fill, in reverse.
|
|
|
|
iterator_stack.push_back(EditorHelp::get_doc_data()->inheriting[""].back());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorHelpSearch::Runner::_phase_fill_classes() {
|
|
|
|
if (iterator_stack.is_empty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iterator_stack[iterator_stack.size() - 1]) {
|
|
|
|
DocData::ClassDoc *class_doc = EditorHelp::get_doc_data()->class_list.getptr(iterator_stack[iterator_stack.size() - 1]->get());
|
|
|
|
|
|
|
|
// Decrement stack.
|
|
|
|
iterator_stack[iterator_stack.size() - 1] = iterator_stack[iterator_stack.size() - 1]->prev();
|
|
|
|
|
|
|
|
// Drop last element of stack if empty.
|
|
|
|
if (!iterator_stack[iterator_stack.size() - 1]) {
|
|
|
|
iterator_stack.resize(iterator_stack.size() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!class_doc || class_doc->name.is_empty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If class matches the flags, add it to the matched stack.
|
|
|
|
const bool class_matched =
|
|
|
|
(search_flags & SEARCH_CLASSES) ||
|
|
|
|
((search_flags & SEARCH_CONSTRUCTORS) && !class_doc->constructors.is_empty()) ||
|
|
|
|
((search_flags & SEARCH_METHODS) && !class_doc->methods.is_empty()) ||
|
|
|
|
((search_flags & SEARCH_OPERATORS) && !class_doc->operators.is_empty()) ||
|
|
|
|
((search_flags & SEARCH_SIGNALS) && !class_doc->signals.is_empty()) ||
|
|
|
|
((search_flags & SEARCH_CONSTANTS) && !class_doc->constants.is_empty()) ||
|
|
|
|
((search_flags & SEARCH_PROPERTIES) && !class_doc->properties.is_empty()) ||
|
|
|
|
((search_flags & SEARCH_THEME_ITEMS) && !class_doc->theme_properties.is_empty()) ||
|
|
|
|
((search_flags & SEARCH_ANNOTATIONS) && !class_doc->annotations.is_empty());
|
|
|
|
|
|
|
|
if (class_matched) {
|
|
|
|
if (term.is_empty() || class_doc->name.containsn(term)) {
|
|
|
|
matched_classes.push_back(Pair<DocData::ClassDoc *, String>(class_doc, String()));
|
|
|
|
} else if (String keyword = _match_keywords(term, class_doc->keywords); !keyword.is_empty()) {
|
|
|
|
matched_classes.push_back(Pair<DocData::ClassDoc *, String>(class_doc, keyword));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add inheriting classes, in reverse.
|
|
|
|
if (class_doc && EditorHelp::get_doc_data()->inheriting.has(class_doc->name)) {
|
|
|
|
iterator_stack.push_back(EditorHelp::get_doc_data()->inheriting[class_doc->name].back());
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Drop last element of stack if empty.
|
|
|
|
if (!iterator_stack[iterator_stack.size() - 1]) {
|
|
|
|
iterator_stack.resize(iterator_stack.size() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return iterator_stack.is_empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorHelpSearch::Runner::_phase_fill_member_items_init() {
|
|
|
|
// Prepare tree.
|
|
|
|
class_items.clear();
|
|
|
|
_populate_cache();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
TreeItem *EditorHelpSearch::Runner::_create_category_item(TreeItem *p_parent, const String &p_class, const StringName &p_icon, const String &p_metatype, const String &p_text) {
|
|
|
|
const String item_meta = "class_" + p_metatype + ":" + p_class;
|
|
|
|
|
|
|
|
TreeItem *item = nullptr;
|
|
|
|
if (_find_or_create_item(p_parent, item_meta, item)) {
|
|
|
|
item->set_icon(0, ui_service->get_editor_theme_icon(p_icon));
|
|
|
|
item->set_text(0, p_text);
|
|
|
|
item->set_metadata(0, item_meta);
|
|
|
|
}
|
|
|
|
item->set_collapsed(true);
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorHelpSearch::Runner::_phase_fill_member_items() {
|
|
|
|
if (matched_classes.is_empty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pop working item from stack.
|
|
|
|
Pair<DocData::ClassDoc *, String> match = matched_classes[matched_classes.size() - 1];
|
|
|
|
DocData::ClassDoc *class_doc = match.first;
|
|
|
|
const String &keyword = match.second;
|
|
|
|
matched_classes.resize(matched_classes.size() - 1);
|
|
|
|
|
|
|
|
if (class_doc) {
|
|
|
|
TreeItem *item = _create_class_hierarchy(class_doc, keyword, !(search_flags & SEARCH_CLASSES));
|
|
|
|
|
|
|
|
// If the class has no inheriting classes, fold its item.
|
|
|
|
item->set_collapsed(!item->get_first_child());
|
|
|
|
|
|
|
|
if (search_flags & SEARCH_CLASSES) {
|
|
|
|
item->clear_custom_color(0);
|
|
|
|
item->clear_custom_color(1);
|
|
|
|
} else {
|
|
|
|
item->set_custom_color(0, disabled_color);
|
|
|
|
item->set_custom_color(1, disabled_color);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create common header if required.
|
|
|
|
const bool search_all = (search_flags & SEARCH_ALL) == SEARCH_ALL;
|
|
|
|
|
|
|
|
if ((search_flags & SEARCH_CONSTRUCTORS) && !class_doc->constructors.is_empty()) {
|
|
|
|
TreeItem *parent_item = item;
|
|
|
|
if (search_all) {
|
|
|
|
parent_item = _create_category_item(parent_item, class_doc->name, SNAME("MemberConstructor"), TTRC("Constructors"), "constructors");
|
|
|
|
}
|
|
|
|
for (const DocData::MethodDoc &constructor_doc : class_doc->constructors) {
|
|
|
|
_create_constructor_item(parent_item, class_doc, &constructor_doc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((search_flags & SEARCH_METHODS) && !class_doc->methods.is_empty()) {
|
|
|
|
TreeItem *parent_item = item;
|
|
|
|
if (search_all) {
|
|
|
|
parent_item = _create_category_item(parent_item, class_doc->name, SNAME("MemberMethod"), TTRC("Methods"), "methods");
|
|
|
|
}
|
|
|
|
for (const DocData::MethodDoc &method_doc : class_doc->methods) {
|
|
|
|
_create_method_item(parent_item, class_doc, &method_doc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((search_flags & SEARCH_OPERATORS) && !class_doc->operators.is_empty()) {
|
|
|
|
TreeItem *parent_item = item;
|
|
|
|
if (search_all) {
|
|
|
|
parent_item = _create_category_item(parent_item, class_doc->name, SNAME("MemberOperator"), TTRC("Operators"), "operators");
|
|
|
|
}
|
|
|
|
for (const DocData::MethodDoc &operator_doc : class_doc->operators) {
|
|
|
|
_create_operator_item(parent_item, class_doc, &operator_doc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((search_flags & SEARCH_SIGNALS) && !class_doc->signals.is_empty()) {
|
|
|
|
TreeItem *parent_item = item;
|
|
|
|
if (search_all) {
|
|
|
|
parent_item = _create_category_item(parent_item, class_doc->name, SNAME("MemberSignal"), TTRC("Signals"), "signals");
|
|
|
|
}
|
|
|
|
for (const DocData::MethodDoc &signal_doc : class_doc->signals) {
|
|
|
|
_create_signal_item(parent_item, class_doc, &signal_doc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((search_flags & SEARCH_CONSTANTS) && !class_doc->constants.is_empty()) {
|
|
|
|
TreeItem *parent_item = item;
|
|
|
|
if (search_all) {
|
|
|
|
parent_item = _create_category_item(parent_item, class_doc->name, SNAME("MemberConstant"), TTRC("Constants"), "constants");
|
|
|
|
}
|
|
|
|
for (const DocData::ConstantDoc &constant_doc : class_doc->constants) {
|
|
|
|
_create_constant_item(parent_item, class_doc, &constant_doc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((search_flags & SEARCH_PROPERTIES) && !class_doc->properties.is_empty()) {
|
|
|
|
TreeItem *parent_item = item;
|
|
|
|
if (search_all) {
|
|
|
|
parent_item = _create_category_item(parent_item, class_doc->name, SNAME("MemberProperty"), TTRC("Prtoperties"), "propertiess");
|
|
|
|
}
|
|
|
|
for (const DocData::PropertyDoc &property_doc : class_doc->properties) {
|
|
|
|
_create_property_item(parent_item, class_doc, &property_doc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((search_flags & SEARCH_THEME_ITEMS) && !class_doc->theme_properties.is_empty()) {
|
|
|
|
TreeItem *parent_item = item;
|
|
|
|
if (search_all) {
|
|
|
|
parent_item = _create_category_item(parent_item, class_doc->name, SNAME("MemberTheme"), TTRC("Theme Properties"), "theme_items");
|
|
|
|
}
|
|
|
|
for (const DocData::ThemeItemDoc &theme_property_doc : class_doc->theme_properties) {
|
|
|
|
_create_theme_property_item(parent_item, class_doc, &theme_property_doc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((search_flags & SEARCH_ANNOTATIONS) && !class_doc->annotations.is_empty()) {
|
|
|
|
TreeItem *parent_item = item;
|
|
|
|
if (search_all) {
|
|
|
|
parent_item = _create_category_item(parent_item, class_doc->name, SNAME("MemberAnnotation"), TTRC("Annotations"), "annotations");
|
|
|
|
}
|
|
|
|
for (const DocData::MethodDoc &annotation_doc : class_doc->annotations) {
|
|
|
|
_create_annotation_item(parent_item, class_doc, &annotation_doc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return matched_classes.is_empty();
|
|
|
|
}
|
|
|
|
|
2017-12-10 23:56:49 +00:00
|
|
|
bool EditorHelpSearch::Runner::_slice() {
|
|
|
|
bool phase_done = false;
|
|
|
|
switch (phase) {
|
|
|
|
case PHASE_MATCH_CLASSES_INIT:
|
|
|
|
phase_done = _phase_match_classes_init();
|
|
|
|
break;
|
|
|
|
case PHASE_MATCH_CLASSES:
|
|
|
|
phase_done = _phase_match_classes();
|
|
|
|
break;
|
|
|
|
case PHASE_CLASS_ITEMS_INIT:
|
|
|
|
phase_done = _phase_class_items_init();
|
|
|
|
break;
|
|
|
|
case PHASE_CLASS_ITEMS:
|
|
|
|
phase_done = _phase_class_items();
|
|
|
|
break;
|
|
|
|
case PHASE_MEMBER_ITEMS_INIT:
|
|
|
|
phase_done = _phase_member_items_init();
|
|
|
|
break;
|
|
|
|
case PHASE_MEMBER_ITEMS:
|
|
|
|
phase_done = _phase_member_items();
|
|
|
|
break;
|
|
|
|
case PHASE_SELECT_MATCH:
|
|
|
|
phase_done = _phase_select_match();
|
|
|
|
break;
|
|
|
|
case PHASE_MAX:
|
|
|
|
return true;
|
|
|
|
default:
|
2019-11-07 08:44:15 +00:00
|
|
|
WARN_PRINT("Invalid or unhandled phase in EditorHelpSearch::Runner, aborting search.");
|
2017-12-10 23:56:49 +00:00
|
|
|
return true;
|
2023-12-07 14:51:40 +00:00
|
|
|
}
|
2017-12-10 23:56:49 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (phase_done) {
|
2017-12-10 23:56:49 +00:00
|
|
|
phase++;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-12-10 23:56:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorHelpSearch::Runner::_phase_match_classes_init() {
|
2023-08-16 12:00:59 +00:00
|
|
|
iterator_doc = nullptr;
|
|
|
|
iterator_stack.clear();
|
|
|
|
if (search_flags & SEARCH_SHOW_HIERARCHY) {
|
|
|
|
iterator_stack.push_back(EditorHelp::get_doc_data()->inheriting[""].front());
|
|
|
|
} else {
|
|
|
|
iterator_doc = EditorHelp::get_doc_data()->class_list.begin();
|
|
|
|
}
|
2017-12-10 23:56:49 +00:00
|
|
|
matches.clear();
|
2020-04-01 23:20:12 +00:00
|
|
|
matched_item = nullptr;
|
2021-03-19 21:49:21 +00:00
|
|
|
match_highest_score = 0;
|
2017-12-10 23:56:49 +00:00
|
|
|
|
2023-12-07 14:51:40 +00:00
|
|
|
if (!term.is_empty()) {
|
|
|
|
terms = term.split_spaces();
|
|
|
|
if (terms.is_empty()) {
|
|
|
|
terms.append(term);
|
|
|
|
}
|
2022-09-04 08:18:23 +00:00
|
|
|
}
|
|
|
|
|
2017-12-10 23:56:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorHelpSearch::Runner::_phase_match_classes() {
|
2023-08-16 12:00:59 +00:00
|
|
|
if (!iterator_doc && iterator_stack.is_empty()) {
|
2022-09-19 11:26:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-08-16 12:00:59 +00:00
|
|
|
DocData::ClassDoc *class_doc = nullptr;
|
|
|
|
if (iterator_doc) {
|
|
|
|
class_doc = &iterator_doc->value;
|
|
|
|
} else if (!iterator_stack.is_empty() && iterator_stack[iterator_stack.size() - 1]) {
|
|
|
|
class_doc = EditorHelp::get_doc_data()->class_list.getptr(iterator_stack[iterator_stack.size() - 1]->get());
|
2021-10-30 01:42:57 +00:00
|
|
|
}
|
2022-09-19 11:26:50 +00:00
|
|
|
|
2023-08-16 12:00:59 +00:00
|
|
|
if (class_doc && class_doc->name.is_empty()) {
|
|
|
|
class_doc = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (class_doc && !_is_class_disabled_by_feature_profile(class_doc->name)) {
|
2021-10-30 01:42:57 +00:00
|
|
|
ClassMatch match;
|
2023-08-16 12:00:59 +00:00
|
|
|
match.doc = class_doc;
|
2019-06-07 01:04:25 +00:00
|
|
|
|
|
|
|
// Match class name.
|
2020-05-14 14:41:43 +00:00
|
|
|
if (search_flags & SEARCH_CLASSES) {
|
2023-12-07 14:51:40 +00:00
|
|
|
match.name = _match_string(term, class_doc->name);
|
2024-02-17 17:06:35 +00:00
|
|
|
match.keyword = _match_keywords(term, class_doc->keywords);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2019-06-07 01:04:25 +00:00
|
|
|
|
2023-12-07 14:51:40 +00:00
|
|
|
if (search_flags & SEARCH_CONSTRUCTORS) {
|
|
|
|
_match_method_name_and_push_back(class_doc->constructors, &match.constructors);
|
|
|
|
}
|
|
|
|
if (search_flags & SEARCH_METHODS) {
|
|
|
|
_match_method_name_and_push_back(class_doc->methods, &match.methods);
|
|
|
|
}
|
|
|
|
if (search_flags & SEARCH_OPERATORS) {
|
|
|
|
_match_method_name_and_push_back(class_doc->operators, &match.operators);
|
|
|
|
}
|
|
|
|
if (search_flags & SEARCH_SIGNALS) {
|
|
|
|
for (const DocData::MethodDoc &signal_doc : class_doc->signals) {
|
|
|
|
MemberMatch<DocData::MethodDoc> signal;
|
|
|
|
signal.name = _all_terms_in_name(signal_doc.name);
|
|
|
|
signal.keyword = _match_keywords_in_all_terms(signal_doc.keywords);
|
|
|
|
if (signal.name || !signal.keyword.is_empty()) {
|
|
|
|
signal.doc = &signal_doc;
|
|
|
|
match.signals.push_back(signal);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
|
|
|
}
|
2023-12-07 14:51:40 +00:00
|
|
|
}
|
|
|
|
if (search_flags & SEARCH_CONSTANTS) {
|
|
|
|
for (const DocData::ConstantDoc &constant_doc : class_doc->constants) {
|
|
|
|
MemberMatch<DocData::ConstantDoc> constant;
|
|
|
|
constant.name = _all_terms_in_name(constant_doc.name);
|
|
|
|
constant.keyword = _match_keywords_in_all_terms(constant_doc.keywords);
|
|
|
|
if (constant.name || !constant.keyword.is_empty()) {
|
|
|
|
constant.doc = &constant_doc;
|
|
|
|
match.constants.push_back(constant);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
|
|
|
}
|
2023-12-07 14:51:40 +00:00
|
|
|
}
|
|
|
|
if (search_flags & SEARCH_PROPERTIES) {
|
|
|
|
for (const DocData::PropertyDoc &property_doc : class_doc->properties) {
|
|
|
|
MemberMatch<DocData::PropertyDoc> property;
|
|
|
|
property.name = _all_terms_in_name(property_doc.name);
|
|
|
|
property.keyword = _match_keywords_in_all_terms(property_doc.keywords);
|
|
|
|
if (property.name || !property.keyword.is_empty()) {
|
|
|
|
property.doc = &property_doc;
|
|
|
|
match.properties.push_back(property);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
|
|
|
}
|
2023-12-07 14:51:40 +00:00
|
|
|
}
|
|
|
|
if (search_flags & SEARCH_THEME_ITEMS) {
|
|
|
|
for (const DocData::ThemeItemDoc &theme_property_doc : class_doc->theme_properties) {
|
|
|
|
MemberMatch<DocData::ThemeItemDoc> theme_property;
|
|
|
|
theme_property.name = _all_terms_in_name(theme_property_doc.name);
|
|
|
|
theme_property.keyword = _match_keywords_in_all_terms(theme_property_doc.keywords);
|
|
|
|
if (theme_property.name || !theme_property.keyword.is_empty()) {
|
|
|
|
theme_property.doc = &theme_property_doc;
|
|
|
|
match.theme_properties.push_back(theme_property);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
|
|
|
}
|
2023-12-07 14:51:40 +00:00
|
|
|
}
|
|
|
|
if (search_flags & SEARCH_ANNOTATIONS) {
|
|
|
|
for (const DocData::MethodDoc &annotation_doc : class_doc->annotations) {
|
|
|
|
MemberMatch<DocData::MethodDoc> annotation;
|
|
|
|
annotation.name = _all_terms_in_name(annotation_doc.name);
|
|
|
|
annotation.keyword = _match_keywords_in_all_terms(annotation_doc.keywords);
|
|
|
|
if (annotation.name || !annotation.keyword.is_empty()) {
|
|
|
|
annotation.doc = &annotation_doc;
|
|
|
|
match.annotations.push_back(annotation);
|
2022-09-01 16:11:19 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-07 01:04:25 +00:00
|
|
|
}
|
2023-08-16 12:00:59 +00:00
|
|
|
matches[class_doc->name] = match;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iterator_doc) {
|
|
|
|
++iterator_doc;
|
|
|
|
return !iterator_doc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!iterator_stack.is_empty()) {
|
2023-12-07 14:51:40 +00:00
|
|
|
// Iterate on stack.
|
2023-08-16 12:00:59 +00:00
|
|
|
if (iterator_stack[iterator_stack.size() - 1]) {
|
|
|
|
iterator_stack[iterator_stack.size() - 1] = iterator_stack[iterator_stack.size() - 1]->next();
|
|
|
|
}
|
2023-12-07 14:51:40 +00:00
|
|
|
// Drop last element of stack.
|
2023-08-16 12:00:59 +00:00
|
|
|
if (!iterator_stack[iterator_stack.size() - 1]) {
|
|
|
|
iterator_stack.resize(iterator_stack.size() - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (class_doc && EditorHelp::get_doc_data()->inheriting.has(class_doc->name)) {
|
|
|
|
iterator_stack.push_back(EditorHelp::get_doc_data()->inheriting[class_doc->name].front());
|
2017-12-10 23:56:49 +00:00
|
|
|
}
|
|
|
|
|
2023-08-16 12:00:59 +00:00
|
|
|
return iterator_stack.is_empty();
|
2017-12-10 23:56:49 +00:00
|
|
|
}
|
|
|
|
|
2023-12-02 12:44:40 +00:00
|
|
|
void EditorHelpSearch::Runner::_populate_cache() {
|
2024-01-22 16:06:42 +00:00
|
|
|
// Deselect to prevent re-selection issues.
|
|
|
|
results_tree->deselect_all();
|
|
|
|
|
2023-12-02 12:44:40 +00:00
|
|
|
root_item = results_tree->get_root();
|
|
|
|
|
|
|
|
if (root_item) {
|
|
|
|
LocalVector<TreeItem *> stack;
|
|
|
|
|
|
|
|
// Add children of root item to stack.
|
|
|
|
for (TreeItem *child = root_item->get_first_child(); child; child = child->get_next()) {
|
|
|
|
stack.push_back(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Traverse stack and cache items.
|
|
|
|
while (!stack.is_empty()) {
|
|
|
|
TreeItem *cur_item = stack[stack.size() - 1];
|
|
|
|
stack.resize(stack.size() - 1);
|
|
|
|
|
|
|
|
// Add to the cache.
|
|
|
|
tree_cache->item_cache.insert(cur_item->get_metadata(0).operator String(), cur_item);
|
|
|
|
|
|
|
|
// Add any children to the stack.
|
|
|
|
for (TreeItem *child = cur_item->get_first_child(); child; child = child->get_next()) {
|
|
|
|
stack.push_back(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove from parent.
|
|
|
|
cur_item->get_parent()->remove_child(cur_item);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
root_item = results_tree->create_item();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-10 23:56:49 +00:00
|
|
|
bool EditorHelpSearch::Runner::_phase_class_items_init() {
|
2022-05-13 13:04:37 +00:00
|
|
|
iterator_match = matches.begin();
|
2017-12-10 23:56:49 +00:00
|
|
|
|
2023-12-02 12:44:40 +00:00
|
|
|
_populate_cache();
|
2017-12-10 23:56:49 +00:00
|
|
|
class_items.clear();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorHelpSearch::Runner::_phase_class_items() {
|
2021-10-30 01:42:57 +00:00
|
|
|
if (!iterator_match) {
|
2022-09-10 17:34:26 +00:00
|
|
|
return true;
|
2021-10-30 01:42:57 +00:00
|
|
|
}
|
2022-05-13 13:04:37 +00:00
|
|
|
ClassMatch &match = iterator_match->value;
|
2017-12-10 23:56:49 +00:00
|
|
|
|
|
|
|
if (search_flags & SEARCH_SHOW_HIERARCHY) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (match.required()) {
|
2017-12-10 23:56:49 +00:00
|
|
|
_create_class_hierarchy(match);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-12-10 23:56:49 +00:00
|
|
|
} else {
|
2024-02-17 17:06:35 +00:00
|
|
|
if (match.name || !match.keyword.is_empty()) {
|
|
|
|
_create_class_item(root_item, match.doc, false, match.name ? String() : match.keyword);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-12-10 23:56:49 +00:00
|
|
|
}
|
|
|
|
|
2022-05-13 13:04:37 +00:00
|
|
|
++iterator_match;
|
2017-12-10 23:56:49 +00:00
|
|
|
return !iterator_match;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorHelpSearch::Runner::_phase_member_items_init() {
|
2022-05-13 13:04:37 +00:00
|
|
|
iterator_match = matches.begin();
|
2017-12-10 23:56:49 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorHelpSearch::Runner::_phase_member_items() {
|
2022-12-01 21:47:02 +00:00
|
|
|
if (!iterator_match) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-05-13 13:04:37 +00:00
|
|
|
ClassMatch &match = iterator_match->value;
|
2017-12-10 23:56:49 +00:00
|
|
|
|
2022-09-10 17:34:26 +00:00
|
|
|
if (!match.doc || match.doc->name.is_empty()) {
|
|
|
|
++iterator_match;
|
2021-10-30 01:42:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-12-07 14:51:40 +00:00
|
|
|
// Pick appropriate parent item if showing hierarchy, otherwise pick root.
|
2022-09-29 09:53:28 +00:00
|
|
|
TreeItem *parent_item = (search_flags & SEARCH_SHOW_HIERARCHY) ? class_items[match.doc->name] : root_item;
|
2023-12-07 14:51:40 +00:00
|
|
|
|
|
|
|
for (const MemberMatch<DocData::MethodDoc> &constructor_item : match.constructors) {
|
|
|
|
_create_constructor_item(parent_item, match.doc, constructor_item);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2023-12-07 14:51:40 +00:00
|
|
|
for (const MemberMatch<DocData::MethodDoc> &method_item : match.methods) {
|
|
|
|
_create_method_item(parent_item, match.doc, method_item);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2023-12-07 14:51:40 +00:00
|
|
|
for (const MemberMatch<DocData::MethodDoc> &operator_item : match.operators) {
|
|
|
|
_create_operator_item(parent_item, match.doc, operator_item);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2023-12-07 14:51:40 +00:00
|
|
|
for (const MemberMatch<DocData::MethodDoc> &signal_item : match.signals) {
|
|
|
|
_create_signal_item(parent_item, match.doc, signal_item);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2023-12-07 14:51:40 +00:00
|
|
|
for (const MemberMatch<DocData::ConstantDoc> &constant_item : match.constants) {
|
|
|
|
_create_constant_item(parent_item, match.doc, constant_item);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2023-12-07 14:51:40 +00:00
|
|
|
for (const MemberMatch<DocData::PropertyDoc> &property_item : match.properties) {
|
|
|
|
_create_property_item(parent_item, match.doc, property_item);
|
|
|
|
}
|
|
|
|
for (const MemberMatch<DocData::ThemeItemDoc> &theme_property_item : match.theme_properties) {
|
|
|
|
_create_theme_property_item(parent_item, match.doc, theme_property_item);
|
|
|
|
}
|
|
|
|
for (const MemberMatch<DocData::MethodDoc> &annotation_item : match.annotations) {
|
|
|
|
_create_annotation_item(parent_item, match.doc, annotation_item);
|
2022-09-01 16:11:19 +00:00
|
|
|
}
|
2017-12-10 23:56:49 +00:00
|
|
|
|
2022-05-13 13:04:37 +00:00
|
|
|
++iterator_match;
|
2017-12-10 23:56:49 +00:00
|
|
|
return !iterator_match;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorHelpSearch::Runner::_phase_select_match() {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (matched_item) {
|
2017-12-10 23:56:49 +00:00
|
|
|
matched_item->select(0);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-12-10 23:56:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-12-07 14:51:40 +00:00
|
|
|
void EditorHelpSearch::Runner::_match_method_name_and_push_back(Vector<DocData::MethodDoc> &p_methods, LocalVector<MemberMatch<DocData::MethodDoc>> *r_match_methods) {
|
2022-09-04 08:18:23 +00:00
|
|
|
// Constructors, Methods, Operators...
|
|
|
|
for (int i = 0; i < p_methods.size(); i++) {
|
|
|
|
String method_name = (search_flags & SEARCH_CASE_SENSITIVE) ? p_methods[i].name : p_methods[i].name.to_lower();
|
2023-07-03 16:18:46 +00:00
|
|
|
String keywords = (search_flags & SEARCH_CASE_SENSITIVE) ? p_methods[i].keywords : p_methods[i].keywords.to_lower();
|
2024-02-17 17:06:35 +00:00
|
|
|
MemberMatch<DocData::MethodDoc> method;
|
|
|
|
method.name = _all_terms_in_name(method_name);
|
|
|
|
method.keyword = _match_keywords_in_all_terms(keywords);
|
|
|
|
if (method.name || !method.keyword.is_empty() ||
|
2022-09-04 08:18:23 +00:00
|
|
|
(term.begins_with(".") && method_name.begins_with(term.substr(1))) ||
|
|
|
|
(term.ends_with("(") && method_name.ends_with(term.left(term.length() - 1).strip_edges())) ||
|
|
|
|
(term.begins_with(".") && term.ends_with("(") && method_name == term.substr(1, term.length() - 2).strip_edges())) {
|
2024-02-17 17:06:35 +00:00
|
|
|
method.doc = const_cast<DocData::MethodDoc *>(&p_methods[i]);
|
|
|
|
r_match_methods->push_back(method);
|
2022-09-04 08:18:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-03 16:18:46 +00:00
|
|
|
bool EditorHelpSearch::Runner::_all_terms_in_name(const String &p_name) const {
|
2022-09-04 08:18:23 +00:00
|
|
|
for (int i = 0; i < terms.size(); i++) {
|
2023-07-03 16:18:46 +00:00
|
|
|
if (!_match_string(terms[i], p_name)) {
|
2022-09-04 08:18:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-02-17 17:06:35 +00:00
|
|
|
String EditorHelpSearch::Runner::_match_keywords_in_all_terms(const String &p_keywords) const {
|
|
|
|
String matching_keyword;
|
|
|
|
for (int i = 0; i < terms.size(); i++) {
|
|
|
|
matching_keyword = _match_keywords(terms[i], p_keywords);
|
|
|
|
if (matching_keyword.is_empty()) {
|
|
|
|
return String();
|
2023-07-03 16:18:46 +00:00
|
|
|
}
|
|
|
|
}
|
2024-02-17 17:06:35 +00:00
|
|
|
return matching_keyword;
|
2023-07-03 16:18:46 +00:00
|
|
|
}
|
|
|
|
|
2017-12-10 23:56:49 +00:00
|
|
|
bool EditorHelpSearch::Runner::_match_string(const String &p_term, const String &p_string) const {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (search_flags & SEARCH_CASE_SENSITIVE) {
|
2024-05-06 14:20:20 +00:00
|
|
|
return p_string.contains(p_term);
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2024-05-06 08:26:10 +00:00
|
|
|
return p_string.containsn(p_term);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-12-10 23:56:49 +00:00
|
|
|
}
|
|
|
|
|
2024-02-17 17:06:35 +00:00
|
|
|
String EditorHelpSearch::Runner::_match_keywords(const String &p_term, const String &p_keywords) const {
|
|
|
|
for (const String &k : p_keywords.split(",")) {
|
|
|
|
const String keyword = k.strip_edges();
|
|
|
|
if (_match_string(p_term, keyword)) {
|
|
|
|
return keyword;
|
2023-07-03 16:18:46 +00:00
|
|
|
}
|
|
|
|
}
|
2024-02-17 17:06:35 +00:00
|
|
|
return String();
|
2023-07-03 16:18:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorHelpSearch::Runner::_match_item(TreeItem *p_item, const String &p_text, bool p_is_keywords) {
|
|
|
|
if (p_text.is_empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-12-07 14:51:40 +00:00
|
|
|
float inverse_length = 1.0f / float(p_text.length());
|
2021-03-19 21:49:21 +00:00
|
|
|
|
|
|
|
// Favor types where search term is a substring close to the start of the type.
|
|
|
|
float w = 0.5f;
|
|
|
|
int pos = p_text.findn(term);
|
2023-12-07 14:51:40 +00:00
|
|
|
float score = (pos > -1) ? 1.0f - w * MIN(1, 3 * pos * inverse_length) : MAX(0.0f, 0.9f - w);
|
2021-03-19 21:49:21 +00:00
|
|
|
|
|
|
|
// Favor shorter items: they resemble the search term more.
|
|
|
|
w = 0.1f;
|
|
|
|
score *= (1 - w) + w * (term.length() * inverse_length);
|
|
|
|
|
2023-07-03 16:18:46 +00:00
|
|
|
// Reduce the score of keywords, since they are an indirect match.
|
|
|
|
if (p_is_keywords) {
|
|
|
|
score *= 0.9f;
|
|
|
|
}
|
|
|
|
|
2023-12-07 14:51:40 +00:00
|
|
|
// Replace current match if term is short as we are searching in reverse.
|
|
|
|
if (match_highest_score == 0 || score > match_highest_score || (score == match_highest_score && term.length() == 1)) {
|
2021-03-19 21:49:21 +00:00
|
|
|
matched_item = p_item;
|
|
|
|
match_highest_score = score;
|
2017-12-10 23:56:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-01 16:11:19 +00:00
|
|
|
String EditorHelpSearch::Runner::_build_method_tooltip(const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc) const {
|
|
|
|
String tooltip = p_doc->return_type + " " + p_class_doc->name + "." + p_doc->name + "(";
|
|
|
|
for (int i = 0; i < p_doc->arguments.size(); i++) {
|
|
|
|
const DocData::ArgumentDoc &arg = p_doc->arguments[i];
|
|
|
|
tooltip += arg.type + " " + arg.name;
|
|
|
|
if (!arg.default_value.is_empty()) {
|
|
|
|
tooltip += " = " + arg.default_value;
|
|
|
|
}
|
|
|
|
if (i < p_doc->arguments.size() - 1) {
|
|
|
|
tooltip += ", ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tooltip += ")";
|
2024-02-17 17:06:35 +00:00
|
|
|
tooltip += _build_keywords_tooltip(p_doc->keywords);
|
2022-09-01 16:11:19 +00:00
|
|
|
return tooltip;
|
|
|
|
}
|
|
|
|
|
2024-02-17 17:06:35 +00:00
|
|
|
String EditorHelpSearch::Runner::_build_keywords_tooltip(const String &p_keywords) const {
|
|
|
|
String tooltip;
|
|
|
|
if (p_keywords.is_empty()) {
|
|
|
|
return tooltip;
|
|
|
|
}
|
|
|
|
|
|
|
|
tooltip = "\n\n" + TTR("Keywords") + ": ";
|
|
|
|
|
|
|
|
for (const String &keyword : p_keywords.split(",")) {
|
|
|
|
tooltip += keyword.strip_edges().quote() + ", ";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove trailing comma and space.
|
|
|
|
return tooltip.left(-2);
|
|
|
|
}
|
|
|
|
|
2023-12-07 14:51:40 +00:00
|
|
|
TreeItem *EditorHelpSearch::Runner::_create_class_hierarchy(const DocData::ClassDoc *p_class_doc, const String &p_matching_keyword, bool p_gray) {
|
|
|
|
if (p_class_doc->name.is_empty()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (TreeItem **found = class_items.getptr(p_class_doc->name)) {
|
|
|
|
return *found;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure parent nodes are created first.
|
|
|
|
TreeItem *parent_item = root_item;
|
|
|
|
if (!p_class_doc->inherits.is_empty()) {
|
|
|
|
if (class_items.has(p_class_doc->inherits)) {
|
|
|
|
parent_item = class_items[p_class_doc->inherits];
|
|
|
|
} else if (const DocData::ClassDoc *found = EditorHelp::get_doc_data()->class_list.getptr(p_class_doc->inherits)) {
|
|
|
|
parent_item = _create_class_hierarchy(found, String(), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TreeItem *class_item = _create_class_item(parent_item, p_class_doc, p_gray, p_matching_keyword);
|
|
|
|
class_items[p_class_doc->name] = class_item;
|
|
|
|
return class_item;
|
|
|
|
}
|
|
|
|
|
2017-12-10 23:56:49 +00:00
|
|
|
TreeItem *EditorHelpSearch::Runner::_create_class_hierarchy(const ClassMatch &p_match) {
|
2021-10-30 01:42:57 +00:00
|
|
|
if (p_match.doc->name.is_empty()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-05-14 14:41:43 +00:00
|
|
|
if (class_items.has(p_match.doc->name)) {
|
2017-12-10 23:56:49 +00:00
|
|
|
return class_items[p_match.doc->name];
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-12-10 23:56:49 +00:00
|
|
|
|
|
|
|
// Ensure parent nodes are created first.
|
2022-09-29 09:53:28 +00:00
|
|
|
TreeItem *parent_item = root_item;
|
2021-12-09 09:42:46 +00:00
|
|
|
if (!p_match.doc->inherits.is_empty()) {
|
2017-12-10 23:56:49 +00:00
|
|
|
if (class_items.has(p_match.doc->inherits)) {
|
2022-09-29 09:53:28 +00:00
|
|
|
parent_item = class_items[p_match.doc->inherits];
|
2017-12-10 23:56:49 +00:00
|
|
|
} else {
|
|
|
|
ClassMatch &base_match = matches[p_match.doc->inherits];
|
2021-10-30 01:42:57 +00:00
|
|
|
if (base_match.doc) {
|
2022-09-29 09:53:28 +00:00
|
|
|
parent_item = _create_class_hierarchy(base_match);
|
2021-10-30 01:42:57 +00:00
|
|
|
}
|
2017-12-10 23:56:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-17 17:06:35 +00:00
|
|
|
TreeItem *class_item = _create_class_item(parent_item, p_match.doc, !p_match.name && p_match.keyword.is_empty(), p_match.name ? String() : p_match.keyword);
|
2017-12-10 23:56:49 +00:00
|
|
|
class_items[p_match.doc->name] = class_item;
|
|
|
|
return class_item;
|
|
|
|
}
|
|
|
|
|
2023-12-02 12:44:40 +00:00
|
|
|
bool EditorHelpSearch::Runner::_find_or_create_item(TreeItem *p_parent, const String &p_item_meta, TreeItem *&r_item) {
|
|
|
|
// Attempt to find in cache.
|
|
|
|
if (tree_cache->item_cache.has(p_item_meta)) {
|
|
|
|
r_item = tree_cache->item_cache[p_item_meta];
|
|
|
|
|
|
|
|
// Remove from cache.
|
|
|
|
tree_cache->item_cache.erase(p_item_meta);
|
|
|
|
|
|
|
|
// Add to tree.
|
|
|
|
p_parent->add_child(r_item);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
// Otherwise create item.
|
|
|
|
r_item = results_tree->create_item(p_parent);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-17 17:06:35 +00:00
|
|
|
TreeItem *EditorHelpSearch::Runner::_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray, const String &p_matching_keyword) {
|
2022-03-07 13:50:02 +00:00
|
|
|
String tooltip = DTR(p_doc->brief_description.strip_edges());
|
2024-02-17 17:06:35 +00:00
|
|
|
tooltip += _build_keywords_tooltip(p_doc->keywords);
|
2017-12-10 23:56:49 +00:00
|
|
|
|
2023-12-02 12:44:40 +00:00
|
|
|
const String item_meta = "class_name:" + p_doc->name;
|
|
|
|
|
|
|
|
TreeItem *item = nullptr;
|
|
|
|
if (_find_or_create_item(p_parent, item_meta, item)) {
|
|
|
|
item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_doc->name));
|
|
|
|
item->set_text(1, TTR("Class"));
|
|
|
|
item->set_tooltip_text(0, tooltip);
|
|
|
|
item->set_tooltip_text(1, tooltip);
|
|
|
|
item->set_metadata(0, item_meta);
|
|
|
|
if (p_doc->is_deprecated) {
|
|
|
|
Ref<Texture2D> error_icon = ui_service->get_editor_theme_icon(SNAME("StatusError"));
|
|
|
|
item->add_button(0, error_icon, 0, false, TTR("This class is marked as deprecated."));
|
|
|
|
} else if (p_doc->is_experimental) {
|
|
|
|
Ref<Texture2D> warning_icon = ui_service->get_editor_theme_icon(SNAME("NodeWarning"));
|
|
|
|
item->add_button(0, warning_icon, 0, false, TTR("This class is marked as experimental."));
|
|
|
|
}
|
|
|
|
}
|
2023-12-07 14:51:40 +00:00
|
|
|
// Cached item might be collapsed.
|
|
|
|
item->set_collapsed(false);
|
2023-12-02 12:44:40 +00:00
|
|
|
|
2017-12-10 23:56:49 +00:00
|
|
|
if (p_gray) {
|
|
|
|
item->set_custom_color(0, disabled_color);
|
|
|
|
item->set_custom_color(1, disabled_color);
|
2023-12-02 12:44:40 +00:00
|
|
|
} else {
|
|
|
|
item->clear_custom_color(0);
|
|
|
|
item->clear_custom_color(1);
|
2022-08-28 06:17:25 +00:00
|
|
|
}
|
|
|
|
|
2024-02-17 17:06:35 +00:00
|
|
|
if (p_matching_keyword.is_empty()) {
|
|
|
|
item->set_text(0, p_doc->name);
|
|
|
|
} else {
|
|
|
|
item->set_text(0, p_doc->name + " - " + TTR(vformat("Matches the \"%s\" keyword.", p_matching_keyword)));
|
|
|
|
}
|
|
|
|
|
2023-12-07 14:51:40 +00:00
|
|
|
if (!term.is_empty()) {
|
|
|
|
_match_item(item, p_doc->name);
|
|
|
|
}
|
2023-07-03 16:18:46 +00:00
|
|
|
for (const String &keyword : p_doc->keywords.split(",")) {
|
|
|
|
_match_item(item, keyword.strip_edges(), true);
|
|
|
|
}
|
2017-12-10 23:56:49 +00:00
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2023-12-07 14:51:40 +00:00
|
|
|
TreeItem *EditorHelpSearch::Runner::_create_constructor_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::MethodDoc> &p_match) {
|
|
|
|
String tooltip = p_class_doc->name + "(";
|
|
|
|
String text = p_class_doc->name + "(";
|
|
|
|
for (int i = 0; i < p_match.doc->arguments.size(); i++) {
|
|
|
|
const DocData::ArgumentDoc &arg = p_match.doc->arguments[i];
|
|
|
|
tooltip += arg.type + " " + arg.name;
|
|
|
|
text += arg.type;
|
|
|
|
if (!arg.default_value.is_empty()) {
|
|
|
|
tooltip += " = " + arg.default_value;
|
|
|
|
}
|
|
|
|
if (i < p_match.doc->arguments.size() - 1) {
|
|
|
|
tooltip += ", ";
|
|
|
|
text += ", ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tooltip += ")";
|
|
|
|
tooltip += _build_keywords_tooltip(p_match.doc->keywords);
|
|
|
|
text += ")";
|
|
|
|
return _create_member_item(p_parent, p_class_doc->name, SNAME("MemberConstructor"), p_match.doc->name, text, TTRC("Constructor"), "method", tooltip, p_match.doc->keywords, p_match.doc->is_deprecated, p_match.doc->is_experimental, p_match.name ? String() : p_match.keyword);
|
|
|
|
}
|
|
|
|
|
|
|
|
TreeItem *EditorHelpSearch::Runner::_create_method_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::MethodDoc> &p_match) {
|
2024-02-17 17:06:35 +00:00
|
|
|
String tooltip = _build_method_tooltip(p_class_doc, p_match.doc);
|
2023-12-07 14:51:40 +00:00
|
|
|
return _create_member_item(p_parent, p_class_doc->name, SNAME("MemberMethod"), p_match.doc->name, p_match.doc->name, TTRC("Method"), "method", tooltip, p_match.doc->keywords, p_match.doc->is_deprecated, p_match.doc->is_experimental, p_match.name ? String() : p_match.keyword);
|
|
|
|
}
|
|
|
|
|
|
|
|
TreeItem *EditorHelpSearch::Runner::_create_operator_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::MethodDoc> &p_match) {
|
|
|
|
String tooltip = _build_method_tooltip(p_class_doc, p_match.doc);
|
|
|
|
String text = p_match.doc->name;
|
|
|
|
if (!p_match.doc->arguments.is_empty()) {
|
|
|
|
text += "(" + p_match.doc->arguments[0].type + ")";
|
|
|
|
}
|
|
|
|
return _create_member_item(p_parent, p_class_doc->name, SNAME("MemberOperator"), p_match.doc->name, text, TTRC("Operator"), "method", tooltip, p_match.doc->keywords, p_match.doc->is_deprecated, p_match.doc->is_experimental, p_match.name ? String() : p_match.keyword);
|
2017-12-10 23:56:49 +00:00
|
|
|
}
|
|
|
|
|
2024-02-17 17:06:35 +00:00
|
|
|
TreeItem *EditorHelpSearch::Runner::_create_signal_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::MethodDoc> &p_match) {
|
|
|
|
String tooltip = _build_method_tooltip(p_class_doc, p_match.doc);
|
2023-12-07 14:51:40 +00:00
|
|
|
return _create_member_item(p_parent, p_class_doc->name, SNAME("MemberSignal"), p_match.doc->name, p_match.doc->name, TTRC("Signal"), "signal", tooltip, p_match.doc->keywords, p_match.doc->is_deprecated, p_match.doc->is_experimental, p_match.name ? String() : p_match.keyword);
|
2017-12-10 23:56:49 +00:00
|
|
|
}
|
|
|
|
|
2024-02-17 17:06:35 +00:00
|
|
|
TreeItem *EditorHelpSearch::Runner::_create_annotation_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::MethodDoc> &p_match) {
|
|
|
|
String tooltip = _build_method_tooltip(p_class_doc, p_match.doc);
|
|
|
|
// Hide the redundant leading @ symbol.
|
|
|
|
String text = p_match.doc->name.substr(1);
|
2023-12-07 14:51:40 +00:00
|
|
|
return _create_member_item(p_parent, p_class_doc->name, SNAME("MemberAnnotation"), p_match.doc->name, text, TTRC("Annotation"), "annotation", tooltip, p_match.doc->keywords, p_match.doc->is_deprecated, p_match.doc->is_experimental, p_match.name ? String() : p_match.keyword);
|
2022-09-01 16:11:19 +00:00
|
|
|
}
|
|
|
|
|
2024-02-17 17:06:35 +00:00
|
|
|
TreeItem *EditorHelpSearch::Runner::_create_constant_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::ConstantDoc> &p_match) {
|
|
|
|
String tooltip = p_class_doc->name + "." + p_match.doc->name;
|
|
|
|
tooltip += _build_keywords_tooltip(p_match.doc->keywords);
|
2023-12-07 14:51:40 +00:00
|
|
|
return _create_member_item(p_parent, p_class_doc->name, SNAME("MemberConstant"), p_match.doc->name, p_match.doc->name, TTRC("Constant"), "constant", tooltip, p_match.doc->keywords, p_match.doc->is_deprecated, p_match.doc->is_experimental, p_match.name ? String() : p_match.keyword);
|
2017-12-10 23:56:49 +00:00
|
|
|
}
|
|
|
|
|
2024-02-17 17:06:35 +00:00
|
|
|
TreeItem *EditorHelpSearch::Runner::_create_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::PropertyDoc> &p_match) {
|
|
|
|
String tooltip = p_match.doc->type + " " + p_class_doc->name + "." + p_match.doc->name;
|
|
|
|
tooltip += "\n " + p_class_doc->name + "." + p_match.doc->setter + "(value) setter";
|
|
|
|
tooltip += "\n " + p_class_doc->name + "." + p_match.doc->getter + "() getter";
|
2023-12-07 14:51:40 +00:00
|
|
|
return _create_member_item(p_parent, p_class_doc->name, SNAME("MemberProperty"), p_match.doc->name, p_match.doc->name, TTRC("Property"), "property", tooltip, p_match.doc->keywords, p_match.doc->is_deprecated, p_match.doc->is_experimental, p_match.name ? String() : p_match.keyword);
|
2017-12-10 23:56:49 +00:00
|
|
|
}
|
|
|
|
|
2024-02-17 17:06:35 +00:00
|
|
|
TreeItem *EditorHelpSearch::Runner::_create_theme_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::ThemeItemDoc> &p_match) {
|
|
|
|
String tooltip = p_match.doc->type + " " + p_class_doc->name + "." + p_match.doc->name;
|
|
|
|
tooltip += _build_keywords_tooltip(p_match.doc->keywords);
|
2024-09-04 07:54:50 +00:00
|
|
|
return _create_member_item(p_parent, p_class_doc->name, SNAME("MemberTheme"), p_match.doc->name, p_match.doc->name, TTRC("Theme Property"), "theme_item", p_match.doc->keywords, tooltip, p_match.doc->is_deprecated, p_match.doc->is_experimental, p_match.name ? String() : p_match.keyword);
|
2017-12-10 23:56:49 +00:00
|
|
|
}
|
|
|
|
|
2023-12-07 14:51:40 +00:00
|
|
|
TreeItem *EditorHelpSearch::Runner::_create_member_item(TreeItem *p_parent, const String &p_class_name, const StringName &p_icon, const String &p_name, const String &p_text, const String &p_type, const String &p_metatype, const String &p_tooltip, const String &p_keywords, bool p_is_deprecated, bool p_is_experimental, const String &p_matching_keyword) {
|
2023-12-02 12:44:40 +00:00
|
|
|
const String item_meta = "class_" + p_metatype + ":" + p_class_name + ":" + p_name;
|
|
|
|
|
|
|
|
TreeItem *item = nullptr;
|
|
|
|
if (_find_or_create_item(p_parent, item_meta, item)) {
|
|
|
|
item->set_icon(0, ui_service->get_editor_theme_icon(p_icon));
|
|
|
|
item->set_text(1, TTRGET(p_type));
|
|
|
|
item->set_tooltip_text(0, p_tooltip);
|
|
|
|
item->set_tooltip_text(1, p_tooltip);
|
|
|
|
item->set_metadata(0, item_meta);
|
|
|
|
|
2024-02-17 17:06:35 +00:00
|
|
|
if (p_is_deprecated) {
|
2023-12-02 12:44:40 +00:00
|
|
|
Ref<Texture2D> error_icon = ui_service->get_editor_theme_icon(SNAME("StatusError"));
|
|
|
|
item->add_button(0, error_icon, 0, false, TTR("This member is marked as deprecated."));
|
2024-02-17 17:06:35 +00:00
|
|
|
} else if (p_is_experimental) {
|
2023-12-02 12:44:40 +00:00
|
|
|
Ref<Texture2D> warning_icon = ui_service->get_editor_theme_icon(SNAME("NodeWarning"));
|
|
|
|
item->add_button(0, warning_icon, 0, false, TTR("This member is marked as experimental."));
|
|
|
|
}
|
2017-12-10 23:56:49 +00:00
|
|
|
}
|
|
|
|
|
2024-02-17 17:06:35 +00:00
|
|
|
String text;
|
2023-12-02 12:44:40 +00:00
|
|
|
if (search_flags & SEARCH_SHOW_HIERARCHY) {
|
2024-02-17 17:06:35 +00:00
|
|
|
text = p_text;
|
2023-12-02 12:44:40 +00:00
|
|
|
} else {
|
2024-02-17 17:06:35 +00:00
|
|
|
text = p_class_name + "." + p_text;
|
|
|
|
}
|
|
|
|
if (!p_matching_keyword.is_empty()) {
|
|
|
|
text += " - " + TTR(vformat("Matches the \"%s\" keyword.", p_matching_keyword));
|
2022-08-28 06:17:25 +00:00
|
|
|
}
|
2024-02-17 17:06:35 +00:00
|
|
|
item->set_text(0, text);
|
2022-08-28 06:17:25 +00:00
|
|
|
|
2023-12-07 14:51:40 +00:00
|
|
|
// Don't match member items for short searches.
|
|
|
|
if (term.length() > 1 || term == "@") {
|
|
|
|
_match_item(item, p_name);
|
|
|
|
}
|
2023-07-03 16:18:46 +00:00
|
|
|
for (const String &keyword : p_keywords.split(",")) {
|
|
|
|
_match_item(item, keyword.strip_edges(), true);
|
|
|
|
}
|
2017-12-10 23:56:49 +00:00
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorHelpSearch::Runner::work(uint64_t slot) {
|
|
|
|
// Return true when the search has been completed, otherwise false.
|
|
|
|
const uint64_t until = OS::get_singleton()->get_ticks_usec() + slot;
|
2023-12-07 14:51:40 +00:00
|
|
|
if (term.length() > 1 || term == "@") {
|
|
|
|
while (!_slice()) {
|
|
|
|
if (OS::get_singleton()->get_ticks_usec() > until) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while (!_fill()) {
|
|
|
|
if (OS::get_singleton()->get_ticks_usec() > until) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-10 23:56:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-12-02 12:44:40 +00:00
|
|
|
EditorHelpSearch::Runner::Runner(Control *p_icon_service, Tree *p_results_tree, TreeCache *p_tree_cache, const String &p_term, int p_search_flags) :
|
2018-12-08 20:07:33 +00:00
|
|
|
ui_service(p_icon_service),
|
|
|
|
results_tree(p_results_tree),
|
2023-12-02 12:44:40 +00:00
|
|
|
tree_cache(p_tree_cache),
|
2023-12-07 14:51:40 +00:00
|
|
|
term((p_search_flags & SEARCH_CASE_SENSITIVE) == 0 ? p_term.to_lower() : p_term),
|
2018-12-08 20:07:33 +00:00
|
|
|
search_flags(p_search_flags),
|
2024-01-15 12:14:55 +00:00
|
|
|
disabled_color(ui_service->get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor))) {
|
2017-12-10 23:56:49 +00:00
|
|
|
}
|