diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-11-25 20:59:58 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-11-25 22:07:47 +0300 |
commit | e840f0a90ba726663f8bd0f4df24baee6e4f7d80 (patch) | |
tree | 6652b727d607af7472bcde98f3d869302dd56a56 | |
parent | 7051a955166b47edc7bbc9cba91aa222da16f66f (diff) |
Keymaps: add 3D view click empty space to deselect all.
The implementation of this operator was modified to be more efficient and
ensure the undo history has the exact operator used.
-rw-r--r-- | release/scripts/presets/keyconfig/keymap_data/blender_default.py | 20 | ||||
-rw-r--r-- | release/scripts/startup/bl_operators/view3d.py | 82 |
2 files changed, 56 insertions, 46 deletions
diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py index 182dfd0870b..3e481d84096 100644 --- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py +++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py @@ -977,18 +977,18 @@ def km_view3d(params): ("view3d.view_axis", {"type": 'NDOF_BUTTON_TOP', "value": 'PRESS', "shift": True}, {"properties": [("type", 'TOP'), ("align_active", True)]}), # Selection. - *(("view3d.select", + *((operator, {"type": params.select_mouse, "value": params.select_mouse_value, **{m: True for m in mods}}, {"properties": [(c, True) for c in props]}, - ) for props, mods in ( - ((), ()), - (("toggle",), ("shift",)), - (("center", "object"), ("ctrl",)), - (("enumerate",), ("alt",)), - (("extend", "toggle", "center"), ("shift", "ctrl")), - (("center", "enumerate"), ("ctrl", "alt")), - (("toggle", "enumerate"), ("shift", "alt")), - (("toggle", "center", "enumerate"), ("shift", "ctrl", "alt")), + ) for operator, props, mods in ( + ("view3d.select_or_deselect_all" if not params.legacy else "view3d.select", (), ()), + ("view3d.select", ("toggle",), ("shift",)), + ("view3d.select", ("center", "object"), ("ctrl",)), + ("view3d.select", ("enumerate",), ("alt",)), + ("view3d.select", ("extend", "toggle", "center"), ("shift", "ctrl")), + ("view3d.select", ("center", "enumerate"), ("ctrl", "alt")), + ("view3d.select", ("toggle", "enumerate"), ("shift", "alt")), + ("view3d.select", ("toggle", "center", "enumerate"), ("shift", "ctrl", "alt")), )), ("view3d.select_box", {"type": 'B', "value": 'PRESS'}, None), ("view3d.select_lasso", {"type": params.action_tweak, "value": 'ANY', "ctrl": True}, diff --git a/release/scripts/startup/bl_operators/view3d.py b/release/scripts/startup/bl_operators/view3d.py index b43f4446802..e8c56346ee9 100644 --- a/release/scripts/startup/bl_operators/view3d.py +++ b/release/scripts/startup/bl_operators/view3d.py @@ -141,42 +141,47 @@ class VIEW3D_OT_select_or_deselect_all(Operator): """Select element under the mouse, deselect everything is there's nothing under the mouse""" bl_label = "Select or Deselect All" bl_idname = "view3d.select_or_deselect_all" - bl_options = {'UNDO'} extend: BoolProperty( name="Extend", description="Extend selection instead of deselecting everything first", default=False, + options={'SKIP_SAVE'}, ) toggle: BoolProperty( name="Toggle", description="Toggle the selection", default=False, + options={'SKIP_SAVE'}, ) deselect: BoolProperty( name="Deselect", description="Remove from selection", default=False, + options={'SKIP_SAVE'}, ) center: BoolProperty( name="Center", description="Use the object center when selecting, in editmode used to extend object selection", default=False, + options={'SKIP_SAVE'}, ) enumerate: BoolProperty( name="Enumerate", description="List objects under the mouse (object mode only)", default=False, + options={'SKIP_SAVE'}, ) object: BoolProperty( name="Object", description="Use object selection (editmode only)", default=False, + options={'SKIP_SAVE'}, ) @classmethod @@ -187,42 +192,47 @@ class VIEW3D_OT_select_or_deselect_all(Operator): return True def invoke(self, context, event): - x = event.mouse_region_x - y = event.mouse_region_y - - if self.extend is False and self.toggle is False and self.deselect is False: - active_object = context.active_object - - if active_object: - if active_object.mode == 'EDIT': - if active_object.type == 'MESH': - bpy.ops.mesh.select_all(action='DESELECT') - elif active_object.type == 'CURVE': - bpy.ops.curve.select_all(action='DESELECT') - elif active_object.type == 'SURFACE': - bpy.ops.curve.select_all(action='DESELECT') - elif active_object.type == 'LATTICE': - bpy.ops.lattice.select_all(action='DESELECT') - elif active_object.type == 'META': - bpy.ops.mball.select_all(action='DESELECT') - elif active_object.type == 'ARMATURE': - bpy.ops.armature.select_all(action='DESELECT') - elif active_object.mode == 'POSE': - bpy.ops.pose.select_all(action='DESELECT') - elif active_object.mode == 'PARTICLE_EDIT': - bpy.ops.particle.select_all(action='DESELECT') - else: - bpy.ops.object.select_all(action='DESELECT') + retval = bpy.ops.view3d.select('INVOKE_DEFAULT', + True, # undo push + extend=self.extend, + deselect=self.deselect, + toggle=self.toggle, + center=self.center, + enumerate=self.enumerate, + object=self.object) + + # Finished means something was selected. + if 'FINISHED' in retval: + return retval + if self.extend or self.toggle or self.deselect: + return retval + + active_object = context.active_object + + if active_object: + if active_object.mode == 'EDIT': + if active_object.type == 'MESH': + select_all = bpy.ops.mesh.select_all + elif active_object.type == 'CURVE': + select_all = bpy.ops.curve.select_all + elif active_object.type == 'SURFACE': + select_all = bpy.ops.curve.select_all + elif active_object.type == 'LATTICE': + select_all = bpy.ops.lattice.select_all + elif active_object.type == 'META': + select_all = bpy.ops.mball.select_all + elif active_object.type == 'ARMATURE': + select_all = bpy.ops.armature.select_all + elif active_object.mode == 'POSE': + select_all = bpy.ops.pose.select_all + elif active_object.mode == 'PARTICLE_EDIT': + select_all = bpy.ops.particle.select_all else: - bpy.ops.object.select_all(action='DESELECT') - - return bpy.ops.view3d.select(extend=self.extend, - deselect=self.deselect, - toggle=self.toggle, - center=self.center, - enumerate=self.enumerate, - object=self.object, - location=(x, y)) + select_all = bpy.ops.object.select_all + else: + select_all = bpy.ops.object.select_all + + return select_all('INVOKE_DEFAULT', True, action='DESELECT') classes = ( |