summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editor/script_create_dialog.cpp34
-rw-r--r--editor/script_create_dialog.h2
2 files changed, 25 insertions, 11 deletions
diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp
index 00fdcb676b..47675bcffe 100644
--- a/editor/script_create_dialog.cpp
+++ b/editor/script_create_dialog.cpp
@@ -58,6 +58,7 @@ void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_
file_path->set_text("");
}
_lang_changed(current_language);
+ _template_changed(template_menu->get_selected());
_parent_name_changed(parent_name->get_text());
_class_name_changed("");
_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) {
+ 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) {
//default
script_template = "";
return;
}
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;
}
@@ -148,15 +151,19 @@ void ScriptCreateDialog::_create_new() {
Ref<Script> scr;
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);
} else {
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 != "")
scr->set_name(cname);
@@ -240,13 +247,22 @@ void ScriptCreateDialog::_lang_changed(int l) {
bool use_templates = language->is_using_templates();
template_menu->set_disabled(!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->add_item(TTR("Default"));
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();
@@ -506,8 +522,6 @@ void ScriptCreateDialog::_bind_methods() {
ScriptCreateDialog::ScriptCreateDialog() {
- editor_settings = EditorSettings::get_singleton();
-
GridContainer *gc = memnew(GridContainer);
VBoxContainer *vb = memnew(VBoxContainer);
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 != "") {
for (int i = 0; i < language_menu->get_item_count(); i++) {
if (language_menu->get_item_text(i) == last_selected_language) {
diff --git a/editor/script_create_dialog.h b/editor/script_create_dialog.h
index 1adbfe3f7d..f503b878f5 100644
--- a/editor/script_create_dialog.h
+++ b/editor/script_create_dialog.h
@@ -59,7 +59,6 @@ class ScriptCreateDialog : public ConfirmationDialog {
bool create_new;
bool is_browsing_parent;
String initial_bp;
- EditorSettings *editor_settings;
bool is_new_script_created;
bool is_path_valid;
bool has_named_classes;
@@ -70,6 +69,7 @@ class ScriptCreateDialog : public ConfirmationDialog {
int current_language;
bool re_check_path;
String script_template;
+ Vector<String> template_list;
void _path_changed(const String &p_path = String());
void _lang_changed(int l = 0);