1 /*************************************************************************/
2 /*  editor_help_search.cpp                                               */
3 /*************************************************************************/
4 /*                       This file is part of:                           */
5 /*                           GODOT ENGINE                                */
6 /*                      https://godotengine.org                          */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */
9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */
10 /*                                                                       */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the       */
13 /* "Software"), to deal in the Software without restriction, including   */
14 /* without limitation the rights to use, copy, modify, merge, publish,   */
15 /* distribute, sublicense, and/or sell copies of the Software, and to    */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions:                                             */
18 /*                                                                       */
19 /* The above copyright notice and this permission notice shall be        */
20 /* included in all copies or substantial portions of the Software.       */
21 /*                                                                       */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
29 /*************************************************************************/
30 
31 #include "editor_help_search.h"
32 
33 #include "core/os/keyboard.h"
34 #include "editor_feature_profile.h"
35 #include "editor_node.h"
36 #include "editor_scale.h"
37 
_update_icons()38 void EditorHelpSearch::_update_icons() {
39 
40 	search_box->set_right_icon(get_icon("Search", "EditorIcons"));
41 	search_box->set_clear_button_enabled(true);
42 	search_box->add_icon_override("right_icon", get_icon("Search", "EditorIcons"));
43 	case_sensitive_button->set_icon(get_icon("MatchCase", "EditorIcons"));
44 	hierarchy_button->set_icon(get_icon("ClassList", "EditorIcons"));
45 
46 	if (is_visible_in_tree())
47 		_update_results();
48 }
49 
_update_results()50 void EditorHelpSearch::_update_results() {
51 
52 	String term = search_box->get_text();
53 
54 	int search_flags = filter_combo->get_selected_id();
55 	if (case_sensitive_button->is_pressed())
56 		search_flags |= SEARCH_CASE_SENSITIVE;
57 	if (hierarchy_button->is_pressed())
58 		search_flags |= SEARCH_SHOW_HIERARCHY;
59 
60 	search = Ref<Runner>(memnew(Runner(this, results_tree, term, search_flags)));
61 	set_process(true);
62 }
63 
_search_box_gui_input(const Ref<InputEvent> & p_event)64 void EditorHelpSearch::_search_box_gui_input(const Ref<InputEvent> &p_event) {
65 
66 	// Redirect up and down navigational key events to the results list.
67 	Ref<InputEventKey> key = p_event;
68 	if (key.is_valid()) {
69 		switch (key->get_scancode()) {
70 			case KEY_UP:
71 			case KEY_DOWN:
72 			case KEY_PAGEUP:
73 			case KEY_PAGEDOWN: {
74 				results_tree->call("_gui_input", key);
75 				search_box->accept_event();
76 			} break;
77 		}
78 	}
79 }
80 
_search_box_text_changed(const String & p_text)81 void EditorHelpSearch::_search_box_text_changed(const String &p_text) {
82 
83 	_update_results();
84 }
85 
_filter_combo_item_selected(int p_option)86 void EditorHelpSearch::_filter_combo_item_selected(int p_option) {
87 
88 	_update_results();
89 }
90 
_confirmed()91 void EditorHelpSearch::_confirmed() {
92 
93 	TreeItem *item = results_tree->get_selected();
94 	if (!item)
95 		return;
96 
97 	// Activate the script editor and emit the signal with the documentation link to display.
98 	EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
99 
100 	emit_signal("go_to_help", item->get_metadata(0));
101 
102 	hide();
103 }
104 
_notification(int p_what)105 void EditorHelpSearch::_notification(int p_what) {
106 
107 	switch (p_what) {
108 		case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
109 
110 			_update_icons();
111 		} break;
112 		case NOTIFICATION_ENTER_TREE: {
113 
114 			connect("confirmed", this, "_confirmed");
115 			_update_icons();
116 		} break;
117 		case NOTIFICATION_POPUP_HIDE: {
118 
119 			results_tree->call_deferred("clear"); // Wait for the Tree's mouse event propagation.
120 			get_ok()->set_disabled(true);
121 			EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "search_help", get_rect());
122 		} break;
123 		case NOTIFICATION_PROCESS: {
124 
125 			// Update background search.
126 			if (search.is_valid()) {
127 				if (search->work()) {
128 					// Search done.
129 
130 					// Only point to the perfect match if it's a new search, and not just reopening a old one.
131 					if (!old_search)
132 						results_tree->ensure_cursor_is_visible();
133 					else
134 						old_search = false;
135 
136 					get_ok()->set_disabled(!results_tree->get_selected());
137 
138 					search = Ref<Runner>();
139 					set_process(false);
140 				}
141 			} else {
142 				set_process(false);
143 			}
144 		} break;
145 	}
146 }
147 
_bind_methods()148 void EditorHelpSearch::_bind_methods() {
149 
150 	ClassDB::bind_method(D_METHOD("_update_results"), &EditorHelpSearch::_update_results);
151 	ClassDB::bind_method(D_METHOD("_search_box_gui_input"), &EditorHelpSearch::_search_box_gui_input);
152 	ClassDB::bind_method(D_METHOD("_search_box_text_changed"), &EditorHelpSearch::_search_box_text_changed);
153 	ClassDB::bind_method(D_METHOD("_filter_combo_item_selected"), &EditorHelpSearch::_filter_combo_item_selected);
154 	ClassDB::bind_method(D_METHOD("_confirmed"), &EditorHelpSearch::_confirmed);
155 	ADD_SIGNAL(MethodInfo("go_to_help"));
156 }
157 
popup_dialog()158 void EditorHelpSearch::popup_dialog() {
159 
160 	popup_dialog(search_box->get_text());
161 }
162 
popup_dialog(const String & p_term)163 void EditorHelpSearch::popup_dialog(const String &p_term) {
164 
165 	// Restore valid window bounds or pop up at default size.
166 	Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "search_help", Rect2());
167 	if (saved_size != Rect2())
168 		popup(saved_size);
169 	else
170 		popup_centered_ratio(0.5F);
171 
172 	if (p_term == "") {
173 		search_box->clear();
174 	} else {
175 		if (old_term == p_term)
176 			old_search = true;
177 		else
178 			old_term = p_term;
179 
180 		search_box->set_text(p_term);
181 		search_box->select_all();
182 	}
183 	search_box->grab_focus();
184 	_update_results();
185 }
186 
EditorHelpSearch()187 EditorHelpSearch::EditorHelpSearch() {
188 
189 	old_search = false;
190 
191 	set_hide_on_ok(false);
192 	set_resizable(true);
193 	set_title(TTR("Search Help"));
194 
195 	get_ok()->set_disabled(true);
196 	get_ok()->set_text(TTR("Open"));
197 
198 	// Split search and results area.
199 	VBoxContainer *vbox = memnew(VBoxContainer);
200 	add_child(vbox);
201 
202 	// Create the search box and filter controls (at the top).
203 	HBoxContainer *hbox = memnew(HBoxContainer);
204 	vbox->add_child(hbox);
205 
206 	search_box = memnew(LineEdit);
207 	search_box->set_custom_minimum_size(Size2(200, 0) * EDSCALE);
208 	search_box->set_h_size_flags(SIZE_EXPAND_FILL);
209 	search_box->connect("gui_input", this, "_search_box_gui_input");
210 	search_box->connect("text_changed", this, "_search_box_text_changed");
211 	register_text_enter(search_box);
212 	hbox->add_child(search_box);
213 
214 	case_sensitive_button = memnew(ToolButton);
215 	case_sensitive_button->set_tooltip(TTR("Case Sensitive"));
216 	case_sensitive_button->connect("pressed", this, "_update_results");
217 	case_sensitive_button->set_toggle_mode(true);
218 	case_sensitive_button->set_focus_mode(FOCUS_NONE);
219 	hbox->add_child(case_sensitive_button);
220 
221 	hierarchy_button = memnew(ToolButton);
222 	hierarchy_button->set_tooltip(TTR("Show Hierarchy"));
223 	hierarchy_button->connect("pressed", this, "_update_results");
224 	hierarchy_button->set_toggle_mode(true);
225 	hierarchy_button->set_pressed(true);
226 	hierarchy_button->set_focus_mode(FOCUS_NONE);
227 	hbox->add_child(hierarchy_button);
228 
229 	filter_combo = memnew(OptionButton);
230 	filter_combo->set_custom_minimum_size(Size2(200, 0) * EDSCALE);
231 	filter_combo->set_stretch_ratio(0); // Fixed width.
232 	filter_combo->add_item(TTR("Display All"), SEARCH_ALL);
233 	filter_combo->add_separator();
234 	filter_combo->add_item(TTR("Classes Only"), SEARCH_CLASSES);
235 	filter_combo->add_item(TTR("Methods Only"), SEARCH_METHODS);
236 	filter_combo->add_item(TTR("Signals Only"), SEARCH_SIGNALS);
237 	filter_combo->add_item(TTR("Constants Only"), SEARCH_CONSTANTS);
238 	filter_combo->add_item(TTR("Properties Only"), SEARCH_PROPERTIES);
239 	filter_combo->add_item(TTR("Theme Properties Only"), SEARCH_THEME_ITEMS);
240 	filter_combo->connect("item_selected", this, "_filter_combo_item_selected");
241 	hbox->add_child(filter_combo);
242 
243 	// Create the results tree.
244 	results_tree = memnew(Tree);
245 	results_tree->set_v_size_flags(SIZE_EXPAND_FILL);
246 	results_tree->set_columns(2);
247 	results_tree->set_column_title(0, TTR("Name"));
248 	results_tree->set_column_title(1, TTR("Member Type"));
249 	results_tree->set_column_expand(1, false);
250 	results_tree->set_column_min_width(1, 150 * EDSCALE);
251 	results_tree->set_custom_minimum_size(Size2(0, 100) * EDSCALE);
252 	results_tree->set_hide_root(true);
253 	results_tree->set_select_mode(Tree::SELECT_ROW);
254 	results_tree->connect("item_activated", this, "_confirmed");
255 	results_tree->connect("item_selected", get_ok(), "set_disabled", varray(false));
256 	vbox->add_child(results_tree, true);
257 }
258 
_is_class_disabled_by_feature_profile(const StringName & p_class)259 bool EditorHelpSearch::Runner::_is_class_disabled_by_feature_profile(const StringName &p_class) {
260 
261 	Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile();
262 	if (profile.is_null()) {
263 		return false;
264 	}
265 
266 	StringName class_name = p_class;
267 	while (class_name != StringName()) {
268 
269 		if (!ClassDB::class_exists(class_name)) {
270 			return false;
271 		}
272 
273 		if (profile->is_class_disabled(class_name)) {
274 			return true;
275 		}
276 		class_name = ClassDB::get_parent_class(class_name);
277 	}
278 
279 	return false;
280 }
281 
_slice()282 bool EditorHelpSearch::Runner::_slice() {
283 
284 	bool phase_done = false;
285 	switch (phase) {
286 		case PHASE_MATCH_CLASSES_INIT:
287 			phase_done = _phase_match_classes_init();
288 			break;
289 		case PHASE_MATCH_CLASSES:
290 			phase_done = _phase_match_classes();
291 			break;
292 		case PHASE_CLASS_ITEMS_INIT:
293 			phase_done = _phase_class_items_init();
294 			break;
295 		case PHASE_CLASS_ITEMS:
296 			phase_done = _phase_class_items();
297 			break;
298 		case PHASE_MEMBER_ITEMS_INIT:
299 			phase_done = _phase_member_items_init();
300 			break;
301 		case PHASE_MEMBER_ITEMS:
302 			phase_done = _phase_member_items();
303 			break;
304 		case PHASE_SELECT_MATCH:
305 			phase_done = _phase_select_match();
306 			break;
307 		case PHASE_MAX:
308 			return true;
309 		default:
310 			WARN_PRINTS("Invalid or unhandled phase in EditorHelpSearch::Runner, aborting search.");
311 			return true;
312 	};
313 
314 	if (phase_done)
315 		phase++;
316 	return false;
317 }
318 
_phase_match_classes_init()319 bool EditorHelpSearch::Runner::_phase_match_classes_init() {
320 
321 	iterator_doc = EditorHelp::get_doc_data()->class_list.front();
322 	matches.clear();
323 	matched_item = NULL;
324 
325 	return true;
326 }
327 
_phase_match_classes()328 bool EditorHelpSearch::Runner::_phase_match_classes() {
329 
330 	DocData::ClassDoc &class_doc = iterator_doc->value();
331 	if (!_is_class_disabled_by_feature_profile(class_doc.name)) {
332 
333 		matches[class_doc.name] = ClassMatch();
334 		ClassMatch &match = matches[class_doc.name];
335 
336 		match.doc = &class_doc;
337 
338 		// Match class name.
339 		if (search_flags & SEARCH_CLASSES)
340 			match.name = term == "" || _match_string(term, class_doc.name);
341 
342 		// Match members if the term is long enough.
343 		if (term.length() > 1) {
344 			if (search_flags & SEARCH_METHODS)
345 				for (int i = 0; i < class_doc.methods.size(); i++) {
346 					String method_name = (search_flags & SEARCH_CASE_SENSITIVE) ? class_doc.methods[i].name : class_doc.methods[i].name.to_lower();
347 					if (method_name.find(term) > -1 ||
348 							(term.begins_with(".") && method_name.begins_with(term.right(1))) ||
349 							(term.ends_with("(") && method_name.ends_with(term.left(term.length() - 1).strip_edges())) ||
350 							(term.begins_with(".") && term.ends_with("(") && method_name == term.substr(1, term.length() - 2).strip_edges())) {
351 						match.methods.push_back(const_cast<DocData::MethodDoc *>(&class_doc.methods[i]));
352 					}
353 				}
354 			if (search_flags & SEARCH_SIGNALS)
355 				for (int i = 0; i < class_doc.signals.size(); i++)
356 					if (_match_string(term, class_doc.signals[i].name))
357 						match.signals.push_back(const_cast<DocData::MethodDoc *>(&class_doc.signals[i]));
358 			if (search_flags & SEARCH_CONSTANTS)
359 				for (int i = 0; i < class_doc.constants.size(); i++)
360 					if (_match_string(term, class_doc.constants[i].name))
361 						match.constants.push_back(const_cast<DocData::ConstantDoc *>(&class_doc.constants[i]));
362 			if (search_flags & SEARCH_PROPERTIES)
363 				for (int i = 0; i < class_doc.properties.size(); i++)
364 					if (_match_string(term, class_doc.properties[i].name) || _match_string(term, class_doc.properties[i].getter) || _match_string(term, class_doc.properties[i].setter))
365 						match.properties.push_back(const_cast<DocData::PropertyDoc *>(&class_doc.properties[i]));
366 			if (search_flags & SEARCH_THEME_ITEMS)
367 				for (int i = 0; i < class_doc.theme_properties.size(); i++)
368 					if (_match_string(term, class_doc.theme_properties[i].name))
369 						match.theme_properties.push_back(const_cast<DocData::PropertyDoc *>(&class_doc.theme_properties[i]));
370 		}
371 	}
372 
373 	iterator_doc = iterator_doc->next();
374 	return !iterator_doc;
375 }
376 
_phase_class_items_init()377 bool EditorHelpSearch::Runner::_phase_class_items_init() {
378 
379 	iterator_match = matches.front();
380 
381 	results_tree->clear();
382 	root_item = results_tree->create_item();
383 	class_items.clear();
384 
385 	return true;
386 }
387 
_phase_class_items()388 bool EditorHelpSearch::Runner::_phase_class_items() {
389 
390 	ClassMatch &match = iterator_match->value();
391 
392 	if (search_flags & SEARCH_SHOW_HIERARCHY) {
393 		if (match.required())
394 			_create_class_hierarchy(match);
395 	} else {
396 		if (match.name)
397 			_create_class_item(root_item, match.doc, false);
398 	}
399 
400 	iterator_match = iterator_match->next();
401 	return !iterator_match;
402 }
403 
_phase_member_items_init()404 bool EditorHelpSearch::Runner::_phase_member_items_init() {
405 
406 	iterator_match = matches.front();
407 
408 	return true;
409 }
410 
_phase_member_items()411 bool EditorHelpSearch::Runner::_phase_member_items() {
412 
413 	ClassMatch &match = iterator_match->value();
414 
415 	TreeItem *parent = (search_flags & SEARCH_SHOW_HIERARCHY) ? class_items[match.doc->name] : root_item;
416 	for (int i = 0; i < match.methods.size(); i++)
417 		_create_method_item(parent, match.doc, match.methods[i]);
418 	for (int i = 0; i < match.signals.size(); i++)
419 		_create_signal_item(parent, match.doc, match.signals[i]);
420 	for (int i = 0; i < match.constants.size(); i++)
421 		_create_constant_item(parent, match.doc, match.constants[i]);
422 	for (int i = 0; i < match.properties.size(); i++)
423 		_create_property_item(parent, match.doc, match.properties[i]);
424 	for (int i = 0; i < match.theme_properties.size(); i++)
425 		_create_theme_property_item(parent, match.doc, match.theme_properties[i]);
426 
427 	iterator_match = iterator_match->next();
428 	return !iterator_match;
429 }
430 
_phase_select_match()431 bool EditorHelpSearch::Runner::_phase_select_match() {
432 
433 	if (matched_item)
434 		matched_item->select(0);
435 	return true;
436 }
437 
_match_string(const String & p_term,const String & p_string) const438 bool EditorHelpSearch::Runner::_match_string(const String &p_term, const String &p_string) const {
439 	if (search_flags & SEARCH_CASE_SENSITIVE) {
440 		return p_string.find(p_term) > -1;
441 	} else {
442 		return p_string.findn(p_term) > -1;
443 	}
444 }
445 
_match_item(TreeItem * p_item,const String & p_text)446 void EditorHelpSearch::Runner::_match_item(TreeItem *p_item, const String &p_text) {
447 
448 	if (!matched_item) {
449 		if (search_flags & SEARCH_CASE_SENSITIVE) {
450 			if (p_text.casecmp_to(term) == 0)
451 				matched_item = p_item;
452 		} else {
453 			if (p_text.nocasecmp_to(term) == 0)
454 				matched_item = p_item;
455 		}
456 	}
457 }
458 
_create_class_hierarchy(const ClassMatch & p_match)459 TreeItem *EditorHelpSearch::Runner::_create_class_hierarchy(const ClassMatch &p_match) {
460 
461 	if (class_items.has(p_match.doc->name))
462 		return class_items[p_match.doc->name];
463 
464 	// Ensure parent nodes are created first.
465 	TreeItem *parent = root_item;
466 	if (p_match.doc->inherits != "") {
467 		if (class_items.has(p_match.doc->inherits)) {
468 			parent = class_items[p_match.doc->inherits];
469 		} else {
470 			ClassMatch &base_match = matches[p_match.doc->inherits];
471 			parent = _create_class_hierarchy(base_match);
472 		}
473 	}
474 
475 	TreeItem *class_item = _create_class_item(parent, p_match.doc, !p_match.name);
476 	class_items[p_match.doc->name] = class_item;
477 	return class_item;
478 }
479 
_create_class_item(TreeItem * p_parent,const DocData::ClassDoc * p_doc,bool p_gray)480 TreeItem *EditorHelpSearch::Runner::_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray) {
481 
482 	Ref<Texture> icon = empty_icon;
483 	if (ui_service->has_icon(p_doc->name, "EditorIcons"))
484 		icon = ui_service->get_icon(p_doc->name, "EditorIcons");
485 	else if (ClassDB::class_exists(p_doc->name) && ClassDB::is_parent_class(p_doc->name, "Object"))
486 		icon = ui_service->get_icon("Object", "EditorIcons");
487 	String tooltip = p_doc->brief_description.strip_edges();
488 
489 	TreeItem *item = results_tree->create_item(p_parent);
490 	item->set_icon(0, icon);
491 	item->set_text(0, p_doc->name);
492 	item->set_text(1, TTR("Class"));
493 	item->set_tooltip(0, tooltip);
494 	item->set_tooltip(1, tooltip);
495 	item->set_metadata(0, "class_name:" + p_doc->name);
496 	if (p_gray) {
497 		item->set_custom_color(0, disabled_color);
498 		item->set_custom_color(1, disabled_color);
499 	}
500 
501 	_match_item(item, p_doc->name);
502 
503 	return item;
504 }
505 
_create_method_item(TreeItem * p_parent,const DocData::ClassDoc * p_class_doc,const DocData::MethodDoc * p_doc)506 TreeItem *EditorHelpSearch::Runner::_create_method_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc) {
507 
508 	String tooltip = p_doc->return_type + " " + p_class_doc->name + "." + p_doc->name + "(";
509 	for (int i = 0; i < p_doc->arguments.size(); i++) {
510 		const DocData::ArgumentDoc &arg = p_doc->arguments[i];
511 		tooltip += arg.type + " " + arg.name;
512 		if (arg.default_value != "")
513 			tooltip += " = " + arg.default_value;
514 		if (i < p_doc->arguments.size() - 1)
515 			tooltip += ", ";
516 	}
517 	tooltip += ")";
518 	return _create_member_item(p_parent, p_class_doc->name, "MemberMethod", p_doc->name, TTRC("Method"), "method", tooltip);
519 }
520 
_create_signal_item(TreeItem * p_parent,const DocData::ClassDoc * p_class_doc,const DocData::MethodDoc * p_doc)521 TreeItem *EditorHelpSearch::Runner::_create_signal_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc) {
522 
523 	String tooltip = p_doc->return_type + " " + p_class_doc->name + "." + p_doc->name + "(";
524 	for (int i = 0; i < p_doc->arguments.size(); i++) {
525 		const DocData::ArgumentDoc &arg = p_doc->arguments[i];
526 		tooltip += arg.type + " " + arg.name;
527 		if (arg.default_value != "")
528 			tooltip += " = " + arg.default_value;
529 		if (i < p_doc->arguments.size() - 1)
530 			tooltip += ", ";
531 	}
532 	tooltip += ")";
533 	return _create_member_item(p_parent, p_class_doc->name, "MemberSignal", p_doc->name, TTRC("Signal"), "signal", tooltip);
534 }
535 
_create_constant_item(TreeItem * p_parent,const DocData::ClassDoc * p_class_doc,const DocData::ConstantDoc * p_doc)536 TreeItem *EditorHelpSearch::Runner::_create_constant_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ConstantDoc *p_doc) {
537 
538 	String tooltip = p_class_doc->name + "." + p_doc->name;
539 	return _create_member_item(p_parent, p_class_doc->name, "MemberConstant", p_doc->name, TTRC("Constant"), "constant", tooltip);
540 }
541 
_create_property_item(TreeItem * p_parent,const DocData::ClassDoc * p_class_doc,const DocData::PropertyDoc * p_doc)542 TreeItem *EditorHelpSearch::Runner::_create_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::PropertyDoc *p_doc) {
543 
544 	String tooltip = p_doc->type + " " + p_class_doc->name + "." + p_doc->name;
545 	tooltip += "\n    " + p_class_doc->name + "." + p_doc->setter + "(value) setter";
546 	tooltip += "\n    " + p_class_doc->name + "." + p_doc->getter + "() getter";
547 	return _create_member_item(p_parent, p_class_doc->name, "MemberProperty", p_doc->name, TTRC("Property"), "property", tooltip);
548 }
549 
_create_theme_property_item(TreeItem * p_parent,const DocData::ClassDoc * p_class_doc,const DocData::PropertyDoc * p_doc)550 TreeItem *EditorHelpSearch::Runner::_create_theme_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::PropertyDoc *p_doc) {
551 
552 	String tooltip = p_doc->type + " " + p_class_doc->name + "." + p_doc->name;
553 	return _create_member_item(p_parent, p_class_doc->name, "MemberTheme", p_doc->name, TTRC("Theme Property"), "theme_item", tooltip);
554 }
555 
_create_member_item(TreeItem * p_parent,const String & p_class_name,const String & p_icon,const String & p_name,const String & p_type,const String & p_metatype,const String & p_tooltip)556 TreeItem *EditorHelpSearch::Runner::_create_member_item(TreeItem *p_parent, const String &p_class_name, const String &p_icon, const String &p_name, const String &p_type, const String &p_metatype, const String &p_tooltip) {
557 
558 	Ref<Texture> icon;
559 	String text;
560 	if (search_flags & SEARCH_SHOW_HIERARCHY) {
561 		icon = ui_service->get_icon(p_icon, "EditorIcons");
562 		text = p_name;
563 	} else {
564 		icon = ui_service->get_icon(p_icon, "EditorIcons");
565 		/*// In flat mode, show the class icon.
566 		if (ui_service->has_icon(p_class_name, "EditorIcons"))
567 			icon = ui_service->get_icon(p_class_name, "EditorIcons");
568 		else if (ClassDB::is_parent_class(p_class_name, "Object"))
569 			icon = ui_service->get_icon("Object", "EditorIcons");*/
570 		text = p_class_name + "." + p_name;
571 	}
572 
573 	TreeItem *item = results_tree->create_item(p_parent);
574 	item->set_icon(0, icon);
575 	item->set_text(0, text);
576 	item->set_text(1, TTRGET(p_type));
577 	item->set_tooltip(0, p_tooltip);
578 	item->set_tooltip(1, p_tooltip);
579 	item->set_metadata(0, "class_" + p_metatype + ":" + p_class_name + ":" + p_name);
580 
581 	_match_item(item, p_name);
582 
583 	return item;
584 }
585 
work(uint64_t slot)586 bool EditorHelpSearch::Runner::work(uint64_t slot) {
587 
588 	// Return true when the search has been completed, otherwise false.
589 	const uint64_t until = OS::get_singleton()->get_ticks_usec() + slot;
590 	while (!_slice())
591 		if (OS::get_singleton()->get_ticks_usec() > until)
592 			return false;
593 	return true;
594 }
595 
Runner(Control * p_icon_service,Tree * p_results_tree,const String & p_term,int p_search_flags)596 EditorHelpSearch::Runner::Runner(Control *p_icon_service, Tree *p_results_tree, const String &p_term, int p_search_flags) :
597 		phase(0),
598 		ui_service(p_icon_service),
599 		results_tree(p_results_tree),
600 		term((p_search_flags & SEARCH_CASE_SENSITIVE) == 0 ? p_term.strip_edges().to_lower() : p_term.strip_edges()),
601 		search_flags(p_search_flags),
602 		empty_icon(ui_service->get_icon("ArrowRight", "EditorIcons")),
603 		disabled_color(ui_service->get_color("disabled_font_color", "Editor")) {
604 }
605