UI Templates: RNA-Path Builder (Skeleton Code)

Added a base-template for editing/creating RNA-Paths. This is now used for KeyingSets and Driver UI's, so that when the actual magic gets put in, it will work.
This commit is contained in:
Joshua Leung 2009-10-15 10:13:59 +00:00
parent 29e738f60c
commit 384a1b5a5c
5 changed files with 52 additions and 5 deletions

@ -97,7 +97,7 @@ class SCENE_PT_keying_set_paths(SceneButtonsPanel):
col = layout.column()
col.itemL(text="Target:")
col.template_any_ID(ksp, "id", "id_type")
col.itemR(ksp, "rna_path")
col.template_path_builder(ksp, "rna_path", ksp.id)
row = layout.row()

@ -622,6 +622,8 @@ void uiTemplateID(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr,
char *newop, char *openop, char *unlinkop);
void uiTemplateAnyID(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, char *propname,
char *proptypename, char *text);
void uiTemplatePathBuilder(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, char *propname,
struct PointerRNA *root_ptr, char *text);
uiLayout *uiTemplateModifier(uiLayout *layout, struct PointerRNA *ptr);
uiLayout *uiTemplateConstraint(uiLayout *layout, struct PointerRNA *ptr);
void uiTemplatePreview(uiLayout *layout, struct ID *id, struct ID *parent, struct MTex *slot);

@ -405,9 +405,10 @@ void uiTemplateID(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propname
}
/************************ ID Chooser Template ***************************/
/* This is for selecting the type of ID-block to use, and then from the relevant type choosing the block to use */
/* - propname: property identifier for property that ID-pointer gets stored to
/* This is for selecting the type of ID-block to use, and then from the relevant type choosing the block to use
*
* - propname: property identifier for property that ID-pointer gets stored to
* - proptypename: property identifier for property used to determine the type of ID-pointer that can be used
*/
void uiTemplateAnyID(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propname, char *proptypename, char *text)
@ -438,12 +439,42 @@ void uiTemplateAnyID(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propn
uiItemL(row, "ID-Block:", 0);
/* ID-Type Selector - just have a menu of icons */
// FIXME: the icon-only setting doesn't work when we supply a blank name
uiItemFullR(row, "", 0, ptr, propType, 0, 0, UI_ITEM_R_ICON_ONLY);
/* ID-Block Selector - just use pointer widget... */
uiItemFullR(row, "", 0, ptr, propID, 0, 0, 0);
}
/********************* RNA Path Builder Template ********************/
/* This is creating/editing RNA-Paths
*
* - ptr: struct which holds the path property
* - propname: property identifier for property that path gets stored to
* - root_ptr: struct that path gets built from
*/
void uiTemplatePathBuilder(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propname, PointerRNA *root_ptr, char *text)
{
PropertyRNA *propPath;
uiLayout *row;
/* check that properties are valid */
propPath= RNA_struct_find_property(ptr, propname);
if (!propPath || RNA_property_type(propPath) != PROP_STRING) {
printf("uiTemplatePathBuilder: path property not found: %s\n", propname);
return;
}
/* Start drawing UI Elements using standard defines */
row= uiLayoutRow(layout, 1);
/* Path (existing string) Widget */
uiItemR(row, text, ICON_RNA, ptr, propname, 0);
// TODO: attach something to this to make allow searching of nested properties to 'build' the path
}
/************************ Modifier Template *************************/
#define ERROR_LIBDATA_MESSAGE "Can't edit external libdata"

@ -339,11 +339,15 @@ static void graph_panel_drivers(const bContext *C, Panel *pa)
/* Target Property */
// TODO: make this less technical...
if (dtar->id) {
PointerRNA root_ptr;
/* get pointer for resolving the property selected */
RNA_id_pointer_create(dtar->id, &root_ptr);
col= uiLayoutColumn(box, 1);
block= uiLayoutGetBlock(col);
/* rna path */
// TODO: this needs path constructor widget
uiItemR(col, "Path", 0, &dtar_ptr, "rna_path", 0);
uiTemplatePathBuilder(col, (bContext *)C, &dtar_ptr, "rna_path", &root_ptr, "Path");
/* array index */
// TODO: this needs selector which limits it to ok values

@ -266,6 +266,16 @@ void RNA_api_ui_layout(StructRNA *srna)
RNA_def_property_flag(parm, PROP_REQUIRED);
parm= RNA_def_string(func, "text", "", 0, "", "Custom label to display in UI.");
func= RNA_def_function(srna, "template_path_builder", "uiTemplatePathBuilder");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
parm= RNA_def_pointer(func, "data", "AnyType", "", "Data from which to take property.");
RNA_def_property_flag(parm, PROP_REQUIRED|PROP_RNAPTR|PROP_NEVER_NULL);
parm= RNA_def_string(func, "property", "", 0, "", "Identifier of property in data.");
RNA_def_property_flag(parm, PROP_REQUIRED);
parm= RNA_def_pointer(func, "root", "ID", "", "ID-block from which path is evaluated from.");
RNA_def_property_flag(parm, PROP_REQUIRED|PROP_RNAPTR);
parm= RNA_def_string(func, "text", "", 0, "", "Custom label to display in UI.");
func= RNA_def_function(srna, "template_modifier", "uiTemplateModifier");
parm= RNA_def_pointer(func, "data", "Modifier", "", "Modifier data.");
RNA_def_property_flag(parm, PROP_REQUIRED|PROP_RNAPTR|PROP_NEVER_NULL);