diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-07-03 19:33:52 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-07-03 19:38:08 +0300 |
commit | 81a23d1f2db5d3c21e3c35cf3128f5e6326df54a (patch) | |
tree | abb1e5a5866d6928d1ad1ed5406d8b84299cc249 | |
parent | 51acd547605a9c3b1644fba9d6e3168e37973c68 (diff) |
Tool System: add operator for introspection
In some cases we want associate use an operator for a tool
for introspection, so we can for eg, automatically
use the same binding for in the popup toolbar.
Space-G/R/S for transform now work as accelerator keys again.
Also Space-E for extrude.
4 files changed, 32 insertions, 11 deletions
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py index 20db56af416..2d7afb7a56a 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_common.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py @@ -88,6 +88,8 @@ ToolDef = namedtuple( # Optional data-block assosiated with this tool. # (Typically brush name, usage depends on mode, we could use for non-brush ID's in other modes). "data_block", + # Optional primary operator (for introspection only). + "operator", # Optional draw settings (operator options, toolsettings). "draw_settings", ) @@ -107,6 +109,7 @@ def from_dict(kw_args): "widget": None, "keymap": None, "data_block": None, + "operator": None, "draw_settings": None, } kw.update(kw_args) @@ -568,6 +571,7 @@ def _activate_by_item(context, space_type, item, index): cursor=item.cursor or 'DEFAULT', manipulator_group=item.widget or "", data_block=item.data_block or "", + operator=item.operator or "", index=index, ) @@ -643,15 +647,21 @@ def keymap_from_context(context, space_type): kmi.properties.name = item.text continue - if not item.keymap: - continue - # Only check the first item in the tools key-map (a little arbitrary). - kmi_first = item.keymap[0].keymap_items[0] - kmi_found = wm.keyconfigs.find_item_from_operator( - idname=kmi_first.idname, - # properties=kmi_first.properties, # prevents matches, don't use. - )[1] + if item.operator is not None: + kmi_found = wm.keyconfigs.find_item_from_operator( + idname=item.operator, + )[1] + elif item.keymap is not None: + kmi_first = item.keymap[0].keymap_items[0] + kmi_found = wm.keyconfigs.find_item_from_operator( + idname=kmi_first.idname, + # properties=kmi_first.properties, # prevents matches, don't use. + )[1] + del kmi_first + else: + kmi_found = None + if kmi_found is not None: kmi_found_type = kmi_found.type # Only for single keys. diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py index a6e1d511b4c..b0bff84b8eb 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py @@ -134,6 +134,7 @@ class _defs_transform: # cursor='SCROLL_XY', icon="ops.transform.translate", widget="TRANSFORM_WGT_manipulator", + operator="transform.translate", # TODO, implement as optional fallback manipulator # keymap=( # ("transform.translate", dict(release_confirm=True), dict(type='EVT_TWEAK_A', value='ANY')), @@ -147,6 +148,7 @@ class _defs_transform: # cursor='SCROLL_XY', icon="ops.transform.rotate", widget="TRANSFORM_WGT_manipulator", + operator="transform.rotate", # TODO, implement as optional fallback manipulator # keymap=( # ("transform.rotate", dict(release_confirm=True), dict(type='EVT_TWEAK_A', value='ANY')), @@ -160,6 +162,7 @@ class _defs_transform: # cursor='SCROLL_XY', icon="ops.transform.resize", widget="TRANSFORM_WGT_manipulator", + operator="transform.resize", # TODO, implement as optional fallback manipulator # keymap=( # ("transform.resize", dict(release_confirm=True), dict(type='EVT_TWEAK_A', value='ANY')), @@ -172,6 +175,7 @@ class _defs_transform: text="Scale Cage", icon="ops.transform.resize.cage", widget="VIEW3D_WGT_xform_cage", + operator="transform.resize", ) @ToolDef.from_fn @@ -459,6 +463,7 @@ class _defs_edit_mesh: text="Extrude Region", icon="ops.mesh.extrude_region_move", widget="MESH_WGT_extrude", + operator="view3d.edit_mesh_extrude_move_normal", keymap=( ("mesh.extrude_context_move", dict(TRANSFORM_OT_translate=dict(release_confirm=True)), dict(type='EVT_TWEAK_A', value='ANY')), diff --git a/source/blender/makesdna/DNA_workspace_types.h b/source/blender/makesdna/DNA_workspace_types.h index 585794fbe97..f07dc195455 100644 --- a/source/blender/makesdna/DNA_workspace_types.h +++ b/source/blender/makesdna/DNA_workspace_types.h @@ -58,12 +58,15 @@ typedef struct bToolRef_Runtime { int cursor; - /* One of these 3 must be defined. */ + /** One of these 3 must be defined. */ char keymap[64]; char manipulator_group[64]; char data_block[64]; - /* index when a tool is a member of a group */ + /** Use to infer primary operator to use when setting accelerator keys. */ + char operator[64]; + + /** Index when a tool is a member of a group. */ int index; } bToolRef_Runtime; @@ -76,7 +79,7 @@ typedef struct bToolRef { /** Use to avoid initializing the same tool multiple times. */ short tag; - /** bToolKey (spacetype, mode), used in 'WM_api.h' */ + /** #bToolKey (spacetype, mode), used in 'WM_api.h' */ short space_type; /** * Value depends ont the 'space_type', object mode for 3D view, image editor has own mode too. diff --git a/source/blender/makesrna/intern/rna_workspace_api.c b/source/blender/makesrna/intern/rna_workspace_api.c index 0db192e8347..eceaaeec3a4 100644 --- a/source/blender/makesrna/intern/rna_workspace_api.c +++ b/source/blender/makesrna/intern/rna_workspace_api.c @@ -53,6 +53,7 @@ static void rna_WorkspaceTool_setup( const char *keymap, const char *manipulator_group, const char *data_block, + const char *operator, int index) { bToolRef_Runtime tref_rt = {0}; @@ -61,6 +62,7 @@ static void rna_WorkspaceTool_setup( STRNCPY(tref_rt.keymap, keymap); STRNCPY(tref_rt.manipulator_group, manipulator_group); STRNCPY(tref_rt.data_block, data_block); + STRNCPY(tref_rt.operator, operator); tref_rt.index = index; WM_toolsystem_ref_set_from_runtime(C, (WorkSpace *)id, tref, &tref_rt, name); @@ -110,6 +112,7 @@ void RNA_api_workspace_tool(StructRNA *srna) RNA_def_string(func, "keymap", NULL, KMAP_MAX_NAME, "Key Map", ""); RNA_def_string(func, "manipulator_group", NULL, MAX_NAME, "Manipulator Group", ""); RNA_def_string(func, "data_block", NULL, MAX_NAME, "Data Block", ""); + RNA_def_string(func, "operator", NULL, MAX_NAME, "Operator", ""); RNA_def_int(func, "index", 0, INT_MIN, INT_MAX, "Index", "", INT_MIN, INT_MAX); /* Access tool operator options (optionally create). */ |