From c8e75c2b00cfb7e87bcb800c9acc8f126949749d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 17 Jan 2019 16:39:38 +1100 Subject: 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. --- .../editors/interface/interface_eyedropper_color.c | 13 ++++++++++--- .../editors/interface/interface_eyedropper_colorband.c | 12 +++++++++--- .../editors/interface/interface_eyedropper_datablock.c | 16 +++++++++------- .../editors/interface/interface_eyedropper_depth.c | 13 ++++++++++--- .../editors/interface/interface_eyedropper_driver.c | 17 +++++++++++++---- 5 files changed, 51 insertions(+), 20 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/interface/interface_eyedropper_color.c b/source/blender/editors/interface/interface_eyedropper_color.c index 580d07aee2c..7bd98669a56 100644 --- a/source/blender/editors/interface/interface_eyedropper_color.c +++ b/source/blender/editors/interface/interface_eyedropper_color.c @@ -69,6 +69,7 @@ typedef struct Eyedropper { PointerRNA ptr; PropertyRNA *prop; int index; + bool is_undo; 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__); 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) || (eye->prop == NULL) || @@ -97,6 +98,8 @@ static bool eyedropper_init(bContext *C, wmOperator *op) } op->customdata = eye; + eye->is_undo = UI_but_flag_is_set(but, UI_BUT_UNDO); + if (RNA_property_subtype(eye->prop) != PROP_COLOR) { Scene *scene = CTX_data_scene(C); const char *display_device; @@ -259,11 +262,15 @@ static int eyedropper_modal(bContext *C, wmOperator *op, const wmEvent *event) eyedropper_cancel(C, op); return OPERATOR_CANCELLED; case EYE_MODAL_SAMPLE_CONFIRM: + { + const bool is_undo = eye->is_undo; if (eye->accum_tot == 0) { eyedropper_color_sample(C, eye, event->x, event->y); } eyedropper_exit(C, op); - return OPERATOR_FINISHED; + /* Could support finished & undo-skip. */ + return is_undo ? OPERATOR_FINISHED : OPERATOR_CANCELLED; + } case EYE_MODAL_SAMPLE_BEGIN: /* enable accum and make first sample */ eye->accum_start = true; @@ -343,7 +350,7 @@ void UI_OT_eyedropper_color(wmOperatorType *ot) ot->poll = eyedropper_poll; /* flags */ - ot->flag = OPTYPE_BLOCKING | OPTYPE_INTERNAL; + ot->flag = OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_INTERNAL; /* properties */ PropertyRNA *prop; diff --git a/source/blender/editors/interface/interface_eyedropper_colorband.c b/source/blender/editors/interface/interface_eyedropper_colorband.c index 262aed77b37..dd4524c9066 100644 --- a/source/blender/editors/interface/interface_eyedropper_colorband.c +++ b/source/blender/editors/interface/interface_eyedropper_colorband.c @@ -72,6 +72,7 @@ typedef struct EyedropperColorband { ColorBand *color_band; PointerRNA ptr; PropertyRNA *prop; + bool is_undo; } EyedropperColorband; /* 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->ptr = ((Colorband_RNAUpdateCb *)but->func_argN)->ptr; eye->prop = ((Colorband_RNAUpdateCb *)but->func_argN)->prop; + eye->is_undo = UI_but_flag_is_set(but, UI_BUT_UNDO); op->customdata = eye; @@ -192,10 +194,14 @@ static int eyedropper_colorband_modal(bContext *C, wmOperator *op, const wmEvent eyedropper_colorband_cancel(C, op); return OPERATOR_CANCELLED; case EYE_MODAL_SAMPLE_CONFIRM: + { + const bool is_undo = eye->is_undo; eyedropper_colorband_sample_segment(C, eye, event->x, event->y); eyedropper_colorband_apply(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: /* enable accum and make first sample */ eye->sample_start = true; @@ -312,7 +318,7 @@ void UI_OT_eyedropper_colorband(wmOperatorType *ot) ot->poll = eyedropper_colorband_poll; /* flags */ - ot->flag = OPTYPE_BLOCKING | OPTYPE_INTERNAL; + ot->flag = OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_INTERNAL; /* properties */ } @@ -332,7 +338,7 @@ void UI_OT_eyedropper_colorband_point(wmOperatorType *ot) ot->poll = eyedropper_colorband_poll; /* flags */ - ot->flag = OPTYPE_BLOCKING | OPTYPE_INTERNAL; + ot->flag = OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_INTERNAL; /* properties */ } diff --git a/source/blender/editors/interface/interface_eyedropper_datablock.c b/source/blender/editors/interface/interface_eyedropper_datablock.c index f39c8bdf889..594488ff148 100644 --- a/source/blender/editors/interface/interface_eyedropper_datablock.c +++ b/source/blender/editors/interface/interface_eyedropper_datablock.c @@ -68,6 +68,7 @@ typedef struct DataDropper { PropertyRNA *prop; short idcode; const char *idcode_name; + bool is_undo; 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__); - 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) || (ddr->prop == NULL) || @@ -109,6 +110,8 @@ static int datadropper_init(bContext *C, wmOperator *op) } op->customdata = ddr; + ddr->is_undo = UI_but_flag_is_set(but, UI_BUT_UNDO); + ddr->art = art; 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; case EYE_MODAL_SAMPLE_CONFIRM: { - bool success; - - success = datadropper_id_sample(C, ddr, event->x, event->y); + const bool is_undo = ddr->is_undo; + const bool success = datadropper_id_sample(C, ddr, event->x, event->y); datadropper_exit(C, op); - if (success) { - return OPERATOR_FINISHED; + /* Could support finished & undo-skip. */ + return is_undo ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } else { 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; /* flags */ - ot->flag = OPTYPE_BLOCKING | OPTYPE_INTERNAL; + ot->flag = OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_INTERNAL; /* properties */ } diff --git a/source/blender/editors/interface/interface_eyedropper_depth.c b/source/blender/editors/interface/interface_eyedropper_depth.c index 49788c7cecf..4d0a95a6bbd 100644 --- a/source/blender/editors/interface/interface_eyedropper_depth.c +++ b/source/blender/editors/interface/interface_eyedropper_depth.c @@ -67,6 +67,7 @@ typedef struct DepthDropper { PointerRNA ptr; PropertyRNA *prop; + bool is_undo; 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__); - 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 */ if (ddr->prop == NULL) { @@ -123,6 +124,8 @@ static int depthdropper_init(bContext *C, wmOperator *op) } op->customdata = ddr; + ddr->is_undo = UI_but_flag_is_set(but, UI_BUT_UNDO); + ddr->art = art; 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); @@ -268,6 +271,8 @@ static int depthdropper_modal(bContext *C, wmOperator *op, const wmEvent *event) depthdropper_cancel(C, op); return OPERATOR_CANCELLED; case EYE_MODAL_SAMPLE_CONFIRM: + { + const bool is_undo = ddr->is_undo; if (ddr->accum_tot == 0) { 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_exit(C, op); - return OPERATOR_FINISHED; + /* Could support finished & undo-skip. */ + return is_undo ? OPERATOR_FINISHED : OPERATOR_CANCELLED; + } case EYE_MODAL_SAMPLE_BEGIN: /* enable accum and make first sample */ ddr->accum_start = true; @@ -380,7 +387,7 @@ void UI_OT_eyedropper_depth(wmOperatorType *ot) ot->poll = depthdropper_poll; /* flags */ - ot->flag = OPTYPE_BLOCKING | OPTYPE_INTERNAL; + ot->flag = OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_INTERNAL; /* properties */ } diff --git a/source/blender/editors/interface/interface_eyedropper_driver.c b/source/blender/editors/interface/interface_eyedropper_driver.c index 57d63bafc82..c9b29da2e61 100644 --- a/source/blender/editors/interface/interface_eyedropper_driver.c +++ b/source/blender/editors/interface/interface_eyedropper_driver.c @@ -64,6 +64,7 @@ typedef struct DriverDropper { PointerRNA ptr; PropertyRNA *prop; int index; + bool is_undo; // TODO: new target? } DriverDropper; @@ -85,6 +86,8 @@ static bool driverdropper_init(bContext *C, wmOperator *op) } op->customdata = ddr; + ddr->is_undo = UI_but_flag_is_set(but, UI_BUT_UNDO); + return true; } @@ -153,18 +156,24 @@ static void driverdropper_cancel(bContext *C, wmOperator *op) /* main modal status check */ static int driverdropper_modal(bContext *C, wmOperator *op, const wmEvent *event) { + DriverDropper *ddr = op->customdata; + /* handle modal keymap */ if (event->type == EVT_MODAL_MAP) { switch (event->val) { case EYE_MODAL_CANCEL: + { driverdropper_cancel(C, op); return OPERATOR_CANCELLED; - + } case EYE_MODAL_SAMPLE_CONFIRM: + { + const bool is_undo = ddr->is_undo; driverdropper_sample(C, op, event); driverdropper_exit(C, op); - - return OPERATOR_FINISHED; + /* Could support finished & undo-skip. */ + return is_undo ? OPERATOR_FINISHED : OPERATOR_CANCELLED; + } } } @@ -224,7 +233,7 @@ void UI_OT_eyedropper_driver(wmOperatorType *ot) ot->poll = driverdropper_poll; /* flags */ - ot->flag = OPTYPE_BLOCKING | OPTYPE_INTERNAL | OPTYPE_UNDO; + ot->flag = OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_INTERNAL; /* properties */ RNA_def_enum(ot->srna, "mapping_type", prop_driver_create_mapping_types, 0, -- cgit v1.2.3