From f1ae6952a86ba1b74e0b4a9d50e83d41b2019d1a Mon Sep 17 00:00:00 2001 From: Colin Basnett Date: Thu, 14 Apr 2022 11:30:12 +0200 Subject: 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 --- source/blender/editors/animation/anim_markers.c | 78 +++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'source/blender/editors/animation') 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 @@ -1464,6 +1464,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 * @@ -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); -- cgit v1.2.3