Add more template to Script_Create_dialog.cpp
This commit is contained in:
parent
aafb06cf9f
commit
875fd90467
@ -176,6 +176,9 @@ public:
|
||||
virtual void get_comment_delimiters(List<String> *p_delimiters) const = 0;
|
||||
virtual void get_string_delimiters(List<String> *p_delimiters) const = 0;
|
||||
virtual String get_template(const String &p_class_name, const String &p_base_class_name) const = 0;
|
||||
virtual String get_empty_template(const String &p_class_name, const String &p_base_class_name) const = 0;
|
||||
virtual String get_nocomment_template(const String &p_class_name, const String &p_base_class_name) const = 0;
|
||||
|
||||
virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = NULL) const = 0;
|
||||
virtual Script *create_script() const = 0;
|
||||
virtual bool has_named_classes() const = 0;
|
||||
|
@ -123,7 +123,17 @@ void ScriptCreateDialog::_create_new() {
|
||||
if (class_name->is_editable())
|
||||
cname = class_name->get_text();
|
||||
|
||||
String text = ScriptServer::get_language(language_menu->get_selected())->get_template(cname, parent_name->get_text());
|
||||
String text;
|
||||
if (template_select==0) {
|
||||
text = ScriptServer::get_language(language_menu->get_selected())->get_template(cname, parent_name->get_text());
|
||||
} else if (template_select==1) {
|
||||
text = ScriptServer::get_language(language_menu->get_selected())->get_empty_template(cname, parent_name->get_text());
|
||||
} else if (template_select == 2) {
|
||||
text = ScriptServer::get_language(language_menu->get_selected())->get_nocomment_template(cname, parent_name->get_text());
|
||||
} else {
|
||||
text = ScriptServer::get_language(language_menu->get_selected())->get_template(cname, parent_name->get_text());
|
||||
}
|
||||
|
||||
Script *script = ScriptServer::get_language(language_menu->get_selected())->create_script();
|
||||
script->set_source_code(text);
|
||||
if (cname != "")
|
||||
@ -209,6 +219,11 @@ void ScriptCreateDialog::_lang_changed(int l) {
|
||||
_class_name_changed(class_name->get_text());
|
||||
}
|
||||
|
||||
void ScriptCreateDialog::_template_changed(int p_template) {
|
||||
|
||||
template_select = p_template;
|
||||
}
|
||||
|
||||
void ScriptCreateDialog::_built_in_pressed() {
|
||||
|
||||
if (internal->is_pressed()) {
|
||||
@ -330,6 +345,7 @@ void ScriptCreateDialog::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method("_class_name_changed", &ScriptCreateDialog::_class_name_changed);
|
||||
ObjectTypeDB::bind_method("_lang_changed", &ScriptCreateDialog::_lang_changed);
|
||||
ObjectTypeDB::bind_method("_template_changed", &ScriptCreateDialog::_template_changed);
|
||||
ObjectTypeDB::bind_method("_built_in_pressed", &ScriptCreateDialog::_built_in_pressed);
|
||||
ObjectTypeDB::bind_method("_browse_path", &ScriptCreateDialog::_browse_path);
|
||||
ObjectTypeDB::bind_method("_file_selected", &ScriptCreateDialog::_file_selected);
|
||||
@ -370,6 +386,15 @@ ScriptCreateDialog::ScriptCreateDialog() {
|
||||
language_menu->select(0);
|
||||
language_menu->connect("item_selected", this, "_lang_changed");
|
||||
|
||||
template_menu = memnew(OptionButton);
|
||||
vb->add_margin_child(TTR("Template"), template_menu);
|
||||
|
||||
template_menu->add_item(TTR("Default"));
|
||||
template_menu->add_item(TTR("Empty GD File"));
|
||||
template_menu->add_item(TTR("No Comment GD File"));
|
||||
|
||||
template_menu->select(0);
|
||||
template_menu->connect("item_selected", this, "_template_changed");
|
||||
//parent_name->set_text();
|
||||
|
||||
vb2 = memnew(VBoxContainer);
|
||||
|
@ -44,6 +44,7 @@ class ScriptCreateDialog : public ConfirmationDialog {
|
||||
Label *path_error_label;
|
||||
LineEdit *parent_name;
|
||||
OptionButton *language_menu;
|
||||
OptionButton *template_menu;
|
||||
LineEdit *file_path;
|
||||
EditorFileDialog *file_browse;
|
||||
CheckButton *internal;
|
||||
@ -52,9 +53,11 @@ class ScriptCreateDialog : public ConfirmationDialog {
|
||||
bool path_valid;
|
||||
bool create_new;
|
||||
String initial_bp;
|
||||
int template_select;
|
||||
|
||||
void _path_changed(const String &p_path = String());
|
||||
void _lang_changed(int l = 0);
|
||||
void _template_changed(int l = 0);
|
||||
void _built_in_pressed();
|
||||
bool _validate(const String &p_strin);
|
||||
void _class_name_changed(const String &p_name);
|
||||
|
@ -58,6 +58,24 @@ String GDScriptLanguage::get_template(const String &p_class_name, const String &
|
||||
return _template.replace("%BASE%", p_base_class_name);
|
||||
}
|
||||
|
||||
String GDScriptLanguage::get_empty_template(const String &p_class_name, const String &p_base_class_name) const {
|
||||
|
||||
String _template = String() +
|
||||
"extends %BASE%\n\n";
|
||||
|
||||
return _template.replace("%BASE%", p_base_class_name);
|
||||
}
|
||||
|
||||
String GDScriptLanguage::get_nocomment_template(const String &p_class_name, const String &p_base_class_name) const {
|
||||
|
||||
String _template = String() +
|
||||
"extends %BASE%\n\n" +
|
||||
"func _ready():\n" +
|
||||
"\tpass\n";
|
||||
|
||||
return _template.replace("%BASE%", p_base_class_name);
|
||||
}
|
||||
|
||||
bool GDScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions) const {
|
||||
|
||||
GDParser parser;
|
||||
|
@ -356,6 +356,8 @@ public:
|
||||
virtual void get_comment_delimiters(List<String> *p_delimiters) const;
|
||||
virtual void get_string_delimiters(List<String> *p_delimiters) const;
|
||||
virtual String get_template(const String &p_class_name, const String &p_base_class_name) const;
|
||||
virtual String get_empty_template(const String &p_class_name, const String &p_base_class_name) const;
|
||||
virtual String get_nocomment_template(const String &p_class_name, const String &p_base_class_name) const;
|
||||
virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = NULL) const;
|
||||
virtual Script *create_script() const;
|
||||
virtual bool has_named_classes() const;
|
||||
|
Loading…
Reference in New Issue
Block a user