Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2018-10-31 14:18:36 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2018-10-31 15:34:06 +0300
commit08a92d8578ea57109406022f75bc7b123e9cbcbb (patch)
tree9e80c392c4cd726ed1b929888fafa1b2c66c40bc /source/blender
parent7fe1ecf89dae2df2b0474df44defb806b4fa00c3 (diff)
UI/Unique ID name: add library ID name if present.
Also reshuffle a bit that whole code, did some renaming, `BKE_id_to_unique_string_key()` is now using same base code (instead of using whole library filepath...), etc.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/BKE_library.h6
-rw-r--r--source/blender/blenkernel/intern/library.c55
-rw-r--r--source/blender/editors/interface/interface_templates.c4
-rw-r--r--source/blender/editors/interface/interface_utils.c4
-rw-r--r--source/blender/makesrna/intern/rna_main.c9
5 files changed, 51 insertions, 27 deletions
diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h
index 050e9368a43..897d6206641 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -198,8 +198,10 @@ void BKE_main_id_clear_newpoins(struct Main *bmain);
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);
+#define MAX_ID_FULL_NAME (64 + 64 + 3 + 1) /* 64 is MAX_ID_NAME - 2 */
+#define MAX_ID_FULL_NAME_UI (MAX_ID_FULL_NAME + 3) /* Adds 'keycode' two letters at begining. */
+void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const struct ID *id);
+void BKE_id_full_name_ui_prefix_get(char name[MAX_ID_FULL_NAME_UI], const struct ID *id);
char *BKE_id_to_unique_string_key(const struct ID *id);
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index f88614eb0ca..c842c6033e2 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -2526,35 +2526,58 @@ void BKE_libblock_rename(Main *bmain, ID *id, const char *name)
}
/**
- * Returns in name the name of the block, with a 3-character prefix prepended
- * indicating whether it comes from a library, has a fake user, or no users.
+ * Generate full name of the data-block (without ID code, but with library is any)
+ *
+ * \note Result is unique to a given ID type in a given Main database.
+ *
+ * \param name An allocated string of minimal length MAX_ID_FULL_NAME, will be filled with generated string.
*/
-void BKE_id_ui_prefix(char name[MAX_ID_NAME + 1], const ID *id)
+void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const ID *id)
+{
+ strcpy(name, id->name + 2);
+
+ if (id->lib != NULL) {
+ const size_t idname_len = strlen(id->name + 2);
+ const size_t libname_len = strlen(id->lib->id.name + 2);
+
+ name[idname_len] = ' ';
+ name[idname_len + 1] = '[';
+ strcpy(name + idname_len + 2, id->lib->id.name + 2);
+ name[idname_len + 2 + libname_len] = ']';
+ name[idname_len + 2 + libname_len + 1] = '\0';
+ }
+}
+
+/**
+ * Generate full name of the data-block (without ID code, but with library is any), with a 3-character prefix prepended
+ * indicating whether it comes from a library, is overriding, has a fake or no user, etc.
+ *
+ * \note Result is unique to a given ID type in a given Main database.
+ *
+ * \param name An allocated string of minimal length MAX_ID_FULL_NAME_UI, will be filled with generated string.
+ */
+void BKE_id_full_name_ui_prefix_get(char name[MAX_ID_FULL_NAME_UI], const ID *id)
{
name[0] = id->lib ? (ID_MISSING(id) ? 'M' : 'L') : ID_IS_STATIC_OVERRIDE(id) ? 'O' : ' ';
name[1] = (id->flag & LIB_FAKEUSER) ? 'F' : ((id->us == 0) ? '0' : ' ');
name[2] = ' ';
- strcpy(name + 3, id->name + 2);
+ BKE_id_full_name_get(name + 3, id);
}
/**
- * Returns an allocated string concatenating ID name (including two-chars type code) and its lib name if any,
- * which is expected to be unique in a given Main database..
+ * Generate a concatenation of ID name (including two-chars type code) and its lib name, if any.
+ *
+ * \return A unique allocated string key for any ID in the whole Main database.
*/
char *BKE_id_to_unique_string_key(const struct ID *id)
{
- const size_t key_len_base = strlen(id->name) + 1;
- const size_t key_len_ext = ((id->lib != NULL) ? strlen(id->lib->name) : 0) + 1;
- const size_t key_len = key_len_base + key_len_ext - 1;
- char *key = MEM_mallocN(key_len, __func__);
-
- BLI_strncpy(key, id->name, key_len_base);
- if (id->lib != NULL) {
- BLI_strncpy(key + key_len_base - 1, id->lib->name, key_len_ext);
- }
+ char name[MAX_ID_FULL_NAME + 2];
+ name[0] = id->name[0];
+ name[1] = id->name[1];
+ BKE_id_full_name_get(name + 2, id);
- return key;
+ return BLI_strdup(name);
}
void BKE_library_filepath_set(Main *bmain, Library *lib, const char *filepath)
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 32b942283c7..7acbb0633b5 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -300,8 +300,8 @@ static bool id_search_add(
/* +1 is needed because BKE_id_ui_prefix uses 3 letter prefix
* followed by ID_NAME-2 characters from id->name.
*/
- char name_ui[MAX_ID_NAME + 1];
- BKE_id_ui_prefix(name_ui, id);
+ char name_ui[MAX_ID_FULL_NAME];
+ BKE_id_full_name_ui_prefix_get(name_ui, id);
int iconid = ui_id_icon_get(C, id, template_ui->preview);
diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c
index 4a051b9a4e8..d74bfe93f2f 100644
--- a/source/blender/editors/interface/interface_utils.c
+++ b/source/blender/editors/interface/interface_utils.c
@@ -273,8 +273,8 @@ void ui_rna_collection_search_cb(const struct bContext *C, void *arg, const char
iconid = 0;
if (itemptr.type && RNA_struct_is_ID(itemptr.type)) {
- name = MEM_malloc_arrayN(MAX_ID_NAME + 1, sizeof(*name), __func__);
- BKE_id_ui_prefix(name, itemptr.data);
+ name = MEM_malloc_arrayN(MAX_ID_FULL_NAME, sizeof(*name), __func__);
+ BKE_id_full_name_ui_prefix_get(name, itemptr.data);
iconid = ui_id_icon_get(C, itemptr.data, false);
}
else {
diff --git a/source/blender/makesrna/intern/rna_main.c b/source/blender/makesrna/intern/rna_main.c
index a807e363842..4f145d1f48d 100644
--- a/source/blender/makesrna/intern/rna_main.c
+++ b/source/blender/makesrna/intern/rna_main.c
@@ -310,15 +310,14 @@ static int rna_ID_lookup_string(ListBase *lb, const char *key, PointerRNA *r_ptr
{
ID *id;
for (id = lb->first; id != NULL; id = id->next) {
- printf("%s vs %s\n", id->name, key);
if (STREQ(id->name + 2, key)) {
break;
}
else if (strstr(key, id->name + 2) != NULL) {
- char uiname[MAX_ID_NAME * 3];
- BKE_id_ui_prefix(uiname, id);
- printf("second chance: %s vs %s\n", uiname, key);
- if (STREQ(uiname, key)) {
+ char full_name_ui[MAX_ID_FULL_NAME_UI];
+ BKE_id_full_name_ui_prefix_get(full_name_ui, id);
+ /* Second check skips the three 'UI keycode letters' prefix. */
+ if (STREQ(full_name_ui, key) || STREQ(full_name_ui + 3, key)) {
break;
}
}