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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-01-30 01:36:38 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-01-30 01:41:28 +0300
commita1ae04d15a9faaa9b4dc59e8a5bec02a7c69b255 (patch)
tree56ebc632b9e2358a7fb0c57b220576c12587b727 /source
parent7894d6c6f1982f58dc479f3f01dd79afb6f5c1a0 (diff)
Versioning: add renaming utility function
Avoids accidents creating duplicate names. Also ensure screens are sorted on rename.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenloader/intern/versioning_defaults.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c
index c5df6a6fb83..8217483cf35 100644
--- a/source/blender/blenloader/intern/versioning_defaults.c
+++ b/source/blender/blenloader/intern/versioning_defaults.c
@@ -114,6 +114,33 @@ void BLO_update_defaults_userpref_blend(void)
BKE_keyconfig_pref_set_select_mouse(&U, 0, true);
}
+
+/**
+ * Rename if the ID doesn't exist.
+ */
+static ID *rename_id_for_versioning(Main *bmain, const short id_type, const char *name_src, const char *name_dst)
+{
+ /* We can ignore libraries */
+ ListBase *lb = which_libbase(bmain, id_type);
+ ID *id = NULL;
+ for (ID *idtest = lb->first; idtest; idtest = idtest->next) {
+ if (idtest->lib == NULL) {
+ if (STREQ(idtest->name + 2, name_src)) {
+ id = idtest;
+ }
+ if (STREQ(idtest->name + 2, name_dst)) {
+ return NULL;
+ }
+ }
+ }
+ if (id != NULL) {
+ BLI_strncpy(id->name + 2, name_dst, sizeof(id->name) - 2);
+ /* We know it's unique, this just sorts. */
+ BLI_libblock_ensure_unique_name(bmain, id->name);
+ }
+ return id;
+}
+
/**
* Update defaults in startup.blend, without having to save and embed the file.
* This function can be emptied each time the startup.blend is updated. */
@@ -176,6 +203,7 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
WorkSpaceLayout *layout = BKE_workspace_hook_layout_for_workspace_get(win->workspace_hook, workspace);
bScreen *screen = layout->screen;
BLI_strncpy(screen->id.name + 2, workspace->id.name + 2, sizeof(screen->id.name) - 2);
+ BLI_libblock_ensure_unique_name(bmain, screen->id.name);
}
}
@@ -300,16 +328,8 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
}
/* Rename lamp objects. */
- for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
- if (STREQ(ob->id.name, "OBLamp")) {
- STRNCPY(ob->id.name, "OBLight");
- }
- }
- for (Lamp *lamp = bmain->lamp.first; lamp; lamp = lamp->id.next) {
- if (STREQ(lamp->id.name, "LALamp")) {
- STRNCPY(lamp->id.name, "LALight");
- }
- }
+ rename_id_for_versioning(bmain, ID_OB, "Lamp", "Light");
+ rename_id_for_versioning(bmain, ID_LA, "Lamp", "Light");
for (Mesh *mesh = bmain->mesh.first; mesh; mesh = mesh->id.next) {
/* Match default for new meshes. */