add ENUM support for layout.prop_search() / uiItemPointerR
authorCampbell Barton <ideasman42@gmail.com>
Sat, 24 Nov 2012 05:15:48 +0000 (05:15 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 24 Nov 2012 05:15:48 +0000 (05:15 +0000)
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_layout.c

index e2f105b57613832184b5c133370dd2414ff00d9f..535239cd46274883b382775db9d7b432812c9834 100644 (file)
@@ -1677,7 +1677,7 @@ void ui_get_but_string(uiBut *but, char *str, size_t maxlen)
 {
        if (but->rnaprop && ELEM3(but->type, TEX, IDPOIN, SEARCH_MENU)) {
                PropertyType type;
-               char *buf = NULL;
+               const char *buf = NULL;
                int buf_len;
 
                type = RNA_property_type(but->rnaprop);
@@ -1686,11 +1686,22 @@ void ui_get_but_string(uiBut *but, char *str, size_t maxlen)
                        /* RNA string */
                        buf = RNA_property_string_get_alloc(&but->rnapoin, but->rnaprop, str, maxlen, &buf_len);
                }
+               else if (type == PROP_ENUM) {
+                       /* RNA enum */
+                       int value = RNA_property_enum_get(&but->rnapoin, but->rnaprop);
+                       if (RNA_property_enum_name(but->block->evil_C, &but->rnapoin, but->rnaprop, value, &buf)) {
+                               BLI_strncpy(str, buf, maxlen);
+                               buf = str;
+                       }
+               }
                else if (type == PROP_POINTER) {
                        /* RNA pointer */
                        PointerRNA ptr = RNA_property_pointer_get(&but->rnapoin, but->rnaprop);
                        buf = RNA_struct_name_get_alloc(&ptr, str, maxlen, &buf_len);
                }
+               else {
+                       BLI_assert(0);
+               }
 
                if (!buf) {
                        str[0] = '\0';
@@ -1698,7 +1709,7 @@ void ui_get_but_string(uiBut *but, char *str, size_t maxlen)
                else if (buf && buf != str) {
                        /* string was too long, we have to truncate */
                        memcpy(str, buf, MIN2(maxlen, (size_t)buf_len + 1));
-                       MEM_freeN(buf);
+                       MEM_freeN((void *)buf);
                }
        }
        else if (but->type == IDPOIN) {
@@ -1841,6 +1852,17 @@ int ui_set_but_string(bContext *C, uiBut *but, const char *str)
 
                                return 0;
                        }
+                       else if (type == PROP_ENUM) {
+                               int value;
+                               if (RNA_property_enum_value(but->block->evil_C, &but->rnapoin, but->rnaprop, str, &value)) {
+                                       RNA_property_enum_set(&but->rnapoin, but->rnaprop, value);
+                                       return 1;
+                               }
+                               return 0;
+                       }
+                       else {
+                               BLI_assert(0);
+                       }
                }
        }
        else if (but->type == IDPOIN) {
index 7fa0f79b14d4d7b5b3d0b7d81870ac48161f5b64..9759c22f30efe611cba2965729fc8654c7b55154 100644 (file)
@@ -1384,6 +1384,12 @@ void ui_but_add_search(uiBut *but, PointerRNA *ptr, PropertyRNA *prop, PointerRN
                but->rnasearchprop = searchprop;
                but->flag |= UI_ICON_LEFT | UI_TEXT_LEFT;
 
+               if (RNA_property_type(prop) == PROP_ENUM) {
+                       /* XXX, this will have a menu string,
+                        * but in this case we just want the text */
+                       but->str[0] = 0;
+               }
+
                uiButSetSearchFunc(but, rna_search_cb, but, NULL, NULL);
        }
 }
@@ -1407,8 +1413,8 @@ void uiItemPointerR(uiLayout *layout, struct PointerRNA *ptr, const char *propna
        }
        
        type = RNA_property_type(prop);
-       if (!ELEM(type, PROP_POINTER, PROP_STRING)) {
-               RNA_warning("Property %s must be a pointer or string", propname);
+       if (!ELEM3(type, PROP_POINTER, PROP_STRING, PROP_ENUM)) {
+               RNA_warning("Property %s must be a pointer, string or enum", propname);
                return;
        }