1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-02 16:48:55 +00:00

Fixed validation error with export preset names

This commit is contained in:
Miracle Aigbogun
2025-11-11 17:07:18 -06:00
parent ef34c3d534
commit b630d374a2
4 changed files with 41 additions and 2 deletions

View File

@@ -156,6 +156,19 @@ int EditorExport::get_export_platform_index_by_name(const String &p_name) {
return -1; 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<EditorExportPlatform> EditorExport::get_export_platform(int p_idx) { Ref<EditorExportPlatform> EditorExport::get_export_platform(int p_idx) {
ERR_FAIL_INDEX_V(p_idx, export_platforms.size(), Ref<EditorExportPlatform>()); ERR_FAIL_INDEX_V(p_idx, export_platforms.size(), Ref<EditorExportPlatform>());

View File

@@ -88,6 +88,7 @@ public:
void load_config(); void load_config();
void update_export_presets(); void update_export_presets();
bool poll_export_platforms(); 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); void connect_presets_runnable_updated(const Callable &p_target);
EditorExport(); EditorExport();

View File

@@ -534,10 +534,33 @@ void ProjectExportDialog::_name_changed(const String &p_string) {
Ref<EditorExportPreset> current = get_current_preset(); Ref<EditorExportPreset> current = get_current_preset();
ERR_FAIL_COND(current.is_null()); 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(); _update_presets();
} }
void ProjectExportDialog::_name_editing_finished() {
if (updating) {
return;
}
_name_changed(name->get_text());
}
void ProjectExportDialog::set_export_path(const String &p_value) { void ProjectExportDialog::set_export_path(const String &p_value) {
Ref<EditorExportPreset> current = get_current_preset(); Ref<EditorExportPreset> current = get_current_preset();
ERR_FAIL_COND(current.is_null()); ERR_FAIL_COND(current.is_null());
@@ -1506,7 +1529,8 @@ ProjectExportDialog::ProjectExportDialog() {
name = memnew(LineEdit); name = memnew(LineEdit);
settings_vb->add_margin_child(TTR("Name:"), name); 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 = memnew(CheckButton);
runnable->set_text(TTR("Runnable")); runnable->set_text(TTR("Runnable"));

View File

@@ -133,6 +133,7 @@ class ProjectExportDialog : public ConfirmationDialog {
void _runnable_pressed(); void _runnable_pressed();
void _update_parameters(const String &p_edited_property); void _update_parameters(const String &p_edited_property);
void _name_changed(const String &p_string); 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 _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 _add_preset(int p_platform);
void _edit_preset(int p_index); void _edit_preset(int p_index);