From 8671dc4e03ab8daf5b05e7851601f97ef7cfe541 Mon Sep 17 00:00:00 2001 From: Eugene Yang Date: Sat, 6 May 2023 16:54:46 +0800 Subject: [PATCH] Add validation pane to create plugin dialog --- editor/plugin_config_dialog.cpp | 114 +++++++++++--------------------- editor/plugin_config_dialog.h | 16 +++-- 2 files changed, 48 insertions(+), 82 deletions(-) diff --git a/editor/plugin_config_dialog.cpp b/editor/plugin_config_dialog.cpp index 97398b8b690..7d7b156bd0a 100644 --- a/editor/plugin_config_dialog.cpp +++ b/editor/plugin_config_dialog.cpp @@ -35,6 +35,7 @@ #include "editor/editor_node.h" #include "editor/editor_plugin.h" #include "editor/editor_scale.h" +#include "editor/gui/editor_validation_panel.h" #include "editor/project_settings_editor.h" #include "scene/gui/grid_container.h" @@ -96,52 +97,28 @@ void PluginConfigDialog::_on_canceled() { _clear_fields(); } -void PluginConfigDialog::_on_language_changed(const int) { - _on_required_text_changed(String()); -} - -void PluginConfigDialog::_on_required_text_changed(const String &) { +void PluginConfigDialog::_on_required_text_changed() { int lang_idx = script_option_edit->get_selected(); String ext = ScriptServer::get_language(lang_idx)->get_extension(); - Ref valid_icon = get_theme_icon(SNAME("StatusSuccess"), SNAME("EditorIcons")); - Ref invalid_icon = get_theme_icon(SNAME("StatusWarning"), SNAME("EditorIcons")); - - // Set variables to assume all is valid - bool is_valid = true; - name_validation->set_texture(valid_icon); - subfolder_validation->set_texture(valid_icon); - script_validation->set_texture(valid_icon); - name_validation->set_tooltip_text(""); - subfolder_validation->set_tooltip_text(""); - script_validation->set_tooltip_text(""); - - // Change valid status to invalid depending on conditions. - Vector errors; if (name_edit->get_text().is_empty()) { - is_valid = false; - name_validation->set_texture(invalid_icon); - name_validation->set_tooltip_text(TTR("Plugin name cannot be blank.")); + validation_panel->set_message(MSG_ID_PLUGIN, TTR("Plugin name cannot be blank."), EditorValidationPanel::MSG_ERROR); } if ((!script_edit->get_text().get_extension().is_empty() && script_edit->get_text().get_extension() != ext) || script_edit->get_text().ends_with(".")) { - is_valid = false; - script_validation->set_texture(invalid_icon); - script_validation->set_tooltip_text(vformat(TTR("Script extension must match chosen language extension (.%s)."), ext)); + validation_panel->set_message(MSG_ID_SCRIPT, vformat(TTR("Script extension must match chosen language extension (.%s)."), ext), EditorValidationPanel::MSG_ERROR); } - if (!subfolder_edit->get_text().is_empty() && !subfolder_edit->get_text().is_valid_filename()) { - is_valid = false; - subfolder_validation->set_texture(invalid_icon); - subfolder_validation->set_tooltip_text(TTR("Subfolder name is not a valid folder name.")); - } else { - String path = "res://addons/" + _get_subfolder(); - if (!_edit_mode && DirAccess::exists(path)) { // Only show this error if in "create" mode. - is_valid = false; - subfolder_validation->set_texture(invalid_icon); - subfolder_validation->set_tooltip_text(TTR("Subfolder cannot be one which already exists.")); + if (subfolder_edit->is_visible()) { + if (!subfolder_edit->get_text().is_empty() && !subfolder_edit->get_text().is_valid_filename()) { + validation_panel->set_message(MSG_ID_SUBFOLDER, TTR("Subfolder name is not a valid folder name."), EditorValidationPanel::MSG_ERROR); + } else { + String path = "res://addons/" + _get_subfolder(); + if (!_edit_mode && DirAccess::exists(path)) { // Only show this error if in "create" mode. + validation_panel->set_message(MSG_ID_SUBFOLDER, TTR("Subfolder cannot be one which already exists."), EditorValidationPanel::MSG_ERROR); + } } + } else { + validation_panel->set_message(MSG_ID_SUBFOLDER, "", EditorValidationPanel::MSG_OK); } - - get_ok_button()->set_disabled(!is_valid); } String PluginConfigDialog::_get_subfolder() { @@ -182,23 +159,20 @@ void PluginConfigDialog::config(const String &p_config_path) { _edit_mode = true; active_edit->hide(); - Object::cast_to