WM: avoid hard coded modifier key checks in object.hide_collection

These checks aren't always valid when there are multiple events
in the queue.
This commit is contained in:
Campbell Barton 2022-03-14 15:43:24 +11:00
parent 541ba68991
commit d7dd7403a8
Notes: blender-bot 2023-03-29 11:06:54 +02:00
Referenced by issue #106251, Regression: object.hide_collection "Shift to extend" doesn't work in 3D View Collections panel
Referenced by commit bb2c89b20d, Fix #106251: "Shift to extend" doesn't work in 3D View Collections panel
2 changed files with 21 additions and 20 deletions

View File

@ -326,6 +326,22 @@ def _template_items_hide_reveal_actions(op_hide, op_reveal):
]
def _template_object_hide_collection_from_number_keys():
return [
("object.hide_collection", {
"type": NUMBERS_1[i], "value": 'PRESS',
**({"shift": True} if extend else {}),
**({"alt": True} if add_10 else {}),
}, {"properties": [
("collection_index", i + (11 if add_10 else 1)),
("extend", extend),
]})
for extend in (False, True)
for add_10 in (False, True)
for i in range(10)
]
def _template_items_object_subdivision_set():
return [
("object.subdivision_set",
@ -4410,13 +4426,7 @@ def km_pose(params):
("pose.breakdown", {"type": 'E', "value": 'PRESS', "shift": True}, None),
("pose.blend_to_neighbor", {"type": 'E', "value": 'PRESS', "shift": True, "alt": True}, None),
op_menu("VIEW3D_MT_pose_propagate", {"type": 'P', "value": 'PRESS', "alt": True}),
*(
(("object.hide_collection",
{"type": NUMBERS_1[i], "value": 'PRESS', "any": True},
{"properties": [("collection_index", i + 1)]})
for i in range(10)
)
),
*_template_object_hide_collection_from_number_keys(),
*_template_items_context_menu("VIEW3D_MT_pose_context_menu", params.context_menu_event),
])
@ -4486,13 +4496,7 @@ def km_object_mode(params):
("object.link_to_collection", {"type": 'M', "value": 'PRESS', "shift": True}, None),
*_template_items_hide_reveal_actions("object.hide_view_set", "object.hide_view_clear"),
("object.hide_collection", {"type": 'H', "value": 'PRESS', "ctrl": True}, None),
*(
(("object.hide_collection",
{"type": NUMBERS_1[i], "value": 'PRESS', "any": True},
{"properties": [("collection_index", i + 1)]})
for i in range(10)
)
),
*_template_object_hide_collection_from_number_keys(),
*_template_items_context_menu("VIEW3D_MT_object_context_menu", params.context_menu_event),
])

View File

@ -338,17 +338,12 @@ void OBJECT_OT_hide_view_set(wmOperatorType *ot)
static int object_hide_collection_exec(bContext *C, wmOperator *op)
{
wmWindow *win = CTX_wm_window(C);
View3D *v3d = CTX_wm_view3d(C);
int index = RNA_int_get(op->ptr, "collection_index");
const bool extend = (win->eventstate->modifier & KM_SHIFT) != 0;
const bool extend = RNA_boolean_get(op->ptr, "extend");
const bool toggle = RNA_boolean_get(op->ptr, "toggle");
if (win->eventstate->modifier & KM_ALT) {
index += 10;
}
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
LayerCollection *lc = BKE_layer_collection_from_index(view_layer, index);
@ -467,6 +462,8 @@ void OBJECT_OT_hide_collection(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN);
prop = RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "Toggle visibility");
RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN);
prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend visibility");
RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN);
}
/** \} */