Clarify that Tree.create_item(), Tree.set_columns & Tree.clear can fail & when.

Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
This commit is contained in:
AR-DEV-1 2025-11-26 12:00:19 +05:00 committed by AR
parent aa094e93e3
commit 26b8af6bf0
2 changed files with 6 additions and 3 deletions

View file

@ -40,6 +40,7 @@
<return type="void" />
<description>
Clears the tree. This removes all items.
Prints an error and does not allow clearing the tree if called during mouse selection.
</description>
</method>
<method name="create_item">
@ -50,6 +51,7 @@
Creates an item in the tree and adds it as a child of [param parent], which can be either a valid [TreeItem] or [code]null[/code].
If [param parent] is [code]null[/code], the root item will be the parent, or the new item will be the root itself if the tree is empty.
The new item will be the [param index]-th child of parent, or it will be the last child if there are not enough siblings.
Prints an error and returns [code]null[/code] if called during mouse selection, or if the [param parent] does not belong to this tree.
</description>
</method>
<method name="deselect_all">
@ -365,6 +367,7 @@
</member>
<member name="columns" type="int" setter="set_columns" getter="get_columns" default="1">
The number of columns.
Prints an error and does not allow setting the columns during mouse selection.
</member>
<member name="drop_mode_flags" type="int" setter="set_drop_mode_flags" getter="get_drop_mode_flags" default="0">
The drop mode as an OR combination of flags. See [enum DropModeFlags] constants. Once dropping is done, reverts to [constant DROP_MODE_DISABLED]. Setting this during [method Control._can_drop_data] is recommended.

View file

@ -5323,7 +5323,7 @@ Size2 Tree::get_minimum_size() const {
}
TreeItem *Tree::create_item(TreeItem *p_parent, int p_index) {
ERR_FAIL_COND_V(blocked > 0, nullptr);
ERR_FAIL_COND_V_MSG(blocked > 0, nullptr, "The tree cannot create items during mouse selection events.");
TreeItem *ti = nullptr;
@ -5487,7 +5487,7 @@ bool Tree::is_anything_selected() {
}
void Tree::clear() {
ERR_FAIL_COND(blocked > 0);
ERR_FAIL_COND_MSG(blocked > 0, "The tree cannot be cleared during mouse selection events.");
if (pressing_for_editor) {
if (range_drag_enabled) {
@ -5764,7 +5764,7 @@ void Tree::propagate_set_columns(TreeItem *p_item) {
void Tree::set_columns(int p_columns) {
ERR_FAIL_COND(p_columns < 1);
ERR_FAIL_COND(blocked > 0);
ERR_FAIL_COND_MSG(blocked > 0, "The number of columns cannot be changed during mouse selection events.");
if (columns.size() > p_columns) {
for (int i = p_columns; i < columns.size(); i++) {