コード例 #1
0
static wmKeyMapItem *wm_keymap_item_find(
        const bContext *C, const char *opname, int opcontext,
        IDProperty *properties, const short hotkey, const bool strict, wmKeyMap **keymap_r)
{
	wmKeyMapItem *found = wm_keymap_item_find_props(C, opname, opcontext, properties, strict, hotkey, keymap_r);

	if (!found && properties) {
		wmOperatorType *ot = WM_operatortype_find(opname, TRUE);
		if (ot) {
			/* make a copy of the properties and set any unset props
			 * to their default values, so the ID property compare function succeeds */
			PointerRNA opptr;
			IDProperty *properties_default = IDP_CopyProperty(properties);

			RNA_pointer_create(NULL, ot->srna, properties_default, &opptr);

			if (WM_operator_properties_default(&opptr, true) ||
			    (!strict && ot->prop && RNA_property_is_set(&opptr, ot->prop)))
			{
				/* for operator that has enum menu, unset it so it always matches */
				if (!strict && ot->prop) {
					RNA_property_unset(&opptr, ot->prop);
				}

				found = wm_keymap_item_find_props(C, opname, opcontext, properties_default, false, hotkey, keymap_r);
			}

			IDP_FreeProperty(properties_default);
			MEM_freeN(properties_default);
		}
	}

	return found;
}
コード例 #2
0
ファイル: wm.c プロジェクト: GeniaPenksik/blender
/**
 * Use with extreme care!,
 * properties, customdata etc - must be compatible.
 *
 * \param op  Operator to assign the type to.
 * \param ot  OperatorType to assign.
 */
void WM_operator_type_set(wmOperator *op, wmOperatorType *ot)
{
	/* not supported for Python */
	BLI_assert(op->py_instance == NULL);

	op->type = ot;
	op->ptr->type = ot->srna;

	/* ensure compatible properties */
	if (op->properties) {
		PointerRNA ptr;

		WM_operator_properties_create_ptr(&ptr, ot);

		WM_operator_properties_default(&ptr, false);

		if (ptr.data) {
			IDP_SyncGroupTypes(op->properties, ptr.data, true);
		}

		WM_operator_properties_free(&ptr);
	}
}