diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-05-13 11:01:56 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-05-13 11:01:56 +0300 |
commit | e7ee9cfd9e510561d87d2fd974a9f336e7eb32eb (patch) | |
tree | e6a630e10e307d11b0c563154b0cce03873116af /release | |
parent | e1772dac7065c92859a1db40ccb569b570b0159a (diff) |
Tool System: tools are now set by name
This avoids having to store the tool definition in the operator
properties (on redraw).
Now just set the name, note this means we can't show the keymap in the
tool-tip anymore. This will eventually be shown in the status bar.
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/startup/bl_ui/space_toolsystem_common.py | 53 |
1 files changed, 16 insertions, 37 deletions
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py index ee2f11c46d0..84c9b57f590 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_common.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py @@ -295,16 +295,8 @@ class ToolSelectPanelHelper: ) @staticmethod - def _tool_vars_from_button_with_index(context): - props = context.button_operator - return ( - ( - props.keymap or None or None, - props.manipulator_group or None, - props.data_block or None, - ), - props.index, - ) + def _tool_text_from_button(context): + return context.button_operator.name @classmethod def _km_action_simple(cls, kc, context_mode, text, keymap_fn): @@ -500,24 +492,20 @@ class ToolSelectPanelHelper: sub = ui_gen.send(False) if use_menu: - props = sub.operator_menu_hold( - "wm.tool_set", + sub.operator_menu_hold( + "wm.tool_set_by_name", text=item.text if show_text else "", depress=is_active, menu="WM_MT_toolsystem_submenu", icon_value=icon_value, - ) + ).name = item.text else: - props = sub.operator( - "wm.tool_set", + sub.operator( + "wm.tool_set_by_name", text=item.text if show_text else "", depress=is_active, icon_value=icon_value, - ) - props.keymap = tool_def[0] or "" - props.manipulator_group = tool_def[1] or "" - props.data_block = tool_def[2] or "" - props.index = index + ).name = item.text # Signal to finish any remaining layout edits. ui_gen.send(None) @@ -544,29 +532,25 @@ class WM_MT_toolsystem_submenu(Menu): # Lookup the tool definitions based on the space-type. cls = ToolSelectPanelHelper._tool_class_from_space_type(context.space_data.type) if cls is not None: - tool_def_button, index_button = ToolSelectPanelHelper._tool_vars_from_button_with_index(context) + button_text = ToolSelectPanelHelper._tool_text_from_button(context) for item_group in cls.tools_from_context(context): if type(item_group) is tuple: - if index_button < len(item_group): - item = item_group[index_button] - tool_def, icon_name = ToolSelectPanelHelper._tool_vars_from_def(item, context_mode) - is_active = (tool_def == tool_def_button) - if is_active: - return cls, item_group, index_button - return None, None, -1 + for sub_item in item_group: + if sub_item.text == button_text: + return cls, item_group + return None, None def draw(self, context): context_mode = context.mode layout = self.layout layout.scale_y = 2.0 - cls, item_group, index_active = self._tool_group_from_button(context) + cls, item_group = self._tool_group_from_button(context) if item_group is None: # Should never happen, just in case layout.label("Unable to find toolbar group") return - index = 0 for item in item_group: if item is None: layout.separator() @@ -574,15 +558,10 @@ class WM_MT_toolsystem_submenu(Menu): tool_def, icon_name = ToolSelectPanelHelper._tool_vars_from_def(item, context_mode) icon_value = ToolSelectPanelHelper._icon_value_from_icon_handle(icon_name) props = layout.operator( - "wm.tool_set", + "wm.tool_set_by_name", text=item.text, icon_value=icon_value, - ) - props.keymap = tool_def[0] or "" - props.manipulator_group = tool_def[1] or "" - props.data_block = tool_def[2] or "" - props.index = index - index += 1 + ).name = item.text def activate_by_name(context, text): |