Skip to content

Commit 376a19e

Browse files
committed
Merge pull request #108125 from Calinou/project-manager-tags-auto-underscore-lowercase
Replace spaces and use lowercase automatically for project manager tags
2 parents 68c125b + afbefa6 commit 376a19e

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

editor/project_manager/project_manager.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,21 +1073,17 @@ void ProjectManager::_set_new_tag_name(const String p_name) {
10731073
return;
10741074
}
10751075

1076-
if (p_name.contains_char(' ')) {
1077-
tag_error->set_text(TTRC("Tag name can't contain spaces."));
1078-
return;
1079-
}
1080-
10811076
if (p_name[0] == '_' || p_name[p_name.length() - 1] == '_') {
10821077
tag_error->set_text(TTRC("Tag name can't begin or end with underscore."));
10831078
return;
10841079
}
10851080

10861081
bool was_underscore = false;
10871082
for (const char32_t &c : p_name.span()) {
1088-
if (c == '_') {
1083+
// Treat spaces as underscores, as we convert spaces to underscores automatically in the tag input field.
1084+
if (c == '_' || c == ' ') {
10891085
if (was_underscore) {
1090-
tag_error->set_text(TTRC("Tag name can't contain consecutive underscores."));
1086+
tag_error->set_text(TTRC("Tag name can't contain consecutive underscores or spaces."));
10911087
return;
10921088
}
10931089
was_underscore = true;
@@ -1103,11 +1099,6 @@ void ProjectManager::_set_new_tag_name(const String p_name) {
11031099
}
11041100
}
11051101

1106-
if (p_name.to_lower() != p_name) {
1107-
tag_error->set_text(TTRC("Tag name must be lowercase."));
1108-
return;
1109-
}
1110-
11111102
tag_error->set_text("");
11121103
create_tag_dialog->get_ok_button()->set_disabled(false);
11131104
}
@@ -1117,8 +1108,12 @@ void ProjectManager::_create_new_tag() {
11171108
return;
11181109
}
11191110
create_tag_dialog->hide(); // When using text_submitted, need to hide manually.
1120-
add_new_tag(new_tag_name->get_text());
1121-
_add_project_tag(new_tag_name->get_text());
1111+
1112+
// Enforce a valid tag name (no spaces, lowercase only) automatically.
1113+
// The project manager displays underscores as spaces, and capitalization is performed automatically.
1114+
const String new_tag = new_tag_name->get_text().strip_edges().to_lower().replace_char(' ', '_');
1115+
add_new_tag(new_tag);
1116+
_add_project_tag(new_tag);
11221117
}
11231118

11241119
void ProjectManager::add_new_tag(const String &p_tag) {
@@ -1880,6 +1875,7 @@ ProjectManager::ProjectManager() {
18801875
new_tag_name = memnew(LineEdit);
18811876
tag_vb->add_child(new_tag_name);
18821877
new_tag_name->set_accessibility_name(TTRC("New Tag Name"));
1878+
new_tag_name->set_placeholder(TTRC("example_tag (will display as Example Tag)"));
18831879
new_tag_name->connect(SceneStringName(text_changed), callable_mp(this, &ProjectManager::_set_new_tag_name));
18841880
new_tag_name->connect(SceneStringName(text_submitted), callable_mp(this, &ProjectManager::_create_new_tag).unbind(1));
18851881
create_tag_dialog->connect("about_to_popup", callable_mp(new_tag_name, &LineEdit::clear));

0 commit comments

Comments
 (0)