Fix T48416: Impossible to append from another file without localizing also all indirectly linked data.

Previous to 2.77, this used to be default behavior, was changed in rB591f4549c958b.

However, in most append cases, you do want a full localization of your data, so this new behavior
is kept by default, but there is now an option in append operator to only localize the 'first level'
of data (i.e. datablocks from linked library itself, and not those from other 'sub-libraries').
This commit is contained in:
Bastien Montagne 2016-05-13 12:54:09 +02:00
parent 6276726bc4
commit 5e0ec49570
Notes: blender-bot 2023-02-14 07:53:51 +01:00
Referenced by issue #48416, Impossible to copy a linked object from a file to another one mantaining the linked library
3 changed files with 38 additions and 9 deletions

View File

@ -119,7 +119,8 @@ void BKE_main_lib_objects_recalc_all(struct Main *bmain);
/* (MAX_ID_NAME - 2) + 3 */
void BKE_id_ui_prefix(char name[66 + 1], const struct ID *id);
void BKE_library_make_local(struct Main *bmain, struct Library *lib, bool untagged_only, bool set_fake);
void BKE_library_make_local(
struct Main *bmain, const struct Library *lib, const bool untagged_only, const bool set_fake);
typedef void (*BKE_library_free_window_manager_cb)(struct bContext *, struct wmWindowManager *);
typedef void (*BKE_library_free_notifier_reference_cb)(const void *);

View File

@ -1830,9 +1830,14 @@ static void lib_indirect_test_id(ID *id, Library *lib)
#undef LIBTAG
}
/* if lib!=NULL, only all from lib local
* bmain is almost certainly G.main */
void BKE_library_make_local(Main *bmain, Library *lib, bool untagged_only, bool set_fake)
/** Make linked datablocks local.
*
* \param bmain Almost certainly G.main.
* \param lib If not NULL, only make local datablocks from this library.
* \param untagged_only If true, only make local datablocks not tagged with LIB_TAG_PRE_EXISTING.
* \param set_fake If true, set fake user on all localized datablocks (except group and objects ones).
*/
void BKE_library_make_local(Main *bmain, const Library *lib, const bool untagged_only, const bool set_fake)
{
ListBase *lbarray[MAX_LIBARRAY];
ID *id, *idn;

View File

@ -405,18 +405,38 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
/* BKE_main_unlock(bmain); */
wm_link_append_data_free(lapp_data);
/* mark all library linked objects to be updated */
BKE_main_lib_objects_recalc_all(bmain);
IMB_colormanagement_check_file_config(bmain);
/* append, rather than linking */
if ((flag & FILE_LINK) == 0) {
bool set_fake = RNA_boolean_get(op->ptr, "set_fake");
BKE_library_make_local(bmain, NULL, true, set_fake);
const bool set_fake = RNA_boolean_get(op->ptr, "set_fake");
const bool do_recursive = RNA_boolean_get(op->ptr, "do_recursive");
if (do_recursive) {
BKE_library_make_local(bmain, NULL, true, set_fake);
}
else {
LinkNode *itemlink;
GSet *done_libraries = BLI_gset_new_ex(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp,
__func__, lapp_data->num_libraries);
for (itemlink = lapp_data->items.list; itemlink; itemlink = itemlink->next) {
ID *new_id = ((WMLinkAppendDataItem *)(itemlink->link))->new_id;
if (new_id && !BLI_gset_haskey(done_libraries, new_id->lib)) {
BKE_library_make_local(bmain, new_id->lib, true, set_fake);
BLI_gset_insert(done_libraries, new_id->lib);
}
}
BLI_gset_free(done_libraries, NULL);
}
}
wm_link_append_data_free(lapp_data);
/* important we unset, otherwise these object wont
* link into other scenes from this blend file */
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
@ -493,5 +513,8 @@ void WM_OT_append(wmOperatorType *ot)
FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA);
wm_link_append_properties_common(ot, false);
RNA_def_boolean(ot->srna, "set_fake", false, "Fake User", "Set Fake User for appended items (except Objects and Groups)");
RNA_def_boolean(ot->srna, "set_fake", false, "Fake User",
"Set Fake User for appended items (except Objects and Groups)");
RNA_def_boolean(ot->srna, "do_recursive", true, "Localize All",
"Localize all appended data, including those indirectly linked from other libraries");
}