2023-01-05 20:25:55 +08:00
|
|
|
/**************************************************************************/
|
|
|
|
/* editor_help_search.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* 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. */
|
|
|
|
/**************************************************************************/
|
2017-12-11 07:56:49 +08:00
|
|
|
|
|
|
|
#ifndef EDITOR_HELP_SEARCH_H
|
|
|
|
#define EDITOR_HELP_SEARCH_H
|
|
|
|
|
2022-05-13 21:04:37 +08:00
|
|
|
#include "core/templates/rb_map.h"
|
2017-12-11 07:56:49 +08:00
|
|
|
#include "editor/code_editor.h"
|
|
|
|
#include "editor/editor_help.h"
|
|
|
|
#include "editor/editor_plugin.h"
|
|
|
|
#include "scene/gui/option_button.h"
|
|
|
|
#include "scene/gui/tree.h"
|
|
|
|
|
|
|
|
class EditorHelpSearch : public ConfirmationDialog {
|
|
|
|
GDCLASS(EditorHelpSearch, ConfirmationDialog);
|
|
|
|
|
|
|
|
enum SearchFlags {
|
|
|
|
SEARCH_CLASSES = 1 << 0,
|
2021-09-21 10:49:02 +08:00
|
|
|
SEARCH_CONSTRUCTORS = 1 << 1,
|
|
|
|
SEARCH_METHODS = 1 << 2,
|
|
|
|
SEARCH_OPERATORS = 1 << 3,
|
|
|
|
SEARCH_SIGNALS = 1 << 4,
|
|
|
|
SEARCH_CONSTANTS = 1 << 5,
|
|
|
|
SEARCH_PROPERTIES = 1 << 6,
|
|
|
|
SEARCH_THEME_ITEMS = 1 << 7,
|
2022-09-02 00:11:19 +08:00
|
|
|
SEARCH_ANNOTATIONS = 1 << 8,
|
|
|
|
SEARCH_ALL = SEARCH_CLASSES | SEARCH_CONSTRUCTORS | SEARCH_METHODS | SEARCH_OPERATORS | SEARCH_SIGNALS | SEARCH_CONSTANTS | SEARCH_PROPERTIES | SEARCH_THEME_ITEMS | SEARCH_ANNOTATIONS,
|
2017-12-11 07:56:49 +08:00
|
|
|
SEARCH_CASE_SENSITIVE = 1 << 29,
|
|
|
|
SEARCH_SHOW_HIERARCHY = 1 << 30
|
|
|
|
};
|
|
|
|
|
2022-04-04 21:06:57 +08:00
|
|
|
LineEdit *search_box = nullptr;
|
|
|
|
Button *case_sensitive_button = nullptr;
|
|
|
|
Button *hierarchy_button = nullptr;
|
|
|
|
OptionButton *filter_combo = nullptr;
|
|
|
|
Tree *results_tree = nullptr;
|
2022-02-15 22:56:58 +08:00
|
|
|
bool old_search = false;
|
2019-11-25 23:23:35 +08:00
|
|
|
String old_term;
|
2017-12-11 07:56:49 +08:00
|
|
|
|
|
|
|
class Runner;
|
|
|
|
Ref<Runner> search;
|
|
|
|
|
|
|
|
void _update_icons();
|
|
|
|
void _update_results();
|
|
|
|
|
2018-11-23 07:20:57 +08:00
|
|
|
void _search_box_gui_input(const Ref<InputEvent> &p_event);
|
2017-12-11 07:56:49 +08:00
|
|
|
void _search_box_text_changed(const String &p_text);
|
|
|
|
void _filter_combo_item_selected(int p_option);
|
|
|
|
void _confirmed();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void popup_dialog();
|
|
|
|
void popup_dialog(const String &p_term);
|
|
|
|
|
|
|
|
EditorHelpSearch();
|
|
|
|
};
|
|
|
|
|
2021-06-05 00:03:15 +08:00
|
|
|
class EditorHelpSearch::Runner : public RefCounted {
|
2017-12-11 07:56:49 +08:00
|
|
|
enum Phase {
|
|
|
|
PHASE_MATCH_CLASSES_INIT,
|
|
|
|
PHASE_MATCH_CLASSES,
|
|
|
|
PHASE_CLASS_ITEMS_INIT,
|
|
|
|
PHASE_CLASS_ITEMS,
|
|
|
|
PHASE_MEMBER_ITEMS_INIT,
|
|
|
|
PHASE_MEMBER_ITEMS,
|
|
|
|
PHASE_SELECT_MATCH,
|
|
|
|
PHASE_MAX
|
|
|
|
};
|
2020-05-12 23:01:17 +08:00
|
|
|
int phase = 0;
|
2017-12-11 07:56:49 +08:00
|
|
|
|
|
|
|
struct ClassMatch {
|
2021-10-30 09:42:57 +08:00
|
|
|
DocData::ClassDoc *doc = nullptr;
|
2020-11-24 17:12:55 +08:00
|
|
|
bool name = false;
|
2021-09-21 10:49:02 +08:00
|
|
|
Vector<DocData::MethodDoc *> constructors;
|
2017-12-11 07:56:49 +08:00
|
|
|
Vector<DocData::MethodDoc *> methods;
|
2021-09-21 10:49:02 +08:00
|
|
|
Vector<DocData::MethodDoc *> operators;
|
2017-12-11 07:56:49 +08:00
|
|
|
Vector<DocData::MethodDoc *> signals;
|
|
|
|
Vector<DocData::ConstantDoc *> constants;
|
|
|
|
Vector<DocData::PropertyDoc *> properties;
|
2021-08-05 00:54:41 +08:00
|
|
|
Vector<DocData::ThemeItemDoc *> theme_properties;
|
2022-09-02 00:11:19 +08:00
|
|
|
Vector<DocData::MethodDoc *> annotations;
|
2017-12-11 07:56:49 +08:00
|
|
|
|
|
|
|
bool required() {
|
2022-09-02 00:11:19 +08:00
|
|
|
return name || methods.size() || signals.size() || constants.size() || properties.size() || theme_properties.size() || annotations.size();
|
2017-12-11 07:56:49 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-04-04 21:06:57 +08:00
|
|
|
Control *ui_service = nullptr;
|
|
|
|
Tree *results_tree = nullptr;
|
2017-12-11 07:56:49 +08:00
|
|
|
String term;
|
2022-09-04 16:18:23 +08:00
|
|
|
Vector<String> terms;
|
2017-12-11 07:56:49 +08:00
|
|
|
int search_flags;
|
|
|
|
|
2019-06-12 02:43:37 +08:00
|
|
|
Ref<Texture2D> empty_icon;
|
2017-12-11 07:56:49 +08:00
|
|
|
Color disabled_color;
|
|
|
|
|
2022-05-13 21:04:37 +08:00
|
|
|
HashMap<String, DocData::ClassDoc>::Iterator iterator_doc;
|
|
|
|
HashMap<String, ClassMatch> matches;
|
|
|
|
HashMap<String, ClassMatch>::Iterator iterator_match;
|
2020-11-24 17:12:55 +08:00
|
|
|
TreeItem *root_item = nullptr;
|
2022-05-13 21:04:37 +08:00
|
|
|
HashMap<String, TreeItem *> class_items;
|
2020-11-24 17:12:55 +08:00
|
|
|
TreeItem *matched_item = nullptr;
|
2021-03-20 05:49:21 +08:00
|
|
|
float match_highest_score = 0;
|
2017-12-11 07:56:49 +08:00
|
|
|
|
2019-06-07 09:04:25 +08:00
|
|
|
bool _is_class_disabled_by_feature_profile(const StringName &p_class);
|
|
|
|
|
2017-12-11 07:56:49 +08:00
|
|
|
bool _slice();
|
|
|
|
bool _phase_match_classes_init();
|
|
|
|
bool _phase_match_classes();
|
|
|
|
bool _phase_class_items_init();
|
|
|
|
bool _phase_class_items();
|
|
|
|
bool _phase_member_items_init();
|
|
|
|
bool _phase_member_items();
|
|
|
|
bool _phase_select_match();
|
|
|
|
|
2022-09-02 00:11:19 +08:00
|
|
|
String _build_method_tooltip(const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc) const;
|
|
|
|
|
2022-09-04 16:18:23 +08:00
|
|
|
void _match_method_name_and_push_back(Vector<DocData::MethodDoc> &p_methods, Vector<DocData::MethodDoc *> *r_match_methods);
|
|
|
|
bool _all_terms_in_name(String name);
|
2017-12-11 07:56:49 +08:00
|
|
|
bool _match_string(const String &p_term, const String &p_string) const;
|
|
|
|
void _match_item(TreeItem *p_item, const String &p_text);
|
|
|
|
TreeItem *_create_class_hierarchy(const ClassMatch &p_match);
|
|
|
|
TreeItem *_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray);
|
2020-12-18 14:36:04 +08:00
|
|
|
TreeItem *_create_method_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const String &p_text, const DocData::MethodDoc *p_doc);
|
2017-12-11 07:56:49 +08:00
|
|
|
TreeItem *_create_signal_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc);
|
2022-09-02 00:11:19 +08:00
|
|
|
TreeItem *_create_annotation_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const String &p_text, const DocData::MethodDoc *p_doc);
|
2017-12-11 07:56:49 +08:00
|
|
|
TreeItem *_create_constant_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ConstantDoc *p_doc);
|
|
|
|
TreeItem *_create_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::PropertyDoc *p_doc);
|
2021-08-05 00:54:41 +08:00
|
|
|
TreeItem *_create_theme_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ThemeItemDoc *p_doc);
|
2022-08-28 14:17:25 +08:00
|
|
|
TreeItem *_create_member_item(TreeItem *p_parent, const String &p_class_name, const String &p_icon, const String &p_name, const String &p_text, const String &p_type, const String &p_metatype, const String &p_tooltip, bool is_deprecated, bool is_experimental);
|
2017-12-11 07:56:49 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
bool work(uint64_t slot = 100000);
|
|
|
|
|
|
|
|
Runner(Control *p_icon_service, Tree *p_results_tree, const String &p_term, int p_search_flags);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // EDITOR_HELP_SEARCH_H
|