Fix T88499: Copy data path operator does not consider library affiliation

When using the operator `ui.copy_data_path_button(full_path=True)` ({key
ctrl shift Alt C} on hover) the copied path does not consider the
library origin. That means that when there is a name clash the data path
is not accurate and refers to the local item instead.

This patch adds the library (if the ID is linked) of the returned string
from RNA_path_full_ID_py.

bpy.data.objects["Cube", "//library.blend"] instead of
bpy.data.objects["Cube"]

note: parsing this happens in
pyrna_prop_collection_subscript_str_lib_pair_ptr

Maniphest Tasks: T88499

Differential Revision: https://developer.blender.org/D11412
This commit is contained in:
Philipp Oeser 2021-05-27 14:36:18 +02:00
parent 3ec57ce6c7
commit 63e50cf265
Notes: blender-bot 2023-02-14 02:58:19 +01:00
Referenced by issue #88499, Copy data path operator does not consider library affiliation
1 changed files with 14 additions and 2 deletions

View File

@ -6115,13 +6115,25 @@ char *RNA_path_full_ID_py(Main *bmain, ID *id)
path = "";
}
char id_esc[(sizeof(id->name) - 2) * 2];
char lib_filepath_esc[(sizeof(id->lib->filepath) * 2) + 4];
if (id->lib != NULL) {
int ofs = 0;
memcpy(lib_filepath_esc, ", \"", 3);
ofs += 3;
ofs += BLI_str_escape(lib_filepath_esc + ofs, id->lib->filepath, sizeof(lib_filepath_esc));
memcpy(lib_filepath_esc + ofs, "\"", 2);
}
else {
lib_filepath_esc[0] = '\0';
}
char id_esc[(sizeof(id->name) - 2) * 2];
BLI_str_escape(id_esc, id->name + 2, sizeof(id_esc));
return BLI_sprintfN("bpy.data.%s[\"%s\"]%s%s",
return BLI_sprintfN("bpy.data.%s[\"%s\"%s]%s%s",
BKE_idtype_idcode_to_name_plural(GS(id->name)),
id_esc,
lib_filepath_esc,
path[0] ? "." : "",
path);
}