ScriptCreateDialog: fix open error crash, remember template
This commit is contained in:
parent
8b362b5009
commit
a94ea0b9fe
@ -58,6 +58,7 @@ void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_
|
|||||||
file_path->set_text("");
|
file_path->set_text("");
|
||||||
}
|
}
|
||||||
_lang_changed(current_language);
|
_lang_changed(current_language);
|
||||||
|
_template_changed(template_menu->get_selected());
|
||||||
_parent_name_changed(parent_name->get_text());
|
_parent_name_changed(parent_name->get_text());
|
||||||
_class_name_changed("");
|
_class_name_changed("");
|
||||||
_path_changed(file_path->get_text());
|
_path_changed(file_path->get_text());
|
||||||
@ -118,13 +119,15 @@ void ScriptCreateDialog::_parent_name_changed(const String &p_parent) {
|
|||||||
|
|
||||||
void ScriptCreateDialog::_template_changed(int p_template) {
|
void ScriptCreateDialog::_template_changed(int p_template) {
|
||||||
|
|
||||||
|
String selected_template = p_template == 0 ? "" : template_menu->get_item_text(template_menu->get_selected());
|
||||||
|
EditorSettings::get_singleton()->set_project_metadata("script_setup", "last_selected_template", selected_template);
|
||||||
if (p_template == 0) {
|
if (p_template == 0) {
|
||||||
//default
|
//default
|
||||||
script_template = "";
|
script_template = "";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String ext = ScriptServer::get_language(language_menu->get_selected())->get_extension();
|
String ext = ScriptServer::get_language(language_menu->get_selected())->get_extension();
|
||||||
String name = template_menu->get_item_text(p_template) + "." + ext;
|
String name = template_list[p_template - 1] + "." + ext;
|
||||||
script_template = EditorSettings::get_singleton()->get_settings_path() + "/script_templates/" + name;
|
script_template = EditorSettings::get_singleton()->get_settings_path() + "/script_templates/" + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,15 +151,19 @@ void ScriptCreateDialog::_create_new() {
|
|||||||
|
|
||||||
Ref<Script> scr;
|
Ref<Script> scr;
|
||||||
if (script_template != "") {
|
if (script_template != "") {
|
||||||
scr = ResourceLoader::load(script_template)->duplicate();
|
scr = ResourceLoader::load(script_template);
|
||||||
|
if (scr.is_null()) {
|
||||||
|
alert->get_ok()->set_text(TTR("OK"));
|
||||||
|
alert->set_text(vformat(TTR("Error loading template '%s'"), script_template));
|
||||||
|
alert->popup_centered();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
scr = scr->duplicate();
|
||||||
ScriptServer::get_language(language_menu->get_selected())->make_template(cname, parent_name->get_text(), scr);
|
ScriptServer::get_language(language_menu->get_selected())->make_template(cname, parent_name->get_text(), scr);
|
||||||
} else {
|
} else {
|
||||||
scr = ScriptServer::get_language(language_menu->get_selected())->get_template(cname, parent_name->get_text());
|
scr = ScriptServer::get_language(language_menu->get_selected())->get_template(cname, parent_name->get_text());
|
||||||
}
|
}
|
||||||
|
|
||||||
String selected_language = language_menu->get_item_text(language_menu->get_selected());
|
|
||||||
editor_settings->set_project_metadata("script_setup", "last_selected_language", selected_language);
|
|
||||||
|
|
||||||
if (cname != "")
|
if (cname != "")
|
||||||
scr->set_name(cname);
|
scr->set_name(cname);
|
||||||
|
|
||||||
@ -240,13 +247,22 @@ void ScriptCreateDialog::_lang_changed(int l) {
|
|||||||
bool use_templates = language->is_using_templates();
|
bool use_templates = language->is_using_templates();
|
||||||
template_menu->set_disabled(!use_templates);
|
template_menu->set_disabled(!use_templates);
|
||||||
if (use_templates) {
|
if (use_templates) {
|
||||||
Vector<String> template_list = EditorSettings::get_singleton()->get_script_templates(language->get_extension());
|
template_list = EditorSettings::get_singleton()->get_script_templates(language->get_extension());
|
||||||
|
|
||||||
|
String last_lang = EditorSettings::get_singleton()->get_project_metadata("script_setup", "last_selected_language", "");
|
||||||
|
String last_template = EditorSettings::get_singleton()->get_project_metadata("script_setup", "last_selected_template", "");
|
||||||
|
|
||||||
template_menu->clear();
|
template_menu->clear();
|
||||||
template_menu->add_item(TTR("Default"));
|
template_menu->add_item(TTR("Default"));
|
||||||
for (int i = 0; i < template_list.size(); i++) {
|
for (int i = 0; i < template_list.size(); i++) {
|
||||||
template_menu->add_item(template_list[i].capitalize());
|
String s = template_list[i].capitalize();
|
||||||
|
template_menu->add_item(s);
|
||||||
|
if (language_menu->get_item_text(l) == last_lang && last_template == s) {
|
||||||
|
template_menu->select(i + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
_template_changed(template_menu->get_selected());
|
||||||
|
EditorSettings::get_singleton()->set_project_metadata("script_setup", "last_selected_language", language_menu->get_item_text(l));
|
||||||
}
|
}
|
||||||
|
|
||||||
_update_dialog();
|
_update_dialog();
|
||||||
@ -506,8 +522,6 @@ void ScriptCreateDialog::_bind_methods() {
|
|||||||
|
|
||||||
ScriptCreateDialog::ScriptCreateDialog() {
|
ScriptCreateDialog::ScriptCreateDialog() {
|
||||||
|
|
||||||
editor_settings = EditorSettings::get_singleton();
|
|
||||||
|
|
||||||
GridContainer *gc = memnew(GridContainer);
|
GridContainer *gc = memnew(GridContainer);
|
||||||
VBoxContainer *vb = memnew(VBoxContainer);
|
VBoxContainer *vb = memnew(VBoxContainer);
|
||||||
HBoxContainer *hb = memnew(HBoxContainer);
|
HBoxContainer *hb = memnew(HBoxContainer);
|
||||||
@ -613,7 +627,7 @@ ScriptCreateDialog::ScriptCreateDialog() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String last_selected_language = editor_settings->get_project_metadata("script_setup", "last_selected_language", "");
|
String last_selected_language = EditorSettings::get_singleton()->get_project_metadata("script_setup", "last_selected_language", "");
|
||||||
if (last_selected_language != "") {
|
if (last_selected_language != "") {
|
||||||
for (int i = 0; i < language_menu->get_item_count(); i++) {
|
for (int i = 0; i < language_menu->get_item_count(); i++) {
|
||||||
if (language_menu->get_item_text(i) == last_selected_language) {
|
if (language_menu->get_item_text(i) == last_selected_language) {
|
||||||
|
@ -59,7 +59,6 @@ class ScriptCreateDialog : public ConfirmationDialog {
|
|||||||
bool create_new;
|
bool create_new;
|
||||||
bool is_browsing_parent;
|
bool is_browsing_parent;
|
||||||
String initial_bp;
|
String initial_bp;
|
||||||
EditorSettings *editor_settings;
|
|
||||||
bool is_new_script_created;
|
bool is_new_script_created;
|
||||||
bool is_path_valid;
|
bool is_path_valid;
|
||||||
bool has_named_classes;
|
bool has_named_classes;
|
||||||
@ -70,6 +69,7 @@ class ScriptCreateDialog : public ConfirmationDialog {
|
|||||||
int current_language;
|
int current_language;
|
||||||
bool re_check_path;
|
bool re_check_path;
|
||||||
String script_template;
|
String script_template;
|
||||||
|
Vector<String> template_list;
|
||||||
|
|
||||||
void _path_changed(const String &p_path = String());
|
void _path_changed(const String &p_path = String());
|
||||||
void _lang_changed(int l = 0);
|
void _lang_changed(int l = 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user