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); } }
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; }
void WM_keyconfig_free(wmKeyConfig *keyconf) { wmKeyMap *km; while((km= keyconf->keymaps.first)) { WM_keymap_free(km); BLI_freelinkN(&keyconf->keymaps, km); } MEM_freeN(keyconf); }
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); } }
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); } }