Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c2246a5

Browse files
committedNov 9, 2023
Merge pull request godotengine#84668 from YuriSizov/gui-dont-warn-when-popup-subs-are-nameless
Allow auto-generated node names in `PopupMenu::add_submenu_item`
2 parents 02e52da + edcad2e commit c2246a5

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed
 

‎core/string/ustring.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -4699,11 +4699,16 @@ String String::property_name_encode() const {
46994699

47004700
static const char32_t invalid_node_name_characters[] = { '.', ':', '@', '/', '\"', UNIQUE_NODE_PREFIX[0], 0 };
47014701

4702-
String String::get_invalid_node_name_characters() {
4702+
String String::get_invalid_node_name_characters(bool p_allow_internal) {
47034703
// Do not use this function for critical validation.
47044704
String r;
47054705
const char32_t *c = invalid_node_name_characters;
47064706
while (*c) {
4707+
if (p_allow_internal && *c == '@') {
4708+
c++;
4709+
continue;
4710+
}
4711+
47074712
if (c != invalid_node_name_characters) {
47084713
r += " ";
47094714
}

‎core/string/ustring.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ class String {
437437
String property_name_encode() const;
438438

439439
// node functions
440-
static String get_invalid_node_name_characters();
440+
static String get_invalid_node_name_characters(bool p_allow_internal = false);
441441
String validate_node_name() const;
442442
String validate_identifier() const;
443443
String validate_filename() const;

‎scene/gui/popup_menu.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,11 @@ void PopupMenu::add_icon_radio_check_shortcut(const Ref<Texture2D> &p_icon, cons
14871487
}
14881488

14891489
void PopupMenu::add_submenu_item(const String &p_label, const String &p_submenu, int p_id) {
1490-
ERR_FAIL_COND_MSG(p_submenu.validate_node_name() != p_submenu, "Invalid node name for submenu, the following characters are not allowed:\n" + String::get_invalid_node_name_characters());
1490+
String submenu_name_safe = p_submenu.replace("@", "_"); // Allow special characters for auto-generated names.
1491+
if (submenu_name_safe.validate_node_name() != submenu_name_safe) {
1492+
ERR_FAIL_MSG(vformat("Invalid node name '%s' for a submenu, the following characters are not allowed:\n%s", p_submenu, String::get_invalid_node_name_characters(true)));
1493+
}
1494+
14911495
Item item;
14921496
item.text = p_label;
14931497
item.xl_text = atr(p_label);

0 commit comments

Comments
 (0)
Please sign in to comment.