Outliner: Use general warning mechanics for library overrides

Library overrides were basically using their own system to display
warnings for tree elements, even though for other display elements we
have a more general solution. With the previous commit this has been
generalized further and made trivial to extend.
This commit is contained in:
Julian Eisel
2022-05-25 19:29:39 +02:00
parent f1df685f57
commit 6feca52349
4 changed files with 29 additions and 90 deletions

View File

@@ -1921,91 +1921,6 @@ static void outliner_draw_overrides_restrictbuts(Main *bmain,
}
}
static bool outliner_draw_overrides_warning_buts(uiBlock *block,
ARegion *region,
SpaceOutliner *space_outliner,
ListBase *lb,
const bool is_open)
{
bool any_item_has_warnings = false;
LISTBASE_FOREACH (TreeElement *, te, lb) {
bool item_has_warnings = false;
const bool do_draw = outliner_is_element_in_view(te, &region->v2d);
int but_flag = UI_BUT_DRAG_LOCK;
const char *tip = nullptr;
TreeStoreElem *tselem = TREESTORE(te);
switch (tselem->type) {
case TSE_LIBRARY_OVERRIDE_BASE: {
ID *id = tselem->id;
if (id->flag & LIB_LIB_OVERRIDE_RESYNC_LEFTOVER) {
item_has_warnings = true;
if (do_draw) {
tip = TIP_(
"This override data-block is not needed anymore, but was detected as user-edited");
}
}
else if (ID_IS_OVERRIDE_LIBRARY_REAL(id) && ID_REAL_USERS(id) == 0) {
item_has_warnings = true;
if (do_draw) {
tip = TIP_("This override data-block is unused");
}
}
break;
}
case TSE_LIBRARY_OVERRIDE: {
TreeElementOverridesProperty &te_override_prop =
*tree_element_cast<TreeElementOverridesProperty>(te);
if (!te_override_prop.is_rna_path_valid) {
item_has_warnings = true;
if (do_draw) {
tip = TIP_(
"This override property does not exist in current data, it will be removed on "
"next .blend file save");
}
}
break;
}
default:
break;
}
const bool any_child_has_warnings = outliner_draw_overrides_warning_buts(
block,
region,
space_outliner,
&te->subtree,
is_open && TSELEM_OPEN(tselem, space_outliner));
if (do_draw &&
(item_has_warnings || (any_child_has_warnings && !TSELEM_OPEN(tselem, space_outliner)))) {
if (tip == nullptr) {
tip = TIP_("Some sub-items require attention");
}
uiBut *bt = uiDefIconBut(block,
UI_BTYPE_BUT,
1,
ICON_ERROR,
(int)(region->v2d.cur.xmax - OL_TOG_USER_BUTS_STATUS),
te->ys,
UI_UNIT_X,
UI_UNIT_Y,
nullptr,
0.0,
0.0,
0.0,
0.0,
tip);
UI_but_flag_enable(bt, but_flag);
}
any_item_has_warnings = any_item_has_warnings || item_has_warnings || any_child_has_warnings;
}
return any_item_has_warnings;
}
static void outliner_draw_separator(ARegion *region, const int x)
{
View2D *v2d = &region->v2d;
@@ -3993,10 +3908,6 @@ void draw_outliner(const bContext *C)
outliner_draw_userbuts(block, region, space_outliner, &space_outliner->tree);
}
else if (space_outliner->outlinevis == SO_OVERRIDES_LIBRARY) {
/* Draw overrides status columns. */
outliner_draw_overrides_warning_buts(
block, region, space_outliner, &space_outliner->tree, true);
const int x = region->v2d.cur.xmax - right_column_width;
outliner_draw_separator(region, x);
if (space_outliner->lib_override_view_mode == SO_LIB_OVERRIDE_VIEW_PROPERTIES) {

View File

@@ -61,7 +61,7 @@ class AbstractTreeElement {
* By letting this return a warning message, the tree element will display a warning icon with
* the message in the tooltip.
*/
virtual blender::StringRefNull getWarning() const;
virtual StringRefNull getWarning() const;
/**
* Expand this tree element if it is displayed for the first time (as identified by its

View File

@@ -38,6 +38,19 @@ TreeElementOverridesBase::TreeElementOverridesBase(TreeElement &legacy_te, ID &i
}
}
StringRefNull TreeElementOverridesBase::getWarning() const
{
if (id.flag & LIB_LIB_OVERRIDE_RESYNC_LEFTOVER) {
return TIP_("This override data-block is not needed anymore, but was detected as user-edited");
}
if (ID_IS_OVERRIDE_LIBRARY_REAL(&id) && ID_REAL_USERS(&id) == 0) {
return TIP_("This override data-block is unused");
}
return {};
}
void TreeElementOverridesBase::expand(SpaceOutliner &space_outliner) const
{
BLI_assert(id.override_library != nullptr);
@@ -93,4 +106,15 @@ TreeElementOverridesProperty::TreeElementOverridesProperty(TreeElement &legacy_t
legacy_te.name = override_data.override_property.rna_path;
}
StringRefNull TreeElementOverridesProperty::getWarning() const
{
if (!is_rna_path_valid) {
return TIP_(
"This override property does not exist in current data, it will be removed on "
"next .blend file save");
}
return {};
}
} // namespace blender::ed::outliner

View File

@@ -34,6 +34,8 @@ class TreeElementOverridesBase final : public AbstractTreeElement {
TreeElementOverridesBase(TreeElement &legacy_te, ID &id);
void expand(SpaceOutliner &) const override;
StringRefNull getWarning() const override;
};
class TreeElementOverridesProperty final : public AbstractTreeElement {
@@ -46,6 +48,8 @@ class TreeElementOverridesProperty final : public AbstractTreeElement {
public:
TreeElementOverridesProperty(TreeElement &legacy_te, TreeElementOverridesData &override_data);
StringRefNull getWarning() const override;
};
} // namespace blender::ed::outliner