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
This commit is contained in:
Colin Basnett 2022-04-14 11:30:12 +02:00 committed by Sybren A. Stüvel
parent d6e7241237
commit f1ae6952a8
3 changed files with 100 additions and 0 deletions

View File

@ -150,6 +150,23 @@ class NLA_MT_marker(Menu):
marker_menu_generic(layout, context)
class NLA_MT_marker_select(Menu):
bl_label = 'Select'
def draw(self, context):
layout = self.layout
layout.operator("marker.select_all", text="All").action = 'SELECT'
layout.operator("marker.select_all", text="None").action = 'DESELECT'
layout.operator("marker.select_all", text="Invert").action = 'INVERT'
layout.separator()
layout.operator("marker.select_leftright", text="Before Current Frame").mode = 'LEFT'
layout.operator("marker.select_leftright", text="After Current Frame").mode = 'RIGHT'
class NLA_MT_edit(Menu):
bl_label = "Edit"
@ -312,6 +329,7 @@ classes = (
NLA_MT_view,
NLA_MT_select,
NLA_MT_marker,
NLA_MT_marker_select,
NLA_MT_add,
NLA_MT_edit_transform,
NLA_MT_snap_pie,

View File

@ -194,6 +194,10 @@ def marker_menu_generic(layout, context):
layout.separator()
layout.menu('NLA_MT_marker_select')
layout.separator()
layout.operator("marker.camera_bind")
layout.separator()

View File

@ -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);