Skip to content

Commit bcb694f

Browse files
committed
Merge pull request #112698 from MiracleAig/new_editor_preset_validation_fix
Fix editor preset names not being validated
2 parents 40cba90 + b630d37 commit bcb694f

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

editor/export/editor_export.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,19 @@ int EditorExport::get_export_platform_index_by_name(const String &p_name) {
156156
return -1;
157157
}
158158

159+
bool EditorExport::has_preset_with_name(const String &p_name, int p_exclude_index) const {
160+
for (int i = 0; i < export_presets.size(); i++) {
161+
if (i == p_exclude_index) {
162+
continue;
163+
}
164+
if (export_presets[i]->get_name() == p_name) {
165+
return true;
166+
}
167+
}
168+
169+
return false;
170+
}
171+
159172
Ref<EditorExportPlatform> EditorExport::get_export_platform(int p_idx) {
160173
ERR_FAIL_INDEX_V(p_idx, export_platforms.size(), Ref<EditorExportPlatform>());
161174

editor/export/editor_export.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class EditorExport : public Node {
8888
void load_config();
8989
void update_export_presets();
9090
bool poll_export_platforms();
91+
bool has_preset_with_name(const String &p_name, int p_exclude_index = -1) const;
9192
void connect_presets_runnable_updated(const Callable &p_target);
9293

9394
EditorExport();

editor/export/project_export.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,33 @@ void ProjectExportDialog::_name_changed(const String &p_string) {
534534
Ref<EditorExportPreset> current = get_current_preset();
535535
ERR_FAIL_COND(current.is_null());
536536

537-
current->set_name(p_string);
537+
int current_index = presets->get_current();
538+
539+
String trimmed_name = p_string.strip_edges();
540+
if (trimmed_name.is_empty()) {
541+
ERR_PRINT_ED("Invalid preset name: preset name cannot be empty!");
542+
name->set_text(current->get_name());
543+
return;
544+
}
545+
546+
if (EditorExport::get_singleton()->has_preset_with_name(trimmed_name, current_index)) {
547+
ERR_PRINT_ED(vformat("Invalid preset name: a preset with the name '%s' already exists!", trimmed_name));
548+
name->set_text(current->get_name());
549+
return;
550+
}
551+
552+
current->set_name(trimmed_name);
538553
_update_presets();
539554
}
540555

556+
void ProjectExportDialog::_name_editing_finished() {
557+
if (updating) {
558+
return;
559+
}
560+
561+
_name_changed(name->get_text());
562+
}
563+
541564
void ProjectExportDialog::set_export_path(const String &p_value) {
542565
Ref<EditorExportPreset> current = get_current_preset();
543566
ERR_FAIL_COND(current.is_null());
@@ -1506,7 +1529,8 @@ ProjectExportDialog::ProjectExportDialog() {
15061529

15071530
name = memnew(LineEdit);
15081531
settings_vb->add_margin_child(TTR("Name:"), name);
1509-
name->connect(SceneStringName(text_changed), callable_mp(this, &ProjectExportDialog::_name_changed));
1532+
name->connect(SceneStringName(text_submitted), callable_mp(this, &ProjectExportDialog::_name_changed));
1533+
name->connect(SceneStringName(focus_exited), callable_mp(this, &ProjectExportDialog::_name_editing_finished));
15101534

15111535
runnable = memnew(CheckButton);
15121536
runnable->set_text(TTR("Runnable"));

editor/export/project_export.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ class ProjectExportDialog : public ConfirmationDialog {
133133
void _runnable_pressed();
134134
void _update_parameters(const String &p_edited_property);
135135
void _name_changed(const String &p_string);
136+
void _name_editing_finished();
136137
void _export_path_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing);
137138
void _add_preset(int p_platform);
138139
void _edit_preset(int p_index);

0 commit comments

Comments
 (0)