Cleanup: Use const context for some UI templates

- uiTemplateID: Straightforward, just const for the template
    and the functions it calls
  - uiTemplateCacheFile: Create a function in rna_ui.c because
    the generated RNA callback doesn't have const context.

Differential Revision: https://developer.blender.org/D7895
This commit is contained in:
Hans Goudey 2020-06-02 14:09:01 -04:00
parent dcdbcf1ec1
commit 071cc71fb0
4 changed files with 28 additions and 10 deletions

View File

@ -1938,7 +1938,7 @@ uiLayout *uiLayoutRadial(uiLayout *layout);
/* templates */
void uiTemplateHeader(uiLayout *layout, struct bContext *C);
void uiTemplateID(uiLayout *layout,
struct bContext *C,
const struct bContext *C,
struct PointerRNA *ptr,
const char *propname,
const char *newop,
@ -2111,7 +2111,7 @@ void uiTemplateComponentMenu(uiLayout *layout,
const char *name);
void uiTemplateNodeSocket(uiLayout *layout, struct bContext *C, float *color);
void uiTemplateCacheFile(uiLayout *layout,
struct bContext *C,
const struct bContext *C,
struct PointerRNA *ptr,
const char *propname);
@ -2144,7 +2144,7 @@ void uiTemplateNodeView(uiLayout *layout,
struct bNodeSocket *input);
void uiTemplateTextureUser(uiLayout *layout, struct bContext *C);
void uiTemplateTextureShow(uiLayout *layout,
struct bContext *C,
const struct bContext *C,
struct PointerRNA *ptr,
struct PropertyRNA *prop);

View File

@ -799,7 +799,7 @@ static uiBut *template_id_def_new_but(uiBlock *block,
return but;
}
static void template_ID(bContext *C,
static void template_ID(const bContext *C,
uiLayout *layout,
TemplateID *template_ui,
StructRNA *type,
@ -1140,7 +1140,7 @@ ID *UI_context_active_but_get_tab_ID(bContext *C)
}
}
static void template_ID_tabs(bContext *C,
static void template_ID_tabs(const bContext *C,
uiLayout *layout,
TemplateID *template,
StructRNA *type,
@ -1214,7 +1214,7 @@ static void template_ID_tabs(bContext *C,
}
static void ui_template_id(uiLayout *layout,
bContext *C,
const bContext *C,
PointerRNA *ptr,
const char *propname,
const char *newop,
@ -1298,7 +1298,7 @@ static void ui_template_id(uiLayout *layout,
}
void uiTemplateID(uiLayout *layout,
bContext *C,
const bContext *C,
PointerRNA *ptr,
const char *propname,
const char *newop,
@ -7523,7 +7523,10 @@ void uiTemplateNodeSocket(uiLayout *layout, bContext *UNUSED(C), float *color)
/** \name Cache File Template
* \{ */
void uiTemplateCacheFile(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname)
void uiTemplateCacheFile(uiLayout *layout,
const bContext *C,
PointerRNA *ptr,
const char *propname)
{
if (!ptr->data) {
return;

View File

@ -545,7 +545,7 @@ static void template_texture_show(bContext *C, void *data_p, void *prop_p)
}
}
void uiTemplateTextureShow(uiLayout *layout, bContext *C, PointerRNA *ptr, PropertyRNA *prop)
void uiTemplateTextureShow(uiLayout *layout, const bContext *C, PointerRNA *ptr, PropertyRNA *prop)
{
/* button to quickly show texture in texture tab */
SpaceProperties *sbuts = CTX_wm_space_properties(C);

View File

@ -485,6 +485,21 @@ static void rna_uiTemplateAnyID(uiLayout *layout,
uiTemplateAnyID(layout, ptr, propname, proptypename, name);
}
static void rna_uiTemplateCacheFile(uiLayout *layout,
bContext *C,
PointerRNA *ptr,
const char *propname)
{
PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
if (!prop) {
RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
return;
}
uiTemplateCacheFile(layout, C, ptr, propname);
}
static void rna_uiTemplatePathBuilder(uiLayout *layout,
PointerRNA *ptr,
const char *propname,
@ -1577,7 +1592,7 @@ void RNA_api_ui_layout(StructRNA *srna)
RNA_def_float_array(
func, "color", 4, node_socket_color_default, 0.0f, 1.0f, "Color", "", 0.0f, 1.0f);
func = RNA_def_function(srna, "template_cache_file", "uiTemplateCacheFile");
func = RNA_def_function(srna, "template_cache_file", "rna_uiTemplateCacheFile");
RNA_def_function_ui_description(
func, "Item(s). User interface for selecting cache files and their source paths");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);