diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-05-14 23:09:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-14 23:09:03 +0200 |
commit | 00949f0c5fcc6a4f8382a4a97d5591fd9ec380f8 (patch) | |
tree | 2b1c31f45add24085b64425ce440f577424c16a1 /editor/script_create_dialog.cpp | |
parent | 5046f666a1181675b39f156c38346525dc1c444e (diff) | |
parent | 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 (diff) |
Merge pull request #38738 from akien-mga/cause-we-never-go-out-of-style
Style: Remove new line at block start, enforce line between functions, enforce braces in if and loop blocks
Diffstat (limited to 'editor/script_create_dialog.cpp')
-rw-r--r-- | editor/script_create_dialog.cpp | 69 |
1 files changed, 27 insertions, 42 deletions
diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index f84b7e73ed..04fbfdff9d 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -67,8 +67,8 @@ void ScriptCreateDialog::_theme_changed() { parent_search_button->set_icon(gc->get_theme_icon("ClassList", "EditorIcons")); status_panel->add_theme_style_override("panel", gc->get_theme_stylebox("bg", "Tree")); } -void ScriptCreateDialog::_notification(int p_what) { +void ScriptCreateDialog::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { _theme_changed(); @@ -99,7 +99,6 @@ bool ScriptCreateDialog::_can_be_built_in() { } 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(); parent_name->set_text(p_base_name); @@ -124,57 +123,60 @@ void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_ } void ScriptCreateDialog::set_inheritance_base_type(const String &p_base) { - base_type = p_base; } bool ScriptCreateDialog::_validate_parent(const String &p_string) { - - if (p_string.length() == 0) + if (p_string.length() == 0) { return false; + } if (can_inherit_from_file && p_string.is_quoted()) { String p = p_string.substr(1, p_string.length() - 2); - if (_validate_path(p, true) == "") + if (_validate_path(p, true) == "") { return true; + } } return ClassDB::class_exists(p_string) || ScriptServer::is_global_class(p_string); } bool ScriptCreateDialog::_validate_class(const String &p_string) { - - if (p_string.length() == 0) + if (p_string.length() == 0) { return false; + } for (int i = 0; i < p_string.length(); i++) { - if (i == 0) { - if (p_string[0] >= '0' && p_string[0] <= '9') + if (p_string[0] >= '0' && p_string[0] <= '9') { return false; // no start with number plz + } } bool valid_char = (p_string[i] >= '0' && p_string[i] <= '9') || (p_string[i] >= 'a' && p_string[i] <= 'z') || (p_string[i] >= 'A' && p_string[i] <= 'Z') || p_string[i] == '_' || p_string[i] == '.'; - if (!valid_char) + if (!valid_char) { return false; + } } return true; } String ScriptCreateDialog::_validate_path(const String &p_path, bool p_file_must_exist) { - String p = p_path.strip_edges(); - if (p == "") + if (p == "") { return TTR("Path is empty."); - if (p.get_file().get_basename() == "") + } + if (p.get_file().get_basename() == "") { return TTR("Filename is empty."); + } p = ProjectSettings::get_singleton()->localize_path(p); - if (!p.begins_with("res://")) + if (!p.begins_with("res://")) { return TTR("Path is not local."); + } DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES); if (d->change_dir(p.get_base_dir()) != OK) { @@ -219,22 +221,24 @@ String ScriptCreateDialog::_validate_path(const String &p_path, bool p_file_must index++; } - if (!found) + if (!found) { return TTR("Invalid extension."); - if (!match) + } + if (!match) { return TTR("Wrong extension chosen."); + } /* Let ScriptLanguage do custom validation */ String path_error = ScriptServer::get_language(language_menu->get_selected())->validate_path(p); - if (path_error != "") + if (path_error != "") { return path_error; + } /* All checks passed */ return ""; } void ScriptCreateDialog::_class_name_changed(const String &p_name) { - if (_validate_class(class_name->get_text())) { is_class_name_valid = true; } else { @@ -244,7 +248,6 @@ void ScriptCreateDialog::_class_name_changed(const String &p_name) { } void ScriptCreateDialog::_parent_name_changed(const String &p_parent) { - if (_validate_parent(parent_name->get_text())) { is_parent_name_valid = true; } else { @@ -254,7 +257,6 @@ 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(p_template); EditorSettings::get_singleton()->set_project_metadata("script_setup", "last_selected_template", selected_template); if (p_template == 0) { @@ -274,7 +276,6 @@ void ScriptCreateDialog::_template_changed(int p_template) { } void ScriptCreateDialog::ok_pressed() { - if (is_new_script_created) { _create_new(); } else { @@ -286,7 +287,6 @@ void ScriptCreateDialog::ok_pressed() { } void ScriptCreateDialog::_create_new() { - String cname_param; if (has_named_classes) { @@ -311,8 +311,9 @@ void ScriptCreateDialog::_create_new() { if (has_named_classes) { String cname = class_name->get_text(); - if (cname.length()) + if (cname.length()) { scr->set_name(cname); + } } if (!is_built_in) { @@ -331,7 +332,6 @@ void ScriptCreateDialog::_create_new() { } void ScriptCreateDialog::_load_exist() { - String path = file_path->get_text(); RES p_script = ResourceLoader::load(path, "Script"); if (p_script.is_null()) { @@ -345,14 +345,14 @@ void ScriptCreateDialog::_load_exist() { } void ScriptCreateDialog::_lang_changed(int l) { - ScriptLanguage *language = ScriptServer::get_language(l); has_named_classes = language->has_named_classes(); can_inherit_from_file = language->can_inherit_from_file(); supports_built_in = language->supports_builtin_mode(); - if (!supports_built_in) + if (!supports_built_in) { is_built_in = false; + } String selected_ext = "." + language->get_extension(); String path = file_path->get_text(); @@ -409,7 +409,6 @@ void ScriptCreateDialog::_lang_changed(int l) { // Populate script template items previously sorted and now grouped by origin for (int i = 0; i < template_list.size(); i++) { - if (int(templates[i].origin) != cur_origin) { template_menu->add_separator(); @@ -474,7 +473,6 @@ void ScriptCreateDialog::_lang_changed(int l) { } void ScriptCreateDialog::_update_script_templates(const String &p_extension) { - template_list.clear(); template_overrides.clear(); @@ -485,7 +483,6 @@ void ScriptCreateDialog::_update_script_templates(const String &p_extension) { dirs.push_back(EditorSettings::get_singleton()->get_script_templates_dir()); for (int i = 0; i < dirs.size(); i++) { - Vector<String> list = EditorSettings::get_singleton()->get_script_templates(p_extension, dirs[i]); for (int j = 0; j < list.size(); j++) { @@ -509,7 +506,6 @@ void ScriptCreateDialog::_update_script_templates(const String &p_extension) { } void ScriptCreateDialog::_built_in_pressed() { - if (internal->is_pressed()) { is_built_in = true; is_new_script_created = true; @@ -521,7 +517,6 @@ void ScriptCreateDialog::_built_in_pressed() { } void ScriptCreateDialog::_browse_path(bool browse_parent, bool p_save) { - is_browsing_parent = browse_parent; if (p_save) { @@ -549,7 +544,6 @@ void ScriptCreateDialog::_browse_path(bool browse_parent, bool p_save) { } void ScriptCreateDialog::_file_selected(const String &p_file) { - String p = ProjectSettings::get_singleton()->localize_path(p_file); if (is_browsing_parent) { parent_name->set_text("\"" + p + "\""); @@ -567,19 +561,16 @@ void ScriptCreateDialog::_file_selected(const String &p_file) { } void ScriptCreateDialog::_create() { - parent_name->set_text(select_class->get_selected_type().split(" ")[0]); _parent_name_changed(parent_name->get_text()); } void ScriptCreateDialog::_browse_class_in_tree() { - select_class->set_base_type(base_type); select_class->popup_create(true); } void ScriptCreateDialog::_path_changed(const String &p_path) { - if (is_built_in) { return; } @@ -612,7 +603,6 @@ void ScriptCreateDialog::_path_entered(const String &p_path) { } void ScriptCreateDialog::_msg_script_valid(bool valid, const String &p_msg) { - error_label->set_text("- " + TTR(p_msg)); if (valid) { error_label->add_theme_color_override("font_color", gc->get_theme_color("success_color", "Editor")); @@ -622,7 +612,6 @@ void ScriptCreateDialog::_msg_script_valid(bool valid, const String &p_msg) { } void ScriptCreateDialog::_msg_path_valid(bool valid, const String &p_msg) { - path_error_label->set_text("- " + TTR(p_msg)); if (valid) { path_error_label->add_theme_color_override("font_color", gc->get_theme_color("success_color", "Editor")); @@ -632,7 +621,6 @@ 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; @@ -737,14 +725,12 @@ void ScriptCreateDialog::_update_dialog() { } void ScriptCreateDialog::_bind_methods() { - 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"))); } ScriptCreateDialog::ScriptCreateDialog() { - /* DIALOG */ /* Main Controls */ @@ -799,7 +785,6 @@ ScriptCreateDialog::ScriptCreateDialog() { default_language = 0; for (int i = 0; i < ScriptServer::get_language_count(); i++) { - String lang = ScriptServer::get_language(i)->get_name(); language_menu->add_item(lang); if (lang == "GDScript") { |