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.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user