Fix #149926: Cannot activate tree view items using custom keymap

Keymaps that were exported and imported are handled as a completely new
base keymap, and don't get changes applied from the default keymap
(unlike keymaps simply stored in the Preferences, which are just
"diffs").

Such keymaps need versioning to get any important changes to the default
keymap. The activation & selection handling of tree-view items moved to
operators triggered by the keymap, so without the right keymap items
such basic functionality breaks.

Added versioning for both tree-view activation/selection and scrolling,
since they are crucial to be able to use tree-views.

Pull Request: https://projects.blender.org/blender/blender/pulls/150073
This commit is contained in:
Julian Eisel 2025-11-17 15:46:07 +01:00 • committed by Julian Eisel
parent 64daeac606
commit 4d6992bcce
2 changed files with 48 additions and 1 deletions

View file

@ -31,6 +31,11 @@ def keyconfig_update(keyconfig_data, keyconfig_version):
if km_name == "Transform Modal Map":
return km_items_data
def get_ui_keymap():
for km_name, _km_params, km_items_data in keyconfig_data:
if km_name == "User Interface":
return km_items_data
def remove_properties(op_prop_map):
nonlocal keyconfig_data
nonlocal has_copy
@ -278,4 +283,46 @@ def keyconfig_update(keyconfig_data, keyconfig_version):
item_prop["properties"][toggle_path_index] = (
"use_secondary", ".".join((*updated_path_elements, toggle_path_identifier)))
if keyconfig_version < (5, 0, 118):
has_view_select = False
has_view_scroll = False
if km_ui_items_data := get_ui_keymap():
for (item_op, _item_event, _item_prop) in km_ui_items_data["items"]:
if item_op == "ui.view_item_select":
has_view_select = True
if item_op == "ui.view_scroll":
has_view_scroll = True
if not has_view_select:
if not has_copy:
keyconfig_data = copy.deepcopy(keyconfig_data)
has_copy = True
km_ui_items_data = get_ui_keymap()
select_items = [
("ui.view_item_select", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None),
("ui.view_item_select", {"type": 'LEFTMOUSE', "value": 'PRESS', "ctrl": True},
{"properties": [("extend", True)]}),
("ui.view_item_select", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True},
{"properties": [("range_select", True)]}),
]
km_ui_items_data["items"].extend(select_items)
if not has_view_scroll:
if not has_copy:
keyconfig_data = copy.deepcopy(keyconfig_data)
has_copy = True
km_ui_items_data = get_ui_keymap()
scroll_items = [
("ui.view_scroll", {"type": 'WHEELUPMOUSE', "value": 'ANY'}, None),
("ui.view_scroll", {"type": 'WHEELDOWNMOUSE', "value": 'ANY'}, None),
("ui.view_scroll", {"type": 'TRACKPADPAN', "value": 'ANY'}, None),
]
km_ui_items_data["items"].extend(scroll_items)
else:
print("Error versioning keymap: Missing \"User Interface\" keymap")
return keyconfig_data

View file

@ -27,7 +27,7 @@
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
#define BLENDER_FILE_SUBVERSION 117
#define BLENDER_FILE_SUBVERSION 118
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and cancel loading the file, showing a warning to