Repository: godotengine/godot
File: editor/inspector/editor_properties.cpp (C++)

Code before:
		flags.push_back(cb);

		// Can't use `i == 0` because we want to find the first none-empty option.
		if (first) {
			set_label_reference(cb);
			first = false;
		}
	}
}

EditorPropertyFlags::EditorPropertyFlags() {
	vbox = memnew(VBoxContainer);
	vbox->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
	add_child(vbox);
}

///////////////////// LAYERS /////////////////////////

void EditorPropertyLayersGrid::_rename_pressed(int p_menu) {
	ERR_FAIL_INDEX(renamed_layer_index, names.size());
	String name = names[renamed_layer_index];
	rename_dialog->set_title(vformat(TTR("Renaming layer %d:"), renamed_layer_index + 1));
	rename_dialog_text->set_text(name);
	rename_dialog_text->select(0, name.length());
	rename_dialog->popup_centered(Size2(300, 80) * EDSCALE);
	rename_dialog_text->grab_focus();
}

void EditorPropertyLayersGrid::_rename_operation_confirm() {
	String new_name = rename_dialog_text->get_text().strip_edges();
	if (new_name.length() == 0) {
		EditorNode::get_singleton()->show_warning(TTR("No name provided."));
		return;
	} else if (new_name.contains_char('/') || new_name.contains_char('\\') || new_name.contains_char(':')) {
		EditorNode::get_singleton()->show_warning(TTR("Name contains invalid characters."));
		return;
	}
	names.set(renamed_layer_index, new_name);
	tooltips.set(renamed_layer_index, new_name + "\n" + vformat(TTR("Bit %d, value %d"), renamed_layer_index, 1u << renamed_layer_index));
	emit_signal(SNAME("rename_confirmed"), renamed_layer_index, new_name);
}

EditorPropertyLayersGrid::EditorPropertyLayersGrid() {
	rename_dialog = memnew(ConfirmationDialog);
	VBoxContainer *rename_dialog_vb = memnew(VBoxContainer);
	rename_dialog->add_child(rename_dialog_vb);
	rename_dialog_text = memnew(LineEdit);
	rename_dialog_vb->add_margin_child(TTR("Name:"), rename_dialog_text);
	rename_dialog->set_ok_button_text(TTR("Rename"));
	add_child(rename_dialog);
	rename_dialog->register_text_enter(rename_dialog_text);

Review comment (bug):
`renamed_layer_index ` should always be valid here, would be a bug if it isn't, hence changed to error.

Code after:
		cb->set_text(text_split[0]);
		cb->set_clip_text(true);
		cb->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyFlags::_flag_toggled).bind(flag_index));
		add_focusable(cb);
		vbox->add_child(cb);
		flags.push_back(cb);

		// Can't use `i == 0` because we want to find the first none-empty option.
		if (first) {
			set_label_reference(cb);
			first = false;
		}
	}
}

EditorPropertyFlags::EditorPropertyFlags() {
	vbox = memnew(VBoxContainer);
	vbox->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
	add_child(vbox);
}

///////////////////// LAYERS /////////////////////////

void EditorPropertyLayersGrid::_rename_pressed(int p_menu) {
	// Show rename popup for active layer.
	ERR_FAIL_INDEX(renamed_layer_index, names.size());
	String name = names[renamed_layer_index];
	rename_dialog->set_title(vformat(TTR("Renaming layer %d:"), renamed_layer_index + 1));
	rename_dialog_text->set_text(name);
	rename_dialog_text->select(0, name.length());
	rename_dialog->popup_centered(Size2(300, 80) * EDSCALE);
	rename_dialog_text->grab_focus();
}

void EditorPropertyLayersGrid::_rename_operation_confirm() {
	String new_name = rename_dialog_text->get_text().strip_edges();
	if (new_name.length() == 0) {
		EditorNode::get_singleton()->show_warning(TTR("No name provided."));
		return;
	} else if (new_name.contains_char('/') || new_name.contains_char('\\') || new_name.contains_char(':')) {
		EditorNode::get_singleton()->show_warning(TTR("Name contains invalid characters."));
		return;
	}
	names.set(renamed_layer_index, new_name);
	tooltips.set(renamed_layer_index, new_name + "\n" + vformat(TTR("Bit %d, value %d"), renamed_layer_index, 1u << renamed_layer_index));
	emit_signal(SNAME("rename_confirmed"), renamed_layer_index, new_name);
}

EditorPropertyLayersGrid::EditorPropertyLayersGrid() {
	rename_dialog = memnew(ConfirmationDialog);
	VBoxContainer *rename_dialog_vb = memnew(VBoxContainer);