2017-12-10 23:56:49 +00: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. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
#ifndef EDITOR_HELP_SEARCH_H
|
|
|
|
#define EDITOR_HELP_SEARCH_H
|
|
|
|
|
2022-05-13 13:04:37 +00:00
|
|
|
#include "core/templates/rb_map.h"
|
2017-12-10 23:56:49 +00: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 02:49:02 +00: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-01 16:11:19 +00: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-10 23:56:49 +00:00
|
|
|
SEARCH_CASE_SENSITIVE = 1 << 29,
|
|
|
|
SEARCH_SHOW_HIERARCHY = 1 << 30
|
|
|
|
};
|
|
|
|
|
2022-04-04 13:06:57 +00: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 14:56:58 +00:00
|
|
|
bool old_search = false;
|
2019-11-25 15:23:35 +00:00
|
|
|
String old_term;
|
2017-12-10 23:56:49 +00:00
|
|
|
|
|
|
|
class Runner;
|
|
|
|
Ref<Runner> search;
|
|
|
|
|
2023-12-02 12:44:40 +00:00
|
|
|
struct TreeCache {
|
|
|
|
HashMap<String, TreeItem *> item_cache;
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
~TreeCache() {
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
} tree_cache;
|
|
|
|
|
2017-12-10 23:56:49 +00:00
|
|
|
void _update_results();
|
|
|
|
|
2018-11-22 23:20:57 +00:00
|
|
|
void _search_box_gui_input(const Ref<InputEvent> &p_event);
|
2017-12-10 23:56:49 +00:00
|
|
|
void _search_box_text_changed(const String &p_text);
|
|
|
|
void _filter_combo_item_selected(int p_option);
|
|
|
|
void _confirmed();
|
|
|
|
|
2023-10-22 11:29:56 +00:00
|
|
|
bool _all_terms_in_name(const Vector<String> &p_terms, const String &p_name) const;
|
|
|
|
void _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;
|
|
|
|
void _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;
|
|
|
|
void _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;
|
|
|
|
void _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;
|
|
|
|
|
|
|
|
Dictionary _native_search_cb(const String &p_search_string, int p_result_limit);
|
|
|
|
void _native_action_cb(const String &p_item_string);
|
|
|
|
|
2017-12-10 23:56:49 +00:00
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void popup_dialog();
|
|
|
|
void popup_dialog(const String &p_term);
|
|
|
|
|
|
|
|
EditorHelpSearch();
|
|
|
|
};
|
|
|
|
|
2021-06-04 16:03:15 +00:00
|
|
|
class EditorHelpSearch::Runner : public RefCounted {
|
2017-12-10 23:56:49 +00: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 15:01:17 +00:00
|
|
|
int phase = 0;
|
2017-12-10 23:56:49 +00:00
|
|
|
|
2024-02-17 17:06:35 +00:00
|
|
|
template <typename T>
|
|
|
|
struct MemberMatch {
|
|
|
|
T *doc = nullptr;
|
|
|
|
bool name = false;
|
|
|
|
String keyword;
|
|
|
|
};
|
|
|
|
|
2017-12-10 23:56:49 +00:00
|
|
|
struct ClassMatch {
|
2021-10-30 01:42:57 +00:00
|
|
|
DocData::ClassDoc *doc = nullptr;
|
2020-11-24 09:12:55 +00:00
|
|
|
bool name = false;
|
2024-02-17 17:06:35 +00:00
|
|
|
String keyword;
|
|
|
|
Vector<MemberMatch<DocData::MethodDoc>> constructors;
|
|
|
|
Vector<MemberMatch<DocData::MethodDoc>> methods;
|
|
|
|
Vector<MemberMatch<DocData::MethodDoc>> operators;
|
|
|
|
Vector<MemberMatch<DocData::MethodDoc>> signals;
|
|
|
|
Vector<MemberMatch<DocData::ConstantDoc>> constants;
|
|
|
|
Vector<MemberMatch<DocData::PropertyDoc>> properties;
|
|
|
|
Vector<MemberMatch<DocData::ThemeItemDoc>> theme_properties;
|
|
|
|
Vector<MemberMatch<DocData::MethodDoc>> annotations;
|
2017-12-10 23:56:49 +00:00
|
|
|
|
|
|
|
bool required() {
|
2024-02-17 17:06:35 +00:00
|
|
|
return name || !keyword.is_empty() || methods.size() || signals.size() || constants.size() || properties.size() || theme_properties.size() || annotations.size();
|
2017-12-10 23:56:49 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-04-04 13:06:57 +00:00
|
|
|
Control *ui_service = nullptr;
|
|
|
|
Tree *results_tree = nullptr;
|
2023-12-02 12:44:40 +00:00
|
|
|
TreeCache *tree_cache = nullptr;
|
2017-12-10 23:56:49 +00:00
|
|
|
String term;
|
2022-09-04 08:18:23 +00:00
|
|
|
Vector<String> terms;
|
2017-12-10 23:56:49 +00:00
|
|
|
int search_flags;
|
|
|
|
|
|
|
|
Color disabled_color;
|
|
|
|
|
2022-05-13 13:04:37 +00:00
|
|
|
HashMap<String, DocData::ClassDoc>::Iterator iterator_doc;
|
2023-08-16 12:00:59 +00:00
|
|
|
LocalVector<RBSet<String, NaturalNoCaseComparator>::Element *> iterator_stack;
|
2022-05-13 13:04:37 +00:00
|
|
|
HashMap<String, ClassMatch> matches;
|
|
|
|
HashMap<String, ClassMatch>::Iterator iterator_match;
|
2020-11-24 09:12:55 +00:00
|
|
|
TreeItem *root_item = nullptr;
|
2022-05-13 13:04:37 +00:00
|
|
|
HashMap<String, TreeItem *> class_items;
|
2020-11-24 09:12:55 +00:00
|
|
|
TreeItem *matched_item = nullptr;
|
2021-03-19 21:49:21 +00:00
|
|
|
float match_highest_score = 0;
|
2017-12-10 23:56:49 +00:00
|
|
|
|
2019-06-07 01:04:25 +00:00
|
|
|
bool _is_class_disabled_by_feature_profile(const StringName &p_class);
|
|
|
|
|
2023-12-02 12:44:40 +00:00
|
|
|
void _populate_cache();
|
|
|
|
bool _find_or_create_item(TreeItem *p_parent, const String &p_item_meta, TreeItem *&r_item);
|
|
|
|
|
2017-12-10 23:56:49 +00: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-01 16:11:19 +00:00
|
|
|
String _build_method_tooltip(const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc) const;
|
2024-02-17 17:06:35 +00:00
|
|
|
String _build_keywords_tooltip(const String &p_keywords) const;
|
2022-09-01 16:11:19 +00:00
|
|
|
|
2024-02-17 17:06:35 +00:00
|
|
|
void _match_method_name_and_push_back(Vector<DocData::MethodDoc> &p_methods, Vector<MemberMatch<DocData::MethodDoc>> *r_match_methods);
|
2023-07-03 16:18:46 +00:00
|
|
|
bool _all_terms_in_name(const String &p_name) const;
|
2024-02-17 17:06:35 +00:00
|
|
|
String _match_keywords_in_all_terms(const String &p_keywords) const;
|
2017-12-10 23:56:49 +00:00
|
|
|
bool _match_string(const String &p_term, const String &p_string) const;
|
2024-02-17 17:06:35 +00:00
|
|
|
String _match_keywords(const String &p_term, const String &p_keywords) const;
|
2023-07-03 16:18:46 +00:00
|
|
|
void _match_item(TreeItem *p_item, const String &p_text, bool p_is_keywords = false);
|
2017-12-10 23:56:49 +00:00
|
|
|
TreeItem *_create_class_hierarchy(const ClassMatch &p_match);
|
2024-02-17 17:06:35 +00:00
|
|
|
TreeItem *_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray, const String &p_matching_keyword);
|
|
|
|
TreeItem *_create_method_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const String &p_text, const MemberMatch<DocData::MethodDoc> &p_match);
|
|
|
|
TreeItem *_create_signal_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::MethodDoc> &p_match);
|
|
|
|
TreeItem *_create_annotation_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::MethodDoc> &p_match);
|
|
|
|
TreeItem *_create_constant_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::ConstantDoc> &p_match);
|
|
|
|
TreeItem *_create_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::PropertyDoc> &p_match);
|
|
|
|
TreeItem *_create_theme_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::ThemeItemDoc> &p_match);
|
|
|
|
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, const String &p_keywords, bool p_is_deprecated, bool p_is_experimental, const String &p_matching_keyword);
|
2017-12-10 23:56:49 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
bool work(uint64_t slot = 100000);
|
|
|
|
|
2023-12-02 12:44:40 +00:00
|
|
|
Runner(Control *p_icon_service, Tree *p_results_tree, TreeCache *p_tree_cache, const String &p_term, int p_search_flags);
|
2017-12-10 23:56:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // EDITOR_HELP_SEARCH_H
|