Export_3ds: Improved distance cue node search
[blender-addons.git] / power_sequencer / operators / trim_left_or_right_handles.py
blobaf78b35780605ca6a495fa5d3959d55b01a8a622
1 # SPDX-FileCopyrightText: 2016-2020 by Nathan Lovato, Daniel Oakey, Razvan Radulescu, and contributors
3 # SPDX-License-Identifier: GPL-3.0-or-later
5 from operator import attrgetter
7 import bpy
9 from .utils.doc import doc_brief, doc_description, doc_idname, doc_name
12 class POWER_SEQUENCER_OT_trim_left_or_right_handles(bpy.types.Operator):
13 """
14 Trims or extends the handle closest to the time cursor for all selected strips.
16 If you keep the Shift key down, the edit will ripple through the timeline.
17 Auto selects sequences under the time cursor when you don't have a selection
18 """
20 doc = {
21 "name": doc_name(__qualname__),
22 "demo": "",
23 "description": doc_description(__doc__),
24 "shortcuts": [
26 {"type": "K", "value": "PRESS", "alt": True},
27 {"side": "RIGHT", "ripple": False},
28 "Smart Snap Right",
31 {"type": "K", "value": "PRESS", "alt": True, "shift": True},
32 {"side": "RIGHT", "ripple": True},
33 "Smart Snap Right With Ripple",
36 {"type": "K", "value": "PRESS", "ctrl": True},
37 {"side": "LEFT", "ripple": False},
38 "Smart Snap Left",
41 {"type": "K", "value": "PRESS", "ctrl": True, "shift": True},
42 {"side": "LEFT", "ripple": True},
43 "Smart Snap Left With Ripple",
46 "keymap": "Sequencer",
48 bl_idname = doc_idname(__qualname__)
49 bl_label = doc["name"]
50 bl_description = doc_brief(doc["description"])
51 bl_options = {"REGISTER", "UNDO"}
53 side: bpy.props.EnumProperty(
54 items=[("LEFT", "Left", "Left side"), ("RIGHT", "Right", "Right side")],
55 name="Snap side",
56 description="Handle side to use for the snap",
57 default="LEFT",
59 ripple: bpy.props.BoolProperty(name="Ripple", default=False)
61 @classmethod
62 def poll(cls, context):
63 return context.sequences
65 def execute(self, context):
66 frame_current = context.scene.frame_current
68 # Only select sequences under the time cursor
69 sequences = context.selected_sequences if context.selected_sequences else context.sequences
70 for s in sequences:
71 s.select = s.frame_final_start <= frame_current and s.frame_final_end >= frame_current
72 sequences = [s for s in sequences if s.select]
73 if not sequences:
74 return {"FINISHED"}
76 for s in sequences:
77 if self.side == "LEFT":
78 s.select_left_handle = True
79 if self.side == "RIGHT":
80 s.select_right_handle = True
82 # If trimming from the left, we need to save the start frame before trimming
83 ripple_start_frame = 0
84 if self.ripple and self.side == "LEFT":
85 ripple_start_frame = min(
86 sequences, key=attrgetter("frame_final_start")
87 ).frame_final_start
89 bpy.ops.sequencer.snap(frame=frame_current)
90 for s in sequences:
91 s.select_right_handle = False
92 s.select_left_handle = False
94 if self.ripple and sequences:
95 if self.side == "RIGHT":
96 ripple_start_frame = max(
97 sequences, key=attrgetter("frame_final_end")
98 ).frame_final_end
99 bpy.ops.power_sequencer.gap_remove(frame=ripple_start_frame)
100 else:
101 bpy.ops.power_sequencer.gap_remove(frame=ripple_start_frame)
103 return {"FINISHED"}