Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Gavrilov <angavrilov@gmail.com>2019-09-06 16:26:10 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2019-09-06 22:05:20 +0300
commit9ecbd67dfb672cd13f021c82d83aeb7ae8a8cf10 (patch)
tree9edad541160077d63cd77fe9c0210d29bebad6f3 /source/blender/windowmanager
parentb0b24b77ffc3e34b3aef24ff658826a8aeca7782 (diff)
Python API: implement an Operator callback for dynamic description.
Blender UI Layout API allows supplying parameters to operators via button definitions. If an operator behavior strongly depends on its parameters, it may be difficult to write a tooltip that covers all of its operation modes. Thus it is useful to provide a way for the operator to produce different descriptions based on the input info. Reviewers: campbellbarton Differential Revision: https://developer.blender.org/D5709
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/WM_api.h3
-rw-r--r--source/blender/windowmanager/WM_types.h6
-rw-r--r--source/blender/windowmanager/intern/wm_operator_type.c31
3 files changed, 40 insertions, 0 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index c7b18adf9b1..b933448d0bd 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -547,6 +547,9 @@ struct wmOperatorTypeMacro *WM_operatortype_macro_define(struct wmOperatorType *
const char *idname);
const char *WM_operatortype_name(struct wmOperatorType *ot, struct PointerRNA *properties);
+char *WM_operatortype_description(struct bContext *C,
+ struct wmOperatorType *ot,
+ struct PointerRNA *properties);
/* wm_uilist_type.c */
void WM_uilisttype_init(void);
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index 7fdbf79248b..b3507c7e57e 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -737,6 +737,12 @@ typedef struct wmOperatorType {
*/
const char *(*get_name)(struct wmOperatorType *, struct PointerRNA *);
+ /**
+ * Return a different description to use in the user interface, based on property values.
+ * The returned string must be freed by the caller, unless NULL.
+ */
+ char *(*get_description)(struct bContext *C, struct wmOperatorType *, struct PointerRNA *);
+
/** rna for properties */
struct StructRNA *srna;
diff --git a/source/blender/windowmanager/intern/wm_operator_type.c b/source/blender/windowmanager/intern/wm_operator_type.c
index 8f3052ace5e..96fbac3aecc 100644
--- a/source/blender/windowmanager/intern/wm_operator_type.c
+++ b/source/blender/windowmanager/intern/wm_operator_type.c
@@ -595,4 +595,35 @@ const char *WM_operatortype_name(struct wmOperatorType *ot, struct PointerRNA *p
return (name && name[0]) ? name : RNA_struct_ui_name(ot->srna);
}
+char *WM_operatortype_description(struct bContext *C,
+ struct wmOperatorType *ot,
+ struct PointerRNA *properties)
+{
+ if (ot->get_description && properties) {
+ char *description = ot->get_description(C, ot, properties);
+
+ if (description) {
+ if (description[0]) {
+ return description;
+ }
+ else {
+ MEM_freeN(description);
+ }
+ }
+ }
+
+ const char *info = RNA_struct_ui_description(ot->srna);
+
+ if (!(info && info[0])) {
+ info = RNA_struct_ui_name(ot->srna);
+ }
+
+ if (info && info[0]) {
+ return BLI_strdup(info);
+ }
+ else {
+ return NULL;
+ }
+}
+
/** \} */