RNA: use string-join to simplify operator register

Also sanity check macro-operator ID's.
This commit is contained in:
2017-08-23 18:17:42 +10:00
parent 81c0e643a0
commit cf8d35edc8
3 changed files with 101 additions and 100 deletions

View File

@@ -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);

View File

@@ -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.
*