Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/gui/create_dialog.h
21102 views
1
/**************************************************************************/
2
/* create_dialog.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
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
#pragma once
32
33
#include "scene/gui/dialogs.h"
34
35
class Button;
36
class EditorHelpBit;
37
class FilterLineEdit;
38
class ItemList;
39
class Tree;
40
class TreeItem;
41
42
class CreateDialog : public ConfirmationDialog {
43
GDCLASS(CreateDialog, ConfirmationDialog);
44
45
enum TypeCategory {
46
CPP_TYPE,
47
PATH_TYPE,
48
OTHER_TYPE
49
};
50
51
struct TypeInfo {
52
StringName type_name;
53
PackedStringArray search_keywords;
54
};
55
56
FilterLineEdit *search_box = nullptr;
57
Tree *search_options = nullptr;
58
59
String base_type;
60
bool is_base_type_node = false;
61
bool allow_abstract_scripts = false;
62
String icon_fallback;
63
String preferred_search_result_type;
64
65
Button *favorite = nullptr;
66
Vector<String> favorite_list;
67
Tree *favorites = nullptr;
68
ItemList *recent = nullptr;
69
EditorHelpBit *help_bit = nullptr;
70
71
HashMap<String, TreeItem *> search_options_types;
72
HashMap<String, String> custom_type_parents;
73
HashMap<String, int> custom_type_indices;
74
List<TypeInfo> type_info_list;
75
HashSet<StringName> type_blacklist;
76
HashSet<StringName> custom_type_blocklist;
77
78
void _update_search();
79
bool _should_hide_type(const StringName &p_type) const;
80
void _add_type(const StringName &p_type, TypeCategory p_type_category, const String &p_match_keyword);
81
void _configure_search_option_item(TreeItem *r_item, const StringName &p_type, TypeCategory p_type_category, const String &p_match_keyword);
82
float _score_type(const String &p_type, const String &p_search) const;
83
bool _is_type_preferred(const String &p_type) const;
84
void _script_button_clicked(TreeItem *p_item, int p_column, int p_button_id, MouseButton p_mouse_button_index);
85
86
void _fill_type_list();
87
void _cleanup();
88
89
void _sbox_input(const Ref<InputEvent> &p_event);
90
void _text_changed(const String &p_newtext);
91
void select_type(const String &p_type, bool p_center_on_item = true);
92
void _item_selected();
93
void _hide_requested();
94
95
void _confirmed();
96
virtual void cancel_pressed() override;
97
98
void _favorite_toggled();
99
100
void _history_selected(int p_idx);
101
void _favorite_selected();
102
103
void _history_activated(int p_idx);
104
void _favorite_activated();
105
106
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
107
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
108
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
109
110
bool _is_class_disabled_by_feature_profile(const StringName &p_class) const;
111
void _load_favorites_and_history();
112
113
protected:
114
void _notification(int p_what);
115
static void _bind_methods();
116
117
void _save_and_update_favorite_list();
118
119
public:
120
Variant instantiate_selected();
121
String get_selected_type();
122
String get_selected_type_name();
123
124
void set_base_type(const String &p_base);
125
String get_base_type() const { return base_type; }
126
void select_base();
127
128
void set_type_blocklist(const HashSet<StringName> &p_blocklist) { custom_type_blocklist = p_blocklist; }
129
void set_preferred_search_result_type(const String &p_preferred_type) { preferred_search_result_type = p_preferred_type; }
130
131
void popup_create(bool p_dont_clear, bool p_replace_mode = false, const String &p_current_type = "", const String &p_current_name = "");
132
void for_inherit();
133
134
CreateDialog();
135
};
136
137