Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_outliner/outliner_collections.c
| Show First 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | for (SceneCollection *sc = lb->first; sc; sc = sc->next) { | ||||
| SceneCollection *sc_nested = scene_collection_from_index(&sc->scene_collections, number, i); | SceneCollection *sc_nested = scene_collection_from_index(&sc->scene_collections, number, i); | ||||
| if (sc_nested) { | if (sc_nested) { | ||||
| return sc_nested; | return sc_nested; | ||||
| } | } | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| struct TreeElementFindData | |||||
dfelinto: Why not use BKE_layer_collection_from_index? | |||||
Done Inline ActionsTotally missed that function - thanks :) spockTheGray: Totally missed that function - thanks :) | |||||
| { | |||||
| SceneCollection *sc; | |||||
| TreeElement *te; | |||||
| }; | |||||
| static TreeTraversalAction tree_element_find_by_scene_collection(TreeElement *te, void *customdata) | |||||
| { | |||||
| struct 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, int scene_collection_index) | |||||
| { | |||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | |||||
| SpaceOops *soops = CTX_wm_space_outliner(C); | |||||
| int index = 0; | |||||
| LayerCollection *lc = BKE_layer_collection_from_index(view_layer, 0); | |||||
| if (lc == NULL) { | |||||
| return NULL; | |||||
Done Inline ActionsSee code-style: https://wiki.blender.org/index.php/Dev:Doc/Code_Style#Braces dfelinto: See code-style: https://wiki.blender.org/index.php/Dev:Doc/Code_Style#Braces | |||||
| } | |||||
| /* Find the tree element containing the LayerCollection's scene_collection */ | |||||
| struct TreeElementFindData data = { .sc = lc->scene_collection,.te = NULL }; | |||||
| outliner_tree_traverse(soops, &soops->tree, NULL, NULL, 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); | ||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| SceneCollection *sc_master = BKE_collection_master(&scene->id); | SceneCollection *sc_master = BKE_collection_master(&scene->id); | ||||
| SceneCollection *sc; | SceneCollection *sc; | ||||
| int scene_collection_index = RNA_enum_get(op->ptr, "scene_collection"); | int scene_collection_index = RNA_enum_get(op->ptr, "scene_collection"); | ||||
Done Inline Actionsdfelinto: See code-style: https://wiki.blender.org/index.php/Dev:Doc/Code_Style#Always_Use_Braces | |||||
| if (scene_collection_index == 0) { | if (scene_collection_index == 0) { | ||||
| sc = sc_master; | sc = sc_master; | ||||
| } | } | ||||
| else { | else { | ||||
| int index = 1; | int index = 1; | ||||
| sc = scene_collection_from_index(&sc_master->scene_collections, scene_collection_index, &index); | sc = scene_collection_from_index(&sc_master->scene_collections, scene_collection_index, &index); | ||||
| BLI_assert(sc); | BLI_assert(sc); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 227 Lines • ▼ Show 20 Lines | else { | ||||
| BLI_gset_add(data->collections_to_delete, scene_collection); | BLI_gset_add(data->collections_to_delete, scene_collection); | ||||
| } | } | ||||
| return TRAVERSE_CONTINUE; | return TRAVERSE_CONTINUE; | ||||
| } | } | ||||
| 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); | |||||
Done Inline ActionsNick-picking: - Main *mainvar = CTX_data_main(C); + Main *bmain = CTX_data_main(C); dfelinto: Nick-picking:
```
- Main *mainvar = CTX_data_main(C);
+ 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}; | ||||
| data.collections_to_delete = BLI_gset_ptr_new(__func__); | data.collections_to_delete = BLI_gset_ptr_new(__func__); | ||||
| TODO_LAYER_OVERRIDE; /* handle overrides */ | TODO_LAYER_OVERRIDE; /* handle overrides */ | ||||
| /* We first walk over and find the SceneCollections we actually want to delete (ignoring duplicates). */ | /* We first walk over and find the SceneCollections we actually want to delete (ignoring duplicates). */ | ||||
| outliner_tree_traverse(soops, &soops->tree, 0, TSE_SELECTED, collection_find_data_to_delete, &data); | outliner_tree_traverse(soops, &soops->tree, 0, TSE_SELECTED, collection_find_data_to_delete, &data); | ||||
| /* Effectively delete the collections. */ | /* Effectively delete the collections. */ | ||||
| GSetIterator collections_to_delete_iter; | GSetIterator collections_to_delete_iter; | ||||
| GSET_ITER(collections_to_delete_iter, data.collections_to_delete) { | GSET_ITER(collections_to_delete_iter, data.collections_to_delete) { | ||||
| SceneCollection *sc = BLI_gsetIterator_getKey(&collections_to_delete_iter); | SceneCollection *sc = BLI_gsetIterator_getKey(&collections_to_delete_iter); | ||||
| BKE_collection_remove(&data.scene->id, sc); | BKE_collection_remove(&data.scene->id, sc); | ||||
| } | } | ||||
| 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, 0); | |||||
| if (select_te) { | |||||
Done Inline Actionsdfelinto: See code-style: https://wiki.blender.org/index.php/Dev:Doc/Code_Style#Always_Use_Braces | |||||
| 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. */ | ||||
| DEG_id_tag_update(&scene->id, 0); | DEG_id_tag_update(&scene->id, 0); | ||||
| WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL); | WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| ▲ Show 20 Lines • Show All 182 Lines • Show Last 20 Lines | |||||
Why not use BKE_layer_collection_from_index?