diff options
author | Julian Eisel <julian@blender.org> | 2022-05-25 13:53:07 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2022-05-25 21:16:17 +0300 |
commit | f1df685f570bbd248b0356fdb4afda1b181d6a09 (patch) | |
tree | 9d3ae9b30bd43550059f69d6c2b3b9978ca81d5e /source/blender/editors/space_outliner/tree | |
parent | 1a516bb714bf2892d9d10dc83cc1215a41a3d1ea (diff) |
Outliner: Refactor element warning and mode column querying
Uses a inheritance based approach for querying warning of tree elements
and the mode column support of display modes.
For the warnings, tree elements can override the
`AbstractTreeElement::getWarning()` method and return a warning string.
The UI will draw the warning column with warning icons. This makes the
warning column more generalized and easier to extend to more use-cases.
E.g. library override elements will use this after a followup commit.
To support mode toggles a display mode can now just return true in the
`AbstractTreeDisplay::supportsModeColumn()` method. This makes it
trivial to add mode columns to other display modes, and less error prone
because there's no need to hunt down a bunch of display mode checks in
different places.
Diffstat (limited to 'source/blender/editors/space_outliner/tree')
9 files changed, 58 insertions, 53 deletions
diff --git a/source/blender/editors/space_outliner/tree/tree_display.cc b/source/blender/editors/space_outliner/tree/tree_display.cc index 141c68594e8..6ab497b3fbb 100644 --- a/source/blender/editors/space_outliner/tree/tree_display.cc +++ b/source/blender/editors/space_outliner/tree/tree_display.cc @@ -45,9 +45,9 @@ std::unique_ptr<AbstractTreeDisplay> AbstractTreeDisplay::createFromDisplayMode( return nullptr; } -bool AbstractTreeDisplay::hasWarnings() const +bool AbstractTreeDisplay::supportsModeColumn() const { - return has_warnings; + return false; } } // namespace blender::ed::outliner diff --git a/source/blender/editors/space_outliner/tree/tree_display.hh b/source/blender/editors/space_outliner/tree/tree_display.hh index 327f29aa15e..190e35c81d6 100644 --- a/source/blender/editors/space_outliner/tree/tree_display.hh +++ b/source/blender/editors/space_outliner/tree/tree_display.hh @@ -75,12 +75,16 @@ class AbstractTreeDisplay { */ virtual ListBase buildTree(const TreeSourceData &source_data) = 0; - /** Accessor to whether given tree has some warnings to display. */ - bool hasWarnings() const; + /** + * Define if the display mode should be allowed to show a mode column on the left. This column + * adds an icon to indicate which objects are in the current mode (edit mode, pose mode, etc.) + * and allows adding other objects to the mode by clicking the icon. + * + * Returns false by default. + */ + virtual bool supportsModeColumn() const; protected: - bool has_warnings = false; - /** All derived classes will need a handle to this, so storing it in the base for convenience. */ SpaceOutliner &space_outliner_; }; @@ -100,6 +104,8 @@ class TreeDisplayViewLayer final : public AbstractTreeDisplay { ListBase buildTree(const TreeSourceData &source_data) override; + bool supportsModeColumn() const override; + private: void add_view_layer(Scene &, ListBase &, TreeElement *); void add_layer_collections_recursive(ListBase &, ListBase &, TreeElement &); @@ -212,6 +218,8 @@ class TreeDisplayScenes final : public AbstractTreeDisplay { TreeDisplayScenes(SpaceOutliner &space_outliner); ListBase buildTree(const TreeSourceData &source_data) override; + + bool supportsModeColumn() const override; }; /* -------------------------------------------------------------------- */ diff --git a/source/blender/editors/space_outliner/tree/tree_display_libraries.cc b/source/blender/editors/space_outliner/tree/tree_display_libraries.cc index 476bbdb63ae..46a89f17687 100644 --- a/source/blender/editors/space_outliner/tree/tree_display_libraries.cc +++ b/source/blender/editors/space_outliner/tree/tree_display_libraries.cc @@ -136,9 +136,6 @@ TreeElement *TreeDisplayLibraries::add_library_contents(Main &mainvar, ListBase tenlib = outliner_add_element(&space_outliner_, &lb, &mainvar, nullptr, TSE_ID_BASE, 0); tenlib->name = IFACE_("Current File"); } - if (tenlib->flag & TE_HAS_WARNING) { - has_warnings = true; - } } /* Create data-block list parent element on demand. */ diff --git a/source/blender/editors/space_outliner/tree/tree_display_scenes.cc b/source/blender/editors/space_outliner/tree/tree_display_scenes.cc index 9e00a425a5a..6b1de7f8b95 100644 --- a/source/blender/editors/space_outliner/tree/tree_display_scenes.cc +++ b/source/blender/editors/space_outliner/tree/tree_display_scenes.cc @@ -26,6 +26,11 @@ TreeDisplayScenes::TreeDisplayScenes(SpaceOutliner &space_outliner) { } +bool TreeDisplayScenes::supportsModeColumn() const +{ + return true; +} + ListBase TreeDisplayScenes::buildTree(const TreeSourceData &source_data) { /* On first view we open scenes. */ diff --git a/source/blender/editors/space_outliner/tree/tree_display_view_layer.cc b/source/blender/editors/space_outliner/tree/tree_display_view_layer.cc index 19811e45b90..80b3365766a 100644 --- a/source/blender/editors/space_outliner/tree/tree_display_view_layer.cc +++ b/source/blender/editors/space_outliner/tree/tree_display_view_layer.cc @@ -55,6 +55,11 @@ TreeDisplayViewLayer::TreeDisplayViewLayer(SpaceOutliner &space_outliner) { } +bool TreeDisplayViewLayer::supportsModeColumn() const +{ + return true; +} + ListBase TreeDisplayViewLayer::buildTree(const TreeSourceData &source_data) { ListBase tree = {nullptr}; diff --git a/source/blender/editors/space_outliner/tree/tree_element.cc b/source/blender/editors/space_outliner/tree/tree_element.cc index 1e3fd2df7c2..94d55b70e3c 100644 --- a/source/blender/editors/space_outliner/tree/tree_element.cc +++ b/source/blender/editors/space_outliner/tree/tree_element.cc @@ -100,6 +100,11 @@ std::unique_ptr<AbstractTreeElement> AbstractTreeElement::createFromType(const i return nullptr; } +StringRefNull AbstractTreeElement::getWarning() const +{ + return ""; +} + void AbstractTreeElement::uncollapse_by_default(TreeElement *legacy_te) { if (!TREESTORE(legacy_te)->used) { @@ -118,39 +123,4 @@ void tree_element_expand(const AbstractTreeElement &tree_element, SpaceOutliner tree_element.expand(space_outliner); } -bool tree_element_warnings_get(TreeElement *te, int *r_icon, const char **r_message) -{ - TreeStoreElem *tselem = te->store_elem; - - if (tselem->type != TSE_SOME_ID) { - return false; - } - if (te->idcode != ID_LI) { - return false; - } - - Library *library = (Library *)tselem->id; - if (library->tag & LIBRARY_TAG_RESYNC_REQUIRED) { - if (r_icon) { - *r_icon = ICON_ERROR; - } - if (r_message) { - *r_message = TIP_( - "Contains linked library overrides that need to be resynced, updating the library is " - "recommended"); - } - return true; - } - if (library->id.tag & LIB_TAG_MISSING) { - if (r_icon) { - *r_icon = ICON_ERROR; - } - if (r_message) { - *r_message = TIP_("Missing library"); - } - return true; - } - return false; -} - } // namespace blender::ed::outliner diff --git a/source/blender/editors/space_outliner/tree/tree_element.hh b/source/blender/editors/space_outliner/tree/tree_element.hh index c6593a517dd..d665ff49f53 100644 --- a/source/blender/editors/space_outliner/tree/tree_element.hh +++ b/source/blender/editors/space_outliner/tree/tree_element.hh @@ -8,6 +8,8 @@ #include <memory> +#include "BLI_string_ref.hh" + struct ListBase; struct SpaceOutliner; struct TreeElement; @@ -56,6 +58,12 @@ 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; + + /** * Expand this tree element if it is displayed for the first time (as identified by its * tree-store element). * @@ -96,13 +104,4 @@ struct TreeElement *outliner_add_element(SpaceOutliner *space_outliner, void tree_element_expand(const AbstractTreeElement &tree_element, SpaceOutliner &space_outliner); -/** - * Get actual warning data of a tree element, if any. - * - * \param r_icon: The icon to display as warning. - * \param r_message: The message to display as warning. - * \return true if there is a warning, false otherwise. - */ -bool tree_element_warnings_get(struct TreeElement *te, int *r_icon, const char **r_message); - } // namespace blender::ed::outliner diff --git a/source/blender/editors/space_outliner/tree/tree_element_id_library.cc b/source/blender/editors/space_outliner/tree/tree_element_id_library.cc index 0dcaec0385a..4f1b951ccaf 100644 --- a/source/blender/editors/space_outliner/tree/tree_element_id_library.cc +++ b/source/blender/editors/space_outliner/tree/tree_element_id_library.cc @@ -4,6 +4,8 @@ * \ingroup spoutliner */ +#include "BLT_translation.h" + #include "DNA_ID.h" #include "DNA_listBase.h" @@ -24,4 +26,21 @@ bool TreeElementIDLibrary::isExpandValid() const return true; } +StringRefNull TreeElementIDLibrary::getWarning() const +{ + Library &library = reinterpret_cast<Library &>(id_); + + if (library.tag & LIBRARY_TAG_RESYNC_REQUIRED) { + return TIP_( + "Contains linked library overrides that need to be resynced, updating the library is " + "recommended"); + } + + if (library.id.tag & LIB_TAG_MISSING) { + return TIP_("Missing library"); + } + + return {}; +} + } // namespace blender::ed::outliner diff --git a/source/blender/editors/space_outliner/tree/tree_element_id_library.hh b/source/blender/editors/space_outliner/tree/tree_element_id_library.hh index ed599cf04da..2d89b55813f 100644 --- a/source/blender/editors/space_outliner/tree/tree_element_id_library.hh +++ b/source/blender/editors/space_outliner/tree/tree_element_id_library.hh @@ -17,6 +17,8 @@ class TreeElementIDLibrary final : public TreeElementID { TreeElementIDLibrary(TreeElement &legacy_te, Library &library); bool isExpandValid() const override; + + blender::StringRefNull getWarning() const override; }; } // namespace blender::ed::outliner |