Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_files_link.c
| Show All 17 Lines | |||||
| */ | */ | ||||
| /** \file | /** \file | ||||
| * \ingroup wm | * \ingroup wm | ||||
| * | * | ||||
| * Functions for dealing with append/link operators and helpers. | * Functions for dealing with append/link operators and helpers. | ||||
| */ | */ | ||||
| #include <CLG_log.h> | |||||
| #include <assert.h> | #include <assert.h> | ||||
| #include <ctype.h> | #include <ctype.h> | ||||
| #include <errno.h> | #include <errno.h> | ||||
| #include <float.h> | #include <float.h> | ||||
| #include <stddef.h> | #include <stddef.h> | ||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| ▲ Show 20 Lines • Show All 266 Lines • ▼ Show 20 Lines | static bool wm_link_append_item_poll(ReportList *reports, | ||||
| const char *path, | const char *path, | ||||
| const char *group, | const char *group, | ||||
| const char *name, | const char *name, | ||||
| const bool do_append) | const bool do_append) | ||||
| { | { | ||||
| short idcode; | short idcode; | ||||
| if (!group || !name) { | if (!group || !name) { | ||||
| printf("skipping %s\n", path); | /* TODO (grzelins) convert to report, but write why can not be linked. Right now it fails | ||||
| * silently, not great UX */ | |||||
| CLOG_INFO( | |||||
| WM_LOG_OPERATORS, "Can not be %s, skipping %s", do_append ? "appended" : "linked", path); | |||||
| return false; | return false; | ||||
| } | } | ||||
| idcode = BKE_idtype_idcode_from_name(group); | idcode = BKE_idtype_idcode_from_name(group); | ||||
| /* XXX For now, we do a nasty exception for workspace, forbid linking them. | /* XXX For now, we do a nasty exception for workspace, forbid linking them. | ||||
| * Not nice, ultimately should be solved! */ | * Not nice, ultimately should be solved! */ | ||||
| if (!BKE_idtype_idcode_is_linkable(idcode) && (do_append || idcode != ID_WS)) { | if (!BKE_idtype_idcode_is_linkable(idcode) && (do_append || idcode != ID_WS)) { | ||||
| ▲ Show 20 Lines • Show All 389 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| BLI_assert(old_id); | BLI_assert(old_id); | ||||
| if (do_reload) { | if (do_reload) { | ||||
| /* Since we asked for placeholders in case of missing IDs, | /* Since we asked for placeholders in case of missing IDs, | ||||
| * we expect to always get a valid one. */ | * we expect to always get a valid one. */ | ||||
| BLI_assert(new_id); | BLI_assert(new_id); | ||||
| } | } | ||||
| if (new_id) { | if (new_id) { | ||||
| #ifdef PRINT_DEBUG | CLOG_VERBOSE(WM_LOG_OPERATORS, | ||||
| printf("before remap of %s, old_id users: %d, new_id users: %d\n", | 3, | ||||
| "before remap of %s, old_id users: %d, new_id users: %d", | |||||
| old_id->name, | old_id->name, | ||||
| old_id->us, | old_id->us, | ||||
| new_id->us); | new_id->us); | ||||
| #endif | |||||
| BKE_libblock_remap_locked(bmain, old_id, new_id, remap_flags); | BKE_libblock_remap_locked(bmain, old_id, new_id, remap_flags); | ||||
| if (old_id->flag & LIB_FAKEUSER) { | if (old_id->flag & LIB_FAKEUSER) { | ||||
| id_fake_user_clear(old_id); | id_fake_user_clear(old_id); | ||||
| id_fake_user_set(new_id); | id_fake_user_set(new_id); | ||||
| } | } | ||||
| #ifdef PRINT_DEBUG | CLOG_VERBOSE(WM_LOG_OPERATORS, | ||||
| printf("after remap of %s, old_id users: %d, new_id users: %d\n", | 4, | ||||
| "after remap of %s, old_id users: %d, new_id users: %d", | |||||
| old_id->name, | old_id->name, | ||||
| old_id->us, | old_id->us, | ||||
| new_id->us); | new_id->us); | ||||
| #endif | |||||
| /* In some cases, new_id might become direct link, remove parent of library in this case. */ | /* In some cases, new_id might become direct link, remove parent of library in this case. */ | ||||
| if (new_id->lib->parent && (new_id->tag & LIB_TAG_INDIRECT) == 0) { | if (new_id->lib->parent && (new_id->tag & LIB_TAG_INDIRECT) == 0) { | ||||
| if (do_reload) { | if (do_reload) { | ||||
| BLI_assert(0); /* Should not happen in 'pure' reload case... */ | BLI_assert(0); /* Should not happen in 'pure' reload case... */ | ||||
| } | } | ||||
| new_id->lib->parent = NULL; | new_id->lib->parent = NULL; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | for (; id; id = id->next) { | ||||
| Key *old_key = BKE_key_from_id(id); | Key *old_key = BKE_key_from_id(id); | ||||
| if (old_key != NULL) { | if (old_key != NULL) { | ||||
| BLI_remlink(which_libbase(bmain, GS(old_key->id.name)), &old_key->id); | BLI_remlink(which_libbase(bmain, GS(old_key->id.name)), &old_key->id); | ||||
| } | } | ||||
| item = wm_link_append_data_item_add(lapp_data, id->name + 2, idcode, id); | item = wm_link_append_data_item_add(lapp_data, id->name + 2, idcode, id); | ||||
| BLI_bitmap_set_all(item->libraries, true, lapp_data->num_libraries); | BLI_bitmap_set_all(item->libraries, true, lapp_data->num_libraries); | ||||
| #ifdef PRINT_DEBUG | CLOG_VERBOSE(WM_LOG_OPERATORS, 5, "\tdatablock to seek for: %s", id->name); | ||||
| printf("\tdatablock to seek for: %s\n", id->name); | |||||
| #endif | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (lapp_data->num_items == 0) { | if (lapp_data->num_items == 0) { | ||||
| /* Early out in case there is nothing to do. */ | /* Early out in case there is nothing to do. */ | ||||
| return; | return; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 201 Lines • ▼ Show 20 Lines | if (!BLI_exists(path)) { | ||||
| RPT_ERROR_INVALID_INPUT, | RPT_ERROR_INVALID_INPUT, | ||||
| "Trying to reload or relocate library '%s' to invalid path '%s'", | "Trying to reload or relocate library '%s' to invalid path '%s'", | ||||
| lib->id.name, | lib->id.name, | ||||
| path); | path); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| if (BLI_path_cmp(lib->filepath_abs, path) == 0) { | if (BLI_path_cmp(lib->filepath_abs, path) == 0) { | ||||
| #ifdef PRINT_DEBUG | CLOG_VERBOSE(WM_LOG_OPERATORS, | ||||
| printf("We are supposed to reload '%s' lib (%d)...\n", lib->filepath, lib->id.us); | 2, | ||||
| #endif | "We are supposed to reload '%s' lib (%d)...", | ||||
| lib->filepath, | |||||
| lib->id.us); | |||||
| do_reload = true; | do_reload = true; | ||||
| lapp_data = wm_link_append_data_new(flag); | lapp_data = wm_link_append_data_new(flag); | ||||
| wm_link_append_data_library_add(lapp_data, path); | wm_link_append_data_library_add(lapp_data, path); | ||||
| } | } | ||||
| else { | else { | ||||
| int totfiles = 0; | int totfiles = 0; | ||||
| #ifdef PRINT_DEBUG | CLOG_INFO(WM_LOG_OPERATORS, | ||||
| printf("We are supposed to relocate '%s' lib to new '%s' one...\n", lib->filepath, libname); | "We are supposed to relocate '%s' lib to new '%s' one...\n", | ||||
| #endif | lib->filepath, | ||||
| libname); | |||||
| /* Check if something is indicated for relocate. */ | /* Check if something is indicated for relocate. */ | ||||
| prop = RNA_struct_find_property(op->ptr, "files"); | prop = RNA_struct_find_property(op->ptr, "files"); | ||||
| if (prop) { | if (prop) { | ||||
| totfiles = RNA_property_collection_length(op->ptr, prop); | totfiles = RNA_property_collection_length(op->ptr, prop); | ||||
| if (totfiles == 0) { | if (totfiles == 0) { | ||||
| if (!libname[0]) { | if (!libname[0]) { | ||||
| BKE_report(op->reports, RPT_ERROR, "Nothing indicated"); | BKE_report(op->reports, RPT_ERROR, "Nothing indicated"); | ||||
| Show All 9 Lines | else { | ||||
| RNA_string_get(&itemptr, "name", relname); | RNA_string_get(&itemptr, "name", relname); | ||||
| BLI_join_dirfile(path, sizeof(path), root, relname); | BLI_join_dirfile(path, sizeof(path), root, relname); | ||||
| if (BLI_path_cmp(path, lib->filepath_abs) == 0 || !BLO_has_bfile_extension(relname)) { | if (BLI_path_cmp(path, lib->filepath_abs) == 0 || !BLO_has_bfile_extension(relname)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| #ifdef PRINT_DEBUG | CLOG_VERBOSE( | ||||
| printf("\t candidate new lib to reload datablocks from: %s\n", path); | WM_LOG_OPERATORS, 3, "\t candidate new lib to reload datablocks from: %s", path); | ||||
| #endif | |||||
| wm_link_append_data_library_add(lapp_data, path); | wm_link_append_data_library_add(lapp_data, path); | ||||
| } | } | ||||
| RNA_END; | RNA_END; | ||||
| } | } | ||||
| else { | else { | ||||
| #ifdef PRINT_DEBUG | CLOG_VERBOSE( | ||||
| printf("\t candidate new lib to reload datablocks from: %s\n", path); | WM_LOG_OPERATORS, 3, "\t candidate new lib to reload datablocks from: %s", path); | ||||
| #endif | |||||
| wm_link_append_data_library_add(lapp_data, path); | wm_link_append_data_library_add(lapp_data, path); | ||||
| } | } | ||||
| } | } | ||||
| if (do_reload) { | if (do_reload) { | ||||
| lapp_data->flag |= BLO_LIBLINK_USE_PLACEHOLDERS | BLO_LIBLINK_FORCE_INDIRECT; | lapp_data->flag |= BLO_LIBLINK_USE_PLACEHOLDERS | BLO_LIBLINK_FORCE_INDIRECT; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines | |||||