summaryrefslogtreecommitdiff
path: root/editor/script_create_dialog.cpp
diff options
context:
space:
mode:
authorIgnacio Etcheverry <ignalfonsore@gmail.com>2017-10-24 01:54:47 +0200
committerIgnacio Etcheverry <ignalfonsore@gmail.com>2017-10-24 15:48:58 +0200
commite218a13a64d417505ba8ca0abb79dddfb943f2c7 (patch)
treed8dbc2944129383e6f3e9823e9ea453b916baf96 /editor/script_create_dialog.cpp
parent9905002fa68f151f90a588a2c4b62b939ff31a0d (diff)
Add ScriptLanguage::supports_builtin_mode and improve ScriptCreateDialog
- Make ScriptCreateDialog disable the built-in script checked button if the language does not support it. - ScriptLanguage's get_template and make_template now receive the script path as class name if the the script language does not have named classes.
Diffstat (limited to 'editor/script_create_dialog.cpp')
-rw-r--r--editor/script_create_dialog.cpp35
1 files changed, 27 insertions, 8 deletions
diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp
index 00f44ad9b0..c19b80e649 100644
--- a/editor/script_create_dialog.cpp
+++ b/editor/script_create_dialog.cpp
@@ -145,9 +145,13 @@ void ScriptCreateDialog::ok_pressed() {
void ScriptCreateDialog::_create_new() {
- String cname;
- if (has_named_classes)
- cname = class_name->get_text();
+ String cname_param;
+
+ if (has_named_classes) {
+ cname_param = class_name->get_text();
+ } else {
+ cname_param = ProjectSettings::get_singleton()->localize_path(file_path->get_text()).get_file().get_basename();
+ }
Ref<Script> scr;
if (script_template != "") {
@@ -159,13 +163,16 @@ void ScriptCreateDialog::_create_new() {
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_param, parent_name->get_text(), scr);
} 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_param, parent_name->get_text());
}
- if (cname != "")
- scr->set_name(cname);
+ if (has_named_classes) {
+ String cname = class_name->get_text();
+ if (cname.length())
+ scr->set_name(cname);
+ }
if (!is_built_in) {
String lpath = ProjectSettings::get_singleton()->localize_path(file_path->get_text());
@@ -201,12 +208,20 @@ void ScriptCreateDialog::_lang_changed(int l) {
l = language_menu->get_selected();
ScriptLanguage *language = ScriptServer::get_language(l);
+
if (language->has_named_classes()) {
has_named_classes = true;
} else {
has_named_classes = false;
}
+ if (language->supports_builtin_mode()) {
+ supports_built_in = true;
+ } else {
+ supports_built_in = false;
+ is_built_in = false;
+ }
+
if (ScriptServer::get_language(l)->can_inherit_from_file()) {
can_inherit_from_file = true;
} else {
@@ -496,6 +511,9 @@ void ScriptCreateDialog::_update_dialog() {
}
}
+ if (!supports_built_in)
+ internal->set_pressed(false);
+
/* Is Script created or loaded from existing file */
if (is_new_script_created) {
@@ -503,7 +521,7 @@ void ScriptCreateDialog::_update_dialog() {
get_ok()->set_text(TTR("Create"));
parent_name->set_editable(true);
parent_browse_button->set_disabled(false);
- internal->set_disabled(false);
+ internal->set_disabled(!supports_built_in);
if (is_built_in) {
_msg_path_valid(true, TTR("Built-in script (into scene file)"));
} else {
@@ -734,6 +752,7 @@ ScriptCreateDialog::ScriptCreateDialog() {
is_path_valid = false;
has_named_classes = false;
+ supports_built_in = false;
can_inherit_from_file = false;
is_built_in = false;