ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling).
[blender.git] / source / blender / editors / space_image / space_image.c
index 168f9c0dfdf1f845b3eedefd118d6e8fefaa8996..35a658eac236f0eb51ee61f29111294646ba3bae 100644 (file)
@@ -28,6 +28,7 @@
  *  \ingroup spimage
  */
 
+#include "DNA_gpencil_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_mask_types.h"
 #include "DNA_meshdata_types.h"
@@ -44,6 +45,7 @@
 #include "BKE_colortools.h"
 #include "BKE_context.h"
 #include "BKE_image.h"
+#include "BKE_library.h"
 #include "BKE_scene.h"
 #include "BKE_screen.h"
 
@@ -981,6 +983,31 @@ static void image_header_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa
        }
 }
 
+static void image_id_remap(ScrArea *UNUSED(sa), SpaceLink *slink, ID *old_id, ID *new_id)
+{
+       SpaceImage *simg = (SpaceImage *)slink;
+
+       if (!ELEM(GS(old_id->name), ID_IM, ID_GD, ID_MSK)) {
+               return;
+       }
+
+       if ((ID *)simg->image == old_id) {
+               simg->image = (Image *)new_id;
+               id_us_ensure_real(new_id);
+       }
+
+       if ((ID *)simg->gpd == old_id) {
+               simg->gpd = (bGPdata *)new_id;
+               id_us_min(old_id);
+               id_us_plus(new_id);
+       }
+
+       if ((ID *)simg->mask_info.mask == old_id) {
+               simg->mask_info.mask = (Mask *)new_id;
+               id_us_ensure_real(new_id);
+       }
+}
+
 /**************************** spacetype *****************************/
 
 /* only called once, from space/spacetypes.c */
@@ -1002,7 +1029,8 @@ void ED_spacetype_image(void)
        st->refresh = image_refresh;
        st->listener = image_listener;
        st->context = image_context;
-       
+       st->id_remap = image_id_remap;
+
        /* regions: main window */
        art = MEM_callocN(sizeof(ARegionType), "spacetype image region");
        art->regionid = RGN_TYPE_WINDOW;