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.cpp70
1 files changed, 45 insertions, 25 deletions
diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp
index 08bf52ab57..c4627e6627 100644
--- a/editor/script_create_dialog.cpp
+++ b/editor/script_create_dialog.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -46,7 +46,7 @@ void ScriptCreateDialog::_notification(int p_what) {
case NOTIFICATION_THEME_CHANGED:
case NOTIFICATION_ENTER_TREE: {
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
- String lang = ScriptServer::get_language(i)->get_name();
+ String lang = ScriptServer::get_language(i)->get_type();
Ref<Texture> lang_icon = get_icon(lang, "EditorIcons");
if (lang_icon.is_valid()) {
language_menu->set_item_icon(i, lang_icon);
@@ -84,7 +84,9 @@ void ScriptCreateDialog::_path_hbox_sorted() {
int filename_start_pos = initial_bp.find_last("/") + 1;
int filename_end_pos = initial_bp.length();
- file_path->select(filename_start_pos, filename_end_pos);
+ if (!is_built_in) {
+ file_path->select(filename_start_pos, filename_end_pos);
+ }
// First set cursor to the end of line to scroll LineEdit view
// to the right and then set the actual cursor position.
@@ -99,7 +101,7 @@ 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) {
+void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_path, bool p_built_in_enabled, bool p_load_enabled) {
class_name->set_text("");
class_name->deselect();
@@ -109,6 +111,7 @@ void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_
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());
+ current_language = language_menu->get_selected();
} else {
initial_bp = "";
file_path->set_text("");
@@ -116,6 +119,7 @@ void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_
file_path->deselect();
built_in_enabled = p_built_in_enabled;
+ load_enabled = p_load_enabled;
_lang_changed(current_language);
_class_name_changed("");
@@ -573,6 +577,10 @@ void ScriptCreateDialog::_browse_class_in_tree() {
void ScriptCreateDialog::_path_changed(const String &p_path) {
+ if (is_built_in) {
+ return;
+ }
+
is_path_valid = false;
is_new_script_created = true;
@@ -622,12 +630,12 @@ void ScriptCreateDialog::_msg_path_valid(bool valid, const String &p_msg) {
void ScriptCreateDialog::_update_dialog() {
+ /* "Add Script Dialog" GUI logic and script checks. */
+
bool script_ok = true;
- /* "Add Script Dialog" gui logic and script checks */
+ // Is script path/name valid (order from top to bottom)?
- // Is Script Valid (order from top to bottom)
- get_ok()->set_disabled(true);
if (!is_built_in && !is_path_valid) {
_msg_script_valid(false, TTR("Invalid path."));
script_ok = false;
@@ -640,12 +648,12 @@ void ScriptCreateDialog::_update_dialog() {
_msg_script_valid(false, TTR("Invalid inherited parent name or path."));
script_ok = false;
}
+
if (script_ok) {
- _msg_script_valid(true, TTR("Script is valid."));
- get_ok()->set_disabled(false);
+ _msg_script_valid(true, TTR("Script path/name is valid."));
}
- /* Does script have named classes */
+ // Does script have named classes?
if (has_named_classes) {
if (is_new_script_created) {
@@ -662,7 +670,7 @@ void ScriptCreateDialog::_update_dialog() {
class_name->set_text("");
}
- /* Is script Built-in */
+ // Is script Built-in?
if (is_built_in) {
file_path->set_editable(false);
@@ -677,38 +685,50 @@ void ScriptCreateDialog::_update_dialog() {
}
}
- /* Is Script created or loaded from existing file */
+ if (!_can_be_built_in()) {
+ internal->set_pressed(false);
+ }
+ internal->set_disabled(!_can_be_built_in());
+
+ // Is Script created or loaded from existing file?
if (is_built_in) {
get_ok()->set_text(TTR("Create"));
parent_name->set_editable(true);
parent_search_button->set_disabled(false);
parent_browse_button->set_disabled(!can_inherit_from_file);
- internal->set_visible(_can_be_built_in());
- internal_label->set_visible(_can_be_built_in());
_msg_path_valid(true, TTR("Built-in script (into scene file)."));
} else if (is_new_script_created) {
- // New Script Created
+ // New script created.
+
get_ok()->set_text(TTR("Create"));
parent_name->set_editable(true);
parent_search_button->set_disabled(false);
parent_browse_button->set_disabled(!can_inherit_from_file);
- internal->set_visible(_can_be_built_in());
- internal_label->set_visible(_can_be_built_in());
if (is_path_valid) {
_msg_path_valid(true, TTR("Will create a new script file."));
}
- } else {
- // Script Loaded
+ } else if (load_enabled) {
+ // Script loaded.
+
get_ok()->set_text(TTR("Load"));
parent_name->set_editable(false);
parent_search_button->set_disabled(true);
parent_browse_button->set_disabled(true);
- internal->set_disabled(!_can_be_built_in());
if (is_path_valid) {
_msg_path_valid(true, TTR("Will load an existing script file."));
}
+ } else {
+ get_ok()->set_text(TTR("Create"));
+ parent_name->set_editable(true);
+ parent_search_button->set_disabled(false);
+ parent_browse_button->set_disabled(!can_inherit_from_file);
+ _msg_path_valid(false, TTR("Script file already exists."));
+
+ script_ok = false;
}
+
+ get_ok()->set_disabled(!script_ok);
}
void ScriptCreateDialog::_bind_methods() {
@@ -726,7 +746,7 @@ void ScriptCreateDialog::_bind_methods() {
ClassDB::bind_method("_create", &ScriptCreateDialog::_create);
ClassDB::bind_method("_browse_class_in_tree", &ScriptCreateDialog::_browse_class_in_tree);
- ClassDB::bind_method(D_METHOD("config", "inherits", "path", "built_in_enabled"), &ScriptCreateDialog::config, DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("config", "inherits", "path", "built_in_enabled", "load_enabled"), &ScriptCreateDialog::config, DEFVAL(true), DEFVAL(true));
ADD_SIGNAL(MethodInfo("script_created", PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script")));
}
@@ -833,8 +853,7 @@ ScriptCreateDialog::ScriptCreateDialog() {
internal = memnew(CheckBox);
internal->set_text(TTR("On"));
internal->connect("pressed", this, "_built_in_pressed");
- internal_label = memnew(Label(TTR("Built-in Script:")));
- gc->add_child(internal_label);
+ gc->add_child(memnew(Label(TTR("Built-in Script:"))));
gc->add_child(internal);
/* Path */
@@ -884,8 +903,9 @@ ScriptCreateDialog::ScriptCreateDialog() {
has_named_classes = false;
supports_built_in = false;
can_inherit_from_file = false;
- built_in_enabled = true;
is_built_in = false;
+ built_in_enabled = true;
+ load_enabled = true;
is_new_script_created = true;
}