Fix T60554: Missing undo push changing color
Operators don't have a good way to skip undo, for now check the button undo flag & return cancelled.
This commit is contained in:
@@ -69,6 +69,7 @@ typedef struct Eyedropper {
|
|||||||
PointerRNA ptr;
|
PointerRNA ptr;
|
||||||
PropertyRNA *prop;
|
PropertyRNA *prop;
|
||||||
int index;
|
int index;
|
||||||
|
bool is_undo;
|
||||||
|
|
||||||
float init_col[3]; /* for resetting on cancel */
|
float init_col[3]; /* for resetting on cancel */
|
||||||
|
|
||||||
@@ -84,7 +85,7 @@ static bool eyedropper_init(bContext *C, wmOperator *op)
|
|||||||
Eyedropper *eye = MEM_callocN(sizeof(Eyedropper), __func__);
|
Eyedropper *eye = MEM_callocN(sizeof(Eyedropper), __func__);
|
||||||
eye->use_accum = RNA_boolean_get(op->ptr, "use_accumulate");
|
eye->use_accum = RNA_boolean_get(op->ptr, "use_accumulate");
|
||||||
|
|
||||||
UI_context_active_but_prop_get(C, &eye->ptr, &eye->prop, &eye->index);
|
uiBut *but = UI_context_active_but_prop_get(C, &eye->ptr, &eye->prop, &eye->index);
|
||||||
|
|
||||||
if ((eye->ptr.data == NULL) ||
|
if ((eye->ptr.data == NULL) ||
|
||||||
(eye->prop == NULL) ||
|
(eye->prop == NULL) ||
|
||||||
@@ -97,6 +98,8 @@ static bool eyedropper_init(bContext *C, wmOperator *op)
|
|||||||
}
|
}
|
||||||
op->customdata = eye;
|
op->customdata = eye;
|
||||||
|
|
||||||
|
eye->is_undo = UI_but_flag_is_set(but, UI_BUT_UNDO);
|
||||||
|
|
||||||
if (RNA_property_subtype(eye->prop) != PROP_COLOR) {
|
if (RNA_property_subtype(eye->prop) != PROP_COLOR) {
|
||||||
Scene *scene = CTX_data_scene(C);
|
Scene *scene = CTX_data_scene(C);
|
||||||
const char *display_device;
|
const char *display_device;
|
||||||
@@ -259,11 +262,15 @@ static int eyedropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
|||||||
eyedropper_cancel(C, op);
|
eyedropper_cancel(C, op);
|
||||||
return OPERATOR_CANCELLED;
|
return OPERATOR_CANCELLED;
|
||||||
case EYE_MODAL_SAMPLE_CONFIRM:
|
case EYE_MODAL_SAMPLE_CONFIRM:
|
||||||
|
{
|
||||||
|
const bool is_undo = eye->is_undo;
|
||||||
if (eye->accum_tot == 0) {
|
if (eye->accum_tot == 0) {
|
||||||
eyedropper_color_sample(C, eye, event->x, event->y);
|
eyedropper_color_sample(C, eye, event->x, event->y);
|
||||||
}
|
}
|
||||||
eyedropper_exit(C, op);
|
eyedropper_exit(C, op);
|
||||||
return OPERATOR_FINISHED;
|
/* Could support finished & undo-skip. */
|
||||||
|
return is_undo ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
|
||||||
|
}
|
||||||
case EYE_MODAL_SAMPLE_BEGIN:
|
case EYE_MODAL_SAMPLE_BEGIN:
|
||||||
/* enable accum and make first sample */
|
/* enable accum and make first sample */
|
||||||
eye->accum_start = true;
|
eye->accum_start = true;
|
||||||
@@ -343,7 +350,7 @@ void UI_OT_eyedropper_color(wmOperatorType *ot)
|
|||||||
ot->poll = eyedropper_poll;
|
ot->poll = eyedropper_poll;
|
||||||
|
|
||||||
/* flags */
|
/* flags */
|
||||||
ot->flag = OPTYPE_BLOCKING | OPTYPE_INTERNAL;
|
ot->flag = OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_INTERNAL;
|
||||||
|
|
||||||
/* properties */
|
/* properties */
|
||||||
PropertyRNA *prop;
|
PropertyRNA *prop;
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ typedef struct EyedropperColorband {
|
|||||||
ColorBand *color_band;
|
ColorBand *color_band;
|
||||||
PointerRNA ptr;
|
PointerRNA ptr;
|
||||||
PropertyRNA *prop;
|
PropertyRNA *prop;
|
||||||
|
bool is_undo;
|
||||||
} EyedropperColorband;
|
} EyedropperColorband;
|
||||||
|
|
||||||
/* For user-data only. */
|
/* For user-data only. */
|
||||||
@@ -110,6 +111,7 @@ static bool eyedropper_colorband_init(bContext *C, wmOperator *op)
|
|||||||
eye->init_color_band = *eye->color_band;
|
eye->init_color_band = *eye->color_band;
|
||||||
eye->ptr = ((Colorband_RNAUpdateCb *)but->func_argN)->ptr;
|
eye->ptr = ((Colorband_RNAUpdateCb *)but->func_argN)->ptr;
|
||||||
eye->prop = ((Colorband_RNAUpdateCb *)but->func_argN)->prop;
|
eye->prop = ((Colorband_RNAUpdateCb *)but->func_argN)->prop;
|
||||||
|
eye->is_undo = UI_but_flag_is_set(but, UI_BUT_UNDO);
|
||||||
|
|
||||||
op->customdata = eye;
|
op->customdata = eye;
|
||||||
|
|
||||||
@@ -192,10 +194,14 @@ static int eyedropper_colorband_modal(bContext *C, wmOperator *op, const wmEvent
|
|||||||
eyedropper_colorband_cancel(C, op);
|
eyedropper_colorband_cancel(C, op);
|
||||||
return OPERATOR_CANCELLED;
|
return OPERATOR_CANCELLED;
|
||||||
case EYE_MODAL_SAMPLE_CONFIRM:
|
case EYE_MODAL_SAMPLE_CONFIRM:
|
||||||
|
{
|
||||||
|
const bool is_undo = eye->is_undo;
|
||||||
eyedropper_colorband_sample_segment(C, eye, event->x, event->y);
|
eyedropper_colorband_sample_segment(C, eye, event->x, event->y);
|
||||||
eyedropper_colorband_apply(C, op);
|
eyedropper_colorband_apply(C, op);
|
||||||
eyedropper_colorband_exit(C, op);
|
eyedropper_colorband_exit(C, op);
|
||||||
return OPERATOR_FINISHED;
|
/* Could support finished & undo-skip. */
|
||||||
|
return is_undo ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
|
||||||
|
}
|
||||||
case EYE_MODAL_SAMPLE_BEGIN:
|
case EYE_MODAL_SAMPLE_BEGIN:
|
||||||
/* enable accum and make first sample */
|
/* enable accum and make first sample */
|
||||||
eye->sample_start = true;
|
eye->sample_start = true;
|
||||||
@@ -312,7 +318,7 @@ void UI_OT_eyedropper_colorband(wmOperatorType *ot)
|
|||||||
ot->poll = eyedropper_colorband_poll;
|
ot->poll = eyedropper_colorband_poll;
|
||||||
|
|
||||||
/* flags */
|
/* flags */
|
||||||
ot->flag = OPTYPE_BLOCKING | OPTYPE_INTERNAL;
|
ot->flag = OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_INTERNAL;
|
||||||
|
|
||||||
/* properties */
|
/* properties */
|
||||||
}
|
}
|
||||||
@@ -332,7 +338,7 @@ void UI_OT_eyedropper_colorband_point(wmOperatorType *ot)
|
|||||||
ot->poll = eyedropper_colorband_poll;
|
ot->poll = eyedropper_colorband_poll;
|
||||||
|
|
||||||
/* flags */
|
/* flags */
|
||||||
ot->flag = OPTYPE_BLOCKING | OPTYPE_INTERNAL;
|
ot->flag = OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_INTERNAL;
|
||||||
|
|
||||||
/* properties */
|
/* properties */
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ typedef struct DataDropper {
|
|||||||
PropertyRNA *prop;
|
PropertyRNA *prop;
|
||||||
short idcode;
|
short idcode;
|
||||||
const char *idcode_name;
|
const char *idcode_name;
|
||||||
|
bool is_undo;
|
||||||
|
|
||||||
ID *init_id; /* for resetting on cancel */
|
ID *init_id; /* for resetting on cancel */
|
||||||
|
|
||||||
@@ -97,7 +98,7 @@ static int datadropper_init(bContext *C, wmOperator *op)
|
|||||||
|
|
||||||
DataDropper *ddr = MEM_callocN(sizeof(DataDropper), __func__);
|
DataDropper *ddr = MEM_callocN(sizeof(DataDropper), __func__);
|
||||||
|
|
||||||
UI_context_active_but_prop_get(C, &ddr->ptr, &ddr->prop, &index_dummy);
|
uiBut *but = UI_context_active_but_prop_get(C, &ddr->ptr, &ddr->prop, &index_dummy);
|
||||||
|
|
||||||
if ((ddr->ptr.data == NULL) ||
|
if ((ddr->ptr.data == NULL) ||
|
||||||
(ddr->prop == NULL) ||
|
(ddr->prop == NULL) ||
|
||||||
@@ -109,6 +110,8 @@ static int datadropper_init(bContext *C, wmOperator *op)
|
|||||||
}
|
}
|
||||||
op->customdata = ddr;
|
op->customdata = ddr;
|
||||||
|
|
||||||
|
ddr->is_undo = UI_but_flag_is_set(but, UI_BUT_UNDO);
|
||||||
|
|
||||||
ddr->art = art;
|
ddr->art = art;
|
||||||
ddr->draw_handle_pixel = ED_region_draw_cb_activate(art, datadropper_draw_cb, ddr, REGION_DRAW_POST_PIXEL);
|
ddr->draw_handle_pixel = ED_region_draw_cb_activate(art, datadropper_draw_cb, ddr, REGION_DRAW_POST_PIXEL);
|
||||||
|
|
||||||
@@ -254,13 +257,12 @@ static int datadropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
|||||||
return OPERATOR_CANCELLED;
|
return OPERATOR_CANCELLED;
|
||||||
case EYE_MODAL_SAMPLE_CONFIRM:
|
case EYE_MODAL_SAMPLE_CONFIRM:
|
||||||
{
|
{
|
||||||
bool success;
|
const bool is_undo = ddr->is_undo;
|
||||||
|
const bool success = datadropper_id_sample(C, ddr, event->x, event->y);
|
||||||
success = datadropper_id_sample(C, ddr, event->x, event->y);
|
|
||||||
datadropper_exit(C, op);
|
datadropper_exit(C, op);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
return OPERATOR_FINISHED;
|
/* Could support finished & undo-skip. */
|
||||||
|
return is_undo ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
BKE_report(op->reports, RPT_WARNING, "Failed to set value");
|
BKE_report(op->reports, RPT_WARNING, "Failed to set value");
|
||||||
@@ -349,7 +351,7 @@ void UI_OT_eyedropper_id(wmOperatorType *ot)
|
|||||||
ot->poll = datadropper_poll;
|
ot->poll = datadropper_poll;
|
||||||
|
|
||||||
/* flags */
|
/* flags */
|
||||||
ot->flag = OPTYPE_BLOCKING | OPTYPE_INTERNAL;
|
ot->flag = OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_INTERNAL;
|
||||||
|
|
||||||
/* properties */
|
/* properties */
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,7 @@
|
|||||||
typedef struct DepthDropper {
|
typedef struct DepthDropper {
|
||||||
PointerRNA ptr;
|
PointerRNA ptr;
|
||||||
PropertyRNA *prop;
|
PropertyRNA *prop;
|
||||||
|
bool is_undo;
|
||||||
|
|
||||||
float init_depth; /* for resetting on cancel */
|
float init_depth; /* for resetting on cancel */
|
||||||
|
|
||||||
@@ -99,7 +100,7 @@ static int depthdropper_init(bContext *C, wmOperator *op)
|
|||||||
|
|
||||||
DepthDropper *ddr = MEM_callocN(sizeof(DepthDropper), __func__);
|
DepthDropper *ddr = MEM_callocN(sizeof(DepthDropper), __func__);
|
||||||
|
|
||||||
UI_context_active_but_prop_get(C, &ddr->ptr, &ddr->prop, &index_dummy);
|
uiBut *but = UI_context_active_but_prop_get(C, &ddr->ptr, &ddr->prop, &index_dummy);
|
||||||
|
|
||||||
/* fallback to the active camera's dof */
|
/* fallback to the active camera's dof */
|
||||||
if (ddr->prop == NULL) {
|
if (ddr->prop == NULL) {
|
||||||
@@ -123,6 +124,8 @@ static int depthdropper_init(bContext *C, wmOperator *op)
|
|||||||
}
|
}
|
||||||
op->customdata = ddr;
|
op->customdata = ddr;
|
||||||
|
|
||||||
|
ddr->is_undo = UI_but_flag_is_set(but, UI_BUT_UNDO);
|
||||||
|
|
||||||
ddr->art = art;
|
ddr->art = art;
|
||||||
ddr->draw_handle_pixel = ED_region_draw_cb_activate(art, depthdropper_draw_cb, ddr, REGION_DRAW_POST_PIXEL);
|
ddr->draw_handle_pixel = ED_region_draw_cb_activate(art, depthdropper_draw_cb, ddr, REGION_DRAW_POST_PIXEL);
|
||||||
ddr->init_depth = RNA_property_float_get(&ddr->ptr, ddr->prop);
|
ddr->init_depth = RNA_property_float_get(&ddr->ptr, ddr->prop);
|
||||||
@@ -268,6 +271,8 @@ static int depthdropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
|||||||
depthdropper_cancel(C, op);
|
depthdropper_cancel(C, op);
|
||||||
return OPERATOR_CANCELLED;
|
return OPERATOR_CANCELLED;
|
||||||
case EYE_MODAL_SAMPLE_CONFIRM:
|
case EYE_MODAL_SAMPLE_CONFIRM:
|
||||||
|
{
|
||||||
|
const bool is_undo = ddr->is_undo;
|
||||||
if (ddr->accum_tot == 0) {
|
if (ddr->accum_tot == 0) {
|
||||||
depthdropper_depth_sample(C, ddr, event->x, event->y);
|
depthdropper_depth_sample(C, ddr, event->x, event->y);
|
||||||
}
|
}
|
||||||
@@ -275,7 +280,9 @@ static int depthdropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
|||||||
depthdropper_depth_set_accum(C, ddr);
|
depthdropper_depth_set_accum(C, ddr);
|
||||||
}
|
}
|
||||||
depthdropper_exit(C, op);
|
depthdropper_exit(C, op);
|
||||||
return OPERATOR_FINISHED;
|
/* Could support finished & undo-skip. */
|
||||||
|
return is_undo ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
|
||||||
|
}
|
||||||
case EYE_MODAL_SAMPLE_BEGIN:
|
case EYE_MODAL_SAMPLE_BEGIN:
|
||||||
/* enable accum and make first sample */
|
/* enable accum and make first sample */
|
||||||
ddr->accum_start = true;
|
ddr->accum_start = true;
|
||||||
@@ -380,7 +387,7 @@ void UI_OT_eyedropper_depth(wmOperatorType *ot)
|
|||||||
ot->poll = depthdropper_poll;
|
ot->poll = depthdropper_poll;
|
||||||
|
|
||||||
/* flags */
|
/* flags */
|
||||||
ot->flag = OPTYPE_BLOCKING | OPTYPE_INTERNAL;
|
ot->flag = OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_INTERNAL;
|
||||||
|
|
||||||
/* properties */
|
/* properties */
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ typedef struct DriverDropper {
|
|||||||
PointerRNA ptr;
|
PointerRNA ptr;
|
||||||
PropertyRNA *prop;
|
PropertyRNA *prop;
|
||||||
int index;
|
int index;
|
||||||
|
bool is_undo;
|
||||||
|
|
||||||
// TODO: new target?
|
// TODO: new target?
|
||||||
} DriverDropper;
|
} DriverDropper;
|
||||||
@@ -85,6 +86,8 @@ static bool driverdropper_init(bContext *C, wmOperator *op)
|
|||||||
}
|
}
|
||||||
op->customdata = ddr;
|
op->customdata = ddr;
|
||||||
|
|
||||||
|
ddr->is_undo = UI_but_flag_is_set(but, UI_BUT_UNDO);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,18 +156,24 @@ static void driverdropper_cancel(bContext *C, wmOperator *op)
|
|||||||
/* main modal status check */
|
/* main modal status check */
|
||||||
static int driverdropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
static int driverdropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||||
{
|
{
|
||||||
|
DriverDropper *ddr = op->customdata;
|
||||||
|
|
||||||
/* handle modal keymap */
|
/* handle modal keymap */
|
||||||
if (event->type == EVT_MODAL_MAP) {
|
if (event->type == EVT_MODAL_MAP) {
|
||||||
switch (event->val) {
|
switch (event->val) {
|
||||||
case EYE_MODAL_CANCEL:
|
case EYE_MODAL_CANCEL:
|
||||||
|
{
|
||||||
driverdropper_cancel(C, op);
|
driverdropper_cancel(C, op);
|
||||||
return OPERATOR_CANCELLED;
|
return OPERATOR_CANCELLED;
|
||||||
|
}
|
||||||
case EYE_MODAL_SAMPLE_CONFIRM:
|
case EYE_MODAL_SAMPLE_CONFIRM:
|
||||||
|
{
|
||||||
|
const bool is_undo = ddr->is_undo;
|
||||||
driverdropper_sample(C, op, event);
|
driverdropper_sample(C, op, event);
|
||||||
driverdropper_exit(C, op);
|
driverdropper_exit(C, op);
|
||||||
|
/* Could support finished & undo-skip. */
|
||||||
return OPERATOR_FINISHED;
|
return is_undo ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +233,7 @@ void UI_OT_eyedropper_driver(wmOperatorType *ot)
|
|||||||
ot->poll = driverdropper_poll;
|
ot->poll = driverdropper_poll;
|
||||||
|
|
||||||
/* flags */
|
/* flags */
|
||||||
ot->flag = OPTYPE_BLOCKING | OPTYPE_INTERNAL | OPTYPE_UNDO;
|
ot->flag = OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_INTERNAL;
|
||||||
|
|
||||||
/* properties */
|
/* properties */
|
||||||
RNA_def_enum(ot->srna, "mapping_type", prop_driver_create_mapping_types, 0,
|
RNA_def_enum(ot->srna, "mapping_type", prop_driver_create_mapping_types, 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user