forked from bartvdbraak/blender
Cleanup: de-duplicate active tool panel
This commit is contained in:
parent
6eacb626e0
commit
d09289ff7a
@ -37,6 +37,10 @@ from .properties_paint_common import (
|
||||
from .properties_grease_pencil_common import (
|
||||
AnnotationDataPanel,
|
||||
)
|
||||
from .space_toolsystem_common import (
|
||||
ToolActivePanelHelper,
|
||||
)
|
||||
|
||||
from bpy.app.translations import pgettext_iface as iface_
|
||||
|
||||
|
||||
@ -55,24 +59,11 @@ class BrushButtonsPanel(UnifiedPaintPanel):
|
||||
return tool_settings.brush
|
||||
|
||||
|
||||
class IMAGE_PT_active_tool(Panel):
|
||||
class IMAGE_PT_active_tool(ToolActivePanelHelper, Panel):
|
||||
bl_space_type = 'IMAGE_EDITOR'
|
||||
bl_region_type = 'UI'
|
||||
bl_label = "Active Tool"
|
||||
bl_category = "Tool"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
# Panel display of topbar tool settings.
|
||||
# currently displays in tool settings, keep here since the same functionality is used for the topbar.
|
||||
|
||||
layout.use_property_split = True
|
||||
layout.use_property_decorate = False
|
||||
|
||||
from .space_toolsystem_common import ToolSelectPanelHelper
|
||||
ToolSelectPanelHelper.draw_active_tool_header(context, layout, show_tool_name=True)
|
||||
|
||||
|
||||
class IMAGE_MT_view(Menu):
|
||||
bl_label = "View"
|
||||
|
@ -147,6 +147,25 @@ ToolDef.from_fn = from_fn
|
||||
del from_dict, from_fn, with_args
|
||||
|
||||
|
||||
class ToolActivePanelHelper:
|
||||
# Sub-class must define.
|
||||
# bl_space_type = 'VIEW_3D'
|
||||
# bl_region_type = 'UI'
|
||||
bl_label = "Active Tool"
|
||||
# bl_category = "Tool"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.use_property_split = True
|
||||
layout.use_property_decorate = False
|
||||
ToolSelectPanelHelper.draw_active_tool_header(
|
||||
context,
|
||||
layout,
|
||||
show_tool_name=True,
|
||||
tool_key=ToolSelectPanelHelper._tool_key_from_context(context, space_type=self.bl_space_type),
|
||||
)
|
||||
|
||||
|
||||
class ToolSelectPanelHelper:
|
||||
"""
|
||||
Generic Class, can be used for any toolbar.
|
||||
@ -544,12 +563,16 @@ class ToolSelectPanelHelper:
|
||||
self.draw_cls(self.layout, context)
|
||||
|
||||
@staticmethod
|
||||
def _tool_key_from_context(context):
|
||||
space_data = context.space_data
|
||||
space_type = space_data.type
|
||||
def _tool_key_from_context(context, *, space_type=None):
|
||||
if space_type is None:
|
||||
space_data = context.space_data
|
||||
space_type = space_data.type
|
||||
|
||||
if space_type == 'VIEW_3D':
|
||||
return space_type, context.mode
|
||||
elif space_type == 'IMAGE_EDITOR':
|
||||
if space_type is None:
|
||||
space_data = context.space_data
|
||||
return space_type, space_data.mode
|
||||
elif space_type == 'NODE_EDITOR':
|
||||
return space_type, None
|
||||
|
@ -608,33 +608,6 @@ class TOPBAR_MT_workspace_menu(Menu):
|
||||
props.direction = 'NEXT'
|
||||
|
||||
|
||||
class TOPBAR_PT_active_tool(Panel):
|
||||
bl_space_type = 'PROPERTIES'
|
||||
bl_region_type = 'WINDOW'
|
||||
bl_category = ""
|
||||
bl_context = ".active_tool" # dot on purpose (access from tool settings)
|
||||
bl_label = "Active Tool"
|
||||
bl_options = {'HIDE_HEADER'}
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
tool_mode = context.mode
|
||||
|
||||
# Panel display of topbar tool settings.
|
||||
# currently displays in tool settings, keep here since the same functionality is used for the topbar.
|
||||
|
||||
layout.use_property_split = True
|
||||
layout.use_property_decorate = False
|
||||
|
||||
from .space_toolsystem_common import ToolSelectPanelHelper
|
||||
ToolSelectPanelHelper.draw_active_tool_header(
|
||||
context,
|
||||
layout,
|
||||
show_tool_name=True,
|
||||
tool_key=('VIEW_3D', tool_mode),
|
||||
)
|
||||
|
||||
|
||||
# Grease Pencil Object - Primitive curve
|
||||
class TOPBAR_PT_gpencil_primitive(Panel):
|
||||
bl_space_type = 'VIEW_3D'
|
||||
@ -751,7 +724,6 @@ classes = (
|
||||
TOPBAR_MT_render,
|
||||
TOPBAR_MT_window,
|
||||
TOPBAR_MT_help,
|
||||
TOPBAR_PT_active_tool,
|
||||
TOPBAR_PT_gpencil_layers,
|
||||
TOPBAR_PT_gpencil_primitive,
|
||||
TOPBAR_PT_gpencil_fill,
|
||||
|
@ -31,6 +31,9 @@ from .properties_grease_pencil_common import (
|
||||
AnnotationOnionSkin,
|
||||
GreasePencilMaterialsPanel,
|
||||
)
|
||||
from .space_toolsystem_common import (
|
||||
ToolActivePanelHelper,
|
||||
)
|
||||
from bpy.app.translations import contexts as i18n_contexts
|
||||
|
||||
|
||||
@ -4712,30 +4715,10 @@ class VIEW3D_MT_proportional_editing_falloff_pie(Menu):
|
||||
# ********** Panel **********
|
||||
|
||||
|
||||
class VIEW3D_PT_active_tool(Panel):
|
||||
class VIEW3D_PT_active_tool(Panel, ToolActivePanelHelper):
|
||||
bl_space_type = 'VIEW_3D'
|
||||
bl_region_type = 'UI'
|
||||
bl_label = "Active Tool"
|
||||
bl_category = "Tool"
|
||||
# bl_context = ".active_tool" # dot on purpose (access from tool settings)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
tool_mode = context.mode
|
||||
|
||||
# Panel display of topbar tool settings.
|
||||
# currently displays in tool settings, keep here since the same functionality is used for the topbar.
|
||||
|
||||
layout.use_property_split = True
|
||||
layout.use_property_decorate = False
|
||||
|
||||
from .space_toolsystem_common import ToolSelectPanelHelper
|
||||
ToolSelectPanelHelper.draw_active_tool_header(
|
||||
context,
|
||||
layout,
|
||||
show_tool_name=True,
|
||||
tool_key=('VIEW_3D', tool_mode),
|
||||
)
|
||||
|
||||
|
||||
class VIEW3D_PT_view3d_properties(Panel):
|
||||
|
Loading…
Reference in New Issue
Block a user