The pose library registered a double-click keymap item for the file
browser keymap, because that was the only way to add keymap items to the
asset browser (which is just the file browser under the hood). Since
450f428434, the pose library apply & blend operators are available in
more contexts, since their check for an active asset was moved from the
operator poll to the operator execution. So the pose apply operator
would end up triggering.
The poll function could be adjusted somehow to return false in this
case, e.g. by checking if it's executed from a file browser (not an
asset browser).
However, the operator should be independent of where it's called from.
So instead this registers a separate keymap for the asset browser, so
the pose library operators can be registered exclusively for the asset
browser.
30 lines
810 B
Python
30 lines
810 B
Python
# SPDX-FileCopyrightText: 2010-2023 Blender Foundation
|
|
#
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
from typing import List, Tuple
|
|
|
|
import bpy
|
|
|
|
addon_keymaps: List[Tuple[bpy.types.KeyMap, bpy.types.KeyMapItem]] = []
|
|
|
|
|
|
def register() -> None:
|
|
wm = bpy.context.window_manager
|
|
if wm.keyconfigs.addon is None:
|
|
# This happens when Blender is running in the background.
|
|
return
|
|
|
|
km = wm.keyconfigs.addon.keymaps.new(name="Asset Browser Main", space_type="FILE_BROWSER")
|
|
|
|
# DblClick to apply pose.
|
|
kmi = km.keymap_items.new("poselib.apply_pose_asset", "LEFTMOUSE", "DOUBLE_CLICK")
|
|
addon_keymaps.append((km, kmi))
|
|
|
|
|
|
def unregister() -> None:
|
|
# Clear shortcuts from the keymap.
|
|
for km, kmi in addon_keymaps:
|
|
km.keymap_items.remove(kmi)
|
|
addon_keymaps.clear()
|