[Bf-blender-cvs] [2a31e0c812c] master: Images: make it harder to accidentally undo image texture painting changes

Brecht Van Lommel noreply at git.blender.org
Fri May 17 18:00:28 CEST 2019


Commit: 2a31e0c812c7dfa1645fc1c0692016fa1165b393
Author: Brecht Van Lommel
Date:   Fri May 17 15:10:34 2019 +0200
Branches: master
https://developer.blender.org/rB2a31e0c812c7dfa1645fc1c0692016fa1165b393

Images: make it harder to accidentally undo image texture painting changes

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.

===================================================================

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

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_image.py b/release/scripts/startup/bl_ui/space_image.py
index 8060609791a..5ea3545dbc2 100644
--- a/release/scripts/startup/bl_ui/space_image.py
+++ b/release/scripts/startup/bl_ui/space_image.py
@@ -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")
 
diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c
index 39cb5824627..59896391cca 100644
--- a/source/blender/editors/space_image/image_buttons.c
+++ b/source/blender/editors/space_image/image_buttons.c
@@ -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);
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 873eae07901..03e1d80e267 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -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;



More information about the Bf-blender-cvs mailing list