Fix T51461: Outliner: Problems removing multiple collections in sequence
We now select the LayerCollection at index 0 for the active ViewLayer after a collection deletion operation. Added some functions to query outliner tree data & get LayerCollection by index using a similar approach as we do for SceneCollection indexing. With warning and style cleanups by Dalai Felinto. Reviewers: dfelinto Tags: #bf_blender_2.8 Differential Revision: https://developer.blender.org/D2942
This commit is contained in:
committed by
Dalai Felinto
parent
1b371d199e
commit
32f85c8322
@@ -108,6 +108,46 @@ static SceneCollection *scene_collection_from_index(ListBase *lb, const int numb
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct TreeElementFindData {
|
||||||
|
SceneCollection *sc;
|
||||||
|
TreeElement *te;
|
||||||
|
} TreeElementFindData;
|
||||||
|
|
||||||
|
static TreeTraversalAction tree_element_find_by_scene_collection(TreeElement *te, void *customdata)
|
||||||
|
{
|
||||||
|
TreeElementFindData *data = customdata;
|
||||||
|
|
||||||
|
SceneCollection *current_element_sc = outliner_scene_collection_from_tree_element(te);
|
||||||
|
|
||||||
|
if (current_element_sc == data->sc) {
|
||||||
|
data->te = te;
|
||||||
|
return TRAVERSE_BREAK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRAVERSE_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static TreeElement *outliner_tree_element_from_layer_collection(bContext *C)
|
||||||
|
{
|
||||||
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||||
|
SpaceOops *soops = CTX_wm_space_outliner(C);
|
||||||
|
|
||||||
|
LayerCollection *lc = BKE_layer_collection_from_index(view_layer, 0);
|
||||||
|
|
||||||
|
if (lc == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Find the tree element containing the LayerCollection's scene_collection. */
|
||||||
|
TreeElementFindData data = {
|
||||||
|
.sc = lc->scene_collection,
|
||||||
|
.te = NULL,
|
||||||
|
};
|
||||||
|
outliner_tree_traverse(soops, &soops->tree, 0, 0, tree_element_find_by_scene_collection, &data);
|
||||||
|
|
||||||
|
return data.te;
|
||||||
|
}
|
||||||
|
|
||||||
static int collection_link_exec(bContext *C, wmOperator *op)
|
static int collection_link_exec(bContext *C, wmOperator *op)
|
||||||
{
|
{
|
||||||
Scene *scene = CTX_data_scene(C);
|
Scene *scene = CTX_data_scene(C);
|
||||||
@@ -359,7 +399,9 @@ static TreeTraversalAction collection_find_data_to_delete(TreeElement *te, void
|
|||||||
|
|
||||||
static int collection_delete_exec(bContext *C, wmOperator *UNUSED(op))
|
static int collection_delete_exec(bContext *C, wmOperator *UNUSED(op))
|
||||||
{
|
{
|
||||||
|
Main *bmain = CTX_data_main(C);
|
||||||
Scene *scene = CTX_data_scene(C);
|
Scene *scene = CTX_data_scene(C);
|
||||||
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||||
SpaceOops *soops = CTX_wm_space_outliner(C);
|
SpaceOops *soops = CTX_wm_space_outliner(C);
|
||||||
struct CollectionDeleteData data = {.scene = scene, .soops = soops};
|
struct CollectionDeleteData data = {.scene = scene, .soops = soops};
|
||||||
|
|
||||||
@@ -380,6 +422,15 @@ static int collection_delete_exec(bContext *C, wmOperator *UNUSED(op))
|
|||||||
|
|
||||||
BLI_gset_free(data.collections_to_delete, NULL);
|
BLI_gset_free(data.collections_to_delete, NULL);
|
||||||
|
|
||||||
|
/* Rebuild the outliner tree before we select the tree element */
|
||||||
|
outliner_build_tree(bmain, scene, view_layer, soops);
|
||||||
|
|
||||||
|
TreeElement *select_te = outliner_tree_element_from_layer_collection(C);
|
||||||
|
|
||||||
|
if (select_te) {
|
||||||
|
outliner_item_select(soops, select_te, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
DEG_relations_tag_update(CTX_data_main(C));
|
DEG_relations_tag_update(CTX_data_main(C));
|
||||||
|
|
||||||
/* TODO(sergey): Use proper flag for tagging here. */
|
/* TODO(sergey): Use proper flag for tagging here. */
|
||||||
|
|||||||
@@ -203,6 +203,10 @@ int outliner_item_do_activate_from_cursor(
|
|||||||
struct bContext *C, const int mval[2],
|
struct bContext *C, const int mval[2],
|
||||||
bool extend, bool recursive);
|
bool extend, bool recursive);
|
||||||
|
|
||||||
|
void outliner_item_select(
|
||||||
|
struct SpaceOops *soops, const struct TreeElement *te,
|
||||||
|
const bool extend, const bool toggle);
|
||||||
|
|
||||||
/* outliner_edit.c ---------------------------------------------- */
|
/* outliner_edit.c ---------------------------------------------- */
|
||||||
typedef void (*outliner_operation_cb)(
|
typedef void (*outliner_operation_cb)(
|
||||||
struct bContext *C, struct ReportList *, struct Scene *scene,
|
struct bContext *C, struct ReportList *, struct Scene *scene,
|
||||||
|
|||||||
@@ -973,7 +973,7 @@ static void do_outliner_item_activate_tree_element(
|
|||||||
* \param extend: Don't deselect other items, only modify \a te.
|
* \param extend: Don't deselect other items, only modify \a te.
|
||||||
* \param toggle: Select \a te when not selected, deselect when selected.
|
* \param toggle: Select \a te when not selected, deselect when selected.
|
||||||
*/
|
*/
|
||||||
static void outliner_item_select(SpaceOops *soops, const TreeElement *te, const bool extend, const bool toggle)
|
void outliner_item_select(SpaceOops *soops, const TreeElement *te, const bool extend, const bool toggle)
|
||||||
{
|
{
|
||||||
TreeStoreElem *tselem = TREESTORE(te);
|
TreeStoreElem *tselem = TREESTORE(te);
|
||||||
const short new_flag = toggle ? (tselem->flag ^ TSE_SELECTED) : (tselem->flag | TSE_SELECTED);
|
const short new_flag = toggle ? (tselem->flag ^ TSE_SELECTED) : (tselem->flag | TSE_SELECTED);
|
||||||
|
|||||||
Reference in New Issue
Block a user