diff options
author | Colin Basnett <cmbasnett> | 2022-04-14 12:30:12 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2022-04-14 12:30:12 +0300 |
commit | f1ae6952a86ba1b74e0b4a9d50e83d41b2019d1a (patch) | |
tree | debbbfc0872a01ee18b21848f97f662413828672 /source/blender | |
parent | d6e72412373e2f90969b2f2a6ecfcb420011784b (diff) |
Animation: Select markers before/after current frame
Add operator to select markers left/right of the current frame
(including the current frame).
`bpy.ops.marker.select_leftright(mode='LEFT', extend=False)`
`mode` can be either 'LEFT' or 'RIGHT'.
The naming and defaults of the above variables match similar operators
(e.g., `bpy.ops.nla.select_leftright`)
This also adds a new sub-menu to the Marker menu found in animation
editors, exposing both the new `bpy.ops.marker.select_leftright`
operator as well as the `bpy.ops.marker.select_all` operator.
Despite the name "Before Current Frame" and "After Current Frame", it
also selects a marker that falls on the current from for both of the
modes. This is to match the behavior found in the `nla.select_leftright`
operator.
RCS: https://blender.community/c/rightclickselect/OgmG/
Reviewed by: sybren, looch
Differential Revision: https://developer.blender.org/D14176
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/animation/anim_markers.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c index d7bbc0eab2b..1a3ab100768 100644 --- a/source/blender/editors/animation/anim_markers.c +++ b/source/blender/editors/animation/anim_markers.c @@ -1465,6 +1465,83 @@ static void MARKER_OT_select_all(wmOperatorType *ot) /** \} */ /* -------------------------------------------------------------------- */ +/** \name Select Left/Right of Frame + * \{ */ + +typedef enum eMarkers_LeftRightSelect_Mode { + MARKERS_LRSEL_LEFT = 0, + MARKERS_LRSEL_RIGHT, +} eMarkers_LeftRightSelect_Mode; + +static const EnumPropertyItem prop_markers_select_leftright_modes[] = { + {MARKERS_LRSEL_LEFT, "LEFT", 0, "Before Current Frame", ""}, + {MARKERS_LRSEL_RIGHT, "RIGHT", 0, "After Current Frame", ""}, + {0, NULL, 0, NULL, NULL}, +}; + +static void ED_markers_select_leftright(bAnimContext *ac, + const eMarkers_LeftRightSelect_Mode mode, + const bool extend) +{ + ListBase *markers = ac->markers; + Scene *scene = ac->scene; + + if (markers == NULL) { + return; + } + + if (!extend) { + deselect_markers(markers); + } + + LISTBASE_FOREACH (TimeMarker *, marker, markers) { + if ((mode == MARKERS_LRSEL_LEFT && marker->frame <= CFRA) || + (mode == MARKERS_LRSEL_RIGHT && marker->frame >= CFRA)) { + marker->flag |= SELECT; + } + } +} + +static int ed_marker_select_leftright_exec(bContext *C, wmOperator *op) +{ + const eMarkers_LeftRightSelect_Mode mode = RNA_enum_get(op->ptr, "mode"); + const bool extend = RNA_boolean_get(op->ptr, "extend"); + + bAnimContext ac; + if (ANIM_animdata_get_context(C, &ac) == 0) { + return OPERATOR_CANCELLED; + } + + ED_markers_select_leftright(&ac, mode, extend); + + WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); + + return OPERATOR_FINISHED; +} + +static void MARKER_OT_select_leftright(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Select Markers Before/After Current Frame"; + ot->description = "Select markers on and left/right of the current frame"; + ot->idname = "MARKER_OT_select_leftright"; + + /* api callbacks */ + ot->exec = ed_marker_select_leftright_exec; + ot->poll = ed_markers_poll_markers_exist; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* rna storage */ + RNA_def_enum( + ot->srna, "mode", prop_markers_select_leftright_modes, MARKERS_LRSEL_LEFT, "mode", "Mode"); + RNA_def_boolean(ot->srna, "extend", false, "extend", "Extend"); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ /** \name Remove Marker * * Remove selected time-markers. @@ -1735,6 +1812,7 @@ void ED_operatortypes_marker(void) WM_operatortype_append(MARKER_OT_select); WM_operatortype_append(MARKER_OT_select_box); WM_operatortype_append(MARKER_OT_select_all); + WM_operatortype_append(MARKER_OT_select_leftright); WM_operatortype_append(MARKER_OT_delete); WM_operatortype_append(MARKER_OT_rename); WM_operatortype_append(MARKER_OT_make_links_scene); |