diff --git a/editor/export/editor_export.cpp b/editor/export/editor_export.cpp index 3a1b56ff339..b13b7935c05 100644 --- a/editor/export/editor_export.cpp +++ b/editor/export/editor_export.cpp @@ -156,6 +156,19 @@ int EditorExport::get_export_platform_index_by_name(const String &p_name) { return -1; } +bool EditorExport::has_preset_with_name(const String &p_name, int p_exclude_index) const { + for (int i = 0; i < export_presets.size(); i++) { + if (i == p_exclude_index) { + continue; + } + if (export_presets[i]->get_name() == p_name) { + return true; + } + } + + return false; +} + Ref EditorExport::get_export_platform(int p_idx) { ERR_FAIL_INDEX_V(p_idx, export_platforms.size(), Ref()); diff --git a/editor/export/editor_export.h b/editor/export/editor_export.h index 35270686571..877fca6f271 100644 --- a/editor/export/editor_export.h +++ b/editor/export/editor_export.h @@ -88,6 +88,7 @@ public: void load_config(); void update_export_presets(); bool poll_export_platforms(); + bool has_preset_with_name(const String &p_name, int p_exclude_index = -1) const; void connect_presets_runnable_updated(const Callable &p_target); EditorExport(); diff --git a/editor/export/project_export.cpp b/editor/export/project_export.cpp index d25af38daf2..938d0c0ae32 100644 --- a/editor/export/project_export.cpp +++ b/editor/export/project_export.cpp @@ -534,10 +534,33 @@ void ProjectExportDialog::_name_changed(const String &p_string) { Ref current = get_current_preset(); ERR_FAIL_COND(current.is_null()); - current->set_name(p_string); + int current_index = presets->get_current(); + + String trimmed_name = p_string.strip_edges(); + if (trimmed_name.is_empty()) { + ERR_PRINT_ED("Invalid preset name: preset name cannot be empty!"); + name->set_text(current->get_name()); + return; + } + + if (EditorExport::get_singleton()->has_preset_with_name(trimmed_name, current_index)) { + ERR_PRINT_ED(vformat("Invalid preset name: a preset with the name '%s' already exists!", trimmed_name)); + name->set_text(current->get_name()); + return; + } + + current->set_name(trimmed_name); _update_presets(); } +void ProjectExportDialog::_name_editing_finished() { + if (updating) { + return; + } + + _name_changed(name->get_text()); +} + void ProjectExportDialog::set_export_path(const String &p_value) { Ref current = get_current_preset(); ERR_FAIL_COND(current.is_null()); @@ -1506,7 +1529,8 @@ ProjectExportDialog::ProjectExportDialog() { name = memnew(LineEdit); settings_vb->add_margin_child(TTR("Name:"), name); - name->connect(SceneStringName(text_changed), callable_mp(this, &ProjectExportDialog::_name_changed)); + name->connect(SceneStringName(text_submitted), callable_mp(this, &ProjectExportDialog::_name_changed)); + name->connect(SceneStringName(focus_exited), callable_mp(this, &ProjectExportDialog::_name_editing_finished)); runnable = memnew(CheckButton); runnable->set_text(TTR("Runnable")); diff --git a/editor/export/project_export.h b/editor/export/project_export.h index 5f6ae719d98..922634e815e 100644 --- a/editor/export/project_export.h +++ b/editor/export/project_export.h @@ -133,6 +133,7 @@ class ProjectExportDialog : public ConfirmationDialog { void _runnable_pressed(); void _update_parameters(const String &p_edited_property); void _name_changed(const String &p_string); + void _name_editing_finished(); void _export_path_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing); void _add_preset(int p_platform); void _edit_preset(int p_index);