fix annoying bug where image open from ID template didn't open in the existing images...
authorCampbell Barton <ideasman42@gmail.com>
Wed, 25 Jul 2012 09:04:59 +0000 (09:04 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 25 Jul 2012 09:04:59 +0000 (09:04 +0000)
source/blender/editors/interface/interface_templates.c
source/blender/editors/space_image/image_ops.c

index 4702253140a60b7da0754f1ab3614fde1a886eee..63b201e4cf76c258d317283dfcd9c6ec03b8f53d 100644 (file)
@@ -254,7 +254,7 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)
                        break;
                case UI_ID_OPEN:
                case UI_ID_ADD_NEW:
-                       /* these call uiIDContextPropertySet */
+                       /* these call uiIDContextProperty */
                        break;
                case UI_ID_DELETE:
                        memset(&idptr, 0, sizeof(idptr));
index ca16558f3a6dad68c36a1c515d1678fc186a5c38..7d1328ca2667a207944d1196c5552ba2e7f4ca8e 100644 (file)
@@ -901,6 +901,25 @@ static int image_open_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)
                        ima = tex->ima;
        }
 
+       if (ima == NULL) {
+               PointerRNA ptr;
+               PropertyRNA *prop;
+
+               /* hook into UI */
+               uiIDContextProperty(C, &ptr, &prop);
+
+               if (prop) {
+                       PointerRNA oldptr;
+
+                       oldptr = RNA_property_pointer_get(&ptr, prop);
+                       ima = (Image *)oldptr.id.data;
+                       /* unlikely but better avoid strange crash */
+                       if (ima && GS(ima->id.name) != ID_IM) {
+                               ima = NULL;
+                       }
+               }
+       }
+
        if (ima)
                path = ima->name;