コード例 #1
0
ファイル: wm_keymap.c プロジェクト: OldBrunet/BGERTPS
static wmKeyMap *wm_keymap_preset(wmWindowManager *wm, wmKeyMap *km)
{
	wmKeyConfig *keyconf= WM_keyconfig_active(wm);
	wmKeyMap *keymap;

	keymap= WM_keymap_list_find(&keyconf->keymaps, km->idname, km->spaceid, km->regionid);
	if(!keymap)
		keymap= WM_keymap_list_find(&wm->defaultconf->keymaps, km->idname, km->spaceid, km->regionid);

	return keymap;
}
コード例 #2
0
static void wm_user_modal_keymap_set_items(wmWindowManager *wm, wmKeyMap *km)
{
	/* here we convert propvalue string values delayed, due to python keymaps
	 * being created before the actual modal keymaps, so no modal_items */
	wmKeyMap *defaultkm;
	wmKeyMapItem *kmi;
	int propvalue;

	if (km && (km->flag & KEYMAP_MODAL) && !km->modal_items) {
		defaultkm = WM_keymap_list_find(&wm->defaultconf->keymaps, km->idname, 0, 0);

		if (!defaultkm)
			return;

		km->modal_items = defaultkm->modal_items;
		km->poll = defaultkm->poll;

		for (kmi = km->items.first; kmi; kmi = kmi->next) {
			if (kmi->propvalue_str[0]) {
				if (RNA_enum_value_from_id(km->modal_items, kmi->propvalue_str, &propvalue))
					kmi->propvalue = propvalue;
				kmi->propvalue_str[0] = '\0';
			}
		}
	}
}
コード例 #3
0
ファイル: rna_wm_api.c プロジェクト: dfelinto/blender
static wmKeyMap *rna_keymap_find(wmKeyConfig *keyconf,
                                 const char *idname,
                                 int spaceid,
                                 int regionid)
{
  return WM_keymap_list_find(&keyconf->keymaps, idname, spaceid, regionid);
}
コード例 #4
0
ファイル: wm_keymap.c プロジェクト: OldBrunet/BGERTPS
void WM_keymap_restore_item_to_default(bContext *C, wmKeyMap *keymap, wmKeyMapItem *kmi)
{
	wmWindowManager *wm = CTX_wm_manager(C);
	wmKeyMap *defaultmap, *addonmap;
	wmKeyMapItem *orig;

	if(!keymap)
		return;

	/* construct default keymap from preset + addons */
	defaultmap= wm_keymap_preset(wm, keymap);
	addonmap= WM_keymap_list_find(&wm->addonconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid);

	if(addonmap) {
		defaultmap = wm_keymap_copy(defaultmap);
		wm_keymap_addon_add(defaultmap, addonmap);
	}

	/* find original item */
	orig = WM_keymap_item_find_id(defaultmap, kmi->id);

	if(orig) {
		/* restore to original */
		if(strcmp(orig->idname, kmi->idname) != 0) {
			BLI_strncpy(kmi->idname, orig->idname, sizeof(kmi->idname));
			WM_keymap_properties_reset(kmi, NULL);
		}

		if (orig->properties) {
			if(kmi->properties) {
				IDP_FreeProperty(kmi->properties);
				MEM_freeN(kmi->properties);
				kmi->properties= NULL;
			}

			kmi->properties= IDP_CopyProperty(orig->properties);
			kmi->ptr->data= kmi->properties;
		}

		kmi->propvalue = orig->propvalue;
		kmi->type = orig->type;
		kmi->val = orig->val;
		kmi->shift = orig->shift;
		kmi->ctrl = orig->ctrl;
		kmi->alt = orig->alt;
		kmi->oskey = orig->oskey;
		kmi->keymodifier = orig->keymodifier;
		kmi->maptype = orig->maptype;

		WM_keyconfig_update_tag(keymap, kmi);
	}

	/* free temporary keymap */
	if(addonmap) {
		WM_keymap_free(defaultmap);
		MEM_freeN(defaultmap);
	}
}
コード例 #5
0
ファイル: wm_keymap.c プロジェクト: OldBrunet/BGERTPS
static wmKeyMap *wm_keymap_patch_update(ListBase *lb, wmKeyMap *defaultmap, wmKeyMap *addonmap, wmKeyMap *usermap)
{
	wmKeyMap *km;
	int expanded = 0;

	/* remove previous keymap in list, we will replace it */
	km = WM_keymap_list_find(lb, defaultmap->idname, defaultmap->spaceid, defaultmap->regionid);
	if(km) {
		expanded = (km->flag & (KEYMAP_EXPANDED|KEYMAP_CHILDREN_EXPANDED));
		WM_keymap_free(km);
		BLI_freelinkN(lb, km);
	}

	/* copy new keymap from an existing one */
	if(usermap && !(usermap->flag & KEYMAP_DIFF)) {
		/* for compatibiltiy with old user preferences with non-diff
		   keymaps we override the original entirely */
		wmKeyMapItem *kmi, *orig_kmi;

		km = wm_keymap_copy(usermap);

		/* try to find corresponding id's for items */
		for(kmi=km->items.first; kmi; kmi=kmi->next) {
			orig_kmi = wm_keymap_find_item_equals(defaultmap, kmi);
			if(!orig_kmi)
				orig_kmi = wm_keymap_find_item_equals_result(defaultmap, kmi);

			if(orig_kmi)
				kmi->id = orig_kmi->id;
			else
				kmi->id = -(km->kmi_id++);
		}

		km->flag |= KEYMAP_UPDATE; /* update again to create diff */
	}
	else
		km = wm_keymap_copy(defaultmap);

	/* add addon keymap items */
	if(addonmap)
		wm_keymap_addon_add(km, addonmap);

	/* tag as being user edited */
	if(usermap)
		km->flag |= KEYMAP_USER_MODIFIED;
	km->flag |= KEYMAP_USER|expanded;

	/* apply user changes of diff keymap */
	if(usermap && (usermap->flag & KEYMAP_DIFF))
		wm_keymap_patch(km, usermap);

	/* add to list */
	BLI_addtail(lb, km);
	
	return km;
}
コード例 #6
0
ファイル: wm_keymap.c プロジェクト: OldBrunet/BGERTPS
wmKeyMap *WM_keymap_find(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
{
	wmKeyMap *km= WM_keymap_list_find(&keyconf->keymaps, idname, spaceid, regionid);
	
	if(km==NULL) {
		km= wm_keymap_new(idname, spaceid, regionid);
		BLI_addtail(&keyconf->keymaps, km);

		WM_keyconfig_update_tag(km, NULL);
	}
	
	return km;
}
コード例 #7
0
ファイル: wm_keymap.c プロジェクト: OldBrunet/BGERTPS
wmKeyMap *WM_keymap_active(wmWindowManager *wm, wmKeyMap *keymap)
{
	wmKeyMap *km;

	if(!keymap)
		return NULL;
	
	/* first user defined keymaps */
	km= WM_keymap_list_find(&wm->userconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid);

	if(km)
		return km;

	return keymap;
}
コード例 #8
0
ファイル: wm_keymap.c プロジェクト: OldBrunet/BGERTPS
void WM_keymap_restore_to_default(wmKeyMap *keymap, bContext *C)
{
	wmWindowManager *wm = CTX_wm_manager(C);
	wmKeyMap *usermap;

	/* remove keymap from U.user_keymaps and update */
	usermap= WM_keymap_list_find(&U.user_keymaps, keymap->idname, keymap->spaceid, keymap->regionid);

	if(usermap) {
		WM_keymap_free(usermap);
		BLI_freelinkN(&U.user_keymaps, usermap);

		WM_keyconfig_update_tag(NULL, NULL);
		WM_keyconfig_update(wm);
	}
}
コード例 #9
0
wmKeyMap *WM_modalkeymap_add(wmKeyConfig *keyconf, const char *idname, EnumPropertyItem *items)
{
	wmKeyMap *km = WM_keymap_find(keyconf, idname, 0, 0);
	km->flag |= KEYMAP_MODAL;
	km->modal_items = items;

	if (!items) {
		/* init modal items from default config */
		wmWindowManager *wm = G.main->wm.first;
		wmKeyMap *defaultkm = WM_keymap_list_find(&wm->defaultconf->keymaps, km->idname, 0, 0);

		if (defaultkm) {
			km->modal_items = defaultkm->modal_items;
			km->poll = defaultkm->poll;
		}
	}
	
	return km;
}
コード例 #10
0
static void wm_keymap_diff_update(ListBase *lb, wmKeyMap *defaultmap, wmKeyMap *addonmap, wmKeyMap *km)
{
	wmKeyMap *diffmap, *prevmap, *origmap;

	/* create temporary default + addon keymap for diff */
	origmap = defaultmap;

	if (addonmap) {
		defaultmap = wm_keymap_copy(defaultmap);
		wm_keymap_addon_add(defaultmap, addonmap);
	}

	/* remove previous diff keymap in list, we will replace it */
	prevmap = WM_keymap_list_find(lb, km->idname, km->spaceid, km->regionid);
	if (prevmap) {
		WM_keymap_free(prevmap);
		BLI_freelinkN(lb, prevmap);
	}

	/* create diff keymap */
	diffmap = wm_keymap_new(km->idname, km->spaceid, km->regionid);
	diffmap->flag |= KEYMAP_DIFF;
	if (defaultmap->flag & KEYMAP_MODAL)
		diffmap->flag |= KEYMAP_MODAL;
	wm_keymap_diff(diffmap, defaultmap, km, origmap, addonmap);

	/* add to list if not empty */
	if (diffmap->diff_items.first) {
		BLI_addtail(lb, diffmap);
	}
	else {
		WM_keymap_free(diffmap);
		MEM_freeN(diffmap);
	}

	/* free temporary default map */
	if (addonmap) {
		WM_keymap_free(defaultmap);
		MEM_freeN(defaultmap);
	}
}
コード例 #11
0
ファイル: wm_keymap.c プロジェクト: OldBrunet/BGERTPS
void WM_keyconfig_update(wmWindowManager *wm)
{
	wmKeyMap *km, *defaultmap, *addonmap, *usermap, *kmn;
	wmKeyMapItem *kmi;
	wmKeyMapDiffItem *kmdi;
	int compat_update = 0;

	if(!WM_KEYMAP_UPDATE)
		return;
	
	/* update operator properties for non-modal user keymaps */
	for(km=U.user_keymaps.first; km; km=km->next) {
		if((km->flag & KEYMAP_MODAL) == 0) {
			for(kmdi=km->diff_items.first; kmdi; kmdi=kmdi->next) {
				if(kmdi->add_item)
					wm_keymap_item_properties_set(kmdi->add_item);
				if(kmdi->remove_item)
					wm_keymap_item_properties_set(kmdi->remove_item);
			}

			for(kmi=km->items.first; kmi; kmi=kmi->next)
				wm_keymap_item_properties_set(kmi);
		}
	}

	/* update U.user_keymaps with user key configuration changes */
	for(km=wm->userconf->keymaps.first; km; km=km->next) {
		/* only diff if the user keymap was modified */
		if(wm_keymap_test_and_clear_update(km)) {
			/* find keymaps */
			defaultmap= wm_keymap_preset(wm, km);
			addonmap= WM_keymap_list_find(&wm->addonconf->keymaps, km->idname, km->spaceid, km->regionid);

			/* diff */
			if(defaultmap)
				wm_keymap_diff_update(&U.user_keymaps, defaultmap, addonmap, km);
		}
	}

	/* create user key configuration from preset + addon + user preferences */
	for(km=wm->defaultconf->keymaps.first; km; km=km->next) {
		/* find keymaps */
		defaultmap= wm_keymap_preset(wm, km);
		addonmap= WM_keymap_list_find(&wm->addonconf->keymaps, km->idname, km->spaceid, km->regionid);
		usermap= WM_keymap_list_find(&U.user_keymaps, km->idname, km->spaceid, km->regionid);

		/* add */
		kmn= wm_keymap_patch_update(&wm->userconf->keymaps, defaultmap, addonmap, usermap);

		if(kmn) {
			kmn->modal_items= km->modal_items;
			kmn->poll= km->poll;
		}

		/* in case of old non-diff keymaps, force extra update to create diffs */
		compat_update = compat_update || (usermap && !(usermap->flag & KEYMAP_DIFF));
	}

	WM_KEYMAP_UPDATE= 0;

	if(compat_update) {
		WM_keyconfig_update_tag(NULL, NULL);
		WM_keyconfig_update(wm);
	}
}
コード例 #12
0
ファイル: wm_keymap.c プロジェクト: OldBrunet/BGERTPS
wmKeyMap *WM_keymap_find_all(const bContext *C, const char *idname, int spaceid, int regionid)
{
	wmWindowManager *wm= CTX_wm_manager(C);

	return WM_keymap_list_find(&wm->userconf->keymaps, idname, spaceid, regionid);
}