diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-09-28 22:45:17 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-09-28 22:45:17 +0400 |
commit | 2ad45b5c4f54765ad8804d26dd28b1eca2c235e5 (patch) | |
tree | 908bbba4c048936c779d8b143895636ac79b1a29 /source | |
parent | 4ea3f1cc29b86f0464553c9da05d9f483b7da134 (diff) |
fix 2 bugs with reset-default failing on operators redo panel.
- The operator its self was registered so resetting the defaults would unhelpfully replace the toolbar with the reset to defaults operator panel.
- The callback for the operator wasnt being used so the settings were changed but the operator didnt re-run.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 1 | ||||
-rw-r--r-- | source/blender/editors/interface/interface.c | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 52 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_ops.c | 25 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_ID.h | 2 |
5 files changed, 66 insertions, 16 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 4a895472b33..a5781ab7267 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -787,6 +787,7 @@ void UI_buttons_operatortypes(void); /* Helpers for Operators */ void uiContextActiveProperty(const struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index); +void uiContextActivePropertyHandle(struct bContext *C); void uiContextAnimUpdate(const struct bContext *C); void uiFileBrowseContextProperty(const struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop); void uiIDContextProperty(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop); diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 286906402b9..bcf83f7bfb9 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -746,7 +746,7 @@ static int ui_but_is_rna_undo(uiBut *but) * unforseen conciquences, so best check for ID's we _know_ are not * handled by undo - campbell */ ID *id= but->rnapoin.id.data; - if(ELEM(GS(id->name), ID_SCR, ID_WM)) { + if(ID_CHECK_UNDO(id) == FALSE) { return FALSE; } else { diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 082ddb5b060..929a8bf1dc6 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -5089,19 +5089,16 @@ void ui_button_active_free(const bContext *C, uiBut *but) } } -/* helper function for insert keyframe, reset to default, etc operators */ -void uiContextActiveProperty(const bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index) +static uiBut *ui_context_rna_button_active(const bContext *C) { - ARegion *ar= CTX_wm_region(C); + uiBut *rnabut= NULL; - memset(ptr, 0, sizeof(*ptr)); - *prop= NULL; - *index= 0; + ARegion *ar= CTX_wm_region(C); while(ar) { uiBlock *block; uiBut *but, *activebut= NULL; - + /* find active button */ for(block=ar->uiblocks.first; block; block=block->next) { for(but=block->buttons.first; but; but= but->next) { @@ -5115,24 +5112,53 @@ void uiContextActiveProperty(const bContext *C, struct PointerRNA *ptr, struct P if(activebut && activebut->rnapoin.data) { uiHandleButtonData *data= activebut->active; - /* found RNA button */ - *ptr= activebut->rnapoin; - *prop= activebut->rnaprop; - *index= activebut->rnaindex; + rnabut= activebut; /* recurse into opened menu, like colorpicker case */ if(data && data->menu && (ar != data->menu->region)) { ar = data->menu->region; } else { - return; + return rnabut; } } else { /* no active button */ - return; + return rnabut; } } + + return rnabut; +} + +/* helper function for insert keyframe, reset to default, etc operators */ +void uiContextActiveProperty(const bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index) +{ + uiBut *activebut= ui_context_rna_button_active(C); + + memset(ptr, 0, sizeof(*ptr)); + + if(activebut && activebut->rnapoin.data) { + *ptr= activebut->rnapoin; + *prop= activebut->rnaprop; + *index= activebut->rnaindex; + } + else { + *prop= NULL; + *index= 0; + } +} + +void uiContextActivePropertyHandle(bContext *C) +{ + uiBut *activebut= ui_context_rna_button_active(C); + if(activebut) { + /* TODO, look into a better way to handle the button change + * currently this is mainly so reset defaults works for the + * operator redo panel - campbell */ + uiBlock *block= activebut->block; + block->handle_func(C, block->handle_func_arg, 0); + } } /* helper function for insert keyframe, reset to default, etc operators */ diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c index fd9386dc5ab..ea7e8fb81bc 100644 --- a/source/blender/editors/interface/interface_ops.c +++ b/source/blender/editors/interface/interface_ops.c @@ -295,10 +295,31 @@ static int reset_default_button_exec(bContext *C, wmOperator *op) if(RNA_property_reset(&ptr, prop, (all)? -1: index)) { /* perform updates required for this property */ RNA_property_update(C, &ptr, prop); + + /* as if we pressed the button */ + uiContextActivePropertyHandle(C); + success= 1; } } - + + /* Since we dont want to undo _all_ edits to settings, eg window + * edits on the screen or on operator settings. + * it might be better to move undo's inline - campbell */ + /* Note that buttons already account for this, it might be better to + * have a way to edit the buttons rather than set the rna since block + * callbacks also fail to run. */ + if(success) { + ID *id= ptr.id.data; + if(id && ID_CHECK_UNDO(id)) { + /* do nothing, go ahead with undo */ + } + else { + return OPERATOR_CANCELLED; + } + } + /* end hack */ + return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED; } @@ -314,7 +335,7 @@ static void UI_OT_reset_default_button(wmOperatorType *ot) ot->exec= reset_default_button_exec; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag= OPTYPE_UNDO; /* properties */ RNA_def_boolean(ot->srna, "all", 1, "All", "Reset to default values all elements of the array"); diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h index 80fc6f63363..11c60076423 100644 --- a/source/blender/makesdna/DNA_ID.h +++ b/source/blender/makesdna/DNA_ID.h @@ -204,6 +204,8 @@ typedef struct PreviewImage { #define ID_REAL_USERS(id) (((ID *)id)->us - ((((ID *)id)->flag & LIB_FAKEUSER) ? 1:0)) +#define ID_CHECK_UNDO(id) ((GS((id)->name) != ID_SCR) && (GS((id)->name) != ID_WM)) + #ifdef GS #undef GS #endif |