Fix #34034: keyframe display of color/curve buttons was broken after revision

53132 which changed the RNA index to -1 for these. Also made it so that these
buttons no longer display "Insert Single Keyframe" and only "Insert Keyframe"
as you can't edit individual components here so it's only confusing.
This commit is contained in:
Brecht Van Lommel 2013-01-31 16:19:44 +00:00
parent 757546036c
commit 7b6e78e48a
2 changed files with 34 additions and 19 deletions

@ -57,7 +57,11 @@
static FCurve *ui_but_get_fcurve(uiBut *but, bAction **action, int *driven) static FCurve *ui_but_get_fcurve(uiBut *but, bAction **action, int *driven)
{ {
return rna_get_fcurve(&but->rnapoin, but->rnaprop, but->rnaindex, action, driven); /* for entire array buttons we check the first component, it's not perfect
* but works well enough in typical cases */
int rnaindex = (but->rnaindex == -1)? 0: but->rnaindex;
return rna_get_fcurve(&but->rnapoin, but->rnaprop, rnaindex, action, driven);
} }
void ui_but_anim_flag(uiBut *but, float cfra) void ui_but_anim_flag(uiBut *but, float cfra)
@ -131,6 +135,7 @@ int ui_but_anim_expression_create(uiBut *but, const char *str)
ID *id; ID *id;
FCurve *fcu; FCurve *fcu;
char *path; char *path;
int rnaindex;
short ok = 0; short ok = 0;
/* button must have RNA-pointer to a numeric-capable property */ /* button must have RNA-pointer to a numeric-capable property */
@ -140,6 +145,14 @@ int ui_but_anim_expression_create(uiBut *but, const char *str)
return 0; return 0;
} }
if (RNA_property_array_length(&but->rnapoin, but->rnaprop) != 0) {
if (but->rnaindex == -1) {
if (G.debug & G_DEBUG)
printf("ERROR: create expression failed - can't create expression for entire array\n");
return 0;
}
}
/* make sure we have animdata for this */ /* make sure we have animdata for this */
/* FIXME: until materials can be handled by depsgraph, don't allow drivers to be created for them */ /* FIXME: until materials can be handled by depsgraph, don't allow drivers to be created for them */
id = (ID *)but->rnapoin.id.data; id = (ID *)but->rnapoin.id.data;

@ -4752,7 +4752,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
{ {
uiPopupMenu *pup; uiPopupMenu *pup;
uiLayout *layout; uiLayout *layout;
int length; bool is_array, is_array_component;
const char *name; const char *name;
uiStringInfo label = {BUT_GET_LABEL, NULL}; uiStringInfo label = {BUT_GET_LABEL, NULL};
@ -4779,12 +4779,14 @@ static int ui_but_menu(bContext *C, uiBut *but)
if (is_anim) if (is_anim)
is_anim = RNA_property_path_from_ID_check(&but->rnapoin, but->rnaprop); is_anim = RNA_property_path_from_ID_check(&but->rnapoin, but->rnaprop);
length = RNA_property_array_length(&but->rnapoin, but->rnaprop); /* determine if we can key a single component of an array */
is_array = RNA_property_array_length(&but->rnapoin, but->rnaprop) != 0;
is_array_component = (is_array && but->rnaindex != -1);
/* Keyframes */ /* Keyframes */
if (but->flag & UI_BUT_ANIMATED_KEY) { if (but->flag & UI_BUT_ANIMATED_KEY) {
/* replace/delete keyfraemes */ /* replace/delete keyfraemes */
if (length) { if (is_array_component) {
uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Replace Keyframes"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Replace Keyframes"),
ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 1); ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 1);
uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Replace Single Keyframe"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Replace Single Keyframe"),
@ -4796,9 +4798,9 @@ static int ui_but_menu(bContext *C, uiBut *but)
} }
else { else {
uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Replace Keyframe"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Replace Keyframe"),
ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 0); ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 1);
uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Delete Keyframe"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Delete Keyframe"),
ICON_NONE, "ANIM_OT_keyframe_delete_button", "all", 0); ICON_NONE, "ANIM_OT_keyframe_delete_button", "all", 1);
} }
/* keyframe settings */ /* keyframe settings */
@ -4810,7 +4812,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
/* pass */ /* pass */
} }
else if (is_anim) { else if (is_anim) {
if (length) { if (is_array_component) {
uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Insert Keyframes"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Insert Keyframes"),
ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 1); ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 1);
uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Insert Single Keyframe"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Insert Single Keyframe"),
@ -4818,12 +4820,12 @@ static int ui_but_menu(bContext *C, uiBut *but)
} }
else { else {
uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Insert Keyframe"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Insert Keyframe"),
ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 0); ICON_NONE, "ANIM_OT_keyframe_insert_button", "all", 1);
} }
} }
if (but->flag & UI_BUT_ANIMATED) { if (but->flag & UI_BUT_ANIMATED) {
if (length) { if (is_array_component) {
uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Clear Keyframes"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Clear Keyframes"),
ICON_NONE, "ANIM_OT_keyframe_clear_button", "all", 1); ICON_NONE, "ANIM_OT_keyframe_clear_button", "all", 1);
uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Clear Single Keyframes"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Clear Single Keyframes"),
@ -4831,7 +4833,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
} }
else { else {
uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Clear Keyframes"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Clear Keyframes"),
ICON_NONE, "ANIM_OT_keyframe_clear_button", "all", 0); ICON_NONE, "ANIM_OT_keyframe_clear_button", "all", 1);
} }
} }
@ -4839,7 +4841,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
if (but->flag & UI_BUT_DRIVEN) { if (but->flag & UI_BUT_DRIVEN) {
uiItemS(layout); uiItemS(layout);
if (length) { if (is_array_component) {
uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Delete Drivers"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Delete Drivers"),
ICON_NONE, "ANIM_OT_driver_button_remove", "all", 1); ICON_NONE, "ANIM_OT_driver_button_remove", "all", 1);
uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Delete Single Driver"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Delete Single Driver"),
@ -4847,7 +4849,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
} }
else { else {
uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Delete Driver"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Delete Driver"),
ICON_NONE, "ANIM_OT_driver_button_remove", "all", 0); ICON_NONE, "ANIM_OT_driver_button_remove", "all", 1);
} }
uiItemO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Copy Driver"), uiItemO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Copy Driver"),
@ -4863,7 +4865,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
else if (is_anim) { else if (is_anim) {
uiItemS(layout); uiItemS(layout);
if (length) { if (is_array_component) {
uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add Drivers"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add Drivers"),
ICON_NONE, "ANIM_OT_driver_button_add", "all", 1); ICON_NONE, "ANIM_OT_driver_button_add", "all", 1);
uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add Single Driver"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add Single Driver"),
@ -4871,7 +4873,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
} }
else { else {
uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add Driver"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add Driver"),
ICON_NONE, "ANIM_OT_driver_button_add", "all", 0); ICON_NONE, "ANIM_OT_driver_button_add", "all", 1);
} }
if (ANIM_driver_can_paste()) { if (ANIM_driver_can_paste()) {
@ -4885,7 +4887,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
if (is_anim) { if (is_anim) {
uiItemS(layout); uiItemS(layout);
if (length) { if (is_array_component) {
uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add All to Keying Set"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add All to Keying Set"),
ICON_NONE, "ANIM_OT_keyingset_button_add", "all", 1); ICON_NONE, "ANIM_OT_keyingset_button_add", "all", 1);
uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add Single to Keying Set"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add Single to Keying Set"),
@ -4895,7 +4897,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
} }
else { else {
uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add to Keying Set"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add to Keying Set"),
ICON_NONE, "ANIM_OT_keyingset_button_add", "all", 0); ICON_NONE, "ANIM_OT_keyingset_button_add", "all", 1);
uiItemO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Remove from Keying Set"), uiItemO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Remove from Keying Set"),
ICON_NONE, "ANIM_OT_keyingset_button_remove"); ICON_NONE, "ANIM_OT_keyingset_button_remove");
} }
@ -4908,15 +4910,15 @@ static int ui_but_menu(bContext *C, uiBut *but)
/* Copy Property Value /* Copy Property Value
* Paste Property Value */ * Paste Property Value */
if (length) { if (is_array_component) {
uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Reset All to Default Values"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Reset All to Default Values"),
ICON_NONE, "UI_OT_reset_default_button", "all", 1); ICON_NONE, "UI_OT_reset_default_button", "all", 1);
uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Reset Single to Default Value"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Reset Single to Default Value"),
ICON_NONE, "UI_OT_reset_default_button", "all", 0); ICON_NONE, "UI_OT_reset_default_button", "all", 0);
} }
else { else {
uiItemO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Reset to Default Value"), uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Reset to Default Value"),
ICON_NONE, "UI_OT_reset_default_button"); ICON_NONE, "UI_OT_reset_default_button", "all", 1);
} }
uiItemO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Copy Data Path"), uiItemO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Copy Data Path"),