RNA: use string-join to simplify operator register
Also sanity check macro-operator ID's.
This commit is contained in:
@@ -354,6 +354,7 @@ bool WM_operator_pystring_abbreviate(char *str, int str_len_max);
|
||||
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);
|
||||
bool WM_operator_py_idname_ok_or_report(struct ReportList *reports, const char *classname, const char *idname);
|
||||
|
||||
/* *************** uilist types ******************** */
|
||||
void WM_uilisttype_init(void);
|
||||
|
||||
@@ -572,6 +572,46 @@ void WM_operator_bl_idname(char *to, const char *from)
|
||||
to[0] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanity check to ensure #WM_operator_bl_idname won't fail.
|
||||
* \returns true when there are no problems with \a idname, otherwise report an error.
|
||||
*/
|
||||
bool WM_operator_py_idname_ok_or_report(ReportList *reports, const char *classname, const char *idname)
|
||||
{
|
||||
const char *ch = idname;
|
||||
int dot = 0;
|
||||
int i;
|
||||
for (i = 0; *ch; i++, ch++) {
|
||||
if ((*ch >= 'a' && *ch <= 'z') || (*ch >= '0' && *ch <= '9') || *ch == '_') {
|
||||
/* pass */
|
||||
}
|
||||
else if (*ch == '.') {
|
||||
dot++;
|
||||
}
|
||||
else {
|
||||
BKE_reportf(reports, RPT_ERROR,
|
||||
"Registering operator class: '%s', invalid bl_idname '%s', at position %d",
|
||||
classname, idname, i);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (i > (MAX_NAME - 3)) {
|
||||
BKE_reportf(reports, RPT_ERROR, "Registering operator class: '%s', invalid bl_idname '%s', "
|
||||
"is too long, maximum length is %d", classname, idname,
|
||||
MAX_NAME - 3);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dot != 1) {
|
||||
BKE_reportf(reports, RPT_ERROR,
|
||||
"Registering operator class: '%s', invalid bl_idname '%s', must contain 1 '.' character",
|
||||
classname, idname);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a string representation of the operator, with the args that it runs so python can run it again.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user