UI: add search to popup toolbar
authorCampbell Barton <ideasman42@gmail.com>
Mon, 9 Jul 2018 15:36:25 +0000 (17:36 +0200)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 9 Jul 2018 15:37:15 +0000 (17:37 +0200)
Add for convenience only.

release/scripts/startup/bl_operators/wm.py
release/scripts/startup/bl_ui/space_toolsystem_common.py

index 30a90fb11d453f9c023268ef5a4aaf60ddd56984..a01298f5696a2df5a79b2802ffba430db9d1a4d8 100644 (file)
@@ -2398,6 +2398,10 @@ class WM_OT_toolbar(Operator):
 
         def draw_menu(popover, context):
             layout = popover.layout
+
+            layout.operator_context = 'INVOKE_DEFAULT'
+            layout.operator("wm.search_menu", text="Search Commands...", icon='VIEWZOOM')
+
             cls.draw_cls(layout, context, detect_layout=False, scale_y=1.0)
 
         wm.popover(draw_menu, ui_units_x=8, keymap=keymap)
index 2d7afb7a56a4905be94a0067bbecf004eaa8b165..7fe8360b4da982fd322fd06d1d20898247748bd3 100644 (file)
@@ -624,7 +624,10 @@ def keymap_from_context(context, space_type):
     """
     Keymap for popup toolbar, currently generated each time.
     """
+
+    use_search = False  # allows double tap
     use_simple_keymap = False
+
     km_name = "Toolbar Popup"
     wm = context.window_manager
     keyconf = wm.keyconfigs.active
@@ -634,6 +637,10 @@ def keymap_from_context(context, space_type):
     for kmi in keymap.keymap_items:
         keymap.keymap_items.remove(kmi)
 
+    if use_search:
+        kmi_search = wm.keyconfigs.find_item_from_operator(idname="wm.toolbar")[1]
+        kmi_search_type = None if not kmi_search else kmi_search.type
+
     items = []
     cls = ToolSelectPanelHelper._tool_class_from_space_type(space_type)
     for i, item in enumerate(
@@ -679,6 +686,16 @@ def keymap_from_context(context, space_type):
                     )
                     kmi.properties.name = item.text
 
+                    if use_search:
+                        # Disallow overlap
+                        if kmi_search_type == kmi_found_type:
+                            kmi_search_type = None
+
+    if use_search:
+        # Support double-tap for search.
+        if kmi_search_type:
+            keymap.keymap_items.new("wm.search_menu", type=kmi_search_type, value='PRESS')
+
     wm.keyconfigs.update()
     return keymap