[Bf-blender-cvs] [6f80604] master: RNA/UI: Allow displaying in tooltip why RNA property isn't editable

Julian Eisel noreply at git.blender.org
Thu Sep 22 00:19:36 CEST 2016


Commit: 6f806045093419a55b16c596dd8690ea0bbae138
Author: Julian Eisel
Date:   Thu Sep 22 00:10:53 2016 +0200
Branches: master
https://developer.blender.org/rB6f806045093419a55b16c596dd8690ea0bbae138

RNA/UI: Allow displaying in tooltip why RNA property isn't editable

This commit allows RNA properties to return additional info on their editable state which may then be displayed in tooltips. To show how it works, it also adds some info for the editable check of proxies. For generally un-editable properties or properties of a linked data-block, RNA returns default strings.

| {F362785} | {F362786} | {F362787} |

Reviewed by brecht, thanks!

Differential Revision: https://developer.blender.org/D2243

===================================================================

M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_regions.c
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_ID.c
M	source/blender/makesrna/intern/rna_access.c
M	source/blender/makesrna/intern/rna_animation.c
M	source/blender/makesrna/intern/rna_curve.c
M	source/blender/makesrna/intern/rna_fcurve.c
M	source/blender/makesrna/intern/rna_gpencil.c
M	source/blender/makesrna/intern/rna_internal_types.h
M	source/blender/makesrna/intern/rna_lattice.c
M	source/blender/makesrna/intern/rna_material.c
M	source/blender/makesrna/intern/rna_mesh.c
M	source/blender/makesrna/intern/rna_meta.c
M	source/blender/makesrna/intern/rna_nla.c
M	source/blender/makesrna/intern/rna_object.c
M	source/blender/makesrna/intern/rna_pose.c
M	source/blender/makesrna/intern/rna_sequencer.c
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/makesrna/intern/rna_vfont.c

===================================================================

diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index aca1070..6bba35e 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -3215,10 +3215,10 @@ void ui_def_but_icon(uiBut *but, const int icon, const int flag)
 	}
 }
 
-static void ui_def_but_rna__disable(uiBut *but)
+static void ui_def_but_rna__disable(uiBut *but, const char *info)
 {
 	but->flag |= UI_BUT_DISABLED;
-	but->disabled_info = "";
+	but->disabled_info = info;
 }
 
 static void ui_def_but_rna__menu(bContext *UNUSED(C), uiLayout *layout, void *but_p)
@@ -3483,8 +3483,9 @@ static uiBut *ui_def_but_rna(
 		but->flag |= UI_BUT_ICON_SUBMENU;
 	}
 
-	if (!RNA_property_editable(&but->rnapoin, prop)) {
-		ui_def_but_rna__disable(but);
+	const char *info;
+	if (!RNA_property_editable_info(&but->rnapoin, prop, &info)) {
+		ui_def_but_rna__disable(but, info);
 	}
 
 	if (but->flag & UI_BUT_UNDO && (ui_but_is_rna_undo(but) == false)) {
@@ -3515,7 +3516,7 @@ static uiBut *ui_def_but_rna_propname(uiBlock *block, int type, int retval, cons
 	else {
 		but = ui_def_but(block, type, retval, propname, x, y, width, height, NULL, min, max, a1, a2, tip);
 
-		ui_def_but_rna__disable(but);
+		ui_def_but_rna__disable(but, "Unknown Property.");
 	}
 
 	return but;
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c
index b7f9216..5602e2b 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -467,7 +467,7 @@ static uiTooltipData *ui_tooltip_data_from_button(bContext *C, uiBut *but)
 		}
 		/* alternatively, buttons can store some reasoning too */
 		else if (but->disabled_info) {
-			disabled_msg = but->disabled_info;
+			disabled_msg = TIP_(but->disabled_info);
 		}
 
 		if (disabled_msg && disabled_msg[0]) {
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 2893fab..44d1a6b 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -856,6 +856,7 @@ StructRNA *RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop);
 int RNA_property_pointer_poll(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *value);
 
 bool RNA_property_editable(PointerRNA *ptr, PropertyRNA *prop);
+bool RNA_property_editable_info(PointerRNA *ptr, PropertyRNA *prop, const char **r_info);
 bool RNA_property_editable_index(PointerRNA *ptr, PropertyRNA *prop, int index);
 bool RNA_property_editable_flag(PointerRNA *ptr, PropertyRNA *prop); /* without lib check, only checks the flag */
 bool RNA_property_animateable(PointerRNA *ptr, PropertyRNA *prop);
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index 7e6bdf9..280ad4a 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -122,7 +122,7 @@ void rna_ID_name_set(PointerRNA *ptr, const char *value)
 	BLI_libblock_ensure_unique_name(G.main, id->name);
 }
 
-static int rna_ID_name_editable(PointerRNA *ptr)
+static int rna_ID_name_editable(PointerRNA *ptr, const char **UNUSED(r_info))
 {
 	ID *id = (ID *)ptr->data;
 	
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 6879a05..6f054e5 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -1619,20 +1619,56 @@ bool RNA_property_editable(PointerRNA *ptr, PropertyRNA *prop)
 {
 	ID *id = ptr->id.data;
 	int flag;
+	const char *dummy_info;
 
 	prop = rna_ensure_property(prop);
-	flag = prop->editable ? prop->editable(ptr) : prop->flag;
+	flag = prop->editable ? prop->editable(ptr, &dummy_info) : prop->flag;
+
 	return ((flag & PROP_EDITABLE) &&
 	        (flag & PROP_REGISTER) == 0 &&
 	        (!id || !ID_IS_LINKED_DATABLOCK(id) || (prop->flag & PROP_LIB_EXCEPTION)));
 }
 
+/**
+ * Version of #RNA_property_editable that tries to return additional info in \a r_info that can be exposed in UI.
+ */
+bool RNA_property_editable_info(PointerRNA *ptr, PropertyRNA *prop, const char **r_info)
+{
+	ID *id = ptr->id.data;
+	int flag;
+
+	prop = rna_ensure_property(prop);
+	*r_info = "";
+
+	/* get flag */
+	if (prop->editable) {
+		flag = prop->editable(ptr, r_info);
+	}
+	else {
+		flag = prop->flag;
+		if ((flag & PROP_EDITABLE) == 0 || (flag & PROP_REGISTER)) {
+			*r_info = "This property is for internal use only and can't be edited.";
+		}
+	}
+
+	/* property from linked data-block */
+	if (id && ID_IS_LINKED_DATABLOCK(id) && (prop->flag & PROP_LIB_EXCEPTION) == 0) {
+		if (!(*r_info)[0]) {
+			*r_info = "Can't edit this property from a linked data-block.";
+		}
+		return false;
+	}
+
+	return ((flag & PROP_EDITABLE) && (flag & PROP_REGISTER) == 0);
+}
+
 bool RNA_property_editable_flag(PointerRNA *ptr, PropertyRNA *prop)
 {
 	int flag;
+	const char *dummy_info;
 
 	prop = rna_ensure_property(prop);
-	flag = prop->editable ? prop->editable(ptr) : prop->flag;
+	flag = prop->editable ? prop->editable(ptr, &dummy_info) : prop->flag;
 	return (flag & PROP_EDITABLE) != 0;
 }
 
@@ -1647,9 +1683,11 @@ bool RNA_property_editable_index(PointerRNA *ptr, PropertyRNA *prop, int index)
 	prop = rna_ensure_property(prop);
 
 	flag = prop->flag;
-	
-	if (prop->editable)
-		flag &= prop->editable(ptr);
+
+	if (prop->editable) {
+		const char *dummy_info;
+		flag &= prop->editable(ptr, &dummy_info);
+	}
 
 	if (prop->itemeditable)
 		flag &= prop->itemeditable(ptr, index);
diff --git a/source/blender/makesrna/intern/rna_animation.c b/source/blender/makesrna/intern/rna_animation.c
index e37affc..cdbf758 100644
--- a/source/blender/makesrna/intern/rna_animation.c
+++ b/source/blender/makesrna/intern/rna_animation.c
@@ -89,7 +89,7 @@ static void rna_AnimData_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Point
 	DAG_id_tag_update(id, OB_RECALC_OB | OB_RECALC_DATA);
 }
 
-static int rna_AnimData_action_editable(PointerRNA *ptr)
+static int rna_AnimData_action_editable(PointerRNA *ptr, const char **UNUSED(r_info))
 {
 	AnimData *adt = (AnimData *)ptr->data;
 	
@@ -305,7 +305,7 @@ static StructRNA *rna_ksPath_id_typef(PointerRNA *ptr)
 	return ID_code_to_RNA_type(ksp->idtype);
 }
 
-static int rna_ksPath_id_editable(PointerRNA *ptr)
+static int rna_ksPath_id_editable(PointerRNA *ptr, const char **UNUSED(r_info))
 {
 	KS_Path *ksp = (KS_Path *)ptr->data;
 	return (ksp->idtype) ? PROP_EDITABLE : 0;
@@ -393,7 +393,7 @@ static void rna_KeyingSet_name_set(PointerRNA *ptr, const char *value)
 }
 
 
-static int rna_KeyingSet_active_ksPath_editable(PointerRNA *ptr)
+static int rna_KeyingSet_active_ksPath_editable(PointerRNA *ptr, const char **UNUSED(r_info))
 {
 	KeyingSet *ks = (KeyingSet *)ptr->data;
 	
diff --git a/source/blender/makesrna/intern/rna_curve.c b/source/blender/makesrna/intern/rna_curve.c
index f4fb30e..22e4596 100644
--- a/source/blender/makesrna/intern/rna_curve.c
+++ b/source/blender/makesrna/intern/rna_curve.c
@@ -221,7 +221,7 @@ static void rna_Curve_texspace_set(Main *UNUSED(bmain), Scene *UNUSED(scene), Po
 		BKE_curve_texspace_calc(cu);
 }
 
-static int rna_Curve_texspace_editable(PointerRNA *ptr)
+static int rna_Curve_texspace_editable(PointerRNA *ptr, const char **UNUSED(r_info))
 {
 	Curve *cu = (Curve *)ptr->data;
 	return (cu->texflag & CU_AUTOSPACE) ? 0 : PROP_EDITABLE;
diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c
index c521e93..1d3b65b 100644
--- a/source/blender/makesrna/intern/rna_fcurve.c
+++ b/source/blender/makesrna/intern/rna_fcurve.c
@@ -199,13 +199,13 @@ static StructRNA *rna_DriverTarget_id_typef(PointerRNA *ptr)
 	return ID_code_to_RNA_type(dtar->idtype);
 }
 
-static int rna_DriverTarget_id_editable(PointerRNA *ptr)
+static int rna_DriverTarget_id_editable(PointerRNA *ptr, const char **UNUSED(r_info))
 {
 	DriverTarget *dtar = (DriverTarget *)ptr->data;
 	return (dtar->idtype) ? PROP_EDITABLE : 0;
 }
 
-static int rna_DriverTarget_id_type_editable(PointerRNA *ptr)
+static int rna_DriverTarget_id_type_editable(PointerRNA *ptr, const char **UNUSED(r_info))
 {
 	DriverTarget *dtar = (DriverTarget *)ptr->data;
 	
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index 7eaf8b6..9b881c1 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -120,7 +120,7 @@ static char *rna_GPencilLayer_path(PointerRNA *ptr)
 	return BLI_sprintfN("layers[\"%s\"]", name_esc);
 }
 
-static int rna_GPencilLayer_active_frame_editable(PointerRNA *ptr)
+static int rna_GPencilLayer_active_frame_editable(PointerRNA *ptr, const char **UNUSED(r_info))
 {
 	bGPDlayer *gpl = (bGPDlayer *)ptr->data;
 
diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h
index ba0705b..04b85b8 100644
--- a/source/blender/makesrna/intern/rna_internal_types.h
+++ b/source/blender/makesrna/intern/rna_internal_types.h
@@ -62,7 +62,7 @@ struct Scene;
 typedef void (*UpdateFunc)(struct Main *main, struct Scene *scene, struct PointerRNA *ptr);
 typedef void (*ContextPropUpdateFunc)(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop);
 typedef void (*ContextUpdateFunc)(struct bContext *C, struct PointerRNA *ptr);
-typedef int (*EditableFunc)(struct PointerRNA *ptr);
+typedef int (*EditableFunc)(struct PointerRNA *ptr, const char **r_info);
 typedef int (*ItemEditableFunc)(struct PointerRNA *ptr, int index);
 typedef struct IDProperty *(*IDPropertiesFunc)(struct PointerRNA *ptr, bool create);
 typedef struct StructRNA *(*StructRefineFunc)(struct PointerRNA *ptr);
@@ -188,7 +188,9 @@ struct PropertyRNA {
 	UpdateFunc update;
 	int noteflag;
 
-	/* callback for testing if editable */
+	/* Callback for testing if editable. Its r_info parameter can be used to
+	 * return info on editable state that might be shown to user. E.g. tooltips
+	 * of disabled buttons can show reason why button is disabled using this. */
 	EditableFunc editable;
 	/* callback for testing if array-item editable (if applicable) */
 	ItemEd

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list