diff options
Diffstat (limited to 'release/scripts/startup/bl_ui/space_toolsystem_common.py')
-rw-r--r-- | release/scripts/startup/bl_ui/space_toolsystem_common.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py index 1d401ebd2c9..e7e95c26b55 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_common.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py @@ -296,6 +296,45 @@ class ToolSelectPanelHelper: return None, None, -1 @staticmethod + def _tool_get_by_flat_index(context, space_type, tool_index): + """ + Return the active Python tool definition and index (if in sub-group, else -1). + + Return the index of the expanded list. + """ + cls = ToolSelectPanelHelper._tool_class_from_space_type(space_type) + if cls is not None: + i = 0 + for item, index in ToolSelectPanelHelper._tools_flatten_with_tool_index(cls.tools_from_context(context)): + if item is not None: + if i == tool_index: + return (cls, item, index) + i += 1 + return None, None, -1 + + @staticmethod + def _tool_get_by_index(context, space_type, tool_index): + """ + Return the active Python tool definition and index (if in sub-group, else -1). + + Return the index of the list without expanding. + """ + cls = ToolSelectPanelHelper._tool_class_from_space_type(space_type) + if cls is not None: + i = 0 + for item in cls.tools_from_context(context): + if item is not None: + if i == tool_index: + if type(item) is tuple: + index = cls._tool_group_active.get(item[0].idname, 0) + item = item[index] + else: + index = -1 + return (cls, item, index) + i += 1 + return None, None, -1 + + @staticmethod def _tool_active_from_context(context, space_type, mode=None, create=False): if space_type == 'VIEW_3D': if mode is None: @@ -772,6 +811,16 @@ def item_from_id(context, space_type, idname): return item +def item_from_flat_index(context, space_type, index): + _cls, item, _index = ToolSelectPanelHelper._tool_get_by_flat_index(context, space_type, index) + return item + + +def item_from_index(context, space_type, index): + _cls, item, _index = ToolSelectPanelHelper._tool_get_by_index(context, space_type, index) + return item + + def keymap_from_id(context, space_type, idname): # Used directly for tooltips. _cls, item, _index = ToolSelectPanelHelper._tool_get_by_id(context, space_type, idname) |