User Interface: don't show macro args in tooltips
was often making much too big strings to show in a tip.
This commit is contained in:
parent
07bde9e797
commit
02f90c0001
Notes:
blender-bot
2023-02-14 11:33:27 +01:00
Referenced by issue #37575, Tooltips should not expose Macro settings, instead treat them as normal Operators
|
@ -1549,7 +1549,7 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
|
|||
char *str;
|
||||
opptr = uiButGetOperatorPtrRNA(but); /* allocated when needed, the button owns it */
|
||||
|
||||
str = WM_operator_pystring_ex(C, NULL, false, but->optype, opptr);
|
||||
str = WM_operator_pystring_ex(C, NULL, false, true, but->optype, opptr);
|
||||
|
||||
WM_clipboard_text_set(str, 0);
|
||||
|
||||
|
|
|
@ -2969,7 +2969,7 @@ static void ui_intro_button(DynStr *ds, uiButtonItem *bitem)
|
|||
BLI_dynstr_appendf(ds, "'tip':'''%s''', ", but->tip ? but->tip : ""); /* not exactly needed, rna has this */
|
||||
|
||||
if (but->optype) {
|
||||
char *opstr = WM_operator_pystring_ex(but->block->evil_C, NULL, false, but->optype, but->opptr);
|
||||
char *opstr = WM_operator_pystring_ex(but->block->evil_C, NULL, false, true, but->optype, but->opptr);
|
||||
BLI_dynstr_appendf(ds, "'operator':'''%s''', ", opstr ? opstr : "");
|
||||
MEM_freeN(opstr);
|
||||
}
|
||||
|
|
|
@ -539,7 +539,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
|
|||
/* so the context is passed to itemf functions (some py itemf functions use it) */
|
||||
WM_operator_properties_sanitize(opptr, false);
|
||||
|
||||
str = WM_operator_pystring_ex(C, NULL, false, but->optype, opptr);
|
||||
str = WM_operator_pystring_ex(C, NULL, false, false, but->optype, opptr);
|
||||
|
||||
/* operator info */
|
||||
if ((U.flag & USER_TOOLTIPS_PYTHON) == 0) {
|
||||
|
|
|
@ -1038,11 +1038,11 @@ char *RNA_property_as_string(struct bContext *C, PointerRNA *ptr, PropertyRNA *p
|
|||
char *RNA_pointer_as_string_id(struct bContext *C, PointerRNA *ptr);
|
||||
char *RNA_pointer_as_string(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop_ptr, PointerRNA *ptr_prop);
|
||||
char *RNA_pointer_as_string_keywords_ex(struct bContext *C, PointerRNA *ptr,
|
||||
const bool skip_optional_value, const bool all_args,
|
||||
const bool skip_optional_value, const bool all_args, const bool nested_args,
|
||||
const int max_prop_length,
|
||||
PropertyRNA *iterprop);
|
||||
char *RNA_pointer_as_string_keywords(struct bContext *C, PointerRNA *ptr,
|
||||
const bool skip_optional_value, const bool all_args,
|
||||
const bool skip_optional_value, const bool all_args, const bool nested_args,
|
||||
const int max_prop_length);
|
||||
char *RNA_function_as_string_keywords(struct bContext *C, FunctionRNA *func,
|
||||
const bool as_function, const bool all_args,
|
||||
|
|
|
@ -5040,7 +5040,7 @@ char *RNA_pointer_as_string(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *p
|
|||
|
||||
/* context can be NULL */
|
||||
char *RNA_pointer_as_string_keywords_ex(bContext *C, PointerRNA *ptr,
|
||||
const bool as_function, const bool all_args,
|
||||
const bool as_function, const bool all_args, const bool nested_args,
|
||||
const int max_prop_length,
|
||||
PropertyRNA *iterprop)
|
||||
{
|
||||
|
@ -5069,6 +5069,10 @@ char *RNA_pointer_as_string_keywords_ex(bContext *C, PointerRNA *ptr,
|
|||
continue;
|
||||
}
|
||||
|
||||
if ((nested_args == false) && (RNA_property_type(prop) == PROP_POINTER)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (as_function && (flag & PROP_REQUIRED)) {
|
||||
/* required args don't have useful defaults */
|
||||
BLI_dynstr_appendf(dynstr, first_iter ? "%s" : ", %s", arg_name);
|
||||
|
@ -5113,14 +5117,14 @@ char *RNA_pointer_as_string_keywords_ex(bContext *C, PointerRNA *ptr,
|
|||
}
|
||||
|
||||
char *RNA_pointer_as_string_keywords(bContext *C, PointerRNA *ptr,
|
||||
const bool as_function, const bool all_args,
|
||||
const bool as_function, const bool all_args, const bool nested_args,
|
||||
const int max_prop_length)
|
||||
{
|
||||
PropertyRNA *iterprop;
|
||||
|
||||
iterprop = RNA_struct_iterator_property(ptr->type);
|
||||
|
||||
return RNA_pointer_as_string_keywords_ex(C, ptr, as_function, all_args,
|
||||
return RNA_pointer_as_string_keywords_ex(C, ptr, as_function, all_args, nested_args,
|
||||
max_prop_length, iterprop);
|
||||
}
|
||||
|
||||
|
@ -5137,7 +5141,7 @@ char *RNA_function_as_string_keywords(bContext *C, FunctionRNA *func,
|
|||
|
||||
RNA_struct_iterator_property(funcptr.type);
|
||||
|
||||
return RNA_pointer_as_string_keywords_ex(C, &funcptr, as_function, all_args,
|
||||
return RNA_pointer_as_string_keywords_ex(C, &funcptr, as_function, all_args, true,
|
||||
max_prop_length, iterprop);
|
||||
}
|
||||
|
||||
|
|
|
@ -313,6 +313,7 @@ static PyObject *pyop_as_string(PyObject *UNUSED(self), PyObject *args)
|
|||
char *opname;
|
||||
PyObject *kw = NULL; /* optional args */
|
||||
int all_args = 1;
|
||||
int macro_args = 1;
|
||||
int error_val = 0;
|
||||
|
||||
char *buf = NULL;
|
||||
|
@ -325,7 +326,7 @@ static PyObject *pyop_as_string(PyObject *UNUSED(self), PyObject *args)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s|O!i:_bpy.ops.as_string", &opname, &PyDict_Type, &kw, &all_args))
|
||||
if (!PyArg_ParseTuple(args, "s|O!ii:_bpy.ops.as_string", &opname, &PyDict_Type, &kw, &all_args, ¯o_args))
|
||||
return NULL;
|
||||
|
||||
ot = WM_operatortype_find(opname, true);
|
||||
|
@ -345,7 +346,7 @@ static PyObject *pyop_as_string(PyObject *UNUSED(self), PyObject *args)
|
|||
error_val = pyrna_pydict_to_props(&ptr, kw, 0, "Converting py args to operator properties: ");
|
||||
|
||||
if (error_val == 0)
|
||||
buf = WM_operator_pystring_ex(C, NULL, all_args, ot, &ptr);
|
||||
buf = WM_operator_pystring_ex(C, NULL, all_args, macro_args, ot, &ptr);
|
||||
|
||||
WM_operator_properties_free(&ptr);
|
||||
|
||||
|
|
|
@ -272,9 +272,11 @@ bool WM_operator_last_properties_store(struct wmOperator *op);
|
|||
|
||||
|
||||
/* operator as a python command (resultuing string must be freed) */
|
||||
char *WM_operator_pystring_ex(struct bContext *C, struct wmOperator *op, const bool all_args,
|
||||
char *WM_operator_pystring_ex(struct bContext *C, struct wmOperator *op,
|
||||
const bool all_args, const bool macro_args,
|
||||
struct wmOperatorType *ot, struct PointerRNA *opptr);
|
||||
char *WM_operator_pystring(struct bContext *C, struct wmOperator *op, const bool all_args);
|
||||
char *WM_operator_pystring(struct bContext *C, struct wmOperator *op,
|
||||
const bool all_args, const bool macro_args);
|
||||
char *WM_prop_pystring_assign(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, int index);
|
||||
void WM_operator_bl_idname(char *to, const char *from);
|
||||
void WM_operator_py_idname(char *to, const char *from);
|
||||
|
|
|
@ -491,8 +491,8 @@ int WM_operator_poll_context(bContext *C, wmOperatorType *ot, short context)
|
|||
static void wm_operator_print(bContext *C, wmOperator *op)
|
||||
{
|
||||
/* context is needed for enum function */
|
||||
char *buf = WM_operator_pystring(C, op, false);
|
||||
printf("%s\n", buf);
|
||||
char *buf = WM_operator_pystring(C, op, false, true);
|
||||
puts(buf);
|
||||
MEM_freeN(buf);
|
||||
}
|
||||
|
||||
|
@ -626,7 +626,7 @@ static void wm_operator_reports(bContext *C, wmOperator *op, int retval, int cal
|
|||
if (op->type->flag & OPTYPE_REGISTER) {
|
||||
if (G.background == 0) { /* ends up printing these in the terminal, gets annoying */
|
||||
/* Report the python string representation of the operator */
|
||||
char *buf = WM_operator_pystring(C, op, false);
|
||||
char *buf = WM_operator_pystring(C, op, false, true);
|
||||
BKE_report(CTX_wm_reports(C), RPT_OPERATOR, buf);
|
||||
MEM_freeN(buf);
|
||||
}
|
||||
|
@ -660,7 +660,7 @@ static void wm_operator_finished(bContext *C, wmOperator *op, int repeat)
|
|||
|
||||
if (repeat == 0) {
|
||||
if (G.debug & G_DEBUG_WM) {
|
||||
char *buf = WM_operator_pystring(C, op, false);
|
||||
char *buf = WM_operator_pystring(C, op, false, true);
|
||||
BKE_report(CTX_wm_reports(C), RPT_OPERATOR, buf);
|
||||
MEM_freeN(buf);
|
||||
}
|
||||
|
|
|
@ -528,7 +528,8 @@ void WM_operator_bl_idname(char *to, const char *from)
|
|||
*
|
||||
* Note: both op and opptr may be NULL (op is only used for macro operators).
|
||||
*/
|
||||
char *WM_operator_pystring_ex(bContext *C, wmOperator *op, const bool all_args, wmOperatorType *ot, PointerRNA *opptr)
|
||||
char *WM_operator_pystring_ex(bContext *C, wmOperator *op, const bool all_args, const bool macro_args,
|
||||
wmOperatorType *ot, PointerRNA *opptr)
|
||||
{
|
||||
char idname_py[OP_MAX_TYPENAME];
|
||||
|
||||
|
@ -547,7 +548,10 @@ char *WM_operator_pystring_ex(bContext *C, wmOperator *op, const bool all_args,
|
|||
/* Special handling for macros, else we only get default values in this case... */
|
||||
wmOperator *opm;
|
||||
bool first_op = true;
|
||||
for (opm = op->macro.first; opm; opm = opm->next) {
|
||||
|
||||
opm = macro_args ? op->macro.first : NULL;
|
||||
|
||||
for (; opm; opm = opm->next) {
|
||||
PointerRNA *opmptr = opm->ptr;
|
||||
PointerRNA opmptr_default;
|
||||
if (opmptr == NULL) {
|
||||
|
@ -573,13 +577,14 @@ char *WM_operator_pystring_ex(bContext *C, wmOperator *op, const bool all_args,
|
|||
else {
|
||||
/* only to get the orginal props for comparisons */
|
||||
PointerRNA opptr_default;
|
||||
const bool macro_args_test = ot->macro.first ? macro_args : true;
|
||||
|
||||
if (opptr == NULL) {
|
||||
WM_operator_properties_create_ptr(&opptr_default, ot);
|
||||
opptr = &opptr_default;
|
||||
}
|
||||
|
||||
cstring_args = RNA_pointer_as_string_keywords(C, opptr, false, all_args, max_prop_length);
|
||||
cstring_args = RNA_pointer_as_string_keywords(C, opptr, false, all_args, macro_args_test, max_prop_length);
|
||||
BLI_dynstr_append(dynstr, cstring_args);
|
||||
MEM_freeN(cstring_args);
|
||||
|
||||
|
@ -595,9 +600,10 @@ char *WM_operator_pystring_ex(bContext *C, wmOperator *op, const bool all_args,
|
|||
return cstring;
|
||||
}
|
||||
|
||||
char *WM_operator_pystring(bContext *C, wmOperator *op, const bool all_args)
|
||||
char *WM_operator_pystring(bContext *C, wmOperator *op,
|
||||
const bool all_args, const bool macro_args)
|
||||
{
|
||||
return WM_operator_pystring_ex(C, op, all_args, op->type, op->ptr);
|
||||
return WM_operator_pystring_ex(C, op, all_args, macro_args, op->type, op->ptr);
|
||||
}
|
||||
|
||||
/* return NULL if no match is found */
|
||||
|
|
Loading…
Reference in New Issue