summaryrefslogtreecommitdiff
path: root/editor/script_create_dialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/script_create_dialog.cpp')
-rw-r--r--editor/script_create_dialog.cpp38
1 files changed, 25 insertions, 13 deletions
diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp
index 24c4ba4cb7..df704706af 100644
--- a/editor/script_create_dialog.cpp
+++ b/editor/script_create_dialog.cpp
@@ -30,13 +30,13 @@
#include "script_create_dialog.h"
+#include "core/io/resource_saver.h"
+#include "core/os/file_access.h"
+#include "core/project_settings.h"
+#include "core/script_language.h"
#include "editor/editor_node.h"
#include "editor/editor_scale.h"
#include "editor_file_system.h"
-#include "io/resource_saver.h"
-#include "os/file_access.h"
-#include "project_settings.h"
-#include "script_language.h"
void ScriptCreateDialog::_notification(int p_what) {
@@ -50,12 +50,17 @@ void ScriptCreateDialog::_notification(int p_what) {
}
}
-void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_path) {
+bool ScriptCreateDialog::_can_be_built_in() {
+ return (supports_built_in && built_in_enabled);
+}
+
+void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_path, bool p_built_in_enabled) {
class_name->set_text("");
class_name->deselect();
parent_name->set_text(p_base_name);
parent_name->deselect();
+
if (p_base_path != "") {
initial_bp = p_base_path.get_basename();
file_path->set_text(initial_bp + "." + ScriptServer::get_language(language_menu->get_selected())->get_extension());
@@ -65,6 +70,8 @@ void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_
}
file_path->deselect();
+ built_in_enabled = p_built_in_enabled;
+
_lang_changed(current_language);
_class_name_changed("");
_path_changed(file_path->get_text());
@@ -163,7 +170,6 @@ void ScriptCreateDialog::_create_new() {
if (script_template != "") {
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;
@@ -200,7 +206,6 @@ void ScriptCreateDialog::_load_exist() {
String path = file_path->get_text();
RES p_script = ResourceLoader::load(path, "Script");
if (p_script.is_null()) {
- alert->get_ok()->set_text(TTR("OK"));
alert->set_text(vformat(TTR("Error loading script from %s"), path));
alert->popup_centered();
return;
@@ -359,7 +364,7 @@ void ScriptCreateDialog::_path_changed(const String &p_path) {
is_path_valid = false;
is_new_script_created = true;
- String p = p_path;
+ String p = p_path.strip_edges();
if (p == "") {
_msg_path_valid(false, TTR("Path is empty"));
@@ -367,6 +372,12 @@ void ScriptCreateDialog::_path_changed(const String &p_path) {
return;
}
+ if (p.get_file().get_basename() == "") {
+ _msg_path_valid(false, TTR("Filename is empty"));
+ _update_dialog();
+ return;
+ }
+
p = ProjectSettings::get_singleton()->localize_path(p);
if (!p.begins_with("res://")) {
_msg_path_valid(false, TTR("Path is not local"));
@@ -539,7 +550,7 @@ void ScriptCreateDialog::_update_dialog() {
}
}
- if (!supports_built_in)
+ if (!_can_be_built_in())
internal->set_pressed(false);
/* Is Script created or loaded from existing file */
@@ -548,14 +559,14 @@ void ScriptCreateDialog::_update_dialog() {
get_ok()->set_text(TTR("Create"));
parent_name->set_editable(true);
parent_browse_button->set_disabled(false);
- internal->set_disabled(!supports_built_in);
+ internal->set_disabled(!_can_be_built_in());
_msg_path_valid(true, TTR("Built-in script (into scene file)"));
} else if (is_new_script_created) {
// New Script Created
get_ok()->set_text(TTR("Create"));
parent_name->set_editable(true);
parent_browse_button->set_disabled(false);
- internal->set_disabled(!supports_built_in);
+ internal->set_disabled(!_can_be_built_in());
if (is_path_valid) {
_msg_path_valid(true, TTR("Create new script file"));
}
@@ -564,7 +575,7 @@ void ScriptCreateDialog::_update_dialog() {
get_ok()->set_text(TTR("Load"));
parent_name->set_editable(false);
parent_browse_button->set_disabled(true);
- internal->set_disabled(!supports_built_in);
+ internal->set_disabled(!_can_be_built_in());
if (is_path_valid) {
_msg_path_valid(true, TTR("Load existing script file"));
}
@@ -583,7 +594,7 @@ void ScriptCreateDialog::_bind_methods() {
ClassDB::bind_method("_path_entered", &ScriptCreateDialog::_path_entered);
ClassDB::bind_method("_template_changed", &ScriptCreateDialog::_template_changed);
- ClassDB::bind_method(D_METHOD("config", "inherits", "path"), &ScriptCreateDialog::config);
+ ClassDB::bind_method(D_METHOD("config", "inherits", "path", "built_in_enabled"), &ScriptCreateDialog::config, DEFVAL(true));
ADD_SIGNAL(MethodInfo("script_created", PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script")));
}
@@ -788,6 +799,7 @@ ScriptCreateDialog::ScriptCreateDialog() {
has_named_classes = false;
supports_built_in = false;
can_inherit_from_file = false;
+ built_in_enabled = true;
is_built_in = false;
is_new_script_created = true;