PyAPI: add keyconfig.keymaps.clear()

Add a utility function to clear all key maps from a key configuration.

This allows the add-ons key-config to be cleared so the exported
configuration wont include add-on keymap items,
needed for bl_keymap_validate.py to properly compare the
exported key-map with the data in:
./scripts/presets/keyconfig/keymap_data/blender_default.py
This commit is contained in:
Campbell Barton 2023-09-13 15:09:05 +10:00
parent ec7785fffc
commit b1b6f73487
1 changed files with 10 additions and 0 deletions

View File

@ -493,6 +493,13 @@ static void rna_KeyMaps_remove(wmKeyConfig *keyconfig, ReportList *reports, Poin
RNA_POINTER_INVALIDATE(keymap_ptr);
}
static void rna_KeyMaps_clear(wmKeyConfig *keyconfig)
{
while (wmKeyMap *keymap = static_cast<wmKeyMap *>(keyconfig->keymaps.first)) {
WM_keymap_remove(keyconfig, keymap);
}
}
wmKeyConfig *rna_KeyConfig_new(wmWindowManager *wm, const char *idname)
{
return WM_keyconfig_ensure(wm, idname, true);
@ -1271,6 +1278,9 @@ void RNA_api_keymaps(StructRNA *srna)
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, ParameterFlag(0));
func = RNA_def_function(srna, "clear", "rna_KeyMaps_clear");
RNA_def_function_ui_description(func, "Remove all keymaps.");
func = RNA_def_function(srna, "find", "rna_KeyMaps_find");
parm = RNA_def_string(func, "name", nullptr, 0, "Name", "");
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);