Context: add "active_nla_track" & "active_nla_strip" context members

Selection was already accessible but not active.

Add utility functions:

- ANIM_nla_context_track to access the active track,
  following the convention of ANIM_nla_context_strip.

- ANIM_nla_context_*_ptr versions of these functions,
  needed to for creating context members to access the ID pointer.

Part of fix for T90723.
This commit is contained in:
Campbell Barton 2021-08-31 11:46:46 +10:00
parent 65739ded54
commit aabe6e3b45
4 changed files with 52 additions and 2 deletions

View File

@ -1047,6 +1047,8 @@ context_type_map = {
"active_pose_bone": ("PoseBone", False),
"active_sequence_strip": ("Sequence", False),
"active_editable_fcurve": ("FCurve", False),
"active_nla_strip": ("NlaStrip", False),
"active_nla_track": ("NlaTrack", False),
"annotation_data": ("GreasePencil", False),
"annotation_data_owner": ("ID", False),
"armature": ("Armature", False),

View File

@ -678,6 +678,11 @@ void ANIM_draw_framerange(struct Scene *scene, struct View2D *v2d);
/* ------------- UI Panel Drawing -------------- */
bool ANIM_nla_context_track_ptr(const struct bContext *C, struct PointerRNA *r_ptr);
bool ANIM_nla_context_strip_ptr(const struct bContext *C, struct PointerRNA *r_ptr);
struct NlaTrack *ANIM_nla_context_track(const struct bContext *C);
struct NlaStrip *ANIM_nla_context_strip(const struct bContext *C);
struct FCurve *ANIM_graph_context_fcurve(const struct bContext *C);

View File

@ -96,7 +96,9 @@ const char *screen_context_dir[] = {
"sequences",
"selected_sequences",
"selected_editable_sequences", /* sequencer */
"selected_nla_strips", /* nla editor */
"active_nla_track",
"active_nla_strip",
"selected_nla_strips", /* nla editor */
"gpencil_data",
"gpencil_data_owner", /* grease pencil data */
"annotation_data",
@ -664,6 +666,24 @@ static eContextResult screen_ctx_selected_editable_sequences(const bContext *C,
}
return CTX_RESULT_NO_DATA;
}
static eContextResult screen_ctx_active_nla_track(const bContext *C, bContextDataResult *result)
{
PointerRNA ptr;
if (ANIM_nla_context_track_ptr(C, &ptr)) {
CTX_data_pointer_set(result, ptr.owner_id, ptr.type, ptr.data);
return CTX_RESULT_OK;
}
return CTX_RESULT_NO_DATA;
}
static eContextResult screen_ctx_active_nla_strip(const bContext *C, bContextDataResult *result)
{
PointerRNA ptr;
if (ANIM_nla_context_strip_ptr(C, &ptr)) {
CTX_data_pointer_set(result, ptr.owner_id, ptr.type, ptr.data);
return CTX_RESULT_OK;
}
return CTX_RESULT_NO_DATA;
}
static eContextResult screen_ctx_selected_nla_strips(const bContext *C, bContextDataResult *result)
{
bAnimContext ac;
@ -1115,6 +1135,8 @@ static void ensure_ed_screen_context_functions(void)
register_context_function("sequences", screen_ctx_sequences);
register_context_function("selected_sequences", screen_ctx_selected_sequences);
register_context_function("selected_editable_sequences", screen_ctx_selected_editable_sequences);
register_context_function("active_nla_track", screen_ctx_active_nla_track);
register_context_function("active_nla_strip", screen_ctx_active_nla_strip);
register_context_function("selected_nla_strips", screen_ctx_selected_nla_strips);
register_context_function("gpencil_data", screen_ctx_gpencil_data);
register_context_function("gpencil_data_owner", screen_ctx_gpencil_data_owner);

View File

@ -185,10 +185,31 @@ bool nla_panel_context(const bContext *C,
return (found != 0);
}
bool ANIM_nla_context_track_ptr(const bContext *C, PointerRNA *r_ptr)
{
return nla_panel_context(C, NULL, r_ptr, NULL);
}
bool ANIM_nla_context_strip_ptr(const bContext *C, PointerRNA *r_ptr)
{
return nla_panel_context(C, NULL, NULL, r_ptr);
}
NlaTrack *ANIM_nla_context_track(const bContext *C)
{
PointerRNA track_ptr;
if (!ANIM_nla_context_track_ptr(C, &track_ptr)) {
return NULL;
}
NlaTrack *track = track_ptr.data;
return track;
}
NlaStrip *ANIM_nla_context_strip(const bContext *C)
{
PointerRNA strip_ptr;
if (!nla_panel_context(C, NULL, NULL, &strip_ptr)) {
if (!ANIM_nla_context_strip_ptr(C, &strip_ptr)) {
return NULL;
}
NlaStrip *strip = strip_ptr.data;