Merge pull request #108125 from Calinou/project-manager-tags-auto-underscore-lowercase

Replace spaces and use lowercase automatically for project manager tags
This commit is contained in:
Thaddeus Crews 2025-11-17 19:36:20 -06:00
commit 376a19e0bd
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC

View file

@ -1073,11 +1073,6 @@ void ProjectManager::_set_new_tag_name(const String p_name) {
return;
}
if (p_name.contains_char(' ')) {
tag_error->set_text(TTRC("Tag name can't contain spaces."));
return;
}
if (p_name[0] == '_' || p_name[p_name.length() - 1] == '_') {
tag_error->set_text(TTRC("Tag name can't begin or end with underscore."));
return;
@ -1085,9 +1080,10 @@ void ProjectManager::_set_new_tag_name(const String p_name) {
bool was_underscore = false;
for (const char32_t &c : p_name.span()) {
if (c == '_') {
// Treat spaces as underscores, as we convert spaces to underscores automatically in the tag input field.
if (c == '_' || c == ' ') {
if (was_underscore) {
tag_error->set_text(TTRC("Tag name can't contain consecutive underscores."));
tag_error->set_text(TTRC("Tag name can't contain consecutive underscores or spaces."));
return;
}
was_underscore = true;
@ -1103,11 +1099,6 @@ void ProjectManager::_set_new_tag_name(const String p_name) {
}
}
if (p_name.to_lower() != p_name) {
tag_error->set_text(TTRC("Tag name must be lowercase."));
return;
}
tag_error->set_text("");
create_tag_dialog->get_ok_button()->set_disabled(false);
}
@ -1117,8 +1108,12 @@ void ProjectManager::_create_new_tag() {
return;
}
create_tag_dialog->hide(); // When using text_submitted, need to hide manually.
add_new_tag(new_tag_name->get_text());
_add_project_tag(new_tag_name->get_text());
// Enforce a valid tag name (no spaces, lowercase only) automatically.
// The project manager displays underscores as spaces, and capitalization is performed automatically.
const String new_tag = new_tag_name->get_text().strip_edges().to_lower().replace_char(' ', '_');
add_new_tag(new_tag);
_add_project_tag(new_tag);
}
void ProjectManager::add_new_tag(const String &p_tag) {
@ -1880,6 +1875,7 @@ ProjectManager::ProjectManager() {
new_tag_name = memnew(LineEdit);
tag_vb->add_child(new_tag_name);
new_tag_name->set_accessibility_name(TTRC("New Tag Name"));
new_tag_name->set_placeholder(TTRC("example_tag (will display as Example Tag)"));
new_tag_name->connect(SceneStringName(text_changed), callable_mp(this, &ProjectManager::_set_new_tag_name));
new_tag_name->connect(SceneStringName(text_submitted), callable_mp(this, &ProjectManager::_create_new_tag).unbind(1));
create_tag_dialog->connect("about_to_popup", callable_mp(new_tag_name, &LineEdit::clear));