Images: make it harder to accidentally undo image texture painting changes
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Fri, 17 May 2019 13:10:34 +0000 (15:10 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Fri, 17 May 2019 15:59:26 +0000 (17:59 +0200)
Editing properties like generated X/Y size clears any changes to the image,
and it's not obvious that this is destructive. Now if the image has been
painted on or baked to, buttons to Save or Discard changes will appear and
editing the properties will be disabled until doing one of these.

release/scripts/startup/bl_ui/space_image.py
source/blender/editors/space_image/image_buttons.c
source/blender/editors/space_image/image_ops.c

index 8060609..5ea3545 100644 (file)
@@ -241,6 +241,7 @@ class IMAGE_MT_image(Menu):
                 layout.separator()
                 if ima.packed_file:
                     layout.operator("image.pack", text="Repack")
+                    layout.operator("image.unpack", text="Unpack")
                 else:
                     layout.operator("image.pack", text="Pack")
 
index 39cb582..5989639 100644 (file)
@@ -836,6 +836,7 @@ void uiTemplateImage(uiLayout *layout,
   Image *ima;
   ImageUser *iuser;
   Scene *scene = CTX_data_scene(C);
+  SpaceImage *space_image = CTX_wm_space_image(C);
   uiLayout *row, *split, *col;
   uiBlock *block;
   char str[MAX_IMAGE_INFO_LEN];
@@ -877,7 +878,7 @@ void uiTemplateImage(uiLayout *layout,
   uiLayoutSetContextPointer(layout, "edit_image", &imaptr);
   uiLayoutSetContextPointer(layout, "edit_image_user", userptr);
 
-  if (!compact) {
+  if (!compact && (space_image == NULL || iuser != &space_image->iuser)) {
     uiTemplateID(layout,
                  C,
                  ptr,
@@ -915,6 +916,18 @@ void uiTemplateImage(uiLayout *layout,
       }
     }
     else {
+      /* Disable editing if image was modified, to avoid losing changes. */
+      const bool is_dirty = BKE_image_is_dirty(ima);
+      if (is_dirty) {
+        row = uiLayoutRow(layout, true);
+        uiItemO(row, IFACE_("Save"), ICON_NONE, "image.save");
+        uiItemO(row, IFACE_("Discard Changes"), ICON_NONE, "image.reload");
+        uiItemS(layout);
+      }
+
+      layout = uiLayoutColumn(layout, false);
+      uiLayoutSetEnabled(layout, !is_dirty);
+
       uiItemR(layout, &imaptr, "source", 0, NULL, ICON_NONE);
 
       if (ima->source != IMA_SRC_GENERATED) {
@@ -943,10 +956,14 @@ void uiTemplateImage(uiLayout *layout,
         }
       }
 
+      uiItemS(layout);
+
       col = uiLayoutColumn(layout, false);
       uiTemplateColorspaceSettings(col, &imaptr, "colorspace_settings");
       uiItemR(col, &imaptr, "use_view_as_render", 0, NULL, ICON_NONE);
 
+      uiItemS(layout);
+
       if (ima->source != IMA_SRC_GENERATED) {
         if (compact == 0) { /* background image view doesn't need these */
           ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
index 873eae0..03e1d80 100644 (file)
@@ -2064,6 +2064,17 @@ static int image_save_exec(bContext *C, wmOperator *op)
   return OPERATOR_FINISHED;
 }
 
+static int image_save_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+  if (space_image_file_exists_poll(C)) {
+    return image_save_exec(C, op);
+  }
+  else {
+    WM_operator_name_call(C, "IMAGE_OT_save_as", WM_OP_INVOKE_DEFAULT, NULL);
+    return OPERATOR_CANCELLED;
+  }
+}
+
 void IMAGE_OT_save(wmOperatorType *ot)
 {
   /* identifiers */
@@ -2073,7 +2084,8 @@ void IMAGE_OT_save(wmOperatorType *ot)
 
   /* api callbacks */
   ot->exec = image_save_exec;
-  ot->poll = space_image_file_exists_poll;
+  ot->invoke = image_save_invoke;
+  ot->poll = image_save_as_poll;
 
   /* flags */
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;