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.
This commit is contained in:
Brecht Van Lommel 2018-11-25 18:59:58 +01:00
parent 7051a95516
commit e840f0a90b
2 changed files with 53 additions and 43 deletions

View File

@ -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},

View File

@ -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
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)
if self.extend is False and self.toggle is False and self.deselect is False:
active_object = context.active_object
# Finished means something was selected.
if 'FINISHED' in retval:
return retval
if self.extend or self.toggle or self.deselect:
return retval
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')
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')
select_all = bpy.ops.object.select_all
else:
select_all = bpy.ops.object.select_all
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))
return select_all('INVOKE_DEFAULT', True, action='DESELECT')
classes = (