Add reload button for image textures.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 9 Oct 2009 22:00:33 +0000 (22:00 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 9 Oct 2009 22:00:33 +0000 (22:00 +0000)
source/blender/editors/space_image/image_buttons.c
source/blender/editors/space_image/image_ops.c

index e2990a6d91937c355584cdabbc208405020e8252..87b6ec8bb7194e3a02c494b16cb51a0bb5aea7c7 100644 (file)
@@ -943,6 +943,8 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propn
        cb->prop= prop;
        cb->iuser= iuser;
 
+       uiLayoutSetContextPointer(layout, "edit_image", &imaptr);
+
        if(!compact)
                uiTemplateID(layout, C, ptr, propname, "IMAGE_OT_new", "IMAGE_OT_open", NULL);
 
@@ -992,9 +994,9 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propn
                        uiItemR(row, NULL, 0, &imaptr, "source", (compact)? 0: UI_ITEM_R_EXPAND);
 
                        if(ima->source != IMA_SRC_GENERATED) {
-                               row= uiLayoutRow(layout, 0);
+                               row= uiLayoutRow(layout, 1);
                                uiItemR(row, "", 0, &imaptr, "filename", 0);
-                               //uiItemO(row, "Reload", 0, "image.reload");
+                               uiItemO(row, "", ICON_FILE_REFRESH, "image.reload");
                        }
 
                        // XXX what was this for?
index d5bd736f307d8651db9153cb692fcb3da2712f6e..482750e5b2e022045d84020b535158db525d344c 100644 (file)
@@ -108,6 +108,11 @@ static void sima_zoom_set_factor(SpaceImage *sima, ARegion *ar, float zoomfac)
        sima_zoom_set(sima, ar, sima->zoom*zoomfac);
 }
 
+static int image_poll(bContext *C)
+{
+       return (CTX_data_edit_image(C) != NULL);
+}
+
 static int space_image_poll(bContext *C)
 {
        SpaceImage *sima= CTX_wm_space_image(C);
@@ -1070,19 +1075,16 @@ void IMAGE_OT_save_sequence(wmOperatorType *ot)
 
 static int reload_exec(bContext *C, wmOperator *op)
 {
-       SpaceImage *sima;
-
-       /* retrieve state */
-       sima= CTX_wm_space_image(C);
+       Image *ima= CTX_data_edit_image(C);
+       SpaceImage *sima= CTX_wm_space_image(C);
 
-       if(!sima->image)
+       if(!ima)
                return OPERATOR_CANCELLED;
 
-       BKE_image_signal(sima->image, &sima->iuser, IMA_SIGNAL_RELOAD);
-       /* ED_space_image_set(C, sima, scene, obedit, NULL); - do we really need this? */
+       // XXX other users?
+       BKE_image_signal(ima, (sima)? &sima->iuser: NULL, IMA_SIGNAL_RELOAD);
 
-       // XXX BIF_preview_changed(ID_TE);
-       WM_event_add_notifier(C, NC_IMAGE|NA_EDITED, sima->image);
+       WM_event_add_notifier(C, NC_IMAGE|NA_EDITED, ima);
        ED_area_tag_redraw(CTX_wm_area(C));
        
        return OPERATOR_FINISHED;
@@ -1096,7 +1098,7 @@ void IMAGE_OT_reload(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= reload_exec;
-       ot->poll= space_image_poll;
+       ot->poll= image_poll;
 
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;