From 384a1b5a5c15cfc5311f3865bde095d89130cfa5 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Thu, 15 Oct 2009 10:13:59 +0000 Subject: [PATCH] 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. --- release/scripts/ui/buttons_scene.py | 2 +- source/blender/editors/include/UI_interface.h | 2 ++ .../editors/interface/interface_templates.c | 35 +++++++++++++++++-- .../editors/space_graph/graph_buttons.c | 8 +++-- source/blender/makesrna/intern/rna_ui_api.c | 10 ++++++ 5 files changed, 52 insertions(+), 5 deletions(-) diff --git a/release/scripts/ui/buttons_scene.py b/release/scripts/ui/buttons_scene.py index deb20f2b432..54f47791d59 100644 --- a/release/scripts/ui/buttons_scene.py +++ b/release/scripts/ui/buttons_scene.py @@ -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() diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 2fd870cf696..bd8214db29b 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -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); diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index de0d6191f16..dfe21171928 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -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" diff --git a/source/blender/editors/space_graph/graph_buttons.c b/source/blender/editors/space_graph/graph_buttons.c index fa44b281f15..87a11305bd9 100644 --- a/source/blender/editors/space_graph/graph_buttons.c +++ b/source/blender/editors/space_graph/graph_buttons.c @@ -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 diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c index 79465f64daf..cce8fb0fef7 100644 --- a/source/blender/makesrna/intern/rna_ui_api.c +++ b/source/blender/makesrna/intern/rna_ui_api.c @@ -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);