fix 2 bugs with reset-default failing on operators redo panel.
authorCampbell Barton <ideasman42@gmail.com>
Wed, 28 Sep 2011 18:45:17 +0000 (18:45 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 28 Sep 2011 18:45:17 +0000 (18:45 +0000)
- 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.

source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_handlers.c
source/blender/editors/interface/interface_ops.c
source/blender/makesdna/DNA_ID.h

index 4a89547..a5781ab 100644 (file)
@@ -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);
index 2869064..bcf83f7 100644 (file)
@@ -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 {
index 082ddb5..929a8bf 100644 (file)
@@ -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 */
index fd9386d..ea7e8fb 100644 (file)
@@ -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");
index 80fc6f6..11c6007 100644 (file)
@@ -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