diff options
Diffstat (limited to 'editor/script_create_dialog.cpp')
-rw-r--r-- | editor/script_create_dialog.cpp | 66 |
1 files changed, 44 insertions, 22 deletions
diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index cee356b930..57a003060e 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -41,17 +41,21 @@ void ScriptCreateDialog::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_THEME_CHANGED: case NOTIFICATION_ENTER_TREE: { path_button->set_icon(get_icon("Folder", "EditorIcons")); parent_browse_button->set_icon(get_icon("Folder", "EditorIcons")); - } + status_panel->add_style_override("panel", get_stylebox("bg", "Tree")); + } break; } } void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_path) { 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()); @@ -59,8 +63,9 @@ void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_ initial_bp = ""; file_path->set_text(""); } + file_path->deselect(); + _lang_changed(current_language); - _parent_name_changed(parent_name->get_text()); _class_name_changed(""); _path_changed(file_path->get_text()); } @@ -290,6 +295,7 @@ void ScriptCreateDialog::_lang_changed(int l) { _template_changed(template_menu->get_selected()); EditorSettings::get_singleton()->set_project_metadata("script_setup", "last_selected_language", language_menu->get_item_text(language_menu->get_selected())); + _parent_name_changed(parent_name->get_text()); _update_dialog(); } @@ -303,11 +309,19 @@ void ScriptCreateDialog::_built_in_pressed() { _update_dialog(); } -void ScriptCreateDialog::_browse_path(bool browse_parent) { +void ScriptCreateDialog::_browse_path(bool browse_parent, bool p_save) { is_browsing_parent = browse_parent; - file_browse->set_mode(EditorFileDialog::MODE_SAVE_FILE); + if (p_save) { + file_browse->set_mode(EditorFileDialog::MODE_SAVE_FILE); + file_browse->set_title(TTR("Open Script/Choose Location")); + file_browse->get_ok()->set_text(TTR("Open")); + } else { + file_browse->set_mode(EditorFileDialog::MODE_OPEN_FILE); + file_browse->set_title(TTR("Open Script")); + } + file_browse->set_disable_overwrite_warning(true); file_browse->clear_filters(); List<String> extensions; @@ -380,8 +394,6 @@ void ScriptCreateDialog::_path_changed(const String &p_path) { is_new_script_created = false; is_path_valid = true; _msg_path_valid(true, TTR("File exists, will be reused")); - } else { - path_error_label->set_text(""); } memdelete(f); _update_dialog(); @@ -424,6 +436,13 @@ void ScriptCreateDialog::_path_changed(const String &p_path) { return; } + String path_error = ScriptServer::get_language(language_menu->get_selected())->validate_path(p); + if (path_error != "") { + _msg_path_valid(false, path_error); + _update_dialog(); + return; + } + /* All checks passed */ is_path_valid = true; @@ -525,26 +544,28 @@ void ScriptCreateDialog::_update_dialog() { /* Is Script created or loaded from existing file */ - if (is_new_script_created) { + if (is_built_in) { + get_ok()->set_text(TTR("Create")); + parent_name->set_editable(true); + parent_browse_button->set_disabled(false); + internal->set_disabled(!supports_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); - if (is_built_in) { - _msg_path_valid(true, TTR("Built-in script (into scene file)")); - } else { - if (script_ok) { - _msg_path_valid(true, TTR("Create new script file")); - } + if (is_path_valid) { + _msg_path_valid(true, TTR("Create new script file")); } } else { // Script Loaded get_ok()->set_text(TTR("Load")); parent_name->set_editable(false); parent_browse_button->set_disabled(true); - internal->set_disabled(true); - if (script_ok) { + internal->set_disabled(!supports_built_in); + if (is_path_valid) { _msg_path_valid(true, TTR("Load existing script file")); } } @@ -597,10 +618,10 @@ ScriptCreateDialog::ScriptCreateDialog() { hb->add_child(path_error_label); vb->add_child(hb); - PanelContainer *pc = memnew(PanelContainer); - pc->set_h_size_flags(Control::SIZE_FILL); - pc->add_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_stylebox("bg", "Tree")); - pc->add_child(vb); + status_panel = memnew(PanelContainer); + status_panel->set_h_size_flags(Control::SIZE_FILL); + status_panel->add_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_stylebox("bg", "Tree")); + status_panel->add_child(vb); /* Margins */ @@ -619,7 +640,7 @@ ScriptCreateDialog::ScriptCreateDialog() { vb->add_child(empty_h->duplicate()); vb->add_child(gc); vb->add_child(empty_h->duplicate()); - vb->add_child(pc); + vb->add_child(status_panel); vb->add_child(empty_h->duplicate()); hb = memnew(HBoxContainer); hb->add_child(empty_v->duplicate()); @@ -678,7 +699,7 @@ ScriptCreateDialog::ScriptCreateDialog() { hb->add_child(parent_name); parent_browse_button = memnew(Button); parent_browse_button->set_flat(true); - parent_browse_button->connect("pressed", this, "_browse_path", varray(true)); + parent_browse_button->connect("pressed", this, "_browse_path", varray(true, false)); hb->add_child(parent_browse_button); l = memnew(Label); l->set_text(TTR("Inherits")); @@ -730,7 +751,7 @@ ScriptCreateDialog::ScriptCreateDialog() { hb->add_child(file_path); path_button = memnew(Button); path_button->set_flat(true); - path_button->connect("pressed", this, "_browse_path", varray(false)); + path_button->connect("pressed", this, "_browse_path", varray(false, true)); hb->add_child(path_button); l = memnew(Label); l->set_text(TTR("Path")); @@ -742,6 +763,7 @@ ScriptCreateDialog::ScriptCreateDialog() { file_browse = memnew(EditorFileDialog); file_browse->connect("file_selected", this, "_file_selected"); + file_browse->set_mode(EditorFileDialog::MODE_OPEN_FILE); add_child(file_browse); get_ok()->set_text(TTR("Create")); alert = memnew(AcceptDialog); |