Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/script/script_create_dialog.h
9903 views
1
/**************************************************************************/
2
/* script_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 "core/object/script_language.h"
34
#include "scene/gui/check_box.h"
35
#include "scene/gui/dialogs.h"
36
#include "scene/gui/option_button.h"
37
#include "scene/gui/panel_container.h"
38
39
class CreateDialog;
40
class EditorFileDialog;
41
class EditorValidationPanel;
42
class LineEdit;
43
44
class ScriptCreateDialog : public ConfirmationDialog {
45
GDCLASS(ScriptCreateDialog, ConfirmationDialog);
46
47
enum {
48
MSG_ID_SCRIPT,
49
MSG_ID_PATH,
50
MSG_ID_BUILT_IN,
51
MSG_ID_TEMPLATE,
52
};
53
54
EditorValidationPanel *validation_panel = nullptr;
55
LineEdit *parent_name = nullptr;
56
Button *parent_browse_button = nullptr;
57
Button *parent_search_button = nullptr;
58
OptionButton *language_menu = nullptr;
59
OptionButton *template_menu = nullptr;
60
LineEdit *file_path = nullptr;
61
LineEdit *built_in_name = nullptr;
62
Button *path_button = nullptr;
63
EditorFileDialog *file_browse = nullptr;
64
CheckBox *built_in = nullptr;
65
CheckBox *use_templates = nullptr;
66
VBoxContainer *path_vb = nullptr;
67
AcceptDialog *alert = nullptr;
68
CreateDialog *select_class = nullptr;
69
70
bool is_browsing_parent = false;
71
String path_error;
72
String template_inactive_message;
73
bool is_new_script_created = true;
74
bool is_path_valid = false;
75
bool supports_built_in = false;
76
bool can_inherit_from_file = false;
77
bool is_parent_name_valid = false;
78
bool is_class_name_valid = false;
79
bool is_built_in = false;
80
bool is_using_templates = true;
81
bool built_in_enabled = true;
82
bool load_enabled = true;
83
int default_language;
84
bool re_check_path = false;
85
86
Control *path_controls[2];
87
Control *name_controls[2];
88
89
Vector<ScriptLanguage::ScriptTemplate> template_list;
90
ScriptLanguage *language = nullptr;
91
92
String base_type;
93
94
void _path_hbox_sorted();
95
bool _can_be_built_in();
96
void _path_changed(const String &p_path = String());
97
void _language_changed(int l = 0);
98
void _built_in_pressed();
99
void _use_template_pressed();
100
bool _validate_parent(const String &p_string);
101
String _validate_path(const String &p_path, bool p_file_must_exist, bool *r_path_valid = nullptr);
102
void _parent_name_changed(const String &p_parent);
103
void _template_changed(int p_template = 0);
104
void _browse_path(bool browse_parent, bool p_save);
105
void _file_selected(const String &p_file);
106
void _create();
107
void _browse_class_in_tree();
108
virtual void ok_pressed() override;
109
void _create_new();
110
void _load_exist();
111
void _update_template_menu();
112
void _update_dialog();
113
ScriptLanguage::ScriptTemplate _get_current_template() const;
114
Vector<ScriptLanguage::ScriptTemplate> _get_user_templates(const ScriptLanguage *p_language, const StringName &p_object, const String &p_dir, const ScriptLanguage::TemplateLocation &p_origin) const;
115
ScriptLanguage::ScriptTemplate _parse_template(const ScriptLanguage *p_language, const String &p_path, const String &p_filename, const ScriptLanguage::TemplateLocation &p_origin, const String &p_inherits) const;
116
String _get_script_origin_label(const ScriptLanguage::TemplateLocation &p_origin) const;
117
String _adjust_file_path(const String &p_base_path) const;
118
119
protected:
120
void _notification(int p_what);
121
static void _bind_methods();
122
123
public:
124
void config(const String &p_base_name, const String &p_base_path, bool p_built_in_enabled = true, bool p_load_enabled = true);
125
void set_inheritance_base_type(const String &p_base);
126
ScriptCreateDialog();
127
};
128
129