[Bf-blender-cvs] [f1ae6952a86] master: Animation: Select markers before/after current frame

Colin Basnett noreply at git.blender.org
Thu Apr 14 11:32:01 CEST 2022


Commit: f1ae6952a86ba1b74e0b4a9d50e83d41b2019d1a
Author: Colin Basnett
Date:   Thu Apr 14 11:30:12 2022 +0200
Branches: master
https://developer.blender.org/rBf1ae6952a86ba1b74e0b4a9d50e83d41b2019d1a

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

===================================================================

M	release/scripts/startup/bl_ui/space_nla.py
M	release/scripts/startup/bl_ui/space_time.py
M	source/blender/editors/animation/anim_markers.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_nla.py b/release/scripts/startup/bl_ui/space_nla.py
index 99324ac5d50..961d6525a69 100644
--- a/release/scripts/startup/bl_ui/space_nla.py
+++ b/release/scripts/startup/bl_ui/space_nla.py
@@ -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,
diff --git a/release/scripts/startup/bl_ui/space_time.py b/release/scripts/startup/bl_ui/space_time.py
index b5b124253f3..13ab6e67b00 100644
--- a/release/scripts/startup/bl_ui/space_time.py
+++ b/release/scripts/startup/bl_ui/space_time.py
@@ -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()
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);



More information about the Bf-blender-cvs mailing list