[Bf-blender-cvs] [48ad67f4a3b] blender2.8: Tool System: support for 'dropping' tools

Campbell Barton noreply at git.blender.org
Mon Nov 12 03:18:05 CET 2018


Commit: 48ad67f4a3bc41954fb3196b5e6923d025d2efc6
Author: Campbell Barton
Date:   Mon Nov 12 12:44:49 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB48ad67f4a3bc41954fb3196b5e6923d025d2efc6

Tool System: support for 'dropping' tools

While there is no support for dropping tools exactly,
the cursor tool supports a keyboard oriented workflow
which is often over-ridden by other tools key-maps

While many tools had shortcuts there was no fast way to get back to
the cursor tool.

Now double-tapping space sets the cursor tool
(as long as this tool doesn't have a key mapped).

===================================================================

M	release/scripts/startup/bl_ui/space_toolsystem_common.py

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py
index efbf6b167ec..8a84f2d7d3c 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_common.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py
@@ -744,6 +744,18 @@ def keymap_from_context(context, space_type):
 
     use_simple_keymap = False
 
+    # Press the toolbar popup key again to set the default tool,
+    # this is useful because the cursor tool is useful as a way
+    # to 'drop' currently active tools (it's basically a 'none' tool).
+    # so this allows us to quickly go back to a state that allows
+    # a shortcut based workflow (before the tool system was added).
+    use_tap_reset = True
+    # TODO: support other tools for modes which don't use the cursor.
+    tap_reset_tool = "Cursor"
+    # Check the tool is available in the current context.
+    if ToolSelectPanelHelper._tool_get_by_name(context, space_type, tap_reset_tool)[1] is None:
+        use_tap_reset = False
+
     # Pie-menu style release to activate.
     use_release_confirm = True
 
@@ -782,11 +794,45 @@ def keymap_from_context(context, space_type):
         kmi_hack_brush_select = keymap.keymap_items.new("paint.brush_select", 'A', 'PRESS')
         kmi_hack_brush_select_properties = kmi_hack_brush_select.properties
 
-    if use_release_confirm:
+    if use_release_confirm or use_tap_reset:
         kmi_toolbar = wm.keyconfigs.find_item_from_operator(idname="wm.toolbar")[1]
         kmi_toolbar_type = None if not kmi_toolbar else kmi_toolbar.type
+        if use_tap_reset and kmi_toolbar_type is not None:
+            kmi_toolbar_args = {
+                "type": kmi_toolbar_type,
+                **modifier_keywords_from_item(kmi_toolbar),
+            }
+        else:
+            use_tap_reset = False
         del kmi_toolbar
 
+    if use_tap_reset:
+        kmi_found = None
+        if use_hack_properties:
+            # First check for direct assignment, if this tool already has a key, no need to add a new one.
+            kmi_hack_properties.name = tap_reset_tool
+            kmi_found = wm.keyconfigs.find_item_from_operator(
+                idname="wm.tool_set_by_name",
+                context='INVOKE_REGION_WIN',
+                # properties={"name": item.text},
+                properties=kmi_hack_properties,
+            )[1]
+            if kmi_found:
+                use_tap_reset = False
+        del kmi_found
+
+    if use_tap_reset:
+        kmi_toolbar_tuple = dict_as_tuple(kmi_toolbar_args)
+        if kmi_toolbar_tuple not in kmi_unique_args:
+            kmi = keymap.keymap_items.new(
+                "wm.tool_set_by_name",
+                value='DOUBLE_CLICK',
+                **kmi_toolbar_args,
+            )
+            kmi.properties.name = tap_reset_tool
+        kmi_unique_args.add(kmi_toolbar_tuple)
+        del kmi_toolbar_tuple
+
     if use_simple_keymap:
         # Simply assign a key from A-Z.
         for i, (item, _, _) in enumerate(items_all):



More information about the Bf-blender-cvs mailing list