Merge branch 'blender-v4.0-release'
[blender-addons.git] / power_sequencer / operators / grab.py
blobae3954b2df811d64e7be67634612635a3f503b00
1 # SPDX-FileCopyrightText: 2016-2020 by Nathan Lovato, Daniel Oakey, Razvan Radulescu, and contributors
3 # SPDX-License-Identifier: GPL-3.0-or-later
5 import bpy
7 from .utils.functions import get_mouse_frame_and_channel
8 from .utils.global_settings import SequenceTypes
9 from .utils.doc import doc_name, doc_idname, doc_brief, doc_description
12 class POWER_SEQUENCER_OT_grab(bpy.types.Operator):
13 """
14 *brief* Grab and move sequences. Extends Blender's built-in grab tool
17 Grab and move sequences. If you have no strips selected, it automatically
18 finds the strip closest to the mouse and selects it. If you only select
19 one or multiple crossfades, selects the handles on either side of the
20 crossfades before moving sequences, using POWER_SEQUENCER_OT_crossfade_edit
21 """
23 doc = {
24 "name": doc_name(__qualname__),
25 "demo": "",
26 "description": doc_description(__doc__),
27 "shortcuts": [({"type": "G", "value": "PRESS"}, {}, "")],
28 "keymap": "Sequencer",
30 bl_idname = doc_idname(__qualname__)
31 bl_label = doc["name"]
32 bl_description = doc_brief(doc["description"])
33 bl_options = {"REGISTER", "UNDO"}
35 @classmethod
36 def poll(cls, context):
37 return context.selected_sequences
39 def invoke(self, context, event):
40 frame, channel = get_mouse_frame_and_channel(context, event)
41 if not context.selected_sequences:
42 bpy.ops.power_sequencer.select_closest_to_mouse(frame=frame, channel=channel)
43 return self.execute(context)
45 def execute(self, context):
46 if len(context.selected_sequences) == 0:
47 return {"FINISHED"}
49 strip = context.selected_sequences[0]
50 if len(context.selected_sequences) == 1 and strip.type in SequenceTypes.TRANSITION:
51 context.scene.sequence_editor.active_strip = strip
52 return bpy.ops.power_sequencer.crossfade_edit()
53 else:
54 return bpy.ops.transform.seq_slide("INVOKE_DEFAULT")