Undo: unified undo system w/ linear history
[blender.git] / source / blender / blenkernel / intern / library.c
index d8617ef44e490aef6f1a2fd06c7b72591e464bb7..10b724f9f69706b6f169b6165898611390b8a132 100644 (file)
@@ -162,7 +162,7 @@ void BKE_id_lib_local_paths(Main *bmain, Library *lib, ID *id)
 
 void id_lib_extern(ID *id)
 {
-       if (id && ID_IS_LINKED_DATABLOCK(id)) {
+       if (id && ID_IS_LINKED(id)) {
                BLI_assert(BKE_idcode_is_linkable(GS(id->name)));
                if (id->tag & LIB_TAG_INDIRECT) {
                        id->tag -= LIB_TAG_INDIRECT;
@@ -309,7 +309,7 @@ void BKE_id_expand_local(Main *bmain, ID *id)
  */
 void BKE_id_copy_ensure_local(Main *bmain, const ID *old_id, ID *new_id)
 {
-       if (ID_IS_LINKED_DATABLOCK(old_id)) {
+       if (ID_IS_LINKED(old_id)) {
                BKE_id_expand_local(bmain, new_id);
                BKE_id_lib_local_paths(bmain, old_id->lib, new_id);
        }
@@ -328,7 +328,7 @@ void BKE_id_make_local_generic(Main *bmain, ID *id, const bool id_in_mainlist, c
         * In case we make a whole lib's content local, we always want to localize, and we skip remapping (done later).
         */
 
-       if (!ID_IS_LINKED_DATABLOCK(id)) {
+       if (!ID_IS_LINKED(id)) {
                return;
        }
 
@@ -661,8 +661,12 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
        /* Do not make new copy local in case we are copying outside of main...
         * XXX TODO: is this behavior OK, or should we need own flag to control that? */
        if ((flag & LIB_ID_CREATE_NO_MAIN) == 0) {
+               BLI_assert((flag & LIB_ID_COPY_KEEP_LIB) == 0);
                BKE_id_copy_ensure_local(bmain, id, *r_newid);
        }
+       else {
+               (*r_newid)->lib = id->lib;
+       }
 
        return true;
 }
@@ -753,6 +757,7 @@ void BKE_libblock_management_main_add(Main *bmain, void *idv)
        new_id(lb, id, NULL);
        /* alphabetic insertion: is in new_id */
        id->tag &= ~(LIB_TAG_NO_MAIN | LIB_TAG_NO_USER_REFCOUNT);
+       bmain->is_memfile_undo_written = false;
        BKE_main_unlock(bmain);
 }
 
@@ -772,6 +777,7 @@ void BKE_libblock_management_main_remove(Main *bmain, void *idv)
        BKE_main_lock(bmain);
        BLI_remlink(lb, id);
        id->tag |= LIB_TAG_NO_MAIN;
+       bmain->is_memfile_undo_written = false;
        BKE_main_unlock(bmain);
 }
 
@@ -955,7 +961,7 @@ void BKE_main_lib_objects_recalc_all(Main *bmain)
 
        /* flag for full recalc */
        for (ob = bmain->object.first; ob; ob = ob->id.next) {
-               if (ID_IS_LINKED_DATABLOCK(ob)) {
+               if (ID_IS_LINKED(ob)) {
                        DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
                }
        }
@@ -1134,6 +1140,7 @@ void *BKE_libblock_alloc(Main *bmain, short type, const char *name, const int fl
                        BKE_main_lock(bmain);
                        BLI_addtail(lb, id);
                        new_id(lb, id, name);
+                       bmain->is_memfile_undo_written = false;
                        /* alphabetic insertion: is in new_id */
                        BKE_main_unlock(bmain);
 
@@ -1632,7 +1639,7 @@ static ID *is_dupid(ListBase *lb, ID *id, const char *name)
        
        for (idtest = lb->first; idtest; idtest = idtest->next) {
                /* if idtest is not a lib */ 
-               if (id != idtest && !ID_IS_LINKED_DATABLOCK(idtest)) {
+               if (id != idtest && !ID_IS_LINKED(idtest)) {
                        /* do not test alphabetic! */
                        /* optimized */
                        if (idtest->name[2] == name[0]) {
@@ -1697,7 +1704,7 @@ static bool check_for_dupid(ListBase *lb, ID *id, char *name)
                for (idtest = lb->first; idtest; idtest = idtest->next) {
                        int nrtest;
                        if ( (id != idtest) &&
-                            !ID_IS_LINKED_DATABLOCK(idtest) &&
+                            !ID_IS_LINKED(idtest) &&
                             (*name == *(idtest->name + 2)) &&
                             STREQLEN(name, idtest->name + 2, left_len) &&
                             (BLI_split_name_num(leftest, &nrtest, idtest->name + 2, '.') == left_len)
@@ -1779,13 +1786,9 @@ bool new_id(ListBase *lb, ID *id, const char *tname)
        char name[MAX_ID_NAME - 2];
 
        /* if library, don't rename */
-       if (ID_IS_LINKED_DATABLOCK(id))
+       if (ID_IS_LINKED(id))
                return false;
 
-       /* if no libdata given, look up based on ID */
-       if (lb == NULL)
-               lb = which_libbase(G.main, GS(id->name));
-
        /* if no name given, use name of current ID
         * else make a copy (tname args can be const) */
        if (tname == NULL)
@@ -2026,7 +2029,7 @@ void BKE_library_make_local(
        GSet *loop_tags = BLI_gset_ptr_new(__func__);
        for (LinkNode *it = todo_ids; it; it = it->next) {
                library_make_local_copying_check(it->link, loop_tags, bmain->relations, done_ids);
-               BLI_assert(BLI_gset_size(loop_tags) == 0);
+               BLI_assert(BLI_gset_len(loop_tags) == 0);
        }
        BLI_gset_free(loop_tags, NULL);
        BLI_gset_free(done_ids, NULL);
@@ -2146,8 +2149,8 @@ void BKE_library_make_local(
                         * was not used locally would be a nasty bug! */
                        if (is_local || is_lib) {
                                printf("Warning, made-local proxy object %s will loose its link to %s, "
-                                          "because the linked-in proxy is referenced (is_local=%i, is_lib=%i).\n",
-                                          id->newid->name, ob->proxy->id.name, is_local, is_lib);
+                                      "because the linked-in proxy is referenced (is_local=%i, is_lib=%i).\n",
+                                      id->newid->name, ob->proxy->id.name, is_local, is_lib);
                        }
                        else {
                                /* we can switch the proxy'ing from the linked-in to the made-local proxy.
@@ -2203,8 +2206,8 @@ void BKE_library_make_local(
                                 * was not used locally would be a nasty bug! */
                                else if (is_local || is_lib) {
                                        printf("Warning, made-local proxy object %s will loose its link to %s, "
-                                                  "because the linked-in proxy is referenced (is_local=%i, is_lib=%i).\n",
-                                                  id->newid->name, ob->proxy->id.name, is_local, is_lib);
+                                              "because the linked-in proxy is referenced (is_local=%i, is_lib=%i).\n",
+                                              id->newid->name, ob->proxy->id.name, is_local, is_lib);
                                }
                                else {
                                        /* we can switch the proxy'ing from the linked-in to the made-local proxy.
@@ -2329,7 +2332,6 @@ void BLI_libblock_ensure_unique_name(Main *bmain, const char *name)
        ListBase *lb;
        ID *idtest;
 
-
        lb = which_libbase(bmain, GS(name));
        if (lb == NULL) return;
        
@@ -2388,10 +2390,10 @@ void BKE_library_filepath_set(Library *lib, const char *filepath)
 
 void BKE_id_tag_set_atomic(ID *id, int tag)
 {
-       atomic_fetch_and_or_uint32((uint32_t *)&id->tag, tag);
+       atomic_fetch_and_or_int32(&id->tag, tag);
 }
 
 void BKE_id_tag_clear_atomic(ID *id, int tag)
 {
-       atomic_fetch_and_and_uint32((uint32_t *)&id->tag, ~tag);
+       atomic_fetch_and_and_int32(&id->tag, ~tag);
 }