Blender V5.3
outliner_edit.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10#include <cstring>
11
12#include <fmt/format.h>
13
14#include "MEM_guardedalloc.h"
15
16#include "DNA_ID.h"
17#include "DNA_anim_types.h"
19#include "DNA_object_types.h"
20#include "DNA_scene_types.h"
21
22#include "BLI_listbase.hh"
23#include "BLI_path_utils.hh"
24#include "BLI_string.hh"
25#include "BLI_utildefines.hh"
26
27#include "BLT_translation.hh"
28
29#include "BLF_api.hh"
30
31#include "BKE_action.hh"
32#include "BKE_animsys.hh"
33#include "BKE_appdir.hh"
34#include "BKE_armature.hh"
36#include "BKE_blendfile.hh"
37#include "BKE_context.hh"
38#include "BKE_idtype.hh"
39#include "BKE_layer.hh"
40#include "BKE_lib_id.hh"
41#include "BKE_lib_override.hh"
42#include "BKE_lib_query.hh"
43#include "BKE_lib_remap.hh"
44#include "BKE_library.hh"
45#include "BKE_main.hh"
46#include "BKE_object.hh"
47#include "BKE_report.hh"
48#include "BKE_scene.hh"
49#include "BKE_screen.hh"
50#include "BKE_workspace.hh"
51
52#include "DEG_depsgraph.hh"
54
55#include "ED_keyframing.hh"
56#include "ED_outliner.hh"
57#include "ED_scene.hh"
58#include "ED_screen.hh"
59#include "ED_select_utils.hh"
60
61#include "WM_api.hh"
62#include "WM_types.hh"
63
64#include "UI_interface.hh"
65#include "UI_interface_c.hh"
67#include "UI_view2d.hh"
68
69#include "RNA_access.hh"
70#include "RNA_define.hh"
71#include "RNA_enum_types.hh"
72#include "RNA_path.hh"
73#include "RNA_prototypes.hh"
74
75#include "GPU_material.hh"
76
77#include "outliner_intern.hh"
79#include "tree/tree_iterator.hh"
80
81#include "wm_window.hh"
82
83namespace blender {
84
85using namespace blender::ed::outliner;
86
87namespace ed::outliner {
88
89static void outliner_show_active(SpaceOutliner *space_outliner,
90 ARegion *region,
91 TreeElement *te,
92 ID *id);
93
94/* -------------------------------------------------------------------- */
97
98static void outliner_copybuffer_filepath_get(char filepath[FILE_MAX], size_t filepath_maxncpy)
99{
100 /* NOTE: this uses the same path as the 3D viewport. */
101 BLI_path_join(filepath, filepath_maxncpy, BKE_tempdir_base(), "copybuffer.blend");
102}
103
105
106/* -------------------------------------------------------------------- */
109
111 wmOperator * /*op*/,
112 const wmEvent *event)
113{
114 /* stop highlighting if out of area */
115 if (!ED_screen_area_active(C)) {
117 }
118
119 /* Drag and drop does its own highlighting. */
121 if (wm->runtime->drags.first_) {
123 }
124
125 ARegion *region = CTX_wm_region(C);
126 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
127
128 float view_mval[2];
130 &region->v2d, event->mval[0], event->mval[1], &view_mval[0], &view_mval[1]);
131
133 space_outliner, &space_outliner->runtime->tree, view_mval[1]);
134
135 TreeElement *icon_te = nullptr;
136 bool is_over_icon = false;
137 if (hovered_te) {
139 space_outliner, hovered_te, view_mval[0], nullptr, &is_over_icon);
140 }
141
142 bool changed = false;
143
144 if (!hovered_te || !is_over_icon || !(hovered_te->store_elem->flag & TSE_HIGHLIGHTED) ||
145 !(icon_te->store_elem->flag & TSE_HIGHLIGHTED_ICON))
146 {
147 /* Clear highlights when nothing is hovered or when a new item is hovered. */
148 changed = outliner_flag_set(*space_outliner, TSE_HIGHLIGHTED_ANY | TSE_DRAG_ANY, false);
149 if (hovered_te) {
150 hovered_te->store_elem->flag |= TSE_HIGHLIGHTED;
151 changed = true;
152 }
153 if (is_over_icon) {
155 changed = true;
156 }
157 }
158
159 if (changed) {
161 }
162
164}
165
167{
168 ot->name = "Update Highlight";
169 ot->idname = "OUTLINER_OT_highlight_update";
170 ot->description = "Update the item highlight based on the current mouse position";
171
173
175}
176
178
179/* -------------------------------------------------------------------- */
182
183void outliner_item_openclose(TreeElement *te, bool open, bool toggle_all)
184{
185 /* Only allow opening elements with children. */
186 if (!(te->flag & TE_PRETEND_HAS_CHILDREN) && te->subtree.is_empty()) {
187 return;
188 }
189
190 /* Don't allow collapsing the scene collection. */
191 TreeStoreElem *tselem = TREESTORE(te);
192 if (tselem->type == TSE_VIEW_COLLECTION_BASE) {
193 return;
194 }
195
196 if (open) {
197 tselem->flag &= ~TSE_CLOSED;
198 }
199 else {
200 tselem->flag |= TSE_CLOSED;
201 }
202
203 if (toggle_all) {
205 }
206}
207
213
215 wmOperator *op,
216 const wmEvent *event)
217{
218 ARegion *region = CTX_wm_region(C);
219 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
220 OpenCloseData *data = static_cast<OpenCloseData *>(op->customdata);
221
222 float view_mval[2];
224 &region->v2d, event->mval[0], event->mval[1], &view_mval[0], &view_mval[1]);
225
226 if (event->type == MOUSEMOVE) {
228 space_outliner, &space_outliner->runtime->tree, view_mval[1]);
229
230 /* Only openclose if mouse is not over the previously toggled element */
231 if (te && TREESTORE(te) != data->prev_tselem) {
232
233 /* Only toggle openclose on the same level as the first clicked element */
234 if (te->xs == data->x_location) {
235 outliner_item_openclose(te, data->open, false);
236
238 }
239 }
240
241 if (te) {
242 data->prev_tselem = TREESTORE(te);
243 }
244 else {
245 data->prev_tselem = nullptr;
246 }
247 }
248 else if (event->val == KM_RELEASE) {
249 MEM_delete(data);
250
251 return OPERATOR_FINISHED;
252 }
253
255}
256
258 wmOperator *op,
259 const wmEvent *event)
260{
261 ARegion *region = CTX_wm_region(C);
262 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
263
264 const bool toggle_all = RNA_boolean_get(op->ptr, "all");
265
266 float view_mval[2];
267
268 int mval[2];
269 WM_event_drag_start_mval(event, region, mval);
270
271 ui::view2d_region_to_view(&region->v2d, mval[0], mval[1], &view_mval[0], &view_mval[1]);
272
274 space_outliner, &space_outliner->runtime->tree, view_mval[1]);
275
276 if (te && outliner_item_is_co_within_close_toggle(te, view_mval[0])) {
277 TreeStoreElem *tselem = TREESTORE(te);
278
279 const bool open = (tselem->flag & TSE_CLOSED) ||
280 (toggle_all && outliner_flag_is_any_test(&te->subtree, TSE_CLOSED, 1));
281
282 outliner_item_openclose(te, open, toggle_all);
284
285 /* Only toggle once for single click toggling */
286 if ((event->type == LEFTMOUSE) && (event->val != KM_PRESS_DRAG)) {
287 return OPERATOR_FINISHED;
288 }
289
290 /* Store last expanded tselem and x coordinate of disclosure triangle */
291 OpenCloseData *toggle_data = MEM_new_zeroed<OpenCloseData>("open_close_data");
292 toggle_data->prev_tselem = tselem;
293 toggle_data->open = open;
294 toggle_data->x_location = te->xs;
295
296 /* Store the first clicked on element */
297 op->customdata = toggle_data;
298
301 }
302
304}
305
307{
308 ot->name = "Open/Close";
309 ot->idname = "OUTLINER_OT_item_openclose";
310 ot->description = "Toggle whether item under cursor is open or closed";
311
314
316
317 RNA_def_boolean(ot->srna, "all", false, "All", "Close or open all items");
318}
319
321
322/* -------------------------------------------------------------------- */
325
326static void do_item_rename(ARegion *region,
327 TreeElement *te,
328 TreeStoreElem *tselem,
329 ReportList *reports)
330{
331 bool add_textbut = false;
332
333 /* FIXME: These info messages are often useless, they should be either reworded to be more
334 * informative for the user, or purely removed? */
335
336 /* Can't rename rna datablocks entries or listbases. */
337 if (ELEM(tselem->type,
339 TSE_NLA,
353 TSE_ID_BASE) ||
354 ELEM(tselem->type,
359 {
360 BKE_report(reports, RPT_INFO, "Not an editable name");
361 }
362 else if (ELEM(tselem->type, TSE_STRIP, TSE_STRIP_DATA, TSE_STRIP_DUP)) {
363 BKE_report(reports, RPT_INFO, "Strip names are not editable from the Outliner");
364 }
365 else if (TSE_IS_REAL_ID(tselem) && !ID_IS_EDITABLE(tselem->id)) {
366 BKE_report(reports, RPT_INFO, "External library data is not editable");
367 }
368 else if (TSE_IS_REAL_ID(tselem) && ID_IS_OVERRIDE_LIBRARY(tselem->id)) {
369 BKE_report(reports, RPT_INFO, "Overridden data-blocks names are not editable");
370 }
373
374 if (collection->flag & COLLECTION_IS_MASTER) {
375 BKE_report(reports, RPT_INFO, "Not an editable name");
376 }
377 else {
378 add_textbut = true;
379 }
380 }
381 else if (te->idcode == ID_LI) {
382 BKE_report(reports, RPT_INFO, "Library path is not editable, use the Relocate operation");
383 }
384 else {
385 add_textbut = true;
386 }
387
388 if (add_textbut) {
389 tselem->flag |= TSE_TEXTBUT;
390 ED_region_tag_redraw(region);
391 }
392}
393
395 ReportList *reports,
396 Scene * /*scene*/,
397 TreeElement *te,
398 TreeStoreElem * /*tsep*/,
399 TreeStoreElem *tselem)
400{
401 ARegion *region = CTX_wm_region(C);
402 do_item_rename(region, te, tselem, reports);
403}
404
406 ReportList *reports)
407{
408 TreeElement *active_element = outliner_find_element_with_flag(&space_outliner->runtime->tree,
409 TSE_ACTIVE);
410
411 if (!active_element) {
412 BKE_report(reports, RPT_WARNING, "No active item to rename");
413 return nullptr;
414 }
415
416 return active_element;
417}
418
420 ARegion *region,
421 const wmEvent *event)
422{
423 float fmval[2];
424 ui::view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]);
425
427 space_outliner, &space_outliner->runtime->tree, fmval[1]);
428 if (hovered && outliner_item_is_co_over_name(hovered, fmval[0])) {
429 return hovered;
430 }
431
432 return nullptr;
433}
434
436 wmOperator *op,
437 const wmEvent *event)
438{
439 ARegion *region = CTX_wm_region(C);
440 View2D *v2d = &region->v2d;
441 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
442 const bool use_active = RNA_boolean_get(op->ptr, "use_active");
443
444 TreeElement *te = use_active ? outliner_item_rename_find_active(space_outliner, op->reports) :
445 outliner_item_rename_find_hovered(space_outliner, region, event);
446 if (!te) {
448 }
449
450 /* Force element into view. */
451 outliner_show_active(space_outliner, region, te, TREESTORE(te)->id);
452
453 if (te->ys < int(v2d->cur.ymin + UI_UNIT_Y)) {
454 /* Try to show one full row below. */
455 const int delta_y = te->ys - int(v2d->cur.ymin + UI_UNIT_Y);
456 outliner_scroll_view(space_outliner, region, delta_y);
457 }
458 else if (te->ys > int(v2d->cur.ymax - (UI_UNIT_Y * 2.0f))) {
459 /* Try to show one full row above. */
460 const int delta_y = te->ys - int(v2d->cur.ymax - (UI_UNIT_Y * 2.0f));
461 outliner_scroll_view(space_outliner, region, delta_y);
462 }
463
464 do_item_rename(region, te, TREESTORE(te), op->reports);
465
466 return OPERATOR_FINISHED;
467}
468
470{
471 PropertyRNA *prop;
472
473 ot->name = "Rename";
474 ot->idname = "OUTLINER_OT_item_rename";
475 ot->description = "Rename the active element";
476
478
480
481 /* Flags. No undo, since this operator only activate the name editing text field in the Outliner,
482 * but does not actually change anything. */
483 ot->flag = OPTYPE_REGISTER;
484
485 prop = RNA_def_boolean(ot->srna,
486 "use_active",
487 false,
488 "Use Active",
489 "Rename the active item, rather than the one the mouse is over");
491}
492
494
495/* -------------------------------------------------------------------- */
498
509
515
517 bool can_replace() const
518 {
520 }
521
523 bool is_valid() const
524 {
525 /* Both pointers should be either null, or non-null (in which case they should also not be the
526 * same, and the replacement scene should not be tagged for deletion).
527 *
528 * Otherwise, the scene to be deleted does not have a valid replacement, and cannot be deleted.
529 */
530 return ((!scene_to_delete && !scene_to_activate) ||
533 }
534};
535
537 ReportList *reports,
538 TreeElement *te,
539 TreeStoreElem *tselem,
540 SceneReplaceData &scene_replace_data)
541{
542 Main *bmain = CTX_data_main(C);
543 ID *id = tselem->id;
544
545 BLI_assert(id != nullptr);
546 BLI_assert(((tselem->type == TSE_SOME_ID) && (te->idcode != 0)) ||
547 (tselem->type == TSE_LAYER_COLLECTION));
549
550 if (ID_IS_OVERRIDE_LIBRARY(id)) {
552 (id->override_library->flag & LIBOVERRIDE_FLAG_NO_HIERARCHY) == 0)
553 {
554 BKE_reportf(reports,
556 "Cannot delete library override id '%s', it is part of an override hierarchy",
557 id->name);
558 return false;
559 }
560 }
561
562 /* Current active scene, and the one to use to replace it, in case the former is to be deleted.
563 */
564 Scene *scene_curr = nullptr;
565 Scene *scene_new = nullptr;
566
567 if (te->idcode == ID_LI) {
568 /* Get the scene currently expected to become the active scene. */
569 scene_curr = scene_replace_data.active_scene_get(C);
570 Library *lib = id_cast<Library *>(id);
571 if (lib->runtime->parent != nullptr) {
572 BKE_reportf(reports, RPT_WARNING, "Cannot delete indirectly linked library '%s'", id->name);
573 return false;
574 }
575 Set<Library *> libraries{lib};
576 libraries.add_multiple_new(lib->runtime->archived_libraries.as_span());
577 BLI_assert(!libraries.contains(nullptr));
578 if (libraries.contains(scene_curr->id.lib)) {
579 scene_new = BKE_scene_find_replacement(
580 *bmain, *scene_curr, [&libraries](const Scene &scene) -> bool {
581 return (
582 /* The candidate scene must belong to a different set of libraries (owner library
583 * and all of its archive ones). */
584 !libraries.contains(scene.id.lib) &&
585 /* The candidate scene must not be tagged for deletion. */
586 (scene.id.tag & ID_TAG_DOIT) == 0 &&
587 /* The candidate scene must be locale, or its library must not be tagged for
588 * deletion. */
589 (!scene.id.lib || (scene.id.lib->id.tag & ID_TAG_DOIT) == 0));
590 });
591 if (!scene_new) {
592 BKE_reportf(reports,
594 "Cannot find a scene to replace the active one, which belongs to the to be "
595 "deleted library '%s'",
596 id->name);
597 return false;
598 }
599 }
600 }
601 if (id->tag & ID_TAG_INDIRECT) {
602 BKE_reportf(reports, RPT_WARNING, "Cannot delete indirectly linked id '%s'", id->name);
603 return false;
604 }
605 if (ID_REAL_USERS(id) <= 1 && BKE_library_ID_is_indirectly_used(bmain, id)) {
606 BKE_reportf(reports,
608 "Cannot delete id '%s', indirectly used data-blocks need at least one user",
609 id->name);
610 return false;
611 }
612 if (te->idcode == ID_WS) {
614 if (id->tag & ID_TAG_PRE_EXISTING) {
616 reports, RPT_WARNING, "Cannot delete currently visible workspace id '%s'", id->name);
618 return false;
619 }
621 }
622 else if (te->idcode == ID_SCE) {
623 /* Get the scene currently expected to become the active scene. */
624 scene_curr = scene_replace_data.active_scene_get(C);
625 if (&scene_curr->id == id) {
626 scene_new = BKE_scene_find_replacement(*bmain, *scene_curr, [](const Scene &scene) -> bool {
627 return (
628 /* The candidate scene must not be tagged for deletion. */
629 (scene.id.tag & ID_TAG_DOIT) == 0 &&
630 /* The candidate scene must be locale, or its library must not be tagged for
631 * deletion. */
632 (!scene.id.lib || (scene.id.lib->id.tag & ID_TAG_DOIT) == 0));
633 });
634 if (!scene_new) {
635 BKE_reportf(reports,
637 "Cannot find a scene to replace the active deleted one '%s'",
638 id->name);
639 return false;
640 }
641 }
642 }
643
644 id->tag |= ID_TAG_DOIT;
645 if (scene_curr && scene_new) {
646 BLI_assert(scene_curr != scene_new);
647 BLI_assert((scene_new->id.tag & ID_TAG_DOIT) == 0);
648 if (!scene_replace_data.scene_to_delete) {
649 scene_replace_data.scene_to_delete = scene_curr;
650 }
651 else {
652 BLI_assert(scene_replace_data.scene_to_delete == CTX_data_scene(C));
653 }
654 scene_replace_data.scene_to_activate = scene_new;
655 }
656
658
659 return true;
660}
661
663 ReportList *reports,
664 Scene * /*scene*/,
665 TreeElement *te,
666 TreeStoreElem * /*tsep*/,
667 TreeStoreElem *tselem)
668{
669 SceneReplaceData scene_replace_data;
670 id_delete_tag(C, reports, te, tselem, scene_replace_data);
671
672 BLI_assert(scene_replace_data.is_valid());
673 if (scene_replace_data.can_replace()) {
676 *scene_replace_data.scene_to_delete,
677 scene_replace_data.scene_to_activate);
678 }
679}
680
682 ReportList *reports,
683 TreeElement *te,
684 const float mval[2],
685 SceneReplaceData &scene_replace_data)
686{
687 int id_tagged_num = 0;
688
689 if (mval[1] > te->ys && mval[1] < te->ys + UI_UNIT_Y) {
690 TreeStoreElem *tselem = TREESTORE(te);
691
692 if (te->idcode != 0 && tselem->id) {
693 if (id_delete_tag(C, reports, te, tselem, scene_replace_data)) {
694 id_tagged_num++;
695 }
696 }
697 }
698 else {
699 for (TreeElement &te_sub : te->subtree) {
700 if ((id_tagged_num += outliner_id_delete_tag(
701 C, reports, &te_sub, mval, scene_replace_data)) != 0)
702 {
703 break;
704 }
705 }
706 }
707
708 return id_tagged_num;
709}
710
712 wmOperator *op,
713 const wmEvent *event)
714{
715 Main *bmain = CTX_data_main(C);
716 ARegion *region = CTX_wm_region(C);
717 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
718 float fmval[2];
719
720 BLI_assert(region && space_outliner);
721
722 ui::view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]);
723
724 SceneReplaceData scene_replace_data;
725
726 int id_tagged_num = 0;
727 BKE_main_id_tag_all(bmain, ID_TAG_DOIT, false);
728 for (TreeElement &te : space_outliner->runtime->tree) {
729 if ((id_tagged_num += outliner_id_delete_tag(
730 C, op->reports, &te, fmval, scene_replace_data)) != 0)
731 {
732 break;
733 }
734 }
735 if (id_tagged_num == 0) {
736 BKE_main_id_tag_all(bmain, ID_TAG_DOIT, false);
737 return OPERATOR_CANCELLED;
738 }
739
740 BLI_assert(scene_replace_data.is_valid());
741 if (scene_replace_data.can_replace()) {
743 *C, *bmain, *scene_replace_data.scene_to_delete, scene_replace_data.scene_to_activate);
744 }
745
747 BKE_main_id_tag_all(bmain, ID_TAG_DOIT, false);
748 return OPERATOR_FINISHED;
749}
750
752{
753 ot->name = "Delete Data-Block";
754 ot->idname = "OUTLINER_OT_id_delete";
755 ot->description = "Delete the ID under cursor";
756
759
760 /* Flags. */
762}
763
765
766/* -------------------------------------------------------------------- */
769
771{
772 Main *bmain = CTX_data_main(C);
773 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
774
775 const short id_type = short(RNA_enum_get(op->ptr, "id_type"));
776
777 const uint32_t old_session_uid = RNA_int_get(op->ptr, "old_id");
778 const uint32_t new_session_uid = RNA_int_get(op->ptr, "new_id");
779 ID *old_id = BKE_libblock_find_session_uid(bmain, id_type, old_session_uid);
780 ID *new_id = BKE_libblock_find_session_uid(bmain, id_type, new_session_uid);
781
782 /* check for invalid states */
783 if (space_outliner == nullptr) {
784 return OPERATOR_CANCELLED;
785 }
786
787 if (!(old_id && new_id && (old_id != new_id) && (GS(old_id->name) == GS(new_id->name)))) {
790 "Invalid old/new ID pair ('%s' / '%s')",
791 old_id ? old_id->name : "Invalid ID",
792 new_id ? new_id->name : "Invalid ID");
793 return OPERATOR_CANCELLED;
794 }
795
796 if (!ID_IS_EDITABLE(old_id)) {
799 "Old ID '%s' is linked from a library, indirect usages of this data-block will "
800 "not be remapped",
801 old_id->name);
802 }
803
806
808
809 /* recreate dependency graph to include new objects */
811
812 /* Free gpu materials, some materials depend on existing objects,
813 * such as lights so freeing correctly refreshes. */
814 GPU_materials_free(bmain);
815
817
818 return OPERATOR_FINISHED;
819}
820
822 wmOperator *op,
823 ListBaseT<TreeElement> *tree,
824 const float y)
825{
826 for (TreeElement &te : *tree) {
827 if (y > te.ys && y < te.ys + UI_UNIT_Y) {
828 TreeStoreElem *tselem = TREESTORE(&te);
829
830 if ((tselem->type == TSE_SOME_ID) && tselem->id) {
831 RNA_enum_set(op->ptr, "id_type", GS(tselem->id->name));
832 RNA_int_set(op->ptr, "new_id", int(tselem->id->session_uid));
833 RNA_int_set(op->ptr, "old_id", int(tselem->id->session_uid));
834 return true;
835 }
836 }
837 if (outliner_id_remap_find_tree_element(C, op, &te.subtree, y)) {
838 return true;
839 }
840 }
841 return false;
842}
843
845{
846 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
847 ARegion *region = CTX_wm_region(C);
848 float fmval[2];
849
850 if (!RNA_property_is_set(op->ptr, RNA_struct_find_property(op->ptr, "id_type"))) {
851 ui::view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]);
852
853 outliner_id_remap_find_tree_element(C, op, &space_outliner->runtime->tree, fmval[1]);
854 }
855
856 return WM_operator_props_dialog_popup(C, op, 400, IFACE_("Remap Data ID"), IFACE_("Remap"));
857}
858
860{
861 ui::Layout &layout = *op->layout;
862 layout.use_property_split_set(true);
863 ui::template_ID_session_uid(layout, C, op->ptr, "new_id", RNA_enum_get(op->ptr, "id_type"));
864}
865
867{
868 PropertyRNA *prop;
869
870 /* identifiers */
871 ot->name = "Outliner ID Data Remap";
872 ot->idname = "OUTLINER_OT_id_remap";
873
874 /* callbacks */
879
880 /* Flags. */
882
883 prop = RNA_def_enum(ot->srna, "id_type", rna_enum_id_type_items, ID_OB, "ID Type", "");
885 /* Changing ID type wont make sense, would return early with "Invalid old/new ID pair" anyways.
886 */
888
889 prop = RNA_def_int(
890 ot->srna, "old_id", 0, 0, 0, "Old ID", "Old ID's session uid to remap data from", 0, 0);
892
893 ot->prop = RNA_def_int(ot->srna,
894 "new_id",
895 0,
896 0,
897 0,
898 "New ID",
899 "New ID's session uid to remap all selected IDs' users to",
900 0,
901 0);
902}
903
905{
906 wmOperatorType *ot = WM_operatortype_find("OUTLINER_OT_id_remap", false);
907
908 BLI_assert(tselem->id != nullptr);
909
911
912 RNA_enum_set(&op_props, "id_type", GS(tselem->id->name));
913 RNA_int_set(&op_props, "old_id", int(tselem->id->session_uid));
914
916
918}
919
921
922/* -------------------------------------------------------------------- */
925
929 ReportList *reports)
930{
931 using namespace blender::bke::blendfile;
932
933 if (ID_IS_LINKED(id)) {
934 /* Direct link/append of linked IDs is not supported currently, so neither is their
935 * copy/pasting. */
936 BKE_reportf(reports,
937 RPT_INFO,
938 "Cannot copy the linked data-block '%s' to the internal clipboard",
939 id->name);
940 return false;
941 }
942 if (ID_IS_PACKED(id)) {
943 /* Direct link/append of packed IDs is not supported currently, so neither is their
944 * copy/pasting. */
945 /* NOTE: In practice, should always be shadowed by the more general text on linked data
946 * above currently. */
947 BKE_reportf(reports,
948 RPT_INFO,
949 "Cannot copy the linked packed data-block '%s' to the internal clipboard",
950 id->name);
951 return false;
952 }
953 const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id);
955 BKE_reportf(reports,
956 RPT_INFO,
957 "Copying ID '%s' is not possible, '%s' type of data-blocks is not supported",
958 id->name,
959 id_type->name);
960 return false;
961 }
962 return copybuffer.id_add(id,
967 nullptr) != nullptr;
968}
969
970static int outliner_id_copy_tag(SpaceOutliner *space_outliner,
971 ListBaseT<TreeElement> *tree,
973 ReportList *reports)
974{
975 int num_ids = 0;
976
977 for (TreeElement &te : *tree) {
978 TreeStoreElem *tselem = TREESTORE(&te);
979
980 /* Add selected item and all of its dependencies to the copy buffer. Sub-trees are visited
981 * even if the item itself can't be copied, e.g. local children of a linked object. */
982 if (tselem->flag & TSE_SELECTED && ELEM(tselem->type, TSE_SOME_ID, TSE_LAYER_COLLECTION)) {
983 if (outliner_id_copy_tag_id(tselem->id, copybuffer, reports)) {
984 num_ids++;
985 }
986 }
987
988 /* go over sub-tree */
989 num_ids += outliner_id_copy_tag(space_outliner, &te.subtree, copybuffer, reports);
990 }
991
992 return num_ids;
993}
994
996{
997 using namespace blender::bke::blendfile;
998
999 Main *bmain = CTX_data_main(C);
1000 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
1001 PartialWriteContext copybuffer{*bmain};
1002
1003 const int num_ids = outliner_id_copy_tag(
1004 space_outliner, &space_outliner->runtime->tree, copybuffer, op->reports);
1005 if (num_ids == 0) {
1006 BKE_report(op->reports, RPT_INFO, "No valid selected data-blocks to copy");
1007 return OPERATOR_CANCELLED;
1008 }
1009
1010 char filepath[FILE_MAX];
1011 outliner_copybuffer_filepath_get(filepath, sizeof(filepath));
1012 copybuffer.write_as_copypaste_buffer(filepath, *op->reports);
1013
1014 BKE_reportf(op->reports, RPT_INFO, "Copied %d selected data-block(s)", num_ids);
1015
1016 return OPERATOR_FINISHED;
1017}
1018
1020{
1021 /* identifiers */
1022 ot->name = "Outliner ID Data Copy";
1023 ot->idname = "OUTLINER_OT_id_copy";
1024 ot->description = "Copy the selected data-blocks to the internal clipboard";
1025
1026 /* callbacks */
1029
1030 /* Flags, don't need any undo here (this operator does not change anything in Blender data). */
1031 ot->flag = 0;
1032}
1033
1035
1036/* -------------------------------------------------------------------- */
1039
1041{
1042 char filepath[FILE_MAX];
1043 const short flag = FILE_AUTOSELECT | FILE_ACTIVE_COLLECTION;
1044
1045 outliner_copybuffer_filepath_get(filepath, sizeof(filepath));
1046
1047 const int num_pasted = BKE_copybuffer_paste(C, filepath, flag, op->reports, 0);
1048 if (num_pasted == 0) {
1049 BKE_report(op->reports, RPT_INFO, "No data to paste");
1050 return OPERATOR_CANCELLED;
1051 }
1052
1054
1055 BKE_reportf(op->reports, RPT_INFO, "%d data-block(s) pasted", num_pasted);
1056
1057 return OPERATOR_FINISHED;
1058}
1059
1061{
1062 /* identifiers */
1063 ot->name = "Outliner ID Data Paste";
1064 ot->idname = "OUTLINER_OT_id_paste";
1065 ot->description = "Paste data-blocks from the internal clipboard";
1066
1067 /* callbacks */
1070
1071 /* flags */
1073}
1074
1076
1077/* -------------------------------------------------------------------- */
1080
1082 wmOperator *op,
1083 const wmEvent * /*event*/)
1084{
1085 PointerRNA id_linked_ptr = CTX_data_pointer_get_type(C, "id", RNA_ID);
1086 ID *id_linked = static_cast<ID *>(id_linked_ptr.data);
1087
1088 if (!id_linked) {
1089 BKE_report(op->reports, RPT_ERROR_INVALID_INPUT, "There is no active data-block");
1090 return OPERATOR_CANCELLED;
1091 }
1092 if (!ID_IS_LINKED(id_linked) || !BKE_idtype_idcode_is_linkable(GS(id_linked->name))) {
1093 BKE_reportf(op->reports,
1095 "The active data-block '%s' is not a valid linked one",
1096 BKE_id_name(*id_linked));
1097 return OPERATOR_CANCELLED;
1098 }
1100 BKE_reportf(op->reports,
1102 "The active data-block '%s' is used by other linked data",
1103 BKE_id_name(*id_linked));
1104 return OPERATOR_CANCELLED;
1105 }
1106
1107 wmOperatorType *ot = WM_operatortype_find("WM_OT_id_linked_relocate", false);
1109 RNA_int_set(&op_props, "id_session_uid", *reinterpret_cast<int *>(&id_linked->session_uid));
1110
1112 C, ot, wm::OpCallContext::InvokeDefault, &op_props, nullptr);
1113
1114 WM_operator_properties_free(&op_props);
1115
1116 /* If the matching WM operator invoke was successful, it was added to modal handlers. This
1117 * operator however is _not_ modal, and will leak memory if it returns this status. */
1119}
1120
1122{
1123 ot->name = "Relocate Linked ID";
1124 ot->idname = "OUTLINER_OT_id_linked_relocate";
1125 ot->description =
1126 "Replace the active linked ID (and its dependencies if any) by another one, from the same "
1127 "or a different library";
1128
1131
1132 /* Flags. No undo, no registering, all the actual work/changes is done by the matching WM
1133 * operator. */
1134 ot->flag = 0;
1135}
1136
1138
1139/* -------------------------------------------------------------------- */
1142
1144 bContext *C, TreeElement *te, TreeStoreElem *tselem, wmOperatorType *ot, const bool reload)
1145{
1147
1148 BLI_assert(te->idcode == ID_LI && tselem->id != nullptr);
1150
1152
1153 RNA_string_set(&op_props, "library", tselem->id->name + 2);
1154
1155 if (reload) {
1156 Library *lib = id_cast<Library *>(tselem->id);
1157 char dir[FILE_MAXDIR], filename[FILE_MAX];
1158
1160 lib->runtime->filepath_abs, dir, sizeof(dir), filename, sizeof(filename));
1161
1162 printf("%s, %s\n", tselem->id->name, lib->runtime->filepath_abs);
1163
1164 /* We assume if both paths in lib are not the same then `lib->filepath` was relative. */
1166 &op_props, "relative_path", BLI_path_cmp(lib->runtime->filepath_abs, lib->filepath) != 0);
1167
1168 RNA_string_set(&op_props, "directory", dir);
1169 RNA_string_set(&op_props, "filename", filename);
1170
1172 }
1173 else {
1175 }
1176
1177 WM_operator_properties_free(&op_props);
1178
1179 return ret;
1180}
1181
1183 bContext *C, ReportList *reports, TreeElement *te, const float mval[2], const bool reload)
1184{
1185 if (mval[1] > te->ys && mval[1] < te->ys + UI_UNIT_Y) {
1186 TreeStoreElem *tselem = TREESTORE(te);
1187
1188 if (te->idcode == ID_LI && tselem->id) {
1189 if ((id_cast<Library *>(tselem->id))->runtime->parent && !reload) {
1190 BKE_reportf(reports,
1192 "Cannot relocate indirectly linked library '%s'",
1193 (id_cast<Library *>(tselem->id))->runtime->filepath_abs);
1194 return OPERATOR_CANCELLED;
1195 }
1196
1197 wmOperatorType *ot = WM_operatortype_find(reload ? "WM_OT_lib_reload" : "WM_OT_lib_relocate",
1198 false);
1199 return lib_relocate(C, te, tselem, ot, reload);
1200 }
1201 }
1202 else {
1203 for (TreeElement &te_sub : te->subtree) {
1205 if ((ret = outliner_lib_relocate_invoke_do(C, reports, &te_sub, mval, reload))) {
1206 return ret;
1207 }
1208 }
1209 }
1210
1211 return wmOperatorStatus(0);
1212}
1213
1215 wmOperator *op,
1216 const wmEvent *event)
1217{
1218 ARegion *region = CTX_wm_region(C);
1219 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
1220 float fmval[2];
1221
1222 BLI_assert(region && space_outliner);
1223
1224 ui::view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]);
1225
1226 for (TreeElement &te : space_outliner->runtime->tree) {
1228
1229 if ((ret = outliner_lib_relocate_invoke_do(C, op->reports, &te, fmval, false))) {
1230 return ret;
1231 }
1232 }
1233
1234 return OPERATOR_CANCELLED;
1235}
1236
1238{
1239 ot->name = "Relocate Library";
1240 ot->idname = "OUTLINER_OT_lib_relocate";
1241 ot->description = "Relocate the library under cursor";
1242
1245
1246 /* Flags. */
1248}
1249
1251 ReportList * /*reports*/,
1252 Scene * /*scene*/,
1253 TreeElement *te,
1254 TreeStoreElem * /*tsep*/,
1255 TreeStoreElem *tselem)
1256{
1257 /* XXX: This does not work with several items
1258 * (it is only called once in the end, due to the 'deferred'
1259 * file-browser invocation through event system...). */
1260
1261 wmOperatorType *ot = WM_operatortype_find("WM_OT_lib_relocate", false);
1262
1263 lib_relocate(C, te, tselem, ot, false);
1264}
1265
1267 wmOperator *op,
1268 const wmEvent *event)
1269{
1270 ARegion *region = CTX_wm_region(C);
1271 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
1272 float fmval[2];
1273
1274 BLI_assert(region && space_outliner);
1275
1276 ui::view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]);
1277
1278 for (TreeElement &te : space_outliner->runtime->tree) {
1280
1281 if ((ret = outliner_lib_relocate_invoke_do(C, op->reports, &te, fmval, true))) {
1282 return ret;
1283 }
1284 }
1285
1286 return OPERATOR_CANCELLED;
1287}
1288
1290
1291/* -------------------------------------------------------------------- */
1294
1296{
1297 ot->name = "Reload Library";
1298 ot->idname = "OUTLINER_OT_lib_reload";
1299 ot->description = "Reload the library under cursor";
1300
1303
1304 /* Flags. */
1306}
1307
1309 ReportList * /*reports*/,
1310 Scene * /*scene*/,
1311 TreeElement *te,
1312 TreeStoreElem * /*tsep*/,
1313 TreeStoreElem *tselem)
1314{
1315 wmOperatorType *ot = WM_operatortype_find("WM_OT_lib_reload", false);
1316
1317 lib_relocate(C, te, tselem, ot, true);
1318}
1319
1321
1322/* -------------------------------------------------------------------- */
1325
1326static int outliner_count_levels(ListBaseT<TreeElement> *lb, const int curlevel)
1327{
1328 int level = curlevel;
1329
1330 for (TreeElement &te : *lb) {
1331 int lev = outliner_count_levels(&te.subtree, curlevel + 1);
1332 level = std::max(lev, level);
1333 }
1334 return level;
1335}
1336
1337int outliner_flag_is_any_test(ListBaseT<TreeElement> *lb,
1339 const int curlevel)
1340{
1341 for (TreeElement &te : *lb) {
1342 TreeStoreElem *tselem = TREESTORE(&te);
1343 if (tselem->flag & flag) {
1344 return curlevel;
1345 }
1346
1347 int level = outliner_flag_is_any_test(&te.subtree, flag, curlevel + 1);
1348 if (level) {
1349 return level;
1350 }
1351 }
1352 return 0;
1353}
1354
1356 const eTreeStoreElem_Flag flag,
1357 const short set)
1358{
1359 return outliner_flag_set(space_outliner.runtime->tree, flag, set);
1360}
1361
1362bool outliner_flag_set(ListBaseT<TreeElement> &lb, const eTreeStoreElem_Flag flag, const short set)
1363{
1364 bool changed = false;
1365
1366 tree_iterator::all(lb, [&](TreeElement *te) {
1367 TreeStoreElem *tselem = TREESTORE(te);
1368 bool has_flag = (tselem->flag & flag);
1369 if (set == 0) {
1370 if (has_flag) {
1371 tselem->flag &= ~flag;
1372 changed = true;
1373 }
1374 }
1375 else if (!has_flag) {
1376 tselem->flag |= flag;
1377 changed = true;
1378 }
1379 });
1380
1381 return changed;
1382}
1383
1385{
1386 return outliner_flag_flip(space_outliner.runtime->tree, flag);
1387}
1388
1389bool outliner_flag_flip(ListBaseT<TreeElement> &lb, const eTreeStoreElem_Flag flag)
1390{
1391 bool changed = false;
1392
1393 tree_iterator::all(lb, [&](TreeElement *te) {
1394 TreeStoreElem *tselem = TREESTORE(te);
1395 tselem->flag ^= flag;
1396 });
1397
1398 return changed;
1399}
1400
1402
1403/* -------------------------------------------------------------------- */
1406
1408{
1409 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
1410 ARegion *region = CTX_wm_region(C);
1411
1412 if (outliner_flag_is_any_test(&space_outliner->runtime->tree, TSE_CLOSED, 1)) {
1413 outliner_flag_set(*space_outliner, TSE_CLOSED, 0);
1414 }
1415 else {
1416 outliner_flag_set(*space_outliner, TSE_CLOSED, 1);
1417 }
1418
1419 ED_region_tag_redraw(region);
1420
1421 return OPERATOR_FINISHED;
1422}
1423
1425{
1426 /* identifiers */
1427 ot->name = "Expand/Collapse All";
1428 ot->idname = "OUTLINER_OT_expanded_toggle";
1429 ot->description = "Expand/Collapse all items";
1430
1431 /* callbacks */
1434
1435 /* no undo or registry, UI option */
1436}
1437
1439
1440/* -------------------------------------------------------------------- */
1443
1445{
1446 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
1447 ARegion *region = CTX_wm_region(C);
1448 Scene *scene = CTX_data_scene(C);
1449 int action = RNA_enum_get(op->ptr, "action");
1450 if (action == SEL_TOGGLE) {
1451 action = outliner_flag_is_any_test(&space_outliner->runtime->tree, TSE_SELECTED, 1) ?
1452 SEL_DESELECT :
1453 SEL_SELECT;
1454 }
1455
1456 switch (action) {
1457 case SEL_SELECT:
1458 outliner_flag_set(*space_outliner, TSE_SELECTED, 1);
1459 break;
1460 case SEL_DESELECT:
1461 outliner_flag_set(*space_outliner, TSE_SELECTED, 0);
1462 break;
1463 case SEL_INVERT:
1464 outliner_flag_flip(*space_outliner, TSE_SELECTED);
1465 break;
1466 }
1467
1469
1473
1474 return OPERATOR_FINISHED;
1475}
1476
1478{
1479 /* identifiers */
1480 ot->name = "Toggle Selected";
1481 ot->idname = "OUTLINER_OT_select_all";
1482 ot->description = "Toggle the Outliner selection of items";
1483
1484 /* callbacks */
1487
1488 /* no undo or registry */
1489
1490 /* rna */
1492}
1493
1495
1496/* -------------------------------------------------------------------- */
1499
1501{
1502 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
1503 ScrArea *area = CTX_wm_area(C);
1505
1506 ED_region_activate_rna_prop(C, region, space_outliner, "filter_text");
1507
1508 return OPERATOR_FINISHED;
1509}
1510
1512{
1513 /* Identifiers. */
1514 ot->name = "Filter";
1515 ot->description = "Start entering filter text";
1516 ot->idname = "OUTLINER_OT_start_filter";
1517
1518 /* Callbacks. */
1521}
1522
1524{
1525 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
1526 space_outliner->search_string[0] = '\0';
1528 return OPERATOR_FINISHED;
1529}
1530
1532{
1533 /* Identifiers. */
1534 ot->name = "Clear Filter";
1535 ot->description = "Clear the search filter";
1536 ot->idname = "OUTLINER_OT_clear_filter";
1537
1538 /* Callbacks. */
1541}
1542
1544
1545/* -------------------------------------------------------------------- */
1548
1549void outliner_set_coordinates(const ARegion *region, SpaceOutliner *space_outliner)
1550{
1551 int starty = int(region->v2d.tot.ymax) - UI_UNIT_Y;
1552
1553 tree_iterator::all(space_outliner->runtime->tree, [&](TreeElement *te) {
1554 /* Set coordinates to zero for all elements. This is done to reset coordinates of collapsed
1555 * elements. */
1556 te->xs = 0;
1557 te->ys = 0;
1558 });
1559
1560 tree_iterator::all_open(*space_outliner, [&](TreeElement *te) {
1561 /* store coord and continue, we need coordinates for elements outside view too */
1562 te->ys = float(starty);
1563 starty -= UI_UNIT_Y;
1564 });
1565}
1566
1569{
1570 TreeStoreElem *tselem;
1571 bool retval = false;
1572
1573 for (te = te->parent; te; te = te->parent) {
1574 tselem = TREESTORE(te);
1575 if (tselem->flag & TSE_CLOSED) {
1576 tselem->flag &= ~TSE_CLOSED;
1577 retval = true;
1578 }
1579 }
1580 return retval;
1581}
1582
1587 SpaceOutliner *space_outliner,
1588 const Scene *scene,
1589 ViewLayer *view_layer)
1590{
1591 TreeElement *te;
1592
1593 const Main *bmain = CTX_data_main(C);
1594
1595 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
1596 Object *obact = BKE_view_layer_active_object_get(view_layer);
1597
1598 if (!obact) {
1599 return nullptr;
1600 }
1601
1602 te = outliner_find_id(
1603 space_outliner, &space_outliner->runtime->tree, &obact->id, TE_CHILD_NOT_IN_COLLECTION);
1604
1605 if (te != nullptr && obact->type == OB_ARMATURE) {
1606 /* traverse down the bone hierarchy in case of armature */
1607 TreeElement *te_obact = te;
1608
1609 if (obact->mode & OB_MODE_POSE) {
1610 Object *obpose = BKE_object_pose_armature_get(obact);
1611 bPoseChannel *pchan = BKE_pose_channel_active(obpose, false);
1612 if (pchan) {
1613 te = outliner_find_posechannel(&te_obact->subtree, pchan);
1614 }
1615 }
1616 else if (obact->mode & OB_MODE_EDIT) {
1618 if (ebone) {
1619 te = outliner_find_editbone(&te_obact->subtree, ebone);
1620 }
1621 }
1622 }
1623
1624 return te;
1625}
1626
1627static void outliner_show_active(SpaceOutliner *space_outliner,
1628 ARegion *region,
1629 TreeElement *te,
1630 ID *id)
1631{
1632 /* open up tree to active object/bone */
1633 if (TREESTORE(te)->id == id) {
1634 if (outliner_open_back(te)) {
1635 outliner_set_coordinates(region, space_outliner);
1636 }
1637 return;
1638 }
1639
1640 for (TreeElement &ten : te->subtree) {
1641 outliner_show_active(space_outliner, region, &ten, id);
1642 }
1643}
1644
1645void outliner_scroll_to_active(SpaceOutliner *space_outliner, ARegion *region, short idcode)
1646{
1647 outliner_set_coordinates(region, space_outliner);
1648 const View2D *v2d = &region->v2d;
1649 TreeElement *active_te = nullptr;
1650
1651 tree_iterator::all(space_outliner->runtime->tree, [&](TreeElement *te) {
1652 TreeStoreElem *tselem = TREESTORE(te);
1653 if (te->flag & TE_CHILD_NOT_IN_COLLECTION) {
1654 return;
1655 }
1656 if (tselem->flag & TSE_ACTIVE) {
1657 if (tselem->type == TSE_SOME_ID) {
1658 if (te->idcode == idcode) {
1659 active_te = te;
1660 }
1661 }
1662 else {
1663 active_te = te;
1664 }
1665 }
1666 });
1667
1668 if (!active_te) {
1669 return;
1670 }
1671
1672 TreeElement *scroll_to_te = active_te;
1673 if ((space_outliner->flag & SO_EXPAND_ON_FOCUS) == 0) {
1674 TreeElement *iter = active_te->parent;
1675 while (iter) {
1676 if (!TSELEM_OPEN(iter->store_elem, space_outliner)) {
1677 scroll_to_te = iter;
1678 }
1679 iter = iter->parent;
1680 }
1681 }
1682
1683 if (!(scroll_to_te->ys && BLI_rctf_isect_y(&v2d->cur, scroll_to_te->ys))) {
1684 outliner_show_active(space_outliner, region, scroll_to_te, TREESTORE(scroll_to_te)->id);
1685 const int size_y = BLI_rcti_size_y(&v2d->mask) + 1;
1686 const int ytop = (scroll_to_te->ys + (size_y / 2));
1687 const int delta_y = ytop - v2d->cur.ymax;
1688 outliner_scroll_view(space_outliner, region, delta_y);
1689 }
1690}
1691
1693{
1694 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
1695 const Scene *scene = CTX_data_scene(C);
1696 ViewLayer *view_layer = CTX_data_view_layer(C);
1697 ARegion *region = CTX_wm_region(C);
1698 View2D *v2d = &region->v2d;
1699
1701 C, space_outliner, scene, view_layer);
1702
1703 if (active_element) {
1704 ID *id = TREESTORE(active_element)->id;
1705
1706 /* Expand all elements in the outliner with matching ID */
1707 for (TreeElement &te : space_outliner->runtime->tree) {
1708 outliner_show_active(space_outliner, region, &te, id);
1709 }
1710
1711 /* Also open back from the active_element (only done for the first found occurrence of ID
1712 * though). */
1713 outliner_show_active(space_outliner, region, active_element, id);
1714
1715 /* Center view on first element found */
1716 int size_y = BLI_rcti_size_y(&v2d->mask) + 1;
1717 int ytop = (active_element->ys + (size_y / 2));
1718 int delta_y = ytop - v2d->cur.ymax;
1719
1720 outliner_scroll_view(space_outliner, region, delta_y);
1721 }
1722 else {
1723 return OPERATOR_CANCELLED;
1724 }
1725
1727
1728 return OPERATOR_FINISHED;
1729}
1730
1732{
1733 /* identifiers */
1734 ot->name = "Show Active";
1735 ot->idname = "OUTLINER_OT_show_active";
1736 ot->description =
1737 "Open up the tree and adjust the view so that the active object is shown centered";
1738
1739 /* callbacks */
1742}
1743
1745
1746/* -------------------------------------------------------------------- */
1749
1751{
1752 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
1753 ARegion *region = CTX_wm_region(C);
1754 int size_y = BLI_rcti_size_y(&region->v2d.mask) + 1;
1755
1756 bool up = RNA_boolean_get(op->ptr, "up");
1757
1758 if (!up) {
1759 size_y = -size_y;
1760 }
1761
1762 outliner_scroll_view(space_outliner, region, size_y);
1763
1765
1766 return OPERATOR_FINISHED;
1767}
1768
1770{
1771 PropertyRNA *prop;
1772
1773 /* identifiers */
1774 ot->name = "Scroll Page";
1775 ot->idname = "OUTLINER_OT_scroll_page";
1776 ot->description = "Scroll page up or down";
1777
1778 /* callbacks */
1781
1782 /* properties */
1783 prop = RNA_def_boolean(ot->srna, "up", false, "Up", "Scroll up one page");
1785}
1786
1788
1789/* -------------------------------------------------------------------- */
1792
1793/* helper function for Show/Hide one level operator */
1794static void outliner_openclose_level(ListBaseT<TreeElement> *lb, int curlevel, int level, int open)
1795{
1796 for (TreeElement &te : *lb) {
1797 TreeStoreElem *tselem = TREESTORE(&te);
1798
1799 if (open) {
1800 if (curlevel <= level) {
1801 tselem->flag &= ~TSE_CLOSED;
1802 }
1803 }
1804 else {
1805 if (curlevel >= level) {
1806 tselem->flag |= TSE_CLOSED;
1807 }
1808 }
1809
1810 outliner_openclose_level(&te.subtree, curlevel + 1, level, open);
1811 }
1812}
1813
1815{
1816 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
1817 ARegion *region = CTX_wm_region(C);
1818 const bool add = RNA_boolean_get(op->ptr, "open");
1819 int level;
1820
1821 level = outliner_flag_is_any_test(&space_outliner->runtime->tree, TSE_CLOSED, 1);
1822 if (add == 1) {
1823 if (level) {
1824 outliner_openclose_level(&space_outliner->runtime->tree, 1, level, 1);
1825 }
1826 }
1827 else {
1828 if (level == 0) {
1829 level = outliner_count_levels(&space_outliner->runtime->tree, 0);
1830 }
1831 if (level) {
1832 outliner_openclose_level(&space_outliner->runtime->tree, 1, level - 1, 0);
1833 }
1834 }
1835
1836 ED_region_tag_redraw(region);
1837
1838 return OPERATOR_FINISHED;
1839}
1840
1842{
1843 PropertyRNA *prop;
1844
1845 /* identifiers */
1846 ot->name = "Show/Hide One Level";
1847 ot->idname = "OUTLINER_OT_show_one_level";
1848 ot->description = "Expand/collapse all entries by one level";
1849
1850 /* callbacks */
1853
1854 /* no undo or registry, UI option */
1855
1856 /* properties */
1857 prop = RNA_def_boolean(ot->srna, "open", true, "Open", "Expand all entries one level deep");
1859}
1860
1862
1863/* -------------------------------------------------------------------- */
1866
1871static int subtree_has_objects(ListBaseT<TreeElement> *lb)
1872{
1873 for (TreeElement &te : *lb) {
1874 TreeStoreElem *tselem = TREESTORE(&te);
1875 if ((tselem->type == TSE_SOME_ID) && (te.idcode == ID_OB)) {
1876 return 1;
1877 }
1878 if (subtree_has_objects(&te.subtree)) {
1879 return 1;
1880 }
1881 }
1882 return 0;
1883}
1884
1885/* Helper function for Show Hierarchy operator */
1886static void tree_element_show_hierarchy(Scene *scene, SpaceOutliner *space_outliner)
1887{
1888 /* open all object elems, close others */
1889 tree_iterator::all_open(*space_outliner, [&](TreeElement *te) {
1890 TreeStoreElem *tselem = TREESTORE(te);
1891
1892 if (ELEM(tselem->type,
1897 {
1898 if (te->idcode == ID_SCE) {
1899 if (tselem->id != id_cast<ID *>(scene)) {
1900 tselem->flag |= TSE_CLOSED;
1901 }
1902 else {
1903 tselem->flag &= ~TSE_CLOSED;
1904 }
1905 }
1906 else if (te->idcode == ID_OB) {
1907 if (subtree_has_objects(&te->subtree)) {
1908 tselem->flag &= ~TSE_CLOSED;
1909 }
1910 else {
1911 tselem->flag |= TSE_CLOSED;
1912 }
1913 }
1914 }
1915 else {
1916 tselem->flag |= TSE_CLOSED;
1917 }
1918 });
1919}
1920
1921/* show entire object level hierarchy */
1923{
1924 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
1925 ARegion *region = CTX_wm_region(C);
1926 Scene *scene = CTX_data_scene(C);
1927
1928 /* recursively open/close levels */
1929 tree_element_show_hierarchy(scene, space_outliner);
1930
1931 ED_region_tag_redraw(region);
1932
1933 return OPERATOR_FINISHED;
1934}
1935
1937{
1938 /* identifiers */
1939 ot->name = "Show Hierarchy";
1940 ot->idname = "OUTLINER_OT_show_hierarchy";
1941 ot->description = "Open all object entries and close all others";
1942
1943 /* callbacks */
1945 /* TODO: shouldn't be allowed in RNA views... */
1947
1948 /* no undo or registry, UI option */
1949}
1950
1952
1953/* -------------------------------------------------------------------- */
1956
1961{
1962 ScrArea *area = CTX_wm_area(C);
1963 if ((area) && (area->spacetype == SPACE_OUTLINER)) {
1964 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
1965 return (space_outliner->outlinevis == SO_DATA_API);
1966 }
1967 return false;
1968}
1969
1970/* Helper func to extract an RNA path from selected tree element
1971 * NOTE: the caller must zero-out all values of the pointers that it passes here first, as
1972 * this function does not do that yet
1973 */
1975 TreeStoreElem *tselem,
1976 ID **id,
1977 char **path,
1978 int *array_index,
1979 short *flag,
1980 eKSP_Grouping * /*groupmode*/)
1981{
1982 ListBaseT<LinkData> hierarchy = {nullptr, nullptr};
1983 char *newpath = nullptr;
1984
1985 /* optimize tricks:
1986 * - Don't do anything if the selected item is a 'struct', but arrays are allowed
1987 */
1988 if (tselem->type == TSE_RNA_STRUCT) {
1989 return;
1990 }
1991
1992 /* Overview of Algorithm:
1993 * 1. Go up the chain of parents until we find the 'root', taking note of the
1994 * levels encountered in reverse-order (i.e. items are added to the start of the list
1995 * for more convenient looping later)
1996 * 2. Walk down the chain, adding from the first ID encountered
1997 * (which will become the 'ID' for the KeyingSet Path), and build a
1998 * path as we step through the chain
1999 */
2000
2001 /* step 1: flatten out hierarchy of parents into a flat chain */
2002 for (TreeElement *tem = te->parent; tem; tem = tem->parent) {
2003 LinkData *ld = MEM_new_zeroed<LinkData>("LinkData for tree_element_to_path()");
2004 ld->data = tem;
2005 BLI_addhead(&hierarchy, ld);
2006 }
2007
2008 /* step 2: step down hierarchy building the path
2009 * (NOTE: addhead in previous loop was needed so that we can loop like this) */
2010 for (const LinkData *ld = hierarchy.first(); ld; ld = ld->next) {
2011 /* get data */
2012 TreeElement *tem = static_cast<TreeElement *>(ld->data);
2014 PointerRNA ptr = tem_rna->get_pointer_rna();
2015
2016 /* check if we're looking for first ID, or appending to path */
2017 if (*id) {
2018 /* just 'append' property to path
2019 * - to prevent memory leaks, we must write to newpath not path,
2020 * then free old path + swap them.
2021 */
2023 PropertyRNA *prop = tem_rna_prop->get_property_rna();
2024
2025 if (RNA_property_type(prop) == PROP_POINTER) {
2026 /* for pointer we just append property name */
2027 newpath = RNA_path_append(*path, &ptr, prop, 0, nullptr);
2028 }
2029 else if (RNA_property_type(prop) == PROP_COLLECTION) {
2030 char buf[128], *name;
2031
2032 TreeElement *temnext = static_cast<TreeElement *>(ld->next->data);
2033 PointerRNA nextptr = tree_element_cast<TreeElementRNACommon>(temnext)->get_pointer_rna();
2034 name = RNA_struct_name_get_alloc(&nextptr, buf, sizeof(buf), nullptr);
2035
2036 if (name) {
2037 /* if possible, use name as a key in the path */
2038 newpath = RNA_path_append(*path, nullptr, prop, 0, name);
2039
2040 if (name != buf) {
2041 MEM_delete(name);
2042 }
2043 }
2044 else {
2045 /* otherwise use index */
2046 int index = 0;
2047
2048 for (TreeElement &temsub : tem->subtree) {
2049 if (&temsub == temnext) {
2050 break;
2051 }
2052 index++;
2053 }
2054 newpath = RNA_path_append(*path, nullptr, prop, index, nullptr);
2055 }
2056
2057 ld = ld->next;
2058 }
2059 }
2060
2061 if (newpath) {
2062 if (*path) {
2063 MEM_delete(*path);
2064 }
2065 *path = newpath;
2066 newpath = nullptr;
2067 }
2068 }
2069 else {
2070 /* no ID, so check if entry is RNA-struct,
2071 * and if that RNA-struct is an ID datablock to extract info from. */
2073 /* ptr->data not ptr->owner_id seems to be the one we want,
2074 * since ptr->data is sometimes the owner of this ID? */
2075 if (RNA_struct_is_ID(ptr.type)) {
2076 *id = static_cast<ID *>(ptr.data);
2077
2078 /* clear path */
2079 if (*path) {
2080 MEM_delete(*path);
2081 path = nullptr;
2082 }
2083 }
2084 }
2085 }
2086 }
2087
2088 /* step 3: if we've got an ID, add the current item to the path */
2089 if (*id) {
2090 /* add the active property to the path */
2091 PropertyRNA *prop = tree_element_cast<TreeElementRNACommon>(te)->get_property_rna();
2092
2093 /* array checks */
2094 if (tselem->type == TSE_RNA_ARRAY_ELEM) {
2095 /* item is part of an array, so must set the array_index */
2096 *array_index = te->index;
2097 }
2098 else if (RNA_property_array_check(prop)) {
2099 /* entire array was selected, so keyframe all */
2100 *flag |= KSP_FLAG_WHOLE_ARRAY;
2101 }
2102
2103 /* path */
2104 newpath = RNA_path_append(*path, nullptr, prop, 0, nullptr);
2105 if (*path) {
2106 MEM_delete(*path);
2107 }
2108 *path = newpath;
2109 }
2110
2111 /* free temp data */
2112 hierarchy.free_no_destruct();
2113}
2114
2116
2117/* -------------------------------------------------------------------- */
2120
2127enum {
2130} /*eDrivers_EditModes*/;
2131
2132/* Iterate over tree, finding and working on selected items */
2133static void do_outliner_drivers_editop(SpaceOutliner *space_outliner,
2134 ReportList *reports,
2135 short mode)
2136{
2137 tree_iterator::all_open(*space_outliner, [&](TreeElement *te) {
2138 TreeStoreElem *tselem = TREESTORE(te);
2139
2140 /* if item is selected, perform operation */
2141 if (!(tselem->flag & TSE_SELECTED)) {
2142 return;
2143 }
2144
2145 ID *id = nullptr;
2146 char *path = nullptr;
2147 int array_index = 0;
2148 short flag = 0;
2149 eKSP_Grouping groupmode = KSP_GROUP_KSNAME;
2150
2152 PointerRNA ptr = te_rna ? te_rna->get_pointer_rna() : PointerRNA();
2153 PropertyRNA *prop = te_rna ? te_rna->get_property_rna() : nullptr;
2154
2155 /* check if RNA-property described by this selected element is an animatable prop */
2156 if (prop && RNA_property_anim_editable(&ptr, prop)) {
2157 /* get id + path + index info from the selected element */
2158 tree_element_to_path(te, tselem, &id, &path, &array_index, &flag, &groupmode);
2159 }
2160
2161 /* only if ID and path were set, should we perform any actions */
2162 if (id && path) {
2163 short dflags = CREATEDRIVER_WITH_DEFAULT_DVAR;
2164 int arraylen = 1;
2165
2166 /* array checks */
2167 if (flag & KSP_FLAG_WHOLE_ARRAY) {
2168 /* entire array was selected, so add drivers for all */
2169 arraylen = RNA_property_array_length(&ptr, prop);
2170 }
2171 else {
2172 arraylen = array_index;
2173 }
2174
2175 /* we should do at least one step */
2176 if (arraylen == array_index) {
2177 arraylen++;
2178 }
2179
2180 /* for each array element we should affect, add driver */
2181 for (; array_index < arraylen; array_index++) {
2182 /* action depends on mode */
2183 switch (mode) {
2184 case DRIVERS_EDITMODE_ADD: {
2185 /* add a new driver with the information obtained (only if valid) */
2186 ANIM_add_driver(reports, id, path, array_index, dflags, DRIVER_TYPE_PYTHON);
2187 break;
2188 }
2190 ANIM_remove_driver(id, path, array_index);
2191 break;
2192 }
2193 }
2194 }
2195
2196 /* free path, since it had to be generated */
2197 MEM_delete(path);
2198 }
2199 });
2200}
2201
2203
2204/* -------------------------------------------------------------------- */
2207
2209{
2210 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
2211
2212 /* check for invalid states */
2213 if (space_outliner == nullptr) {
2214 return OPERATOR_CANCELLED;
2215 }
2216
2217 /* recursively go into tree, adding selected items */
2219
2220 /* send notifiers */
2222
2223 return OPERATOR_FINISHED;
2224}
2225
2227{
2228 /* API callbacks. */
2229 ot->idname = "OUTLINER_OT_drivers_add_selected";
2230 ot->name = "Add Drivers for Selected";
2231 ot->description = "Add drivers to selected items";
2232
2233 /* API callbacks. */
2236
2237 /* flags */
2239}
2240
2242
2243/* -------------------------------------------------------------------- */
2246
2248{
2249 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
2250
2251 /* check for invalid states */
2252 if (space_outliner == nullptr) {
2253 return OPERATOR_CANCELLED;
2254 }
2255
2256 /* recursively go into tree, adding selected items */
2258
2259 /* send notifiers */
2260 WM_event_add_notifier(C, ND_KEYS, nullptr); /* XXX */
2261
2262 return OPERATOR_FINISHED;
2263}
2264
2266{
2267 /* identifiers */
2268 ot->idname = "OUTLINER_OT_drivers_delete_selected";
2269 ot->name = "Delete Drivers for Selected";
2270 ot->description = "Delete drivers assigned to selected items";
2271
2272 /* API callbacks. */
2275
2276 /* flags */
2278}
2279
2281
2282/* -------------------------------------------------------------------- */
2285
2292enum {
2295} /*eKeyingSet_EditModes*/;
2296
2297/* Find the 'active' KeyingSet, and add if not found (if adding is allowed). */
2298/* TODO: should this be an API func? */
2299static KeyingSet *verify_active_keyingset(Scene *scene, short add)
2300{
2301 KeyingSet *ks = nullptr;
2302
2303 /* sanity check */
2304 if (scene == nullptr) {
2305 return nullptr;
2306 }
2307
2308 /* try to find one from scene */
2309 if (scene->active_keyingset > 0) {
2310 ks = static_cast<KeyingSet *>(BLI_findlink(&scene->keyingsets, scene->active_keyingset - 1));
2311 }
2312
2313 /* Add if none found */
2314 /* XXX the default settings have yet to evolve. */
2315 if ((add) && (ks == nullptr)) {
2316 ks = BKE_keyingset_add(
2317 &scene->keyingsets, nullptr, nullptr, KEYINGSET_ABSOLUTE, INSERTKEY_NOFLAGS);
2318 scene->active_keyingset = scene->keyingsets.count();
2319 }
2320
2321 return ks;
2322}
2323
2324/* Iterate over tree, finding and working on selected items */
2326 KeyingSet *ks,
2327 const short mode)
2328{
2329 tree_iterator::all_open(*space_outliner, [&](TreeElement *te) {
2330 TreeStoreElem *tselem = TREESTORE(te);
2331
2332 /* if item is selected, perform operation */
2333 if (!(tselem->flag & TSE_SELECTED)) {
2334 return;
2335 }
2336
2337 ID *id = nullptr;
2338 char *path = nullptr;
2339 int array_index = 0;
2340 short flag = 0;
2341 eKSP_Grouping groupmode = KSP_GROUP_KSNAME;
2342
2343 /* check if RNA-property described by this selected element is an animatable prop */
2345 if (te_rna) {
2346 PointerRNA ptr = te_rna->get_pointer_rna();
2347 if (PropertyRNA *prop = te_rna->get_property_rna()) {
2348 if (RNA_property_anim_editable(&ptr, prop)) {
2349 /* get id + path + index info from the selected element */
2350 tree_element_to_path(te, tselem, &id, &path, &array_index, &flag, &groupmode);
2351 }
2352 }
2353 }
2354
2355 /* only if ID and path were set, should we perform any actions */
2356 if (id && path) {
2357 /* action depends on mode */
2358 switch (mode) {
2360 /* add a new path with the information obtained (only if valid) */
2361 /* TODO: what do we do with group name?
2362 * for now, we don't supply one, and just let this use the KeyingSet name */
2364 ks, id, nullptr, path, array_index, eKSP_Settings(flag), groupmode);
2365 ks->active_path = ks->paths.count();
2366 break;
2367 }
2369 /* find the relevant path, then remove it from the KeyingSet */
2370 KS_Path *ksp = BKE_keyingset_find_path(ks, id, nullptr, path, array_index, groupmode);
2371
2372 if (ksp) {
2373 /* free path's data */
2374 BKE_keyingset_free_path(ks, ksp);
2375
2376 ks->active_path = 0;
2377 }
2378 break;
2379 }
2380 }
2381
2382 /* free path, since it had to be generated */
2383 MEM_delete(path);
2384 }
2385 });
2386}
2387
2389
2390/* -------------------------------------------------------------------- */
2393
2395{
2396 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
2397 Scene *scene = CTX_data_scene(C);
2398 KeyingSet *ks = verify_active_keyingset(scene, 1);
2399
2400 /* check for invalid states */
2401 if (ks == nullptr) {
2402 BKE_report(op->reports, RPT_ERROR, "Operation requires an active keying set");
2403 return OPERATOR_CANCELLED;
2404 }
2405 if (space_outliner == nullptr) {
2406 return OPERATOR_CANCELLED;
2407 }
2408
2409 /* recursively go into tree, adding selected items */
2411
2412 /* send notifiers */
2414
2415 return OPERATOR_FINISHED;
2416}
2417
2419{
2420 /* identifiers */
2421 ot->idname = "OUTLINER_OT_keyingset_add_selected";
2422 ot->name = "Keying Set Add Selected";
2423 ot->description = "Add selected items (blue-gray rows) to active Keying Set";
2424
2425 /* API callbacks. */
2428
2429 /* flags */
2431}
2432
2434
2435/* -------------------------------------------------------------------- */
2438
2440{
2441 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
2442 Scene *scene = CTX_data_scene(C);
2443 KeyingSet *ks = verify_active_keyingset(scene, 1);
2444
2445 /* check for invalid states */
2446 if (space_outliner == nullptr) {
2447 return OPERATOR_CANCELLED;
2448 }
2449
2450 /* recursively go into tree, adding selected items */
2452
2453 /* send notifiers */
2455
2456 return OPERATOR_FINISHED;
2457}
2458
2460{
2461 /* identifiers */
2462 ot->idname = "OUTLINER_OT_keyingset_remove_selected";
2463 ot->name = "Keying Set Remove Selected";
2464 ot->description = "Remove selected items (blue-gray rows) from active Keying Set";
2465
2466 /* API callbacks. */
2469
2470 /* flags */
2472}
2473
2475
2476/* -------------------------------------------------------------------- */
2479
2481{
2482 ScrArea *area = CTX_wm_area(C);
2483 if (area != nullptr && area->spacetype == SPACE_OUTLINER) {
2484 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
2485 return (space_outliner->outlinevis == SO_ID_ORPHANS);
2486 }
2487 return true;
2488}
2489
2490static void unused_message_gen(std::string &message,
2491 const std::array<int, INDEX_ID_MAX> &num_tagged)
2492{
2493 bool is_first = true;
2494 if (num_tagged[INDEX_ID_NULL] == 0) {
2495 message += IFACE_("None");
2496 return;
2497 }
2498
2499 /* NOTE: Index is looped in reversed order, since typically 'higher level' IDs (like Collections
2500 * or Objects) have a higher index than 'lower level' ones like object data, materials, etc.
2501 *
2502 * It makes more sense to present to the user the deleted numbers of Collections or Objects
2503 * before the ones for object data or Materials. */
2504 for (int i = INDEX_ID_MAX - 2; i >= 0; i--) {
2505 if (num_tagged[i] != 0) {
2506 message += fmt::format(
2507 "{}{} {}",
2508 (is_first) ? "" : ", ",
2509 num_tagged[i],
2510 (num_tagged[i] > 1) ?
2513 is_first = false;
2514 }
2515 }
2516}
2517
2519{
2520 /* Computation of unused data amounts, with all options ON.
2521 * Used to estimate the maximum required width for the dialog. */
2522 Main *bmain = CTX_data_main(C);
2524 data.do_local_ids = true;
2525 data.do_linked_ids = true;
2526 data.do_recursive = true;
2528
2529 std::string unused_message;
2530 const uiStyle *style = ui::style_get_dpi();
2531 unused_message_gen(unused_message, data.num_local);
2532 float max_messages_width = BLF_width(
2533 style->widget.uifont_id, unused_message.c_str(), BLF_DRAW_STR_DUMMY_MAX);
2534
2535 unused_message = "";
2536 unused_message_gen(unused_message, data.num_linked);
2537 max_messages_width = std::max(
2538 max_messages_width,
2539 BLF_width(style->widget.uifont_id, unused_message.c_str(), BLF_DRAW_STR_DUMMY_MAX));
2540
2541 return int(std::max(max_messages_width, 300.0f));
2542}
2543
2545 wmOperator *op,
2546 const bool is_abort = false)
2547{
2548 if (is_abort) {
2549 /* In case of abort, ensure that temp tag is cleared in all IDs, since they were not deleted.
2550 */
2552 }
2553 if (op->customdata) {
2554 MEM_delete(static_cast<LibQueryUnusedIDsData *>(op->customdata));
2555 op->customdata = nullptr;
2556 }
2557}
2558
2560{
2561 Main *bmain = CTX_data_main(C);
2563
2564 data.do_local_ids = RNA_boolean_get(op->ptr, "do_local_ids");
2565 data.do_linked_ids = RNA_boolean_get(op->ptr, "do_linked_ids");
2566 data.do_recursive = RNA_boolean_get(op->ptr, "do_recursive");
2567
2569
2570 /* Always assume count changed, and request a redraw. */
2571 return true;
2572}
2573
2575 wmOperator *op,
2576 const wmEvent * /*event*/)
2577{
2578 op->customdata = MEM_new<LibQueryUnusedIDsData>(__func__);
2579
2580 /* Compute expected amounts of deleted IDs and store them in 'cached' operator properties. */
2582
2584 op,
2586 IFACE_("Purge Unused Data from This File"),
2587 IFACE_("Delete"));
2588}
2589
2591{
2592 Main *bmain = CTX_data_main(C);
2593 ScrArea *area = CTX_wm_area(C);
2594 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
2595
2596 if (!op->customdata) {
2597 op->customdata = MEM_new<LibQueryUnusedIDsData>(__func__);
2598 }
2600
2601 data.do_local_ids = RNA_boolean_get(op->ptr, "do_local_ids");
2602 data.do_linked_ids = RNA_boolean_get(op->ptr, "do_linked_ids");
2603 data.do_recursive = RNA_boolean_get(op->ptr, "do_recursive");
2604
2605 /* Tag all IDs to delete. */
2607
2608 if (data.num_total[INDEX_ID_NULL] == 0) {
2609 BKE_report(op->reports, RPT_INFO, "No orphaned data-blocks to purge");
2611 return OPERATOR_CANCELLED;
2612 }
2613
2614 if (data.num_total[INDEX_ID_SCE] > 0) {
2615 BKE_report(op->reports,
2617 "Attempt to delete scenes as part of a purge operation, should never happen");
2618
2619 SceneReplaceData scene_replace_data;
2620
2621 /* Get the scene currently expected to become the active scene. */
2622 Scene *scene_curr = scene_replace_data.active_scene_get(C);
2623 if (scene_curr && scene_curr->id.tag & ID_TAG_DOIT) {
2624 Scene *scene_new = BKE_scene_find_replacement(
2625 *bmain, *scene_curr, [](const Scene &scene) -> bool {
2626 return (
2627 /* The candidate scene must not be tagged for deletion. */
2628 (scene.id.tag & ID_TAG_DOIT) == 0 &&
2629 /* The candidate scene must be locale, or its library must not be tagged for
2630 * deletion. */
2631 (!scene.id.lib || (scene.id.lib->id.tag & ID_TAG_DOIT) == 0));
2632 });
2633 if (!scene_new) {
2634 BKE_reportf(op->reports,
2635 RPT_ERROR,
2636 "Cannot find a scene to replace the active purged one '%s'",
2637 scene_curr->id.name);
2639 return OPERATOR_CANCELLED;
2640 }
2641
2642 BLI_assert(scene_curr != scene_new);
2643 BLI_assert((scene_new->id.tag & ID_TAG_DOIT) == 0);
2644 if (!scene_replace_data.scene_to_delete) {
2645 scene_replace_data.scene_to_delete = scene_curr;
2646 }
2647 else {
2648 BLI_assert(scene_replace_data.scene_to_delete == CTX_data_scene(C));
2649 }
2650 scene_replace_data.scene_to_activate = scene_new;
2651 }
2652
2653 BLI_assert(scene_replace_data.is_valid());
2654 if (scene_replace_data.can_replace()) {
2656 *C, *bmain, *scene_replace_data.scene_to_delete, scene_replace_data.scene_to_activate);
2657 }
2658 }
2659
2661
2662 BKE_reportf(op->reports, RPT_INFO, "Deleted %d data-block(s)", data.num_total[INDEX_ID_NULL]);
2663
2664 /* XXX: tree management normally happens from draw_outliner(), but when
2665 * you're clicking to fast on Delete object from context menu in
2666 * outliner several mouse events can be handled in one cycle without
2667 * handling notifiers/redraw which leads to deleting the same object twice.
2668 * cleanup tree here to prevent such cases. */
2669 if ((area != nullptr) && (area->spacetype == SPACE_OUTLINER)) {
2670 outliner_cleanup_tree(space_outliner);
2671 }
2672
2675 /* Force full redraw of the UI. */
2677
2679
2680 return OPERATOR_FINISHED;
2681}
2682
2687
2689{
2690 ui::Layout &layout = *op->layout;
2691 PointerRNA *ptr = op->ptr;
2692 if (!op->customdata) {
2693 /* This should only happen on 'adjust last operation' case, since `invoke` will not have been
2694 * called then before showing the UI (the 'redo panel' UI uses WM-stored operator properties
2695 * and a newly-created operator).
2696 *
2697 * Since that operator is not 'registered' for adjusting from undo stack, this should never
2698 * happen currently. */
2700 op->customdata = MEM_new<LibQueryUnusedIDsData>(__func__);
2701 }
2703
2704 std::string unused_message;
2705 unused_message_gen(unused_message, data.num_local);
2706
2707 ui::Layout &local_col = layout.column(true);
2708 local_col.prop(ptr, "do_local_ids", UI_ITEM_NONE, std::nullopt, ICON_NONE);
2709 ui::Layout &local_sub = local_col.row(true);
2710 local_sub.separator(2.67f);
2711 local_sub.label(unused_message, ICON_NONE);
2712
2713 unused_message = "";
2714 unused_message_gen(unused_message, data.num_linked);
2715 ui::Layout &linked_col = layout.column(true);
2716 linked_col.prop(ptr, "do_linked_ids", UI_ITEM_NONE, std::nullopt, ICON_NONE);
2717 ui::Layout &linked_sub = linked_col.row(true);
2718 linked_sub.separator(2.67f);
2719 linked_sub.label(unused_message, ICON_NONE);
2720
2721 layout.prop(ptr, "do_recursive", UI_ITEM_NONE, std::nullopt, ICON_NONE);
2722}
2723
2725{
2726 /* identifiers */
2727 ot->idname = "OUTLINER_OT_orphans_purge";
2728 ot->name = "Purge All";
2729 ot->description = "Clear all orphaned data-blocks without any users from the file";
2730
2731 /* callbacks */
2735
2739
2740 /* flags */
2741 /* NOTE: No #OPTYPE_REGISTER, since this operator should not be 'adjustable'. */
2742 ot->flag = OPTYPE_UNDO;
2743
2744 /* Actual user-visible settings. */
2746 "do_local_ids",
2747 true,
2748 "Local Data-blocks",
2749 "Include unused local data-blocks into deletion");
2751 "do_linked_ids",
2752 true,
2753 "Linked Data-blocks",
2754 "Include unused linked data-blocks into deletion");
2755
2757 "do_recursive",
2758 true,
2759 "Recursive Delete",
2760 "Recursively check for indirectly unused data-blocks, ensuring that no orphaned "
2761 "data-blocks remain after execution");
2762}
2763
2765
2766/* -------------------------------------------------------------------- */
2769
2771 wmOperator * /*op*/,
2772 const wmEvent * /*event*/)
2773{
2774 if (WM_window_open_temp(C, IFACE_("Manage Unused Data"), SPACE_OUTLINER, false)) {
2776 soutline->outlinevis = SO_ID_ORPHANS;
2777 return OPERATOR_FINISHED;
2778 }
2779 return OPERATOR_CANCELLED;
2780}
2781
2783{
2784 /* identifiers */
2785 ot->idname = "OUTLINER_OT_orphans_manage";
2786 ot->name = "Manage Unused Data";
2787 ot->description = "Open a window to manage unused data";
2788
2789 /* callbacks */
2791
2792 /* flags */
2793 ot->flag = OPTYPE_REGISTER;
2794}
2795
2797
2798} // namespace ed::outliner
2799} // namespace blender
Blender kernel action and pose functionality.
General operations, lookup, etc. for blender objects.
#define BLF_DRAW_STR_DUMMY_MAX
Definition BLF_api.hh:456
#define FILE_MAX
#define BLI_path_join(...)
#define FILE_MAXDIR
#define BLI_path_cmp
#define BLT_I18NCONTEXT_ID_ID
#define IFACE_(msgid)
ID and Library types, which are fundamental for SDNA.
#define ID_IS_PACKED(_id)
Definition DNA_ID.h:703
#define ID_IS_OVERRIDE_LIBRARY_REAL(_id)
Definition DNA_ID.h:729
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
#define INDEX_ID_MAX
Definition DNA_ID.h:1362
#define ID_REAL_USERS(id)
Definition DNA_ID.h:679
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:736
Object groups, one object can be in many groups at once.
Object is a sort of wrapper for general info.
#define TSE_IS_REAL_ID(_tse)
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_ITEM_NONE
#define NC_WINDOW
Definition WM_types.hh:388
#define NC_ID
Definition WM_types.hh:408
#define NC_ANIMATION
Definition WM_types.hh:401
#define ND_OB_SELECT
Definition WM_types.hh:461
#define ND_KEYINGSET
Definition WM_types.hh:467
#define NC_SCENE
Definition WM_types.hh:391
#define ND_FCURVES_ORDER
Definition WM_types.hh:542
#define NA_REMOVED
Definition WM_types.hh:637
#define ND_KEYS
Definition WM_types.hh:504
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
#define ELEM(...)
void add_multiple_new(Span< Key > keys)
Definition BLI_set.hh:298
bool contains(const Key &key) const
Definition BLI_set.hh:310
ID * id_add(const ID *id, IDAddOptions options, FunctionRef< IDAddOperations(LibraryIDLinkCallbackData *cb_data, IDAddOptions options)> dependencies_filter_cb=nullptr)
bool write_as_copypaste_buffer(const char *write_filepath, ReportList &reports)
virtual PropertyRNA * get_property_rna() const
void all_open(const SpaceOutliner &space_outliner, const ConstVisitorFn visitor)
void all(const SpaceOutliner &space_outliner, const ConstVisitorFn visitor)
void OUTLINER_OT_expanded_toggle(wmOperatorType *ot)
bool outliner_item_is_co_within_close_toggle(const TreeElement *te, float view_co_x)
static wmOperatorStatus outliner_keyingset_removeitems_exec(bContext *C, wmOperator *)
static void tree_element_show_hierarchy(Scene *scene, SpaceOutliner *space_outliner)
TreeElement * outliner_find_item_at_y(const SpaceOutliner *space_outliner, const ListBaseT< TreeElement > *tree, float view_co_y)
void outliner_tag_redraw_avoid_rebuild_on_open_change(const SpaceOutliner *space_outliner, ARegion *region)
static void tree_element_to_path(TreeElement *te, TreeStoreElem *tselem, ID **id, char **path, int *array_index, short *flag, eKSP_Grouping *)
void OUTLINER_OT_item_rename(wmOperatorType *ot)
static wmOperatorStatus outliner_item_openclose_modal(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus outliner_id_delete_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static TreeElement * outliner_item_rename_find_hovered(const SpaceOutliner *space_outliner, ARegion *region, const wmEvent *event)
static void do_outliner_keyingset_editop(SpaceOutliner *space_outliner, KeyingSet *ks, const short mode)
static wmOperatorStatus outliner_orphans_manage_invoke(bContext *C, wmOperator *, const wmEvent *)
void OUTLINER_OT_show_hierarchy(wmOperatorType *ot)
int outliner_flag_is_any_test(ListBaseT< TreeElement > *lb, eTreeStoreElem_Flag flag, const int curlevel)
static void outliner_orphans_purge_cancel(bContext *C, wmOperator *op)
static wmOperatorStatus outliner_id_copy_exec(bContext *C, wmOperator *op)
void OUTLINER_OT_highlight_update(wmOperatorType *ot)
bool outliner_is_collection_tree_element(const TreeElement *te)
static wmOperatorStatus outliner_id_relocate_invoke(bContext *C, wmOperator *op, const wmEvent *)
void OUTLINER_OT_drivers_add_selected(wmOperatorType *ot)
static wmOperatorStatus outliner_show_active_exec(bContext *C, wmOperator *)
void OUTLINER_OT_select_all(wmOperatorType *ot)
TreeElement * outliner_find_item_at_x_in_row(const SpaceOutliner *space_outliner, TreeElement *parent_te, float view_co_x, bool *r_is_merged_icon, bool *r_is_over_icon)
void OUTLINER_OT_id_linked_relocate(wmOperatorType *ot)
static wmOperatorStatus outliner_id_remap_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void OUTLINER_OT_lib_relocate(wmOperatorType *ot)
static void do_outliner_drivers_editop(SpaceOutliner *space_outliner, ReportList *reports, short mode)
static wmOperatorStatus lib_relocate(bContext *C, TreeElement *te, TreeStoreElem *tselem, wmOperatorType *ot, const bool reload)
static wmOperatorStatus outliner_item_openclose_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void outliner_orphans_purge_ui(bContext *, wmOperator *op)
static wmOperatorStatus outliner_one_level_exec(bContext *C, wmOperator *op)
static void outliner_orphans_purge_cleanup(bContext *C, wmOperator *op, const bool is_abort=false)
void id_delete_tag_fn(bContext *C, ReportList *reports, Scene *, TreeElement *te, TreeStoreElem *, TreeStoreElem *tselem)
static void outliner_id_remap_ui(bContext *C, wmOperator *op)
static wmOperatorStatus outliner_lib_relocate_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus outliner_id_remap_exec(bContext *C, wmOperator *op)
static bool id_delete_tag(bContext *C, ReportList *reports, TreeElement *te, TreeStoreElem *tselem, SceneReplaceData &scene_replace_data)
static int unused_message_popup_width_compute(bContext *C)
static wmOperatorStatus outliner_drivers_deletesel_exec(bContext *C, wmOperator *op)
static wmOperatorStatus outliner_scroll_page_exec(bContext *C, wmOperator *op)
static int outliner_count_levels(ListBaseT< TreeElement > *lb, const int curlevel)
static bool outliner_id_remap_find_tree_element(bContext *C, wmOperator *op, ListBaseT< TreeElement > *tree, const float y)
void OUTLINER_OT_id_paste(wmOperatorType *ot)
void OUTLINER_OT_clear_filter(wmOperatorType *ot)
TreeElement * outliner_find_id(SpaceOutliner *space_outliner, ListBaseT< TreeElement > *lb, const ID *id, TreeElementFlag exclude_flags)
void outliner_scroll_to_active(SpaceOutliner *space_outliner, ARegion *region, short idcode)
bool outliner_flag_set(SpaceOutliner &space_outliner, const eTreeStoreElem_Flag flag, const short set)
void OUTLINER_OT_start_filter(wmOperatorType *ot)
static wmOperatorStatus outliner_drivers_addsel_exec(bContext *C, wmOperator *op)
void OUTLINER_OT_drivers_delete_selected(wmOperatorType *ot)
TreeElement * outliner_find_posechannel(ListBaseT< TreeElement > *lb, const bPoseChannel *pchan)
void OUTLINER_OT_show_one_level(wmOperatorType *ot)
void OUTLINER_OT_show_active(wmOperatorType *ot)
static wmOperatorStatus outliner_toggle_expanded_exec(bContext *C, wmOperator *)
static TreeElement * outliner_show_active_get_element(const bContext *C, SpaceOutliner *space_outliner, const Scene *scene, ViewLayer *view_layer)
static wmOperatorStatus outliner_orphans_purge_exec(bContext *C, wmOperator *op)
void OUTLINER_OT_id_copy(wmOperatorType *ot)
static void outliner_show_active(SpaceOutliner *space_outliner, ARegion *region, TreeElement *te, ID *id)
void OUTLINER_OT_orphans_manage(wmOperatorType *ot)
static wmOperatorStatus outliner_start_filter_exec(bContext *C, wmOperator *)
Collection * outliner_collection_from_tree_element(const TreeElement *te)
void outliner_scroll_view(SpaceOutliner *space_outliner, ARegion *region, int delta_y)
void lib_relocate_fn(bContext *C, ReportList *, Scene *, TreeElement *te, TreeStoreElem *, TreeStoreElem *tselem)
static wmOperatorStatus outliner_keyingset_additems_exec(bContext *C, wmOperator *op)
TreeElement * outliner_find_editbone(ListBaseT< TreeElement > *lb, const EditBone *ebone)
void OUTLINER_OT_lib_reload(wmOperatorType *ot)
void outliner_item_openclose(TreeElement *te, bool open, bool toggle_all)
void OUTLINER_OT_scroll_page(wmOperatorType *ot)
void OUTLINER_OT_keyingset_remove_selected(wmOperatorType *ot)
void OUTLINER_OT_id_remap(wmOperatorType *ot)
void OUTLINER_OT_id_delete(wmOperatorType *ot)
void id_remap_fn(bContext *C, TreeStoreElem *tselem)
TreeElementT * tree_element_cast(const TreeElement *te)
static wmOperatorStatus outliner_orphans_purge_invoke(bContext *C, wmOperator *op, const wmEvent *)
void OUTLINER_OT_keyingset_add_selected(wmOperatorType *ot)
static bool ed_operator_outliner_id_orphans_active(bContext *C)
static void do_item_rename(ARegion *region, TreeElement *te, TreeStoreElem *tselem, ReportList *reports)
static wmOperatorStatus outliner_lib_relocate_invoke_do(bContext *C, ReportList *reports, TreeElement *te, const float mval[2], const bool reload)
static bool ed_operator_outliner_datablocks_active(bContext *C)
static int outliner_id_delete_tag(bContext *C, ReportList *reports, TreeElement *te, const float mval[2], SceneReplaceData &scene_replace_data)
void lib_reload_fn(bContext *C, ReportList *, Scene *, TreeElement *te, TreeStoreElem *, TreeStoreElem *tselem)
void outliner_cleanup_tree(SpaceOutliner *space_outliner)
static wmOperatorStatus outliner_item_rename_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void OUTLINER_OT_item_openclose(wmOperatorType *ot)
static int subtree_has_objects(ListBaseT< TreeElement > *lb)
static bool outliner_id_copy_tag_id(ID *id, bke::blendfile::PartialWriteContext &copybuffer, ReportList *reports)
bool outliner_item_is_co_over_name(const TreeElement *te, float view_co_x)
static KeyingSet * verify_active_keyingset(Scene *scene, short add)
static bool outliner_open_back(TreeElement *te)
bool outliner_flag_flip(SpaceOutliner &space_outliner, const eTreeStoreElem_Flag flag)
static int outliner_id_copy_tag(SpaceOutliner *space_outliner, ListBaseT< TreeElement > *tree, bke::blendfile::PartialWriteContext &copybuffer, ReportList *reports)
static void outliner_openclose_level(ListBaseT< TreeElement > *lb, int curlevel, int level, int open)
void outliner_set_coordinates(const ARegion *region, SpaceOutliner *space_outliner)
static wmOperatorStatus outliner_clear_filter_exec(bContext *C, wmOperator *)
static wmOperatorStatus outliner_id_paste_exec(bContext *C, wmOperator *op)
void item_rename_fn(bContext *C, ReportList *reports, Scene *, TreeElement *te, TreeStoreElem *, TreeStoreElem *tselem)
static void outliner_copybuffer_filepath_get(char filepath[FILE_MAX], size_t filepath_maxncpy)
static void unused_message_gen(std::string &message, const std::array< int, INDEX_ID_MAX > &num_tagged)
static wmOperatorStatus outliner_highlight_update_invoke(bContext *C, wmOperator *, const wmEvent *event)
static wmOperatorStatus outliner_show_hierarchy_exec(bContext *C, wmOperator *)
static wmOperatorStatus outliner_lib_reload_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static bool outliner_orphans_purge_check(bContext *C, wmOperator *op)
void OUTLINER_OT_orphans_purge(wmOperatorType *ot)
static wmOperatorStatus outliner_select_all_exec(bContext *C, wmOperator *op)
static TreeElement * outliner_item_rename_find_active(const SpaceOutliner *space_outliner, ReportList *reports)
TreeElement * outliner_find_element_with_flag(const ListBaseT< TreeElement > *lb, short flag)
std::string filename(const std::string_view &str, size_t pos)
void template_ID_session_uid(Layout &layout, bContext *C, PointerRNA *ptr, StringRefNull propname, short idcode)
const uiStyle * style_get_dpi()
void view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
Definition view2d.cc:1651
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
const char * BKE_idtype_idcode_to_name(short idcode)
Definition idtype.cc:261
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
bPoseChannel * BKE_pose_channel_active(Object *ob, bool check_bonecoll)
ScrArea * CTX_wm_area(const bContext *C)
short BKE_idtype_index_to_idcode(int idtype_index)
Definition idtype.cc:451
int ANIM_add_driver(ReportList *reports, ID *id, const char rna_path[], int array_index, short flag, eDriver_Types type)
Main Driver Management API calls.
Definition drivers.cc:385
int RNA_enum_get(PointerRNA *ptr, const char *name)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
const EnumPropertyItem rna_enum_id_type_items[]
Definition rna_ID.cc:33
Scene * BKE_scene_find_replacement(const Main &bmain, const Scene &scene, FunctionRef< bool(const Scene &scene)> scene_validate_cb=nullptr)
Definition scene.cc:2170
@ RPT_ERROR_INVALID_INPUT
Definition BKE_report.hh:42
@ RPT_WARNING
Definition BKE_report.hh:40
void BKE_lib_query_unused_ids_tag(Main *bmain, int tag, LibQueryUnusedIDsData &parameters)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
float BLF_width(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition blf.cc:835
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:98
SpaceOutliner * CTX_wm_space_outliner(const bContext *C)
ID * BKE_libblock_find_session_uid(Main *bmain, short type, uint32_t session_uid)
Definition lib_id.cc:1826
void WM_operator_properties_free(PointerRNA *ptr)
KeyingSet * BKE_keyingset_add(ListBaseT< KeyingSet > *list, const char idname[], const char name[], eKS_Settings flag, eInsertKeyFlags keyingflag)
Definition anim_sys.cc:137
void ED_outliner_select_sync_from_outliner(bContext *C, SpaceOutliner *space_outliner)
bool BKE_idtype_idcode_is_linkable(short idcode)
Definition idtype.cc:307
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
void void BKE_libblock_remap(Main *bmain, void *old_idv, void *new_idv, int remap_flags) ATTR_NONNULL(1
Definition lib_remap.cc:701
void BKE_keyingset_free_path(KeyingSet *ks, KS_Path *ksp)
Definition anim_sys.cc:233
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
PointerRNA WM_operator_properties_create_ptr(wmOperatorType *ot)
int RNA_int_get(PointerRNA *ptr, const char *name)
char * RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, int *r_len)
bool ED_operator_outliner_active(bContext *C)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
@ ID_REMAP_SKIP_NEVER_NULL_USAGE
@ ID_REMAP_SKIP_INDIRECT_USAGE
void BKE_workspace_id_tag_all_visible(Main *bmain, int tag) ATTR_NONNULL()
Definition workspace.cc:617
const char * BKE_id_name(const ID &id)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
void GPU_materials_free(Main *bmain)
@ LIBOVERRIDE_FLAG_NO_HIERARCHY
Definition DNA_ID.h:303
void BKE_main_id_tag_idcode(Main *mainvar, short type, int tag, bool value)
Definition lib_id.cc:1307
@ TSE_LIBRARY_OVERRIDE_BASE
@ TSE_SCENE_COLLECTION_BASE
ViewLayer * CTX_data_view_layer(const bContext *C)
void WM_operator_properties_select_all(wmOperatorType *ot)
bool RNA_property_array_check(PropertyRNA *prop)
EditBone * CTX_data_active_bone(const bContext *C)
PropertyType RNA_property_type(PropertyRNA *prop)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
unsigned int uint32_t
Definition BKE_text.h:81
bool ED_scene_replace_active_for_deletion(bContext &C, Main &bmain, Scene &scene, Scene *scene_new=nullptr)
Definition scene_edit.cc:96
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
const IDTypeInfo * BKE_idtype_get_info_from_id(const ID *id)
Definition idtype.cc:232
bool RNA_property_anim_editable(const PointerRNA *ptr, PropertyRNA *prop_orig)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void BKE_lib_query_unused_ids_amounts(Main *bmain, LibQueryUnusedIDsData &parameters)
@ PROP_POINTER
Definition RNA_types.hh:215
@ PROP_COLLECTION
Definition RNA_types.hh:216
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
BMesh const char void * data
Object * BKE_object_pose_armature_get(Object *ob)
Definition object.cc:2507
int ED_screen_area_active(const bContext *C)
wmWindowManager * CTX_wm_manager(const bContext *C)
@ FILE_ACTIVE_COLLECTION
size_t BKE_id_multi_tagged_delete(Main *bmain, const BKEIDDeleteOptions &options={}) ATTR_NONNULL()
bool ANIM_remove_driver(ID *id, const char rna_path[], int array_index)
Main Driver Management API calls.
Definition drivers.cc:511
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
const char * BKE_idtype_idcode_to_name_plural(short idcode)
Definition idtype.cc:268
wmOperatorStatus WM_operator_props_dialog_popup(bContext *C, wmOperator *op, int width, std::optional< std::string > title, std::optional< std::string > confirm_text, const bool cancel_default, std::optional< std::string > message, const bool show_icon)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
const char * BKE_tempdir_base() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
Definition appdir.cc:1288
void BKE_main_id_tag_all(Main *mainvar, int tag, bool value)
Definition lib_id.cc:1314
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void WM_event_drag_start_mval(const wmEvent *event, const ARegion *region, int r_mval[2])
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
bool RNA_struct_is_ID(const StructRNA *type)
wmWindow * WM_window_open_temp(bContext *C, const char *title, int space_type, bool dialog)
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:1024
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
Main * CTX_data_main(const bContext *C)
@ INDEX_ID_SCE
Definition DNA_ID.h:1351
@ INDEX_ID_NULL
Definition DNA_ID.h:1359
@ ID_RECALC_SELECT
Definition DNA_ID.h:1101
wmOperatorStatus WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
ID_Type GS(const char *name)
Definition DNA_ID.h:410
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
void BLI_path_split_dir_file(const char *filepath, char *dir, size_t dir_maxncpy, char *file, size_t file_maxncpy) ATTR_NONNULL(1
@ ID_TAG_INDIRECT
Definition DNA_ID.h:851
@ ID_TAG_PRE_EXISTING
Definition DNA_ID.h:929
@ ID_TAG_DOIT
Definition DNA_ID.h:1029
char * RNA_path_append(const char *path, const PointerRNA *, PropertyRNA *prop, int intkey, const char *strkey)
Definition rna_path.cc:680
int BKE_copybuffer_paste(bContext *C, const char *libname, int flag, ReportList *reports, uint64_t id_types_mask)
@ KM_PRESS_DRAG
Definition WM_types.hh:332
@ KM_RELEASE
Definition WM_types.hh:325
void BKE_main_lib_objects_recalc_all(Main *bmain)
Definition lib_id.cc:1379
void DEG_relations_tag_update(Main *bmain)
Scene * CTX_data_scene(const bContext *C)
KS_Path * BKE_keyingset_find_path(KeyingSet *ks, ID *id, const char group_name[], const char rna_path[], int array_index, int group_mode)
Definition anim_sys.cc:87
@ CREATEDRIVER_WITH_DEFAULT_DVAR
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
bool BKE_library_ID_is_indirectly_used(Main *bmain, void *idv)
Definition lib_query.cc:652
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void ED_region_activate_rna_prop(bContext *C, ARegion *region, const void *data, StringRefNull prop_name)
Definition area.cc:696
bool ED_operator_region_outliner_active(bContext *C)
bool BLI_rctf_isect_y(const rctf *rect, float y)
Definition rct.cc:106
KS_Path * BKE_keyingset_add_path(KeyingSet *ks, ID *id, const char group_name[], const char rna_path[], int array_index, eKSP_Settings flag, eKSP_Grouping groupmode)
Definition anim_sys.cc:170
ARegion * CTX_wm_region(const bContext *C)
void ED_region_tag_redraw_no_rebuild(ARegion *region)
Definition area.cc:727
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:784
@ IDTYPE_FLAGS_NO_COPY
Definition BKE_idtype.hh:36
@ IDTYPE_FLAGS_NO_LIBLINKING
Definition BKE_idtype.hh:38
@ KSP_FLAG_WHOLE_ARRAY
#define TREESTORE(a)
#define TSELEM_OPEN(telm, sv)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
const char * name
char name[258]
Definition DNA_ID.h:433
unsigned int session_uid
Definition DNA_ID.h:463
struct Library * lib
Definition DNA_ID.h:421
ListBaseT< KS_Path > paths
char filepath[1024]
Definition DNA_ID.h:562
bke::library::LibraryRuntime * runtime
Definition DNA_ID.h:591
struct LinkData * next
StructRNA * type
Definition RNA_types.hh:63
ListBaseT< struct KeyingSet > keyingsets
eSpaceOutliner_Mode outlinevis
ed::outliner::SpaceOutliner_Runtime * runtime
eTreeStoreElem_Flag flag
ListBaseT< ed::outliner::TreeElement > tree
void use_property_split_set(bool is_sep)
void label(StringRef name, int icon)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
Layout & column(bool align)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
Layout & row(bool align)
wmEventType type
Definition WM_types.hh:817
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
bool(*) check(bContext *C, wmOperator *op)
Definition WM_types.hh:1133
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
void(*) ui(bContext *C, wmOperator *op)
Definition WM_types.hh:1176
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
struct ReportList * reports
uiFontStyle widget