UI: show active tool in the topbar

This commit is contained in:
Campbell Barton 2018-04-27 10:49:20 +02:00
parent 3556838983
commit 868c9ac408
Notes: blender-bot 2023-02-14 08:58:01 +01:00
Referenced by issue #54900, Radial control drawing broken (offseted)
2 changed files with 55 additions and 0 deletions

View File

@ -283,6 +283,44 @@ class ToolSelectPanelHelper:
return (cls._tools[None], cls._tools.get(context.mode, ()))
@staticmethod
def _active_tool(context, with_icon=False):
"""
Return the active Python tool definition and icon name.
"""
workspace = context.workspace
space_type = workspace.tool_space_type
cls = next(
(cls for cls in ToolSelectPanelHelper.__subclasses__()
if cls.bl_space_type == space_type),
None
)
if cls is not None:
tool_def_active, index_active = ToolSelectPanelHelper._tool_vars_from_active_with_index(context)
context_mode = context.mode
for tool_items in cls.tools_from_context(context):
for item in cls._tools_flatten(tool_items):
tool_def, icon_name = cls._tool_vars_from_def(item, context_mode)
if (tool_def == tool_def_active):
if with_icon:
icon_value = ToolSelectPanelHelper._icon_value_from_icon_handle(icon_name)
else:
icon_value = 0
return (item, icon_value)
return None, 0
@staticmethod
def draw_active_tool_header(context, layout):
item, icon_value = ToolSelectPanelHelper._active_tool(context, with_icon=True)
if item is None:
layout.label("No Tool Found")
return
# Indent until we have better icon scaling.
layout.label(" " + item["text"], icon_value=icon_value)
# The purpose of this menu is to be a generic popup to select between tools
# in cases when a single tool allows to select alternative tools.
class WM_MT_toolsystem_submenu(Menu):

View File

@ -114,12 +114,29 @@ class TOPBAR_HT_lower_bar(Header):
layout = self.layout
layer = context.view_layer
object = layer.objects.active
# Object Mode
# -----------
object_mode = 'OBJECT' if object is None else object.mode
act_mode_item = bpy.types.Object.bl_rna.properties['mode'].enum_items[object_mode]
layout.operator_menu_enum("object.mode_set", "mode", text=act_mode_item.name, icon=act_mode_item.icon)
mode = context.mode
layout.separator()
# Active Tool
# -----------
from .space_toolsystem_common import ToolSelectPanelHelper
ToolSelectPanelHelper.draw_active_tool_header(context, layout)
layout.separator()
# Object Mode Options
# -------------------
# Example of how toolsettings can be accessed as pop-overs.
# TODO(campbell): editing options should be after active tool options