Cleanup: UI: Move related tree view functions closer together
These functions are closely related, keep them together.
This commit is contained in:
@@ -232,6 +232,19 @@ class AbstractTreeViewItem : public AbstractViewItem, public TreeViewItemContain
|
||||
* \returns true when the collapsed state was changed, false otherwise.
|
||||
*/
|
||||
virtual bool set_collapsed(bool collapsed);
|
||||
/**
|
||||
* Called when the view changes an item's state from expanded to collapsed, or vice versa. Will
|
||||
* only be called if the state change is triggered through the view, not through external
|
||||
* changes. E.g. a click on an item calls it, a change in the value returned by
|
||||
* #should_be_collapsed() to reflect an external state change does not.
|
||||
*/
|
||||
virtual void on_collapse_change(bContext &C, bool is_collapsed);
|
||||
/**
|
||||
* If the result is not empty, it controls whether the item should be collapsed or not, usually
|
||||
* depending on the data that the view represents.
|
||||
*/
|
||||
virtual std::optional<bool> should_be_collapsed() const;
|
||||
|
||||
/**
|
||||
* Make this item be uncollapsed on first draw (may later be overridden by
|
||||
* #should_be_collapsed()). Must only be done during tree building.
|
||||
@@ -249,19 +262,6 @@ class AbstractTreeViewItem : public AbstractViewItem, public TreeViewItemContain
|
||||
|
||||
int count_parents() const;
|
||||
|
||||
/**
|
||||
* Called when the view changes an item's state from expanded to collapsed, or vice versa. Will
|
||||
* only be called if the state change is triggered through the view, not through external
|
||||
* changes. E.g. a click on an item calls it, a change in the value returned by
|
||||
* #should_be_collapsed() to reflect an external state change does not.
|
||||
*/
|
||||
virtual void on_collapse_change(bContext &C, bool is_collapsed);
|
||||
/**
|
||||
* If the result is not empty, it controls whether the item should be collapsed or not, usually
|
||||
* depending on the data that the view represents.
|
||||
*/
|
||||
virtual std::optional<bool> should_be_collapsed() const;
|
||||
|
||||
protected:
|
||||
/** See AbstractViewItem::get_rename_string(). */
|
||||
/* virtual */ StringRef get_rename_string() const override;
|
||||
|
||||
@@ -660,6 +660,13 @@ bool AbstractTreeViewItem::toggle_collapsed()
|
||||
return this->set_collapsed(is_open_);
|
||||
}
|
||||
|
||||
void AbstractTreeViewItem::toggle_collapsed_from_view(bContext &C)
|
||||
{
|
||||
if (this->toggle_collapsed()) {
|
||||
this->on_collapse_change(C, this->is_collapsed());
|
||||
}
|
||||
}
|
||||
|
||||
bool AbstractTreeViewItem::set_collapsed(const bool collapsed)
|
||||
{
|
||||
if (!this->is_collapsible()) {
|
||||
@@ -673,6 +680,16 @@ bool AbstractTreeViewItem::set_collapsed(const bool collapsed)
|
||||
return true;
|
||||
}
|
||||
|
||||
void AbstractTreeViewItem::on_collapse_change(bContext & /*C*/, const bool /*is_collapsed*/)
|
||||
{
|
||||
/* Do nothing by default. */
|
||||
}
|
||||
|
||||
std::optional<bool> AbstractTreeViewItem::should_be_collapsed() const
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void AbstractTreeViewItem::uncollapse_by_default()
|
||||
{
|
||||
BLI_assert_msg(this->get_tree_view().is_reconstructed() == false,
|
||||
@@ -692,23 +709,6 @@ bool AbstractTreeViewItem::is_collapsible() const
|
||||
return this->supports_collapsing();
|
||||
}
|
||||
|
||||
void AbstractTreeViewItem::on_collapse_change(bContext & /*C*/, const bool /*is_collapsed*/)
|
||||
{
|
||||
/* Do nothing by default. */
|
||||
}
|
||||
|
||||
std::optional<bool> AbstractTreeViewItem::should_be_collapsed() const
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void AbstractTreeViewItem::toggle_collapsed_from_view(bContext &C)
|
||||
{
|
||||
if (this->toggle_collapsed()) {
|
||||
this->on_collapse_change(C, this->is_collapsed());
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractTreeViewItem::change_state_delayed()
|
||||
{
|
||||
AbstractViewItem::change_state_delayed();
|
||||
|
||||
Reference in New Issue
Block a user