Fix #23847: keyframe insert on button not working in popup menus, e.g.
the vector popup for node inputs.
This commit is contained in:
@@ -372,7 +372,7 @@ static int add_driver_button_exec (bContext *C, wmOperator *op)
|
||||
|
||||
/* try to create driver using property retrieved from UI */
|
||||
memset(&ptr, 0, sizeof(PointerRNA));
|
||||
uiAnimContextProperty(C, &ptr, &prop, &index);
|
||||
uiContextActiveProperty(C, &ptr, &prop, &index);
|
||||
|
||||
if (all)
|
||||
index= -1;
|
||||
@@ -389,6 +389,8 @@ static int add_driver_button_exec (bContext *C, wmOperator *op)
|
||||
|
||||
if (success) {
|
||||
/* send updates */
|
||||
uiContextAnimUpdate(C);
|
||||
|
||||
DAG_ids_flush_update(CTX_data_main(C), 0);
|
||||
|
||||
WM_event_add_notifier(C, NC_ANIMATION|ND_FCURVES_ORDER, NULL); // XXX
|
||||
@@ -427,7 +429,7 @@ static int remove_driver_button_exec (bContext *C, wmOperator *op)
|
||||
|
||||
/* try to find driver using property retrieved from UI */
|
||||
memset(&ptr, 0, sizeof(PointerRNA));
|
||||
uiAnimContextProperty(C, &ptr, &prop, &index);
|
||||
uiContextActiveProperty(C, &ptr, &prop, &index);
|
||||
|
||||
if (all)
|
||||
index= -1;
|
||||
@@ -440,6 +442,8 @@ static int remove_driver_button_exec (bContext *C, wmOperator *op)
|
||||
|
||||
if (success) {
|
||||
/* send updates */
|
||||
uiContextAnimUpdate(C);
|
||||
|
||||
DAG_ids_flush_update(CTX_data_main(C), 0);
|
||||
|
||||
WM_event_add_notifier(C, NC_ANIMATION|ND_FCURVES_ORDER, NULL); // XXX
|
||||
@@ -478,7 +482,7 @@ static int copy_driver_button_exec (bContext *C, wmOperator *op)
|
||||
|
||||
/* try to create driver using property retrieved from UI */
|
||||
memset(&ptr, 0, sizeof(PointerRNA));
|
||||
uiAnimContextProperty(C, &ptr, &prop, &index);
|
||||
uiContextActiveProperty(C, &ptr, &prop, &index);
|
||||
|
||||
if (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)) {
|
||||
path= RNA_path_from_ID_to_property(&ptr, prop);
|
||||
@@ -486,6 +490,8 @@ static int copy_driver_button_exec (bContext *C, wmOperator *op)
|
||||
if (path) {
|
||||
/* only copy the driver for the button that this was involved for */
|
||||
success= ANIM_copy_driver(ptr.id.data, path, index, 0);
|
||||
|
||||
uiContextAnimUpdate(C);
|
||||
|
||||
MEM_freeN(path);
|
||||
}
|
||||
@@ -522,7 +528,7 @@ static int paste_driver_button_exec (bContext *C, wmOperator *op)
|
||||
|
||||
/* try to create driver using property retrieved from UI */
|
||||
memset(&ptr, 0, sizeof(PointerRNA));
|
||||
uiAnimContextProperty(C, &ptr, &prop, &index);
|
||||
uiContextActiveProperty(C, &ptr, &prop, &index);
|
||||
|
||||
if (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)) {
|
||||
path= RNA_path_from_ID_to_property(&ptr, prop);
|
||||
@@ -530,6 +536,8 @@ static int paste_driver_button_exec (bContext *C, wmOperator *op)
|
||||
if (path) {
|
||||
/* only copy the driver for the button that this was involved for */
|
||||
success= ANIM_paste_driver(ptr.id.data, path, index, 0);
|
||||
|
||||
uiContextAnimUpdate(C);
|
||||
|
||||
MEM_freeN(path);
|
||||
}
|
||||
|
||||
@@ -1362,7 +1362,7 @@ static int insert_key_button_exec (bContext *C, wmOperator *op)
|
||||
|
||||
/* try to insert keyframe using property retrieved from UI */
|
||||
memset(&ptr, 0, sizeof(PointerRNA));
|
||||
uiAnimContextProperty(C, &ptr, &prop, &index);
|
||||
uiContextActiveProperty(C, &ptr, &prop, &index);
|
||||
|
||||
if ((ptr.id.data && ptr.data && prop) && RNA_property_animateable(&ptr, prop)) {
|
||||
path= RNA_path_from_ID_to_property(&ptr, prop);
|
||||
@@ -1405,6 +1405,8 @@ static int insert_key_button_exec (bContext *C, wmOperator *op)
|
||||
|
||||
if (success) {
|
||||
/* send updates */
|
||||
uiContextAnimUpdate(C);
|
||||
|
||||
DAG_ids_flush_update(bmain, 0);
|
||||
|
||||
/* send notifiers that keyframes have been changed */
|
||||
@@ -1446,7 +1448,7 @@ static int delete_key_button_exec (bContext *C, wmOperator *op)
|
||||
|
||||
/* try to insert keyframe using property retrieved from UI */
|
||||
memset(&ptr, 0, sizeof(PointerRNA));
|
||||
uiAnimContextProperty(C, &ptr, &prop, &index);
|
||||
uiContextActiveProperty(C, &ptr, &prop, &index);
|
||||
|
||||
if (ptr.id.data && ptr.data && prop) {
|
||||
path= RNA_path_from_ID_to_property(&ptr, prop);
|
||||
@@ -1476,6 +1478,8 @@ static int delete_key_button_exec (bContext *C, wmOperator *op)
|
||||
|
||||
if (success) {
|
||||
/* send updates */
|
||||
uiContextAnimUpdate(C);
|
||||
|
||||
DAG_ids_flush_update(bmain, 0);
|
||||
|
||||
/* send notifiers that keyframes have been changed */
|
||||
|
||||
@@ -323,7 +323,7 @@ static int add_keyingset_button_exec (bContext *C, wmOperator *op)
|
||||
|
||||
/* try to add to keyingset using property retrieved from UI */
|
||||
memset(&ptr, 0, sizeof(PointerRNA));
|
||||
uiAnimContextProperty(C, &ptr, &prop, &index);
|
||||
uiContextActiveProperty(C, &ptr, &prop, &index);
|
||||
|
||||
/* check if property is able to be added */
|
||||
if (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)) {
|
||||
@@ -409,7 +409,7 @@ static int remove_keyingset_button_exec (bContext *C, wmOperator *op)
|
||||
|
||||
/* try to add to keyingset using property retrieved from UI */
|
||||
memset(&ptr, 0, sizeof(PointerRNA));
|
||||
uiAnimContextProperty(C, &ptr, &prop, &index);
|
||||
uiContextActiveProperty(C, &ptr, &prop, &index);
|
||||
|
||||
if (ptr.id.data && ptr.data && prop) {
|
||||
path= RNA_path_from_ID_to_property(&ptr, prop);
|
||||
|
||||
@@ -737,7 +737,8 @@ void uiItemMenuEnumR(uiLayout *layout, struct PointerRNA *ptr, char *propname, c
|
||||
void UI_buttons_operatortypes(void);
|
||||
|
||||
/* Helpers for Operators */
|
||||
void uiAnimContextProperty(const struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index);
|
||||
void uiContextActiveProperty(const struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index);
|
||||
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);
|
||||
|
||||
|
||||
@@ -114,74 +114,50 @@ void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra)
|
||||
}
|
||||
}
|
||||
|
||||
void uiAnimContextProperty(const bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index)
|
||||
{
|
||||
ARegion *ar= CTX_wm_region(C);
|
||||
uiBlock *block;
|
||||
uiBut *but;
|
||||
|
||||
memset(ptr, 0, sizeof(*ptr));
|
||||
*prop= NULL;
|
||||
*index= 0;
|
||||
|
||||
if(ar) {
|
||||
for(block=ar->uiblocks.first; block; block=block->next) {
|
||||
for(but=block->buttons.first; but; but= but->next) {
|
||||
if((but->active || but->flag & UI_BUT_LAST_ACTIVE) && but->rnapoin.data) {
|
||||
*ptr= but->rnapoin;
|
||||
*prop= but->rnaprop;
|
||||
*index= but->rnaindex;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ui_but_anim_insert_keyframe(bContext *C)
|
||||
{
|
||||
/* this operator calls uiAnimContextProperty above */
|
||||
/* this operator calls uiContextActiveProperty */
|
||||
WM_operator_name_call(C, "ANIM_OT_keyframe_insert_button", WM_OP_INVOKE_DEFAULT, NULL);
|
||||
}
|
||||
|
||||
void ui_but_anim_delete_keyframe(bContext *C)
|
||||
{
|
||||
/* this operator calls uiAnimContextProperty above */
|
||||
/* this operator calls uiContextActiveProperty */
|
||||
WM_operator_name_call(C, "ANIM_OT_keyframe_delete_button", WM_OP_INVOKE_DEFAULT, NULL);
|
||||
}
|
||||
|
||||
void ui_but_anim_add_driver(bContext *C)
|
||||
{
|
||||
/* this operator calls uiAnimContextProperty above */
|
||||
/* this operator calls uiContextActiveProperty */
|
||||
WM_operator_name_call(C, "ANIM_OT_driver_button_add", WM_OP_INVOKE_DEFAULT, NULL);
|
||||
}
|
||||
|
||||
void ui_but_anim_remove_driver(bContext *C)
|
||||
{
|
||||
/* this operator calls uiAnimContextProperty above */
|
||||
/* this operator calls uiContextActiveProperty */
|
||||
WM_operator_name_call(C, "ANIM_OT_driver_button_remove", WM_OP_INVOKE_DEFAULT, NULL);
|
||||
}
|
||||
|
||||
void ui_but_anim_copy_driver(bContext *C)
|
||||
{
|
||||
/* this operator calls uiAnimContextProperty above */
|
||||
/* this operator calls uiContextActiveProperty */
|
||||
WM_operator_name_call(C, "ANIM_OT_copy_driver_button", WM_OP_INVOKE_DEFAULT, NULL);
|
||||
}
|
||||
|
||||
void ui_but_anim_paste_driver(bContext *C)
|
||||
{
|
||||
/* this operator calls uiAnimContextProperty above */
|
||||
/* this operator calls uiContextActiveProperty */
|
||||
WM_operator_name_call(C, "ANIM_OT_paste_driver_button", WM_OP_INVOKE_DEFAULT, NULL);
|
||||
}
|
||||
|
||||
void ui_but_anim_add_keyingset(bContext *C)
|
||||
{
|
||||
/* this operator calls uiAnimContextProperty above */
|
||||
/* this operator calls uiContextActiveProperty */
|
||||
WM_operator_name_call(C, "ANIM_OT_keyingset_button_add", WM_OP_INVOKE_DEFAULT, NULL);
|
||||
}
|
||||
|
||||
void ui_but_anim_remove_keyingset(bContext *C)
|
||||
{
|
||||
/* this operator calls uiAnimContextProperty above */
|
||||
/* this operator calls uiContextActiveProperty */
|
||||
WM_operator_name_call(C, "ANIM_OT_keyingset_button_remove", WM_OP_INVOKE_DEFAULT, NULL);
|
||||
}
|
||||
|
||||
@@ -4255,6 +4255,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
|
||||
|
||||
static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event)
|
||||
{
|
||||
Scene *scene= CTX_data_scene(C);
|
||||
uiHandleButtonData *data;
|
||||
int retval;
|
||||
|
||||
@@ -4906,6 +4907,98 @@ 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)
|
||||
{
|
||||
ARegion *ar= CTX_wm_region(C);
|
||||
uiBlock *block;
|
||||
uiBut *but, *activebut;
|
||||
|
||||
memset(ptr, 0, sizeof(*ptr));
|
||||
*prop= NULL;
|
||||
*index= 0;
|
||||
|
||||
while(ar) {
|
||||
/* find active button */
|
||||
activebut= NULL;
|
||||
|
||||
for(block=ar->uiblocks.first; block; block=block->next) {
|
||||
for(but=block->buttons.first; but; but= but->next) {
|
||||
if(but->active)
|
||||
activebut= but;
|
||||
else if(!activebut && (but->flag & UI_BUT_LAST_ACTIVE))
|
||||
activebut= but;
|
||||
}
|
||||
}
|
||||
|
||||
if(activebut) {
|
||||
if(activebut->rnapoin.data) {
|
||||
/* found RNA button */
|
||||
*ptr= activebut->rnapoin;
|
||||
*prop= activebut->rnaprop;
|
||||
*index= activebut->rnaindex;
|
||||
return;
|
||||
}
|
||||
else {
|
||||
/* recurse into opened menu */
|
||||
uiHandleButtonData *data= activebut->active;
|
||||
if(data && data->menu)
|
||||
ar = data->menu->region;
|
||||
else
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* no active button */
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* helper function for insert keyframe, reset to default, etc operators */
|
||||
void uiContextAnimUpdate(const bContext *C)
|
||||
{
|
||||
Scene *scene= CTX_data_scene(C);
|
||||
ARegion *ar= CTX_wm_region(C);
|
||||
uiBlock *block;
|
||||
uiBut *but, *activebut;
|
||||
|
||||
while(ar) {
|
||||
/* find active button */
|
||||
activebut= NULL;
|
||||
|
||||
for(block=ar->uiblocks.first; block; block=block->next) {
|
||||
for(but=block->buttons.first; but; but= but->next) {
|
||||
ui_but_anim_flag(but, (scene)? scene->r.cfra: 0.0f);
|
||||
|
||||
if(but->active)
|
||||
activebut= but;
|
||||
else if(!activebut && (but->flag & UI_BUT_LAST_ACTIVE))
|
||||
activebut= but;
|
||||
}
|
||||
}
|
||||
|
||||
if(activebut) {
|
||||
if(activebut->rnapoin.data) {
|
||||
/* found RNA button */
|
||||
return;
|
||||
}
|
||||
else {
|
||||
/* recurse into opened menu */
|
||||
uiHandleButtonData *data= activebut->active;
|
||||
if(data && data->menu)
|
||||
ar = data->menu->region;
|
||||
else
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* no active button */
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/************** handle activating a button *************/
|
||||
|
||||
static uiBut *uit_but_find_open_event(ARegion *ar, wmEvent *event)
|
||||
|
||||
@@ -68,7 +68,7 @@ static int eyedropper_init(bContext *C, wmOperator *op)
|
||||
|
||||
op->customdata= eye= MEM_callocN(sizeof(Eyedropper), "Eyedropper");
|
||||
|
||||
uiAnimContextProperty(C, &eye->ptr, &eye->prop, &eye->index);
|
||||
uiContextActiveProperty(C, &eye->ptr, &eye->prop, &eye->index);
|
||||
|
||||
return (eye->ptr.data && eye->prop && RNA_property_editable(&eye->ptr, eye->prop));
|
||||
}
|
||||
@@ -228,7 +228,7 @@ static int copy_data_path_button_exec(bContext *C, wmOperator *op)
|
||||
int index;
|
||||
|
||||
/* try to create driver using property retrieved from UI */
|
||||
uiAnimContextProperty(C, &ptr, &prop, &index);
|
||||
uiContextActiveProperty(C, &ptr, &prop, &index);
|
||||
|
||||
if (ptr.id.data && ptr.data && prop) {
|
||||
path= RNA_path_from_ID_to_property(&ptr, prop);
|
||||
@@ -266,7 +266,7 @@ static int reset_default_button_poll(bContext *C)
|
||||
PropertyRNA *prop;
|
||||
int index;
|
||||
|
||||
uiAnimContextProperty(C, &ptr, &prop, &index);
|
||||
uiContextActiveProperty(C, &ptr, &prop, &index);
|
||||
|
||||
return (ptr.data && prop && RNA_property_editable(&ptr, prop));
|
||||
}
|
||||
@@ -279,7 +279,7 @@ static int reset_default_button_exec(bContext *C, wmOperator *op)
|
||||
int index, all = RNA_boolean_get(op->ptr, "all");
|
||||
|
||||
/* try to reset the nominated setting to its default value */
|
||||
uiAnimContextProperty(C, &ptr, &prop, &index);
|
||||
uiContextActiveProperty(C, &ptr, &prop, &index);
|
||||
|
||||
/* if there is a valid property that is editable... */
|
||||
if (ptr.data && prop && RNA_property_editable(&ptr, prop)) {
|
||||
@@ -335,7 +335,7 @@ static int copy_to_selected_button_poll(bContext *C)
|
||||
PropertyRNA *prop;
|
||||
int index, success= 0;
|
||||
|
||||
uiAnimContextProperty(C, &ptr, &prop, &index);
|
||||
uiContextActiveProperty(C, &ptr, &prop, &index);
|
||||
|
||||
if (ptr.data && prop) {
|
||||
CollectionPointerLink *link;
|
||||
@@ -361,7 +361,7 @@ static int copy_to_selected_button_exec(bContext *C, wmOperator *op)
|
||||
int index, all = RNA_boolean_get(op->ptr, "all");
|
||||
|
||||
/* try to reset the nominated setting to its default value */
|
||||
uiAnimContextProperty(C, &ptr, &prop, &index);
|
||||
uiContextActiveProperty(C, &ptr, &prop, &index);
|
||||
|
||||
/* if there is a valid property that is editable... */
|
||||
if (ptr.data && prop) {
|
||||
|
||||
Reference in New Issue
Block a user