Blender V5.3
interface_template_id.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BKE_anim_data.hh"
10#include "BKE_collection.hh"
11#include "BKE_context.hh"
12#include "BKE_idtype.hh"
13#include "BKE_layer.hh"
14#include "BKE_lib_id.hh"
15#include "BKE_lib_override.hh"
16#include "BKE_library.hh"
17#include "BKE_main.hh"
19#include "BKE_packedFile.hh"
20
21#include "BLI_listbase.hh"
22#include "BLI_string_search.hh"
23#include "BLI_string_utf8.hh"
24
25#include "BLT_translation.hh"
26
28
30#include "DNA_scene_types.h"
31#include "DNA_workspace_types.h"
32
33#include "ED_id_management.hh"
34#include "ED_node.hh"
35#include "ED_object.hh"
36#include "ED_undo.hh"
37
38#include "RNA_access.hh"
39#include "RNA_prototypes.hh"
40
41#include "WM_api.hh"
42
44#include "UI_string_search.hh"
45#include "interface_intern.hh"
47
48namespace blender::ui {
49
50enum {
51 UI_ID_RENAME = 1 << 0,
52 UI_ID_BROWSE = 1 << 1,
53 UI_ID_ADD_NEW = 1 << 2,
54 UI_ID_OPEN = 1 << 3,
55 UI_ID_DELETE = 1 << 4,
56 UI_ID_PIN = 1 << 6,
59};
60
61struct TemplateID {
63 PropertyRNA *prop = nullptr;
64
65 ListBaseT<ID> *idlb = nullptr;
66 short idcode = 0;
67 short filter = 0;
68 int prv_rows = 0;
69 int prv_cols = 0;
70 bool preview = false;
71 float scale = 0.0f;
72};
73
74/* Search browse menu, assign. */
75static void template_ID_set_property_exec_fn(bContext *C, void *arg_template, void *item)
76{
77 TemplateID *template_ui = static_cast<TemplateID *>(arg_template);
78
79 /* ID */
80 if (item) {
81 PointerRNA idptr = RNA_id_pointer_create(static_cast<ID *>(item));
82 RNA_property_pointer_set(&template_ui->ptr, template_ui->prop, idptr, nullptr);
83 RNA_property_update(C, &template_ui->ptr, template_ui->prop);
84 }
85}
86
87/* Search browse menu, assign #ID::session_uid as Int Property. */
89 void *arg_template,
90 void *item)
91{
92 TemplateID *template_ui = static_cast<TemplateID *>(arg_template);
93 if (!item) {
94 return;
95 }
97 &template_ui->ptr, template_ui->prop, int(static_cast<ID *>(item)->session_uid));
98}
99
100static bool id_search_allows_id(TemplateID *template_ui, const int flag, ID *id, const char *query)
101{
102 ID *id_from = template_ui->ptr.owner_id;
103
104 /* Do self check. */
105 if ((flag & PROP_ID_SELF_CHECK) && id == id_from) {
106 return false;
107 }
108
109 /* Use filter. */
110 if (RNA_property_type(template_ui->prop) == PROP_POINTER) {
112 if (RNA_property_pointer_poll(&template_ui->ptr, template_ui->prop, &ptr) == 0) {
113 return false;
114 }
115 }
116
117 /* Hide dot prefixed data-blocks, but only if filter does not force them visible. */
118 if (U.flag & USER_HIDE_DOT_DATABLOCK) {
119 if ((id->name[2] == '.') && (query[0] != '.')) {
120 return false;
121 }
122 }
123
124 return true;
125}
126
127static bool id_search_add(const bContext *C, TemplateID *template_ui, SearchItems *items, ID *id)
128{
129 /* +1 is needed because BKE_id_ui_prefix used 3 letter prefix
130 * followed by ID_NAME-2 characters from id->name
131 */
132 char name_ui[MAX_ID_FULL_NAME_UI];
133 int iconid = id_icon_get(C, id, template_ui->preview);
134 const bool use_lib_prefix = template_ui->preview || iconid;
135 const bool has_sep_char = ID_IS_LINKED(id);
136
137 /* When using previews, the library hint (linked, overridden, missing) is added with a
138 * character prefix, otherwise we can use a icon. */
139 int name_prefix_offset;
140 BKE_id_full_name_ui_prefix_get(name_ui, id, use_lib_prefix, UI_SEP_CHAR, &name_prefix_offset);
141 if (!use_lib_prefix) {
142 iconid = icon_from_library(id);
143 }
144
145 if (!search_item_add(items,
146 name_ui,
147 id,
148 iconid,
149 has_sep_char ? int64_t(BUT_HAS_SEP_CHAR) : 0,
150 name_prefix_offset))
151 {
152 return false;
153 }
154
155 return true;
156}
157
158/* ID Search browse menu, do the search */
159static void id_search_cb(const bContext *C,
160 void *arg_template,
161 const char *str,
162 SearchItems *items,
163 const bool /*is_first*/)
164{
165 TemplateID *template_ui = static_cast<TemplateID *>(arg_template);
166 ListBaseT<ID> *lb = template_ui->idlb;
167 const int flag = RNA_property_flag(template_ui->prop);
168
170
171 /* ID listbase */
172 for (ID &id : *lb) {
173 if (id_search_allows_id(template_ui, flag, &id, str)) {
174 search.add(id.name + 2, &id);
175 }
176 }
177
178 const Vector<ID *> filtered_ids = search.query(str);
179
180 for (ID *id : filtered_ids) {
181 if (!id_search_add(C, template_ui, items, id)) {
182 break;
183 }
184 }
185}
186
190static void id_search_cb_tagged(const bContext *C,
191 void *arg_template,
192 const char *str,
193 SearchItems *items)
194{
195 TemplateID *template_ui = static_cast<TemplateID *>(arg_template);
196 ListBaseT<ID> *lb = template_ui->idlb;
197 const int flag = RNA_property_flag(template_ui->prop);
198
201
202 /* ID listbase */
203 for (ID &id : *lb) {
204 if (id.tag & ID_TAG_DOIT) {
205 if (id_search_allows_id(template_ui, flag, &id, str)) {
206 search.add(id.name + 2, &id);
207 }
208 id.tag &= ~ID_TAG_DOIT;
209 }
210 }
211
212 Vector<ID *> filtered_ids = search.query(str);
213
214 for (ID *id : filtered_ids) {
215 if (!id_search_add(C, template_ui, items, id)) {
216 break;
217 }
218 }
219}
220
225 void *arg_template,
226 const char *str,
227 SearchItems *items,
228 const bool /*is_first*/)
229{
230 TemplateID *template_ui = static_cast<TemplateID *>(arg_template);
231 ListBaseT<ID> *lb = template_ui->idlb;
232 Scene *scene = nullptr;
233 ID *id_from = template_ui->ptr.owner_id;
234
235 if (id_from && GS(id_from->name) == ID_SCE) {
236 scene = id_cast<Scene *>(id_from);
237 }
238 else {
239 scene = CTX_data_scene(C);
240 }
241
243
244 FOREACH_SCENE_OBJECT_BEGIN (scene, ob_iter) {
245 ob_iter->id.tag |= ID_TAG_DOIT;
246 }
248 id_search_cb_tagged(C, arg_template, str, items);
249}
250
252 bContext *C, ARegion *region, const rcti *item_rect, void * /*arg*/, void *active)
253{
254 ID *active_id = static_cast<ID *>(active);
255 return tooltip_create_from_search_item_generic(C, region, item_rect, active_id);
256}
257
258/* ID Search browse menu, open */
259static Block *id_search_menu(bContext *C, ARegion *region, void *arg_litem)
260{
261 static TemplateID template_ui;
262 PointerRNA active_item_ptr;
263 void (*id_search_update_fn)(
264 const bContext *, void *, const char *, SearchItems *, const bool) = id_search_cb;
265
266 /* arg_litem is malloced, can be freed by parent button */
267 template_ui = *(static_cast<TemplateID *>(arg_litem));
268 active_item_ptr = RNA_property_pointer_get(&template_ui.ptr, template_ui.prop);
269
270 if (template_ui.filter) {
271 /* Currently only used for objects. */
272 if (template_ui.idcode == ID_OB) {
273 if (template_ui.filter == TEMPLATE_ID_FILTER_AVAILABLE) {
274 id_search_update_fn = id_search_cb_objects_from_scene;
275 }
276 }
277 }
278
280 region,
281 id_search_update_fn,
282 &template_ui,
284 active_item_ptr.data,
286 template_ui.prv_rows,
287 template_ui.prv_cols,
288 template_ui.scale);
289}
290
291static Block *id_search_menu_session_uid(bContext *C, ARegion *region, void *arg_litem)
292{
293 static TemplateID template_ui;
294 void (*id_search_update_fn)(
295 const bContext *, void *, const char *, SearchItems *, const bool) = id_search_cb;
296
297 template_ui = *(static_cast<TemplateID *>(arg_litem));
298 const uint32_t active_session_uid = RNA_property_int_get(&template_ui.ptr, template_ui.prop);
300 CTX_data_main(C), template_ui.idcode, active_session_uid);
301
303 region,
304 id_search_update_fn,
305 &template_ui,
307 active_id,
309 template_ui.prv_rows,
310 template_ui.prv_cols,
311 template_ui.scale);
312}
313
315 PointerRNA *r_ptr,
316 PropertyRNA **r_prop)
317{
319
320 *r_ptr = {};
321 *r_prop = nullptr;
322 if (!but || !but->context) {
323 return;
324 }
325 const PointerRNA *ptr = CTX_store_ptr_lookup(but->context, "template_id_ptr");
326 std::optional<StringRefNull> prop_name = CTX_store_string_lookup(but->context,
327 "template_id_prop");
328
329 if (!ptr || !prop_name) {
330 return;
331 }
332
333 PointerRNA ptr_copy = *ptr;
334 PropertyRNA *prop = RNA_struct_find_property(&ptr_copy, prop_name->c_str());
335
336 if (!prop || RNA_property_type(prop) != PROP_POINTER) {
337 return;
338 }
339
340 StructRNA *type = RNA_property_pointer_type(&ptr_copy, prop);
341 if (!type || !RNA_struct_is_ID(type)) {
342 return;
343 }
344
345 *r_ptr = std::move(ptr_copy);
346 *r_prop = prop;
347}
348
350 Collection *collection,
351 const int parent_level,
352 Collection **r_collection_parent_best,
353 int *r_parent_level_best)
354{
355 if (!ID_IS_LINKED(collection) && !ID_IS_OVERRIDE_LIBRARY_REAL(collection)) {
356 return;
357 }
358 if (ID_IS_OVERRIDABLE_LIBRARY(collection) || ID_IS_OVERRIDE_LIBRARY_REAL(collection)) {
359 if (parent_level > *r_parent_level_best) {
360 *r_parent_level_best = parent_level;
361 *r_collection_parent_best = collection;
362 }
363 }
364 for (CollectionParent *iter = collection->runtime->parents.first(); iter != nullptr;
365 iter = iter->next)
366 {
367 if (iter->collection->id.lib != collection->id.lib && ID_IS_LINKED(iter->collection)) {
368 continue;
369 }
371 iter->collection, parent_level + 1, r_collection_parent_best, r_parent_level_best);
372 }
373}
374
376 Collection *root_collection, ID *target_id, const bool do_parents)
377{
378 root_collection->id.tag |= ID_TAG_DOIT;
379
380 /* Tag all local parents of the root collection, so that usages of the root collection and other
381 * linked ones can be replaced by the local overrides in those parents too. */
382 if (do_parents) {
383 for (CollectionParent *iter = root_collection->runtime->parents.first(); iter != nullptr;
384 iter = iter->next)
385 {
386 if (ID_IS_LINKED(iter->collection)) {
387 continue;
388 }
389 iter->collection->id.tag |= ID_TAG_DOIT;
390 }
391 }
392
393 for (CollectionChild *iter = root_collection->children.first(); iter != nullptr;
394 iter = iter->next)
395 {
396 if (ID_IS_LINKED(iter->collection) && iter->collection->id.lib != target_id->lib) {
397 continue;
398 }
399 if (GS(target_id->name) == ID_OB &&
400 !BKE_collection_has_object_recursive(iter->collection, id_cast<Object *>(target_id)))
401 {
402 continue;
403 }
404 if (GS(target_id->name) == ID_GR &&
405 !BKE_collection_has_collection(iter->collection, id_cast<Collection *>(target_id)))
406 {
407 continue;
408 }
410 iter->collection, target_id, false);
411 }
412}
413
415 bContext *C, Main *bmain, ID *owner_id, ID *id, const char **r_undo_push_label)
416{
417 const char *undo_push_label;
418 if (r_undo_push_label == nullptr) {
419 r_undo_push_label = &undo_push_label;
420 }
421
422 /* If this is called on an already local override, 'toggle' between user-editable state, and
423 * system override with reset. */
424 if (!ID_IS_LINKED(id) && ID_IS_OVERRIDE_LIBRARY(id)) {
426 BKE_lib_override_library_get(bmain, id, nullptr, &id);
427 }
428 if (id->override_library->flag & LIBOVERRIDE_FLAG_SYSTEM_DEFINED) {
429 id->override_library->flag &= ~LIBOVERRIDE_FLAG_SYSTEM_DEFINED;
430 *r_undo_push_label = "Make Library Override Hierarchy Editable";
431 }
432 else {
433 BKE_lib_override_library_id_reset(bmain, id, true);
434 *r_undo_push_label = "Clear Library Override Hierarchy";
435 }
436
440 return id;
441 }
442
443 /* Attempt to perform a hierarchy override, based on contextual data available.
444 * NOTE: do not attempt to perform such hierarchy override at all cost, if there is not enough
445 * context, better to abort than create random overrides all over the place. */
447 WM_global_reportf(RPT_ERROR, "The data-block %s is not overridable", id->name);
448 return nullptr;
449 }
450
451 Object *object_active = CTX_data_active_object(C);
452 if (object_active == nullptr && GS(owner_id->name) == ID_OB) {
453 object_active = id_cast<Object *>(owner_id);
454 }
455 if (object_active != nullptr) {
456 if (ID_IS_LINKED(object_active)) {
457 if (object_active->id.lib != id->lib || !ID_IS_OVERRIDABLE_LIBRARY_HIERARCHY(object_active))
458 {
459 /* The active object is from a different library than the overridden ID, or otherwise
460 * cannot be used in hierarchy. */
461 object_active = nullptr;
462 }
463 }
464 else if (!ID_IS_OVERRIDE_LIBRARY_REAL(object_active)) {
465 /* Fully local object cannot be used in override hierarchy either. */
466 object_active = nullptr;
467 }
468 }
469
470 Collection *collection_active_context = CTX_data_collection(C);
471 Collection *collection_active = collection_active_context;
472 if (collection_active == nullptr && GS(owner_id->name) == ID_GR) {
473 collection_active = id_cast<Collection *>(owner_id);
474 }
475 if (collection_active != nullptr) {
476 if (ID_IS_LINKED(collection_active)) {
477 if (collection_active->id.lib != id->lib ||
478 !ID_IS_OVERRIDABLE_LIBRARY_HIERARCHY(collection_active))
479 {
480 /* The active collection is from a different library than the overridden ID, or otherwise
481 * cannot be used in hierarchy. */
482 collection_active = nullptr;
483 }
484 else {
485 int parent_level_best = -1;
486 Collection *collection_parent_best = nullptr;
488 collection_active, 0, &collection_parent_best, &parent_level_best);
489 collection_active = collection_parent_best;
490 }
491 }
492 else if (!ID_IS_OVERRIDE_LIBRARY_REAL(collection_active)) {
493 /* Fully local collection cannot be used in override hierarchy either. */
494 collection_active = nullptr;
495 }
496 }
497 if (collection_active == nullptr && object_active != nullptr &&
498 (ID_IS_LINKED(object_active) || ID_IS_OVERRIDE_LIBRARY_REAL(object_active)))
499 {
500 /* If we failed to find a valid 'active' collection so far for our override hierarchy, but do
501 * have a valid 'active' object, try to find a collection from that object. */
502 for (Collection &collection_iter : bmain->collections) {
503 if (ID_IS_LINKED(&collection_iter) && collection_iter.id.lib != id->lib) {
504 continue;
505 }
506 if (!ID_IS_OVERRIDE_LIBRARY_REAL(&collection_iter)) {
507 continue;
508 }
509 if (!BKE_collection_has_object_recursive(&collection_iter, object_active)) {
510 continue;
511 }
512 int parent_level_best = -1;
513 Collection *collection_parent_best = nullptr;
515 &collection_iter, 0, &collection_parent_best, &parent_level_best);
516 collection_active = collection_parent_best;
517 break;
518 }
519 }
520
521 ID *id_override = nullptr;
522 Scene *scene = CTX_data_scene(C);
523 ViewLayer *view_layer = CTX_data_view_layer(C);
524 switch (GS(id->name)) {
525 case ID_GR:
526 if (collection_active != nullptr &&
527 BKE_collection_has_collection(collection_active, id_cast<Collection *>(id)))
528 {
530 if (object_active != nullptr) {
531 object_active->id.tag |= ID_TAG_DOIT;
532 }
534 scene,
535 view_layer,
536 nullptr,
537 id,
538 &collection_active->id,
539 nullptr,
540 &id_override,
541 false);
542 }
543 else if (object_active != nullptr && !ID_IS_LINKED(object_active) &&
544 &object_active->instance_collection->id == id)
545 {
546 object_active->id.tag |= ID_TAG_DOIT;
548 scene,
549 view_layer,
550 id->lib,
551 id,
552 &object_active->id,
553 &object_active->id,
554 &id_override,
555 false);
556 }
557 break;
558 case ID_OB:
559 if (collection_active != nullptr &&
560 BKE_collection_has_object_recursive(collection_active, id_cast<Object *>(id)))
561 {
563 if (object_active != nullptr) {
564 object_active->id.tag |= ID_TAG_DOIT;
565 }
567 scene,
568 view_layer,
569 nullptr,
570 id,
571 &collection_active->id,
572 nullptr,
573 &id_override,
574 false);
575 }
576 else {
577 if (object_active != nullptr) {
578 object_active->id.tag |= ID_TAG_DOIT;
579 }
581 bmain, scene, view_layer, nullptr, id, nullptr, nullptr, &id_override, false);
582 BKE_scene_collections_object_remove(bmain, scene, id_cast<Object *>(id), true);
584 }
585 break;
586 case ID_ME:
587 case ID_CU_LEGACY:
588 case ID_MB:
589 case ID_LT:
590 case ID_LA:
591 case ID_CA:
592 case ID_SPK:
593 case ID_AR:
594 case ID_GD_LEGACY:
595 case ID_CV:
596 case ID_PT:
597 case ID_VO:
598 case ID_NT: /* Essentially geometry nodes from modifier currently. */
599 if (object_active != nullptr) {
600 if (collection_active != nullptr &&
601 BKE_collection_has_object_recursive(collection_active, object_active))
602 {
604 object_active->id.tag |= ID_TAG_DOIT;
606 scene,
607 view_layer,
608 nullptr,
609 id,
610 &collection_active->id,
611 nullptr,
612 &id_override,
613 false);
614 }
615 else {
616 object_active->id.tag |= ID_TAG_DOIT;
618 scene,
619 view_layer,
620 nullptr,
621 id,
622 &object_active->id,
623 nullptr,
624 &id_override,
625 false);
626 }
627 }
628 else {
630 bmain, scene, view_layer, nullptr, id, id, nullptr, &id_override, false);
631 }
632 break;
633 case ID_MA:
634 case ID_TE:
635 case ID_IM:
636 WM_global_reportf(RPT_WARNING, "The type of data-block %s is not yet implemented", id->name);
637 break;
638 case ID_WO:
639 WM_global_reportf(RPT_WARNING, "The type of data-block %s is not yet implemented", id->name);
640 break;
641 case ID_PA:
642 WM_global_reportf(RPT_WARNING, "The type of data-block %s is not yet implemented", id->name);
643 break;
644 default:
645 WM_global_reportf(RPT_WARNING, "The type of data-block %s is not yet implemented", id->name);
646 break;
647 }
648
649 if (id_override != nullptr) {
651
652 /* Ensure that the hierarchy root of the newly overridden data is instantiated in the scene, in
653 * case it's a collection or object. */
654 ID *hierarchy_root = id_override->override_library->hierarchy_root;
655 if (GS(hierarchy_root->name) == ID_OB) {
656 Object *object_hierarchy_root = reinterpret_cast<Object *>(hierarchy_root);
657 if (!BKE_scene_has_object(*bmain, scene, object_hierarchy_root)) {
658 if (!ID_IS_LINKED(collection_active_context)) {
659 BKE_collection_object_add(bmain, collection_active_context, object_hierarchy_root);
660 }
661 else {
662 BKE_collection_object_add(bmain, scene->master_collection, object_hierarchy_root);
663 }
664 }
665 }
666 else if (GS(hierarchy_root->name) == ID_GR) {
667 Collection *collection_hierarchy_root = reinterpret_cast<Collection *>(hierarchy_root);
668 if (!BKE_collection_has_collection(scene->master_collection, collection_hierarchy_root)) {
669 if (!ID_IS_LINKED(collection_active_context)) {
670 BKE_collection_child_add(bmain, collection_active_context, collection_hierarchy_root);
671 }
672 else {
673 BKE_collection_child_add(bmain, scene->master_collection, collection_hierarchy_root);
674 }
675 }
676 }
677
678 *r_undo_push_label = "Make Library Override Hierarchy";
679
680 /* In theory we could rely on setting/updating the RNA ID pointer property (as done by calling
681 * code) to be enough.
682 *
683 * However, some rare ID pointers properties (like the "active object in view-layer" one used
684 * for the Object templateID in the Object properties) use notifiers that do not enforce a
685 * rebuild of outliner trees, leading to crashes.
686 *
687 * So for now, add some extra notifiers here. */
690 }
691 return id_override;
692}
693
695 Main *bmain,
696 PropertyPointerRNA &pprop,
697 PointerRNA *idptr,
698 const char **r_undo_push_label)
699{
700 ID *id = static_cast<ID *>(idptr->data);
701 ID *owner_id = pprop.ptr.owner_id;
702
704 C, bmain, owner_id, id, r_undo_push_label);
705
706 if (id_override != nullptr) {
707 /* `idptr` is re-assigned to owner property to ensure proper updates etc. Here we also use it
708 * to ensure remapping of the owner property from the linked data to the newly created
709 * liboverride (note that in theory this remapping has already been done by code above), but
710 * only in case owner ID was already local ID (override or pure local data).
711 *
712 * Otherwise, owner ID will also have been overridden, and remapped already to use it's
713 * override of the data too. */
714 if (!ID_IS_LINKED(owner_id)) {
715 *idptr = RNA_id_pointer_create(id_override);
716 }
717 }
718 else {
719 WM_global_reportf(RPT_ERROR, "The data-block %s could not be overridden", id->name);
720 }
721}
722
724{
725 PointerRNA idptr = RNA_property_pointer_get(&pprop.ptr, pprop.prop);
726 ID *id = static_cast<ID *>(idptr.data);
727
728 const char *undo_push_label;
729
730 idptr = {};
731 RNA_property_pointer_set(&pprop.ptr, pprop.prop, idptr, nullptr);
732 RNA_property_update(&C, &pprop.ptr, pprop.prop);
733
734 if (id && CTX_wm_window(&C)->runtime->eventstate->modifier & KM_SHIFT) {
735 /* only way to force-remove data (on save) */
738 id->us = 0;
739 undo_push_label = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Delete Data-Block");
740 }
741 else {
742 undo_push_label = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Unlink Data-Block");
743 }
744 ED_undo_push(&C, undo_push_label);
746}
747
749{
750 PointerRNA idptr = RNA_property_pointer_get(&pprop.ptr, pprop.prop);
751 ID *id = static_cast<ID *>(idptr.data);
752
753 const char *undo_push_label = nullptr;
754
755 if (!id) {
756 return;
757 }
758 Main *bmain = CTX_data_main(&C);
759 if (CTX_wm_window(&C)->runtime->eventstate->modifier & KM_SHIFT) {
760 template_id_liboverride_hierarchy_make(&C, bmain, pprop, &idptr, &undo_push_label);
761 }
762 else {
765
766 /* Reassign to get proper updates/notifiers. */
767 idptr = RNA_property_pointer_get(&pprop.ptr, pprop.prop);
768 undo_push_label = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Make Local");
769 }
770 }
771 if (undo_push_label) {
772 RNA_property_pointer_set(&pprop.ptr, pprop.prop, idptr, nullptr);
773 RNA_property_update(&C, &pprop.ptr, pprop.prop);
774 ED_undo_push(&C, undo_push_label);
776 }
777}
778
780{
781 PointerRNA idptr = RNA_property_pointer_get(&pprop.ptr, pprop.prop);
782 ID *id = static_cast<ID *>(idptr.data);
783
784 const char *undo_push_label = nullptr;
785
786 if (!(id && ID_IS_OVERRIDE_LIBRARY(id))) {
787 return;
788 }
789 Main *bmain = CTX_data_main(&C);
790 if (CTX_wm_window(&C)->runtime->eventstate->modifier & KM_SHIFT) {
791 template_id_liboverride_hierarchy_make(&C, bmain, pprop, &idptr, &undo_push_label);
792 }
793 else {
795 /* Reassign to get proper updates/notifiers. */
796 idptr = RNA_property_pointer_get(&pprop.ptr, pprop.prop);
797 RNA_property_pointer_set(&pprop.ptr, pprop.prop, idptr, nullptr);
798 RNA_property_update(&C, &pprop.ptr, pprop.prop);
799
800 undo_push_label = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Make Local");
801 }
802 if (undo_push_label != nullptr) {
803 ED_undo_push(&C, undo_push_label);
805 }
806}
807
809{
810 PointerRNA idptr = RNA_property_pointer_get(&pprop.ptr, pprop.prop);
811 ID *id = static_cast<ID *>(idptr.data);
812
813 if (!id) {
814 return;
815 }
816 const bool do_scene_obj = ((GS(id->name) == ID_OB) && (pprop.ptr.type == RNA_LayerObjects));
817
818 /* make copy */
819 if (do_scene_obj) {
820 Main *bmain = CTX_data_main(&C);
821 Scene *scene = CTX_data_scene(&C);
822 ed::object::object_single_user_make(bmain, scene, id_cast<Object *>(id));
825 }
826 else {
827 Main *bmain = CTX_data_main(&C);
828 id_single_user(&C, id, &pprop.ptr, pprop.prop);
831 }
835}
836
838{
839 if (type) {
840 switch (ID_Type(RNA_type_to_ID_code(type))) {
841 case ID_SCE:
842 return N_("Browse Scene to be linked");
843 case ID_OB:
844 return N_("Browse Object to be linked");
845 case ID_ME:
846 return N_("Browse Mesh Data to be linked");
847 case ID_CU_LEGACY:
848 return N_("Browse Curve Data to be linked");
849 case ID_MB:
850 return N_("Browse Metaball Data to be linked");
851 case ID_MA:
852 return N_("Browse Material to be linked");
853 case ID_TE:
854 return N_("Browse Texture to be linked");
855 case ID_IM:
856 return N_("Browse Image to be linked");
857 case ID_LS:
858 return N_("Browse Line Style Data to be linked");
859 case ID_LT:
860 return N_("Browse Lattice Data to be linked");
861 case ID_LA:
862 return N_("Browse Light Data to be linked");
863 case ID_CA:
864 return N_("Browse Camera Data to be linked");
865 case ID_WO:
866 return N_("Browse World Settings to be linked");
867 case ID_SCR:
868 return N_("Choose Screen layout");
869 case ID_TXT:
870 return N_("Browse Text to be linked");
871 case ID_SPK:
872 return N_("Browse Speaker Data to be linked");
873 case ID_SO:
874 return N_("Browse Sound to be linked");
875 case ID_AR:
876 return N_("Browse Armature data to be linked");
877 case ID_AC:
878 return N_("Browse Action to be linked");
879 case ID_NT:
880 return N_("Browse Node Tree to be linked");
881 case ID_BR:
882 return N_("Browse Brush to be linked");
883 case ID_PA:
884 return N_("Browse Particle Settings to be linked");
885 case ID_GD_LEGACY:
886 return N_("Browse Grease Pencil Data to be linked");
887 case ID_MC:
888 return N_("Browse Movie Clip to be linked");
889 case ID_MSK:
890 return N_("Browse Mask to be linked");
891 case ID_PAL:
892 return N_("Browse Palette Data to be linked");
893 case ID_PC:
894 return N_("Browse Paint Curve Data to be linked");
895 case ID_CF:
896 return N_("Browse Cache Files to be linked");
897 case ID_WS:
898 return N_("Browse Workspace to be linked");
899 case ID_LP:
900 return N_("Browse Light Probe to be linked");
901 case ID_CV:
902 return N_("Browse Curves Data to be linked");
903 case ID_PT:
904 return N_("Browse Point Cloud Data to be linked");
905 case ID_VO:
906 return N_("Browse Volume Data to be linked");
907 case ID_GP:
908 return N_("Browse Grease Pencil Data to be linked");
909
910 /* Use generic text. */
911 case ID_LI:
912 case ID_KE:
913 case ID_VF:
914 case ID_GR:
915 case ID_WM:
916 break;
917 }
918 }
919 return N_("Browse ID data to be linked");
920}
921
927static void template_id_workspace_pin_extra_icon(const TemplateID &template_ui, Button *but)
928{
929 if ((template_ui.idcode != ID_SCE) || (template_ui.ptr.type != RNA_Window)) {
930 return;
931 }
932
933 const wmWindow *win = static_cast<const wmWindow *>(template_ui.ptr.data);
934 const WorkSpace *workspace = WM_window_get_active_workspace(win);
936 "WORKSPACE_OT_scene_pin_toggle",
938 (workspace->flags & WORKSPACE_USE_PIN_SCENE) ? ICON_PINNED :
939 ICON_UNPINNED);
940}
941
946#ifdef WITH_INTERNATIONAL
947static const char *template_id_context(StructRNA *type)
948{
949 if (type) {
951 }
953}
954#else
955# define template_id_context(type) 0
956#endif
957
959 const ID *id,
960 const TemplateID &template_ui,
961 StructRNA *type,
962 const char *const newop,
963 const bool editable,
964 const bool id_open,
965 const bool use_tab_but,
966 int but_height)
967{
968 ID *idfrom = template_ui.ptr.owner_id;
969 Button *but;
970 const ButtonType but_type = use_tab_but ? ButtonType::Tab : ButtonType::But;
971
972 /* i18n markup, does nothing! */
1007 /* NOTE: BLT_I18N_MSGID_MULTI_CTXT takes a maximum number of parameters,
1008 * check the definition to see if a new call must be added when the limit
1009 * is exceeded. */
1010
1011 const char *button_text = (id) ? "" : CTX_IFACE_(template_id_context(type), "New");
1012 const int icon = (id && !use_tab_but) ? ICON_DUPLICATE : ICON_ADD;
1013 const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
1014
1015 int w = id ? UI_UNIT_X : id_open ? UI_UNIT_X * 3 : UI_UNIT_X * 6;
1016 if (!id) {
1017 w = std::max(fontstyle_string_width(fstyle, button_text) + int(UI_UNIT_X * 1.5f), w);
1018 }
1019
1020 if (newop) {
1021 but = uiDefIconTextButO(block,
1022 but_type,
1023 newop,
1025 icon,
1026 button_text,
1027 0,
1028 0,
1029 w,
1030 but_height,
1031 std::nullopt);
1032 }
1033 else {
1034 but = uiDefIconTextBut(
1035 block, but_type, icon, button_text, 0, 0, w, but_height, nullptr, std::nullopt);
1036 }
1037
1038 if ((idfrom && !ID_IS_EDITABLE(idfrom)) || !editable) {
1040 }
1041
1042#ifndef WITH_INTERNATIONAL
1043 UNUSED_VARS(type);
1044#endif
1045
1046 return but;
1047}
1048
1049static void template_ID(const bContext *C,
1050 Layout &layout,
1051 TemplateID &template_ui,
1052 StructRNA *type,
1053 int flag,
1054 const char *newop,
1055 const char *openop,
1056 const char *unlinkop,
1057 const std::optional<StringRef> text,
1058 const bool live_icon,
1059 const bool hide_buttons)
1060{
1061 Button *but;
1062 const bool editable = RNA_property_editable(&template_ui.ptr, template_ui.prop);
1063 const bool use_previews = template_ui.preview = (flag & UI_ID_PREVIEWS) != 0;
1064
1065 PointerRNA idptr = RNA_property_pointer_get(&template_ui.ptr, template_ui.prop);
1066 ID *id = static_cast<ID *>(idptr.data);
1067 ID *idfrom = template_ui.ptr.owner_id;
1068
1069 const PropertyPointerRNA pprop = {.ptr = template_ui.ptr, .prop = template_ui.prop};
1070 // lb = template_ui->idlb;
1071
1072 /* Allow operators to take the ID from context. */
1073 layout.context_ptr_set("id", &idptr);
1074 layout.context_ptr_set("template_id_ptr", &template_ui.ptr);
1075 std::string prop_identifier = RNA_property_identifier(template_ui.prop);
1076 if (RNA_property_is_idprop(template_ui.prop)) {
1077 prop_identifier = RNA_path_name_to_infix(prop_identifier);
1078 }
1079 layout.context_string_set("template_id_prop", prop_identifier);
1080
1081 Block *block = layout.block();
1082 block_align_begin(block);
1083
1084 if (idptr.has_type()) {
1085 type = idptr.type;
1086 }
1087
1088 if (text && !text->is_empty()) {
1089 /* Add label respecting the separated layout property split state. */
1090 uiItemL_respect_property_split(&layout, *text, ICON_NONE);
1091 }
1092
1093 if (flag & UI_ID_BROWSE) {
1095 layout,
1096 block,
1097 &template_ui.ptr,
1098 template_ui.prop,
1100 MEM_new<TemplateID>(__func__, template_ui),
1102 use_previews,
1103 editable,
1104 live_icon,
1107 }
1108
1109 /* text button with name */
1110 if (id) {
1111 char name[UI_MAX_NAME_STR];
1112 const bool user_alert = (id->us <= 0);
1113
1114 int width = template_search_textbut_width(&idptr, RNA_struct_find_property(&idptr, "name"));
1115
1116 if ((template_ui.idcode == ID_SCE) && (template_ui.ptr.type == RNA_Window)) {
1117 /* More room needed for "pin" icon. */
1118 width += UI_UNIT_X;
1119 }
1120
1121 const int height = template_search_textbut_height();
1122
1123 // text_idbutton(id, name);
1124 name[0] = '\0';
1125 but = uiDefButR(block,
1127 name,
1128 0,
1129 0,
1130 width,
1131 height,
1132 &idptr,
1133 "name",
1134 -1,
1135 0,
1136 0,
1138 /* Handle undo through the #button_func_set set below. Default undo handling from the button
1139 * code (see #ui_apply_but_undo) would not work here, as the new name is not yet applied to the
1140 * ID. */
1142 Main *bmain = CTX_data_main(C);
1144 but, [bmain, id](StringRefNull new_name) { ED_id_rename(*bmain, *id, new_name); });
1145 button_func_set(but, [](bContext &C) {
1146 ED_undo_push(&C, CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Rename Data-Block"));
1148 });
1149
1150 if (user_alert) {
1152 }
1153
1154 template_id_workspace_pin_extra_icon(template_ui, but);
1155
1156 if (!hide_buttons && !(idfrom && ID_IS_LINKED(idfrom))) {
1157 if (ID_IS_LINKED(id)) {
1158 const bool disabled = !BKE_idtype_idcode_is_localizable(GS(id->name));
1159 if (ID_IS_PACKED(id)) {
1160 but = uiDefIconBut(block,
1162 ICON_PACKAGE,
1163 0,
1164 0,
1165 UI_UNIT_X,
1166 UI_UNIT_Y,
1167 nullptr,
1168 0,
1169 0,
1170 TIP_("Packed library data-block, click to unpack and make local"));
1171 }
1172 else if (id->tag & ID_TAG_INDIRECT) {
1173 but = uiDefIconBut(block,
1175 ICON_LIBRARY_DATA_INDIRECT,
1176 0,
1177 0,
1178 UI_UNIT_X,
1179 UI_UNIT_Y,
1180 nullptr,
1181 0,
1182 0,
1183 TIP_("Indirect library data-block, cannot be made local, "
1184 "Shift + Click to create a library override hierarchy"));
1185 }
1186 else {
1187 but = uiDefIconBut(block,
1189 ICON_LIBRARY_DATA_DIRECT,
1190 0,
1191 0,
1192 UI_UNIT_X,
1193 UI_UNIT_Y,
1194 nullptr,
1195 0,
1196 0,
1197 TIP_("Direct linked library data-block, click to make local, "
1198 "Shift + Click to create a library override"));
1199 }
1200
1201 if (disabled) {
1203 }
1204 /* When displaying the material selector for objects, the material slot may be assigned to
1205 * the object data instead of the object. In that case disable the button if the object
1206 * data is non-editable. Otherwise the button does nothing. */
1207 else if (Object *object;
1208 (GS(idfrom->name) == ID_OB) && (object = id_cast<Object *>(idfrom)) &&
1209 (template_ui.idcode == ID_MA) &&
1210 /* Trying to assign to linked/packed object data. */
1211 (object->data && ID_IS_LINKED(object->data)) &&
1212 /* Means material is assigned to the object data, not the object. */
1213 (object->matbits && (object->matbits[math::max(object->actcol - 1, 0)] == 0)))
1214 {
1215 button_disable(but,
1216 N_("Material is assigned to the object data, which is linked/packed "
1217 "and therefore not editable. Change to link this material slot to the "
1218 "object instead, or make the object data local."));
1219 }
1220 else {
1222 but, [pprop = pprop](bContext &C) mutable { template_ui_make_local(C, pprop); });
1223 }
1224 }
1225 else if (ID_IS_OVERRIDE_LIBRARY(id)) {
1226 but = uiDefIconBut(
1227 block,
1229 ICON_LIBRARY_DATA_OVERRIDE,
1230 0,
1231 0,
1232 UI_UNIT_X,
1233 UI_UNIT_Y,
1234 nullptr,
1235 0,
1236 0,
1237 TIP_("Library override of linked data-block, click to make fully local, "
1238 "Shift + Click to clear the library override and toggle if it can be edited"));
1239 button_func_set(but,
1240 [pprop = pprop](bContext &C) mutable { template_ui_override(C, pprop); });
1241 }
1242 }
1243
1244 if ((ID_REAL_USERS(id) > 1) && (hide_buttons == false)) {
1245 char numstr[32];
1246 short numstr_len;
1247
1248 numstr_len = SNPRINTF_UTF8_RLEN(numstr, "%d", ID_REAL_USERS(id));
1249
1250 but = uiDefBut(
1251 block,
1253 numstr,
1254 0,
1255 0,
1256 numstr_len * 0.2f * UI_UNIT_X + UI_UNIT_X,
1257 UI_UNIT_Y,
1258 nullptr,
1259 0,
1260 0,
1261 TIP_("Display number of users of this data (click to make a single-user copy)"));
1262 but->flag |= BUT_UNDO;
1263 button_func_set(but, [pprop = pprop](bContext &C) mutable { template_ui_alone(C, pprop); });
1264
1265 if (!BKE_id_copy_is_allowed(id) || (idfrom && !ID_IS_EDITABLE(idfrom)) || (!editable) ||
1266 /* object in editmode - don't change data */
1267 (idfrom && GS(idfrom->name) == ID_OB &&
1268 ((id_cast<Object *>(idfrom))->mode & OB_MODE_EDIT)))
1269 {
1271 }
1272 }
1273
1274 if (user_alert) {
1276 }
1277
1278 if (!ID_IS_LINKED(id)) {
1279 if (ID_IS_ASSET(id)) {
1280 uiDefIconButO(block,
1281 /* Using `_N` version allows us to get the 'active' state by default. */
1283 "ASSET_OT_clear_single",
1285 /* 'active' state of a toggle button uses icon + 1, so to get proper asset
1286 * icon we need to pass its value - 1 here. */
1287 ICON_ASSET_MANAGER - 1,
1288 0,
1289 0,
1290 UI_UNIT_X,
1291 UI_UNIT_Y,
1292 std::nullopt);
1293 }
1294 else if (!ELEM(GS(id->name), ID_GR, ID_SCE, ID_SCR, ID_OB, ID_WS) && (hide_buttons == false))
1295 {
1296 uiDefIconButR(block,
1298 ICON_FAKE_USER_OFF,
1299 0,
1300 0,
1301 UI_UNIT_X,
1302 UI_UNIT_Y,
1303 &idptr,
1304 "use_fake_user",
1305 -1,
1306 0,
1307 0,
1308 std::nullopt);
1309 }
1310 }
1311 }
1312
1313 if ((flag & UI_ID_ADD_NEW) && (hide_buttons == false)) {
1315 block, id, template_ui, type, newop, editable, flag & UI_ID_OPEN, false, UI_UNIT_X);
1316 }
1317
1318 /* Due to space limit in UI - skip the "open" icon for packed data, and allow to unpack.
1319 * Only for images, sound and fonts */
1320 if (id && BKE_packedfile_id_check(id)) {
1321 but = uiDefIconButO(block,
1323 "FILE_OT_unpack_item",
1325 ICON_PACKAGE,
1326 0,
1327 0,
1328 UI_UNIT_X,
1329 UI_UNIT_Y,
1330 TIP_("Packed File, click to unpack"));
1332
1333 RNA_string_set(but->opptr, "id_name", id->name + 2);
1334 RNA_int_set(but->opptr, "id_type", GS(id->name));
1335
1336 if (!ID_IS_EDITABLE(id)) {
1338 }
1339 }
1340 else if (flag & UI_ID_OPEN) {
1341 const char *button_text = (id) ? "" : IFACE_("Open");
1342 const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
1343
1344 int w = id ? UI_UNIT_X : (flag & UI_ID_ADD_NEW) ? UI_UNIT_X * 3 : UI_UNIT_X * 6;
1345 if (!id) {
1346 w = std::max(fontstyle_string_width(fstyle, button_text) + int(UI_UNIT_X * 1.5f), w);
1347 }
1348
1349 if (openop) {
1350 but = uiDefIconTextButO(block,
1352 openop,
1354 ICON_FILEBROWSER,
1355 (id) ? "" : IFACE_("Open"),
1356 0,
1357 0,
1358 w,
1359 UI_UNIT_Y,
1360 std::nullopt);
1361 }
1362 else {
1363 but = uiDefIconTextBut(block,
1365 ICON_FILEBROWSER,
1366 (id) ? "" : IFACE_("Open"),
1367 0,
1368 0,
1369 w,
1370 UI_UNIT_Y,
1371 nullptr,
1372 std::nullopt);
1373 }
1374
1375 if ((idfrom && !ID_IS_EDITABLE(idfrom)) || !editable) {
1377 }
1378 }
1379
1380 /* delete button */
1381 /* don't use RNA_property_is_unlink here */
1382 if (id && (flag & UI_ID_DELETE) && (hide_buttons == false)) {
1383 /* allow unlink if 'unlinkop' is passed, even when 'PROP_NEVER_UNLINK' is set */
1384 but = nullptr;
1385
1386 if (unlinkop) {
1387 but = uiDefIconButO(block,
1389 unlinkop,
1391 ICON_X,
1392 0,
1393 0,
1394 UI_UNIT_X,
1395 UI_UNIT_Y,
1396 std::nullopt);
1397 /* so we can access the template from operators, font unlinking needs this */
1398 }
1399 else {
1400 if ((RNA_property_flag(template_ui.prop) & PROP_NEVER_UNLINK) == 0) {
1401 but = uiDefIconBut(
1402 block,
1404 ICON_X,
1405 0,
1406 0,
1407 UI_UNIT_X,
1408 UI_UNIT_Y,
1409 nullptr,
1410 0,
1411 0,
1412 TIP_("Unlink data-block "
1413 "(Shift + Click to set users to zero, data will then not be saved)"));
1414 button_func_set(but,
1415 [pprop = pprop](bContext &C) mutable { template_ui_delete(C, pprop); });
1416
1417 if (RNA_property_flag(template_ui.prop) & PROP_NEVER_NULL) {
1419 }
1420 }
1421 }
1422
1423 if (but) {
1424 if ((idfrom && !ID_IS_EDITABLE(idfrom)) || !editable) {
1426 }
1427 }
1428 }
1429
1430 if (template_ui.idcode == ID_TE) {
1431 uiTemplateTextureShow(&layout, C, &template_ui.ptr, template_ui.prop);
1432 }
1433 block_align_end(block);
1434}
1435
1437{
1439
1440 if (but && but->type == ButtonType::Tab) {
1441 return static_cast<ID *>(but->custom_data);
1442 }
1443 return nullptr;
1444}
1445
1446static void template_ID_tabs(const bContext *C,
1447 Layout &layout,
1449 StructRNA *type,
1450 int flag,
1451 const char *newop,
1452 const char *menu)
1453{
1454 const ARegion *region = CTX_wm_region(C);
1455 const PointerRNA active_ptr = RNA_property_pointer_get(&template_id.ptr, template_id.prop);
1456 MenuType *mt = menu ? WM_menutype_find(menu, false) : nullptr;
1457
1458 /* When horizontal show the tabs as pills, rounded on all corners. */
1459 const bool horizontal =
1460 (region->regiontype == RGN_TYPE_HEADER &&
1462 const int but_align = horizontal ? 0 : button_align_opposite_to_area_align_get(region);
1463
1464 const int but_height = UI_UNIT_Y * 1.1;
1465
1466 Block *block = layout.block();
1467 const uiStyle *style = style_get_dpi();
1468
1469 for (ID *id : BKE_id_ordered_list(template_id.idlb)) {
1470 const int name_width = fontstyle_string_width(&style->widget, id->name + 2);
1471 const int but_width = name_width + UI_UNIT_X;
1472
1473 ButtonTab *tab = static_cast<ButtonTab *>(uiDefButR_prop(block,
1475 id->name + 2,
1476 0,
1477 0,
1478 but_width,
1479 but_height,
1480 &template_id.ptr,
1481 template_id.prop,
1482 0,
1483 0.0f,
1484 sizeof(id->name) - 2,
1485 ""));
1486 button_func_set(tab, [id = id, template_ui = template_id](bContext &C) mutable {
1487 template_ID_set_property_exec_fn(&C, &template_ui, id);
1488 });
1489 button_drag_set_id(tab, id);
1490 tab->custom_data = static_cast<void *>(id);
1491 tab->menu = mt;
1492
1493 button_drawflag_enable(tab, but_align);
1494 }
1495
1496 if (flag & UI_ID_ADD_NEW) {
1497 const bool editable = RNA_property_editable(&template_id.ptr, template_id.prop);
1498 Button *but;
1499
1500 if (active_ptr.has_type()) {
1501 type = active_ptr.type;
1502 }
1503
1504 but = template_id_def_new_but(block,
1505 static_cast<const ID *>(active_ptr.data),
1507 type,
1508 newop,
1509 editable,
1510 flag & UI_ID_OPEN,
1511 true,
1512 but_height);
1513 button_drawflag_enable(but, but_align);
1514 }
1515}
1516
1517static void template_id(Layout &layout,
1518 const bContext *C,
1519 PointerRNA *ptr,
1520 const StringRefNull propname,
1521 const char *newop,
1522 const char *openop,
1523 const char *unlinkop,
1524 /* Only respected by tabs (use_tabs). */
1525 const char *menu,
1526 const std::optional<StringRef> text,
1527 int flag,
1528 int prv_rows,
1529 int prv_cols,
1530 int filter,
1531 bool use_tabs,
1532 float scale,
1533 const bool live_icon,
1534 const bool hide_buttons)
1535{
1536 PropertyRNA *prop = RNA_struct_find_property(ptr, propname.c_str());
1537
1538 if (!prop || RNA_property_type(prop) != PROP_POINTER) {
1540 "pointer property not found: %s.%s", RNA_struct_identifier(ptr->type), propname.c_str());
1541 return;
1542 }
1543
1544 TemplateID template_ui = {};
1545 template_ui.ptr = *ptr;
1546 template_ui.prop = prop;
1547 template_ui.prv_rows = prv_rows;
1548 template_ui.prv_cols = prv_cols;
1549 template_ui.scale = scale;
1550
1551 if ((flag & UI_ID_PIN) == 0) {
1552 template_ui.filter = filter;
1553 }
1554 else {
1555 template_ui.filter = 0;
1556 }
1557
1558 if (newop) {
1559 flag |= UI_ID_ADD_NEW;
1560 }
1561 if (openop) {
1562 flag |= UI_ID_OPEN;
1563 }
1564
1565 StructRNA *type = RNA_property_pointer_type(ptr, prop);
1566 short idcode = RNA_type_to_ID_code(type);
1567 template_ui.idcode = idcode;
1568 template_ui.idlb = which_libbase(CTX_data_main(C), idcode);
1569
1570 /* create UI elements for this template
1571 * - template_ID makes a copy of the template data and assigns it to the relevant buttons
1572 */
1573 if (template_ui.idlb) {
1574 if (use_tabs) {
1575 Layout &row = layout.row(true);
1576 template_ID_tabs(C, row, template_ui, type, flag, newop, menu);
1577 }
1578 else {
1579 Layout &row = layout.row(true);
1581 C, row, template_ui, type, flag, newop, openop, unlinkop, text, live_icon, hide_buttons);
1582 }
1583 }
1584}
1585
1587 Layout &layout, bContext *C, PointerRNA *ptr, const StringRefNull propname, short idcode)
1588{
1589 PropertyRNA *prop = RNA_struct_find_property(ptr, propname.c_str());
1590
1591 if (!prop || RNA_property_type(prop) != PROP_INT) {
1593 "int property not found: %s.%s", RNA_struct_identifier(ptr->type), propname.c_str());
1594 return;
1595 }
1596 ListBaseT<ID> *lb = which_libbase(CTX_data_main(C), idcode);
1597 if (!lb) {
1598 RNA_warning("idcode is not an ID type: %d.", idcode);
1599 return;
1600 }
1601 StructRNA *type = ID_code_to_RNA_type(idcode);
1602 TemplateID template_ui = {};
1603 template_ui.ptr = *ptr;
1604 template_ui.prop = prop;
1605 template_ui.scale = 1.0f;
1606
1607 Block *block = layout.block();
1608
1609 template_ui.idcode = idcode;
1610 template_ui.idlb = lb;
1611
1612 Layout &row = layout.row(true);
1613 if (layout.use_property_split()) {
1615 split.label_column->label(RNA_property_ui_name(prop), 0);
1616 block_layout_set_current(block, split.property_row);
1617 }
1618 const uint32_t session_uid = RNA_property_int_get(ptr, prop);
1619 const ID *id = BKE_libblock_find_session_uid(CTX_data_main(C), template_ui.idcode, session_uid);
1620
1621 const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
1622 const int margin = UI_UNIT_X * 0.75f;
1623 const int estimated_width = id ? (fontstyle_string_width(fstyle, id->name + 2) + margin) : 0;
1624 const int width = std::clamp(
1626
1627 Button *but = uiDefBlockButN(block,
1629 MEM_new<TemplateID>(__func__, template_ui),
1630 id ? id->name + 2 : nullptr,
1631 0,
1632 0,
1633 width,
1634 UI_UNIT_Y,
1635 nullptr,
1638
1640}
1641
1642void template_id(Layout *layout,
1643 const bContext *C,
1644 PointerRNA *ptr,
1645 const StringRefNull propname,
1646 const char *newop,
1647 const char *openop,
1648 const char *unlinkop,
1649 int filter,
1650 const bool live_icon,
1651 const std::optional<StringRef> text)
1652{
1653 template_id(*layout,
1654 C,
1655 ptr,
1656 propname,
1657 newop,
1658 openop,
1659 unlinkop,
1660 nullptr,
1661 text,
1663 0,
1664 0,
1665 filter,
1666 false,
1667 1.0f,
1668 live_icon,
1669 false);
1670}
1671
1673 const bContext *C,
1674 ID *id,
1675 const char *newop,
1676 const char *unlinkop,
1677 const std::optional<StringRef> text)
1678{
1679 if (!id_can_have_animdata(id)) {
1680 RNA_warning("Cannot show Action selector for non-animatable ID: %s", id->name + 2);
1681 return;
1682 }
1683
1684 PropertyRNA *adt_action_prop = RNA_struct_type_find_property(RNA_AnimData, "action");
1685 BLI_assert(adt_action_prop);
1686 BLI_assert(RNA_property_type(adt_action_prop) == PROP_POINTER);
1687
1688 /* Construct a pointer with the animated ID as owner, even when `adt` may be `nullptr`.
1689 * This way it is possible to use this RNA pointer to get/set `adt->action`, as that RNA property
1690 * has a `getter` & `setter` that only need the owner ID and are null-safe regarding the `adt`
1691 * itself.
1692 * FIXME: This is a very dirty hack, would be good to find a way to not rely on typed-but-null
1693 * PointerRNA.
1694 */
1695 AnimData *adt = BKE_animdata_from_id(id);
1696 PointerRNA adt_ptr = PointerRNA{id, RNA_AnimData, adt, RNA_id_pointer_create(id)};
1697
1698 TemplateID template_ui = {};
1699 template_ui.ptr = adt_ptr;
1700 template_ui.prop = adt_action_prop;
1701 template_ui.prv_rows = 0;
1702 template_ui.prv_cols = 0;
1703 template_ui.scale = 1.0f;
1704 template_ui.filter = TEMPLATE_ID_FILTER_ALL;
1705
1706 int flag = UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE;
1707 if (newop) {
1708 flag |= UI_ID_ADD_NEW;
1709 }
1710
1711 template_ui.idcode = ID_AC;
1712 template_ui.idlb = which_libbase(CTX_data_main(C), ID_AC);
1713 BLI_assert(template_ui.idlb);
1714
1715 Layout &row = layout->row(true);
1716 template_ID(C, row, template_ui, RNA_Action, flag, newop, nullptr, unlinkop, text, false, false);
1717}
1718
1720 bContext *C,
1721 PointerRNA *ptr,
1722 const StringRefNull propname,
1723 const char *newop,
1724 const char *openop,
1725 const char *unlinkop,
1726 int filter,
1727 const char *text)
1728{
1729 template_id(*layout,
1730 C,
1731 ptr,
1732 propname,
1733 newop,
1734 openop,
1735 unlinkop,
1736 nullptr,
1737 text,
1739 0,
1740 0,
1741 filter,
1742 false,
1743 1.0f,
1744 false,
1745 false);
1746}
1747
1749 bContext *C,
1750 PointerRNA *ptr,
1751 const StringRefNull propname,
1752 const char *newop,
1753 const char *openop,
1754 const char *unlinkop,
1755 int rows,
1756 int cols,
1757 int filter,
1758 const bool hide_buttons)
1759{
1760 template_id(*layout,
1761 C,
1762 ptr,
1763 propname,
1764 newop,
1765 openop,
1766 unlinkop,
1767 nullptr,
1768 nullptr,
1770 rows,
1771 cols,
1772 filter,
1773 false,
1774 1.0f,
1775 false,
1776 hide_buttons);
1777}
1778
1780 bContext *C,
1781 PointerRNA *ptr,
1782 const StringRefNull propname,
1783 int rows,
1784 int cols,
1785 float scale,
1786 int filter)
1787{
1788 template_id(*layout,
1789 C,
1790 ptr,
1791 propname,
1792 nullptr,
1793 nullptr,
1794 nullptr,
1795 nullptr,
1796 nullptr,
1798 rows,
1799 cols,
1800 filter,
1801 false,
1802 scale < 0.5f ? 0.5f : scale,
1803 false,
1804 false);
1805}
1806
1808 bContext *C,
1809 PointerRNA *ptr,
1810 const StringRefNull propname,
1811 const char *newop,
1812 const char *menu,
1813 int filter)
1814{
1815 template_id(*layout,
1816 C,
1817 ptr,
1818 propname,
1819 newop,
1820 nullptr,
1821 nullptr,
1822 menu,
1823 nullptr,
1825 0,
1826 0,
1827 filter,
1828 true,
1829 1.0f,
1830 false,
1831 false);
1832}
1833
1835 PointerRNA *ptr,
1836 const StringRefNull propname,
1837 const StringRefNull proptypename,
1838 const std::optional<StringRef> text)
1839{
1840 /* get properties... */
1841 PropertyRNA *propID = RNA_struct_find_property(ptr, propname.c_str());
1842 PropertyRNA *propType = RNA_struct_find_property(ptr, proptypename.c_str());
1843
1844 if (!propID || RNA_property_type(propID) != PROP_POINTER) {
1846 "pointer property not found: %s.%s", RNA_struct_identifier(ptr->type), propname.c_str());
1847 return;
1848 }
1849 if (!propType || RNA_property_type(propType) != PROP_ENUM) {
1850 RNA_warning("pointer-type property not found: %s.%s",
1852 proptypename.c_str());
1853 return;
1854 }
1855
1856 /* Start drawing UI Elements using standard defines */
1857
1858 /* NOTE: split amount here needs to be synced with normal labels */
1859 Layout &split = layout->split(0.33f, false);
1860
1861 /* FIRST PART ................................................ */
1862 Layout *row = &split.row(false);
1863
1864 /* Label - either use the provided text, or will become "ID-Block:" */
1865 if (text) {
1866 if (!text->is_empty()) {
1867 row->label(*text, ICON_NONE);
1868 }
1869 }
1870 else {
1871 row->label(IFACE_("ID-Block:"), ICON_NONE);
1872 }
1873
1874 /* SECOND PART ................................................ */
1875 row = &split.row(true);
1876
1877 /* ID-Type Selector - just have a menu of icons */
1878
1879 /* HACK: special group just for the enum,
1880 * otherwise we get ugly layout with text included too... */
1881 Layout *sub = &row->row(true);
1883
1884 sub->prop(ptr, propType, 0, 0, ITEM_R_ICON_ONLY, "", ICON_NONE);
1885
1886 /* ID-Block Selector - just use pointer widget... */
1887
1888 /* HACK: special group to counteract the effects of the previous enum,
1889 * which now pushes everything too far right. */
1890 sub = &row->row(true);
1892
1893 sub->prop(ptr, propID, 0, 0, UI_ITEM_NONE, "", ICON_NONE);
1894}
1895
1896} // namespace blender::ui
#define FOREACH_SCENE_OBJECT_END
#define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance)
#define BKE_idtype_idcode_is_localizable
#define MAX_ID_FULL_NAME_UI
#define SNPRINTF_UTF8_RLEN(dst, format,...)
#define BLT_I18NCONTEXT_ID_FREESTYLELINESTYLE
#define BLT_I18NCONTEXT_ID_WORLD
#define BLT_I18NCONTEXT_ID_ACTION
#define BLT_I18NCONTEXT_ID_TEXT
#define BLT_I18NCONTEXT_ID_VOLUME
#define CTX_N_(context, msgid)
#define BLT_I18NCONTEXT_ID_BRUSH
#define BLT_I18NCONTEXT_ID_NODETREE
#define BLT_I18NCONTEXT_ID_CURVES
#define BLT_I18NCONTEXT_ID_IMAGE
#define BLT_I18NCONTEXT_ID_SPEAKER
#define BLT_I18NCONTEXT_ID_WORKSPACE
#define BLT_I18NCONTEXT_ID_CURVE_LEGACY
#define TIP_(msgid)
#define BLT_I18NCONTEXT_ID_LATTICE
#define BLT_I18NCONTEXT_ID_GPENCIL
#define BLT_I18NCONTEXT_ID_LIGHT
#define BLT_I18NCONTEXT_ID_POINTCLOUD
#define BLT_I18NCONTEXT_ID_METABALL
#define BLT_I18NCONTEXT_ID_SOUND
#define BLT_I18NCONTEXT_ID_PARTICLESETTINGS
#define BLT_I18NCONTEXT_ID_LIGHTPROBE
#define CTX_IFACE_(context, msgid)
#define BLT_I18NCONTEXT_DEFAULT
#define BLT_I18NCONTEXT_ID_SCREEN
#define BLT_I18NCONTEXT_ID_OBJECT
#define BLT_I18NCONTEXT_OPERATOR_DEFAULT
#define IFACE_(msgid)
#define BLT_I18NCONTEXT_ID_PALETTE
#define BLT_I18NCONTEXT_ID_ARMATURE
#define BLT_I18N_MSGID_MULTI_CTXT(msgid,...)
#define BLT_I18NCONTEXT_ID_PAINTCURVE
#define BLT_I18NCONTEXT_ID_SCENE
#define BLT_I18NCONTEXT_ID_MATERIAL
#define BLT_I18NCONTEXT_ID_MESH
#define BLT_I18NCONTEXT_ID_CAMERA
#define BLT_I18NCONTEXT_ID_TEXTURE
#define BLT_I18NCONTEXT_ID_MASK
#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_OVERRIDABLE_LIBRARY(_id)
Definition DNA_ID.h:721
#define ID_IS_OVERRIDABLE_LIBRARY_HIERARCHY(_id)
Definition DNA_ID.h:715
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define ID_IS_ASSET(_id)
Definition DNA_ID.h:743
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
#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.
#define RGN_ALIGN_ENUM_FROM_MASK(align)
#define RNA_warning(format,...)
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_SEP_CHAR
#define UI_FSTYLE_WIDGET
#define UI_UNIT_X
#define UI_ITEM_NONE
#define UI_MAX_NAME_STR
#define NC_WINDOW
Definition WM_types.hh:388
#define NC_ID
Definition WM_types.hh:408
#define NC_WM
Definition WM_types.hh:387
#define ND_DATACHANGED
Definition WM_types.hh:430
#define ND_LIB_OVERRIDE_CHANGED
Definition WM_types.hh:435
#define NA_ADDED
Definition WM_types.hh:636
#define NA_REMOVED
Definition WM_types.hh:637
#define ND_SPACE_VIEW3D
Definition WM_types.hh:571
#define NC_SPACE
Definition WM_types.hh:405
#define ND_SPACE_OUTLINER
Definition WM_types.hh:570
#define UNUSED_VARS(...)
#define ELEM(...)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
constexpr const char * c_str() const
void add(const StringRef str, T *user_data, const int weight=0)
Vector< T * > query(const StringRef query) const
#define str(s)
float3x3 scale(float3x3 mat, float2 scale)
#define template_id_context(type)
#define TEMPLATE_SEARCH_TEXTBUT_MIN_WIDTH
void object_single_user_make(Main *bmain, Scene *scene, Object *ob)
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
Definition abc_util.cc:68
T max(const T &a, const T &b)
void template_greasepencil_color_preview(Layout *layout, bContext *C, PointerRNA *ptr, StringRefNull propname, int rows, int cols, float scale, int filter)
Button * uiDefIconTextBut(Block *block, ButtonTypeWithPointerType but_and_ptr_type, int icon, StringRef str, int x, int y, short width, short height, void *poin, std::optional< StringRef > tip)
Button * uiDefButR(Block *block, ButtonType type, std::optional< StringRef > str, int x, int y, short width, short height, PointerRNA *ptr, StringRefNull propname, int index, float min, float max, std::optional< StringRef > tip)
Button * uiDefIconButR(Block *block, ButtonType type, int icon, int x, int y, short width, short height, PointerRNA *ptr, StringRefNull propname, int index, float min, float max, std::optional< StringRef > tip)
void template_action(Layout *layout, const bContext *C, ID *id, const char *newop, const char *unlinkop, std::optional< StringRef > text)
static void template_ui_alone(bContext &C, PropertyPointerRNA &pprop)
int template_search_textbut_width(PointerRNA *ptr, PropertyRNA *name_prop)
void template_ID_session_uid(Layout &layout, bContext *C, PointerRNA *ptr, StringRefNull propname, short idcode)
static ARegion * template_ID_search_menu_item_tooltip(bContext *C, ARegion *region, const rcti *item_rect, void *, void *active)
ID * context_active_but_get_tab_ID(bContext *C)
void button_func_set(Button *but, std::function< void(bContext &)> func)
static void template_ui_delete(bContext &C, PropertyPointerRNA &pprop)
static Button * template_id_def_new_but(Block *block, const ID *id, const TemplateID &template_ui, StructRNA *type, const char *const newop, const bool editable, const bool id_open, const bool use_tab_but, int but_height)
static void template_ID_tabs(const bContext *C, Layout &layout, TemplateID &template_id, StructRNA *type, int flag, const char *newop, const char *menu)
int fontstyle_string_width(const uiFontStyle *fs, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
void text_button_func_rename_full_set(Button *but, std::function< void(StringRefNull new_name)> rename_full_func)
void template_id_preview(Layout *layout, bContext *C, PointerRNA *ptr, StringRefNull propname, const char *newop, const char *openop, const char *unlinkop, int rows, int cols, int filter=TEMPLATE_ID_FILTER_ALL, bool hide_buttons=false)
void template_add_button_search_menu(const bContext *C, Layout &layout, Block *block, PointerRNA *ptr, PropertyRNA *prop, BlockCreateFunc block_func, void *block_argN, const std::optional< StringRef > tip, const bool use_previews, const bool editable, const bool live_icon, ButtonArgNFree func_argN_free_fn, ButtonArgNCopy func_argN_copy_fn)
static void template_ID_set_int_property_session_uid_exec_fn(bContext *, void *arg_template, void *item)
PointerRNA * button_operator_ptr_ensure(Button *but)
void block_align_begin(Block *block)
static StringRef template_id_browse_tip(const StructRNA *type)
static Block * id_search_menu_session_uid(bContext *C, ARegion *region, void *arg_litem)
Block * template_common_search_menu(const bContext *C, ARegion *region, ButtonSearchUpdateFn search_update_fn, void *search_arg, ButtonHandleFunc search_exec_fn, void *active_item, ButtonSearchTooltipFn item_tooltip_fn, const int preview_rows, const int preview_cols, float scale)
int id_icon_get(const bContext *C, ID *id, const bool big)
Button * uiDefIconButO(Block *block, ButtonType type, StringRefNull opname, wm::OpCallContext opcontext, int icon, int x, int y, short width, short height, std::optional< StringRef > tip)
static void template_ui_make_local(bContext &C, PropertyPointerRNA &pprop)
const uiStyle * style_get_dpi()
void template_id(Layout *layout, const bContext *C, PointerRNA *ptr, StringRefNull propname, const char *newop, const char *openop, const char *unlinkop, int filter=TEMPLATE_ID_FILTER_ALL, bool live_icon=false, std::optional< StringRef > text=std::nullopt)
static void template_id_workspace_pin_extra_icon(const TemplateID &template_ui, Button *but)
void button_drawflag_enable(Button *but, int flag)
void template_id_browse(Layout *layout, bContext *C, PointerRNA *ptr, StringRefNull propname, const char *newop, const char *openop, const char *unlinkop, int filter=TEMPLATE_ID_FILTER_ALL, const char *text=nullptr)
ID * template_id_liboverride_hierarchy_make(bContext *C, Main *bmain, ID *owner_id, ID *id, const char **r_undo_push_label)
static void id_search_cb(const bContext *C, void *arg_template, const char *str, SearchItems *items, const bool)
void button_disable(Button *but, const char *disabled_hint)
void button_flag_enable(Button *but, int64_t flag)
Button * uiDefBut(Block *block, ButtonTypeWithPointerType but_and_ptr_type, StringRef str, int x, int y, short width, short height, void *poin, float min, float max, std::optional< StringRef > tip)
void context_active_but_prop_get_templateID(const bContext *C, PointerRNA *r_ptr, PropertyRNA **r_prop)
Button * uiDefButR_prop(Block *block, ButtonType type, std::optional< StringRef > str, int x, int y, short width, short height, PointerRNA *ptr, PropertyRNA *prop, int index, float min, float max, std::optional< StringRef > tip)
static bool id_search_allows_id(TemplateID *template_ui, const int flag, ID *id, const char *query)
void * but_func_argN_copy(const void *argN)
static void id_search_cb_tagged(const bContext *C, void *arg_template, const char *str, SearchItems *items)
void block_align_end(Block *block)
Button * uiDefIconTextButO(Block *block, ButtonType type, StringRefNull, wm::OpCallContext opcontext, int icon, StringRef str, int x, int y, short width, short height, std::optional< StringRef > tip)
bool search_item_add(SearchItems *items, StringRef name, void *poin, int iconid, int64_t but_flag, uint8_t name_prefix_offset)
static Block * id_search_menu(bContext *C, ARegion *region, void *arg_litem)
void button_flag_disable(Button *but, int64_t flag)
void template_any_id(Layout *layout, PointerRNA *ptr, StringRefNull propname, StringRefNull proptypename, std::optional< StringRef > text)
void but_func_argN_free(void *argN)
void def_but_icon(Button *but, const int icon, const int64_t flag)
Layout * uiItemL_respect_property_split(Layout *layout, StringRef text, int icon)
static void template_id_liboverride_hierarchy_collections_tag_recursive(Collection *root_collection, ID *target_id, const bool do_parents)
Button * uiDefIconBut(Block *block, ButtonTypeWithPointerType but_and_ptr_type, int icon, int x, int y, short width, short height, void *poin, float min, float max, std::optional< StringRef > tip)
PointerRNA * button_extra_operator_icon_add(Button *but, StringRefNull opname, wm::OpCallContext opcontext, int icon)
Button * context_active_but_get(const bContext *C)
static void template_ui_override(bContext &C, PropertyPointerRNA &pprop)
ARegion * tooltip_create_from_search_item_generic(bContext *C, const ARegion *searchbox_region, const rcti *item_rect, ID *id)
Button * uiDefBlockButN(Block *block, BlockCreateFunc func, void *argN, StringRef str, int x, int y, short width, short height, std::optional< StringRef > tip, ButtonArgNFree func_argN_free_fn=MEM_delete_void, ButtonArgNCopy func_argN_copy_fn=MEM_dupalloc_void)
int icon_from_library(const ID *id)
static void template_id_liboverride_hierarchy_collection_root_find_recursive(Collection *collection, const int parent_level, Collection **r_collection_parent_best, int *r_parent_level_best)
static void template_ID(const bContext *C, Layout &layout, TemplateID &template_ui, StructRNA *type, int flag, const char *newop, const char *openop, const char *unlinkop, const std::optional< StringRef > text, const bool live_icon, const bool hide_buttons)
static void template_ID_set_property_exec_fn(bContext *C, void *arg_template, void *item)
void block_layout_set_current(Block *block, Layout *layout)
PropertySplitWrapper uiItemPropertySplitWrapperCreate(Layout *parent_layout)
void template_id_tabs(Layout *layout, bContext *C, PointerRNA *ptr, StringRefNull propname, const char *newop, const char *menu, int filter=TEMPLATE_ID_FILTER_ALL)
static bool id_search_add(const bContext *C, TemplateID *template_ui, SearchItems *items, ID *id)
int template_search_textbut_height()
int button_align_opposite_to_area_align_get(const ARegion *region)
static void id_search_cb_objects_from_scene(const bContext *C, void *arg_template, const char *str, SearchItems *items, const bool)
void button_drag_set_id(Button *but, ID *id)
void BKE_main_id_flag_listbase(ListBaseT< ID > *lb, int flag, bool value)
Definition lib_id.cc:1323
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void WM_global_reportf(eReportType type, const char *format,...)
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
__int64 int64_t
Definition BKE_text.h:90
@ RPT_WARNING
Definition BKE_report.hh:40
const PointerRNA * CTX_store_ptr_lookup(const bContextStore *store, StringRef name, const StructRNA *type=nullptr)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
bool BKE_lib_override_library_create(Main *bmain, Scene *scene, ViewLayer *view_layer, Library *owner_library, ID *id_root_reference, ID *id_hierarchy_root_reference, ID *id_instance_hint, ID **r_id_root_override, const bool do_fully_editable)
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_pointer_set(PointerRNA *ptr, PropertyRNA *prop, PointerRNA ptr_value, ReportList *reports)
PointerRNA RNA_id_pointer_create(ID *id)
ID * BKE_libblock_find_session_uid(Main *bmain, short type, uint32_t session_uid)
Definition lib_id.cc:1826
const char * RNA_property_identifier(const PropertyRNA *prop)
bool BKE_packedfile_id_check(const ID *id)
StructRNA * ID_code_to_RNA_type(short idcode)
bool BKE_collection_child_add(Main *bmain, Collection *parent, Collection *child)
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
std::string RNA_path_name_to_infix(const StringRefNull string)
Definition rna_path.cc:1419
MenuType * WM_menutype_find(const StringRef idname, bool quiet)
bool BKE_scene_collections_object_remove(Main *bmain, Scene *scene, Object *ob, bool free_us)
short RNA_type_to_ID_code(const StructRNA *type)
wmWindow * CTX_wm_window(const bContext *C)
bool id_can_have_animdata(const ID *id)
Definition anim_data.cc:78
void id_us_clear_real(ID *id)
Definition lib_id.cc:406
@ LIBOVERRIDE_FLAG_SYSTEM_DEFINED
Definition DNA_ID.h:308
ViewLayer * CTX_data_view_layer(const bContext *C)
void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
PropertyType RNA_property_type(PropertyRNA *prop)
AnimData * BKE_animdata_from_id(const ID *id)
Definition anim_data.cc:93
unsigned int uint32_t
Definition BKE_text.h:81
bool BKE_scene_has_object(const Main &bmain, Scene *scene, Object *ob)
void BKE_id_full_name_ui_prefix_get(char name[MAX_ID_FULL_NAME_UI], const ID *id, bool add_lib_hint, char separator_char, int *r_prefix_len)
Definition lib_id.cc:2708
StructRNA * RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop)
@ PROP_POINTER
Definition RNA_types.hh:215
void ED_undo_push(bContext *C, const char *str, UndoEncodeHints hints=UndoEncodeHints(0))
Definition ed_undo.cc:103
void BKE_main_ensure_invariants(Main &bmain, std::optional< Span< ID * > > modified_ids=std::nullopt)
int RNA_property_flag(PropertyRNA *prop)
void BKE_lib_override_library_make_local(Main *bmain, ID *id)
void BKE_id_newptr_and_tag_clear(ID *id)
Definition lib_id.cc:487
WorkSpace * WM_window_get_active_workspace(const wmWindow *win)
bool RNA_property_is_idprop(const PropertyRNA *prop)
bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
bool BKE_collection_has_collection(const Collection *parent, const Collection *collection)
void BKE_lib_override_library_id_reset(Main *bmain, ID *id_root, bool do_reset_system_override)
Vector< ID * > BKE_id_ordered_list(const ListBaseT< ID > *lb)
Definition lib_id.cc:2835
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
int RNA_struct_ui_icon(const StructRNA *type)
bool id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop)
Definition lib_id.cc:1142
bool RNA_struct_is_ID(const StructRNA *type)
const char * RNA_struct_identifier(const StructRNA *type)
void uiTemplateTextureShow(ui::Layout *layout, const bContext *C, PointerRNA *ptr, PropertyRNA *prop)
const char * RNA_struct_ui_description(const StructRNA *type)
bool ED_id_rename(Main &bmain, ID &id, StringRefNull name)
Main * CTX_data_main(const bContext *C)
@ USER_HIDE_DOT_DATABLOCK
ID_Type GS(const char *name)
Definition DNA_ID.h:410
@ PROP_NEVER_UNLINK
Definition RNA_types.hh:454
@ PROP_ID_SELF_CHECK
Definition RNA_types.hh:440
@ PROP_NEVER_NULL
Definition RNA_types.hh:447
@ ID_TAG_INDIRECT
Definition DNA_ID.h:851
@ ID_TAG_DOIT
Definition DNA_ID.h:1029
bool RNA_property_editable(const PointerRNA *ptr, PropertyRNA *prop)
std::optional< StringRefNull > CTX_store_string_lookup(const bContextStore *store, StringRef name)
bool BKE_id_copy_is_allowed(const ID *id)
Definition lib_id.cc:740
void DEG_relations_tag_update(Main *bmain)
Scene * CTX_data_scene(const bContext *C)
@ LIB_ID_MAKELOCAL_ASSET_DATA_CLEAR
bool BKE_collection_has_object_recursive(Collection *collection, Object *ob)
bool BKE_lib_id_make_local(Main *bmain, ID *id, int flags)
Definition lib_id.cc:672
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
Object * CTX_data_active_object(const bContext *C)
void id_fake_user_clear(ID *id)
Definition lib_id.cc:479
ARegion * CTX_wm_region(const bContext *C)
bool RNA_property_pointer_poll(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *value)
const char * BKE_idtype_idcode_to_translation_context(short idcode)
Definition idtype.cc:275
const char * RNA_property_ui_name(const PropertyRNA *prop, const PointerRNA *ptr)
IDOverrideLibrary * BKE_lib_override_library_get(Main *bmain, ID *id, ID *owner_id_hint, ID **r_owner_id)
ListBaseT< ID > * which_libbase(Main *bmain, short type)
Definition main.cc:1073
Collection * CTX_data_collection(const bContext *C)
eRegion_Alignment alignment
eRegion_Type regiontype
bke::CollectionRuntime * runtime
ListBaseT< CollectionChild > children
eID_OverrideLib_Flag flag
Definition DNA_ID.h:356
struct ID * hierarchy_root
Definition DNA_ID.h:352
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
IDOverrideLibrary * override_library
Definition DNA_ID.h:495
ListBaseT< Collection > collections
Definition BKE_main.hh:406
struct Collection * instance_collection
bool has_type() const
Definition RNA_types.hh:180
StructRNA * type
Definition RNA_types.hh:63
struct Collection * master_collection
ListBaseT< CollectionParent > parents
const bContextStore * context
void alignment_set(LayoutAlign alignment)
bool use_property_split() const
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 & split(float percentage, bool align)
void context_string_set(StringRef name, StringRef value)
Layout & row(bool align)
void context_ptr_set(StringRef name, const PointerRNA *ptr)
uiFontStyle widget
#define N_(msgid)