diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-12-18 17:46:37 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-12-18 17:46:37 +0400 |
commit | db14a81e04986ce59b6bdfa10c23e798e79f6c02 (patch) | |
tree | a49247b2b7018fc49822ab7324b0a652d9d2e8e8 | |
parent | 8e382fde5759014e8dcb5b998cb492449d8c9c27 (diff) |
some speedup by avoiding translation on entire enum arrays, and just translate the single name that ends up being used.
-rw-r--r-- | source/blender/editors/interface/interface.c | 9 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_layout.c | 21 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 6 |
3 files changed, 25 insertions, 11 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 3a377ade44c..5272b74c745 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -2827,12 +2827,17 @@ static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *s EnumPropertyItem *item; int i, totitem, free; - /* TODO, translate after getting the item, saves many lookups */ - RNA_property_enum_items_gettexted(block->evil_C, ptr, prop, &item, &totitem, &free); + /* get untranslated, then translate the single string we get */ + RNA_property_enum_items(block->evil_C, ptr, prop, &item, &totitem, &free); for (i = 0; i < totitem; i++) { if (item[i].identifier[0] && item[i].value == (int)max) { +#ifdef WITH_INTERNATIONAL + str = BLF_pgettext(RNA_property_translation_context(prop), item[i].name); +#else str = item[i].name; +#endif icon = item[i].icon; + break; } } diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index b976bcad6ac..9edeee7ee2e 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -718,8 +718,13 @@ static const char *ui_menu_enumpropname(uiLayout *layout, PointerRNA *ptr, Prope int totitem, free; const char *name; - RNA_property_enum_items_gettexted(layout->root->block->evil_C, ptr, prop, &item, &totitem, &free); - if (RNA_enum_name(item, retval, &name) == 0) { + RNA_property_enum_items(layout->root->block->evil_C, ptr, prop, &item, &totitem, &free); + if (RNA_enum_name(item, retval, &name)) { +#ifdef WITH_INTERNATIONAL + name = BLF_pgettext(RNA_property_translation_context(prop), name); +#endif + } + else { name = ""; } @@ -907,7 +912,8 @@ void uiItemEnumO_string(uiLayout *layout, const char *name, int icon, const char /* enum lookup */ if ((prop = RNA_struct_find_property(&ptr, propname))) { - RNA_property_enum_items_gettexted(layout->root->block->evil_C, &ptr, prop, &item, NULL, &free); + /* no need for translations here */ + RNA_property_enum_items(layout->root->block->evil_C, &ptr, prop, &item, NULL, &free); if (item == NULL || RNA_enum_value_from_id(item, value_str, &value) == 0) { if (free) { MEM_freeN(item); @@ -1172,7 +1178,7 @@ void uiItemEnumR_string(uiLayout *layout, struct PointerRNA *ptr, const char *pr return; } - RNA_property_enum_items_gettexted(layout->root->block->evil_C, ptr, prop, &item, NULL, &free); + RNA_property_enum_items(layout->root->block->evil_C, ptr, prop, &item, NULL, &free); if (!RNA_enum_value_from_id(item, value, &ivalue)) { if (free) { @@ -1185,7 +1191,12 @@ void uiItemEnumR_string(uiLayout *layout, struct PointerRNA *ptr, const char *pr for (a = 0; item[a].identifier; a++) { if (item[a].value == ivalue) { - uiItemFullR(layout, ptr, prop, RNA_ENUM_VALUE, ivalue, 0, name ? name : item[a].name, icon ? icon : item[a].icon); + const char *item_name = item[a].name; + +#ifdef WITH_INTERNATIONAL + item_name = BLF_pgettext(RNA_property_translation_context(prop), item_name); +#endif + uiItemFullR(layout, ptr, prop, RNA_ENUM_VALUE, ivalue, 0, item_name ? item_name : name, icon ? icon : item[a].icon); break; } } diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 332c6307a0c..7e69b2d2eab 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -1222,10 +1222,8 @@ void RNA_property_enum_items_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA for (i = 0; nitem[i].identifier; i++) { if (nitem[i].name) { - if (prop->translation_context) - nitem[i].name = BLF_pgettext(prop->translation_context, nitem[i].name); - else - nitem[i].name = BLF_pgettext(NULL, nitem[i].name); + /* note: prop->translation_context may be NULL, this just means we dont use a context */ + nitem[i].name = BLF_pgettext(prop->translation_context, nitem[i].name); } if (nitem[i].description) nitem[i].description = BLF_pgettext(NULL, nitem[i].description); |