Merge branch 'blender-v4.0-release'
[blender-addons.git] / power_sequencer / operators / select_linked_strips.py
blob1b5e52c47d1f25e4b3dfa874fc9f4cc505a8c22b
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.doc import doc_name, doc_idname, doc_brief, doc_description
10 class POWER_SEQUENCER_OT_select_linked_strips(bpy.types.Operator):
11 """
12 Add/Remove linked strips near mouse pointer to/from selection without the need to
13 previously have clicked/manually selected
14 """
16 doc = {
17 "name": doc_name(__qualname__),
18 "demo": "",
19 "description": doc_description(__doc__),
20 "shortcuts": [({"type": "L", "value": "PRESS"}, {}, "Add/Remove Linked to/from Selection")],
21 "keymap": "Sequencer",
23 bl_idname = doc_idname(__qualname__)
24 bl_label = doc["name"]
25 bl_description = doc_brief(doc["description"])
26 bl_options = {"UNDO"}
28 @classmethod
29 def poll(cls, context):
30 return context.scene.sequence_editor
32 def execute(self, context):
33 # save current selection first
34 selection = set(context.selected_sequences)
36 # if previously selected strips are linked select links as well to toggle them too
37 bpy.ops.sequencer.select_linked()
38 selection_new = set(context.selected_sequences).difference(selection)
39 # deselect & select only the linked strips near mouse pointer
40 bpy.ops.sequencer.select_all(action="DESELECT")
41 # re-enable linked + add selection near mouse pointer
42 for s in selection_new:
43 s.select = True
44 bpy.ops.sequencer.select_linked()
45 bpy.ops.sequencer.select_linked_pick("INVOKE_DEFAULT", extend=True)
46 selection_new = set(context.selected_sequences)
48 # identify if linked strips under mouse pointer need to be added or removed
49 action = len(selection.intersection(selection_new)) != len(selection_new)
51 # re-enable previous selection
52 for s in selection:
53 s.select = True
55 # take care of toggle for strips under mouse
56 for s in selection_new:
57 s.select = action
58 return {"FINISHED"}