[Bf-blender-cvs] [b8d37d7181b] soc-2020-info-editor: Add function for reports with syntax highlighting
Mateusz GrzeliÅski
noreply at git.blender.org
Wed Jul 29 14:35:38 CEST 2020
Commit: b8d37d7181bdba88913e52ba8072eddd083311e0
Author: Mateusz Grzeliński
Date: Wed Jul 29 13:52:36 2020 +0200
Branches: soc-2020-info-editor
https://developer.blender.org/rBb8d37d7181bdba88913e52ba8072eddd083311e0
Add function for reports with syntax highlighting
===================================================================
M source/blender/blenkernel/BKE_report.h
M source/blender/blenkernel/intern/report.c
M source/blender/editors/interface/interface_handlers.c
M source/blender/windowmanager/intern/wm_event_system.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_report.h b/source/blender/blenkernel/BKE_report.h
index 5318fa99f89..6e875e6cbd4 100644
--- a/source/blender/blenkernel/BKE_report.h
+++ b/source/blender/blenkernel/BKE_report.h
@@ -42,7 +42,10 @@ void BKE_reports_init(ReportList *reports, int flag);
void BKE_reports_clear(ReportList *reports);
ReportList *BKE_reports_duplicate(ReportList *reports);
+void BKE_report_format(ReportList *reports, ReportType type, int flags, const char *message);
void BKE_report(ReportList *reports, ReportType type, const char *message);
+void BKE_reportf_format(ReportList *reports, ReportType type, int flags, const char *format, ...)
+ ATTR_PRINTF_FORMAT(4, 5);
void BKE_reportf(ReportList *reports, ReportType type, const char *format, ...)
ATTR_PRINTF_FORMAT(3, 4);
diff --git a/source/blender/blenkernel/intern/report.c b/source/blender/blenkernel/intern/report.c
index f8aceda9b43..db26c59594e 100644
--- a/source/blender/blenkernel/intern/report.c
+++ b/source/blender/blenkernel/intern/report.c
@@ -146,7 +146,7 @@ ReportList *BKE_reports_duplicate(ReportList *reports)
return reports_new;
}
-void BKE_report(ReportList *reports, ReportType type, const char *_message)
+void BKE_report_format(ReportList *reports, ReportType type, int flags, const char *_message)
{
Report *report;
int len;
@@ -164,16 +164,9 @@ void BKE_report(ReportList *reports, ReportType type, const char *_message)
char *message_alloc;
report = MEM_callocN(sizeof(Report), "Report");
report->type = type;
+ report->flag = flags;
report->typestr = BKE_report_type_str(type);
- /* TODO (grzelins) hack: we want to pass flags in argument */
- if (report->type == RPT_PROPERTY) {
- report->flag = RPT_PYTHON;
- }
- if (report->type == RPT_OPERATOR) {
- report->flag = RPT_PYTHON;
- }
-
len = strlen(message);
message_alloc = MEM_mallocN(sizeof(char) * (len + 1), "ReportMessage");
memcpy(message_alloc, message, sizeof(char) * (len + 1));
@@ -183,9 +176,13 @@ void BKE_report(ReportList *reports, ReportType type, const char *_message)
}
}
-void BKE_reportf(ReportList *reports, ReportType type, const char *_format, ...)
+void BKE_report(ReportList *reports, ReportType type, const char *_message)
+{
+ BKE_report_format(reports, type, 0, _message);
+}
+
+void BKE_reportf_format(ReportList *reports, ReportType type, int flags, const char *_format, ...)
{
- Report *report;
va_list args;
const char *format = TIP_(_format);
DynStr *message = BLI_dynstr_new();
@@ -194,41 +191,29 @@ void BKE_reportf(ReportList *reports, ReportType type, const char *_format, ...)
BLI_dynstr_vappendf(message, format, args);
va_end(args);
- /* TODO (grzelins) it is crucial to show anything when UI is not available, maybe enable this
- * logger on warning level by default (and use appropriate severity level)? for example in
- * versioning_280.c "Eevee material conversion problem" check logger to avoid allocating memory
- * if logger is off
- */
- if (CLOG_CHECK_IN_USE(&LOG)) {
- char *message_cstring = BLI_dynstr_get_cstring(message);
- CLOG_AT_SEVERITY(&LOG,
- report_type_to_severity(type),
- 0,
- "ReportList(%p):%s: %s",
- reports,
- BKE_report_type_str(type),
- message_cstring);
- MEM_freeN(message_cstring);
- }
+ char *cstring = BLI_dynstr_get_cstring(message);
- if (reports) {
- report = MEM_callocN(sizeof(Report), "Report");
+ BKE_report_format(reports, type, flags, cstring);
- report->message = BLI_dynstr_get_cstring(message);
- report->len = BLI_dynstr_get_len(message);
- report->type = type;
- report->typestr = BKE_report_type_str(type);
+ MEM_freeN(cstring);
+ BLI_dynstr_free(message);
+}
- /* TODO (grzelins) hack: we want to pass flags in argument */
- if (report->type == RPT_PROPERTY) {
- report->flag = RPT_PYTHON;
- }
- if (report->type == RPT_OPERATOR) {
- report->flag = RPT_PYTHON;
- }
+void BKE_reportf(ReportList *reports, ReportType type, const char *_format, ...)
+{
+ va_list args;
+ const char *format = TIP_(_format);
+ DynStr *message = BLI_dynstr_new();
- BLI_addtail(&reports->list, report);
- }
+ va_start(args, _format);
+ BLI_dynstr_vappendf(message, format, args);
+ va_end(args);
+
+ char *cstring = BLI_dynstr_get_cstring(message);
+
+ BKE_report_format(reports, type, 0, cstring);
+
+ MEM_freeN(cstring);
BLI_dynstr_free(message);
}
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 3750f29ae57..e76ada2734e 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -866,7 +866,7 @@ static void ui_apply_but_autokey(bContext *C, uiBut *but)
buf = WM_prop_pystring_assign(C, &but->rnapoin, but->rnaprop, but->rnaindex);
if (buf) {
- BKE_report(CTX_wm_reports(C), RPT_PROPERTY, buf);
+ BKE_report_format(CTX_wm_reports(C), RPT_PROPERTY, RPT_PYTHON, buf);
MEM_freeN(buf);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_INFO_REPORT, NULL);
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 551bfb29667..610887d740d 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -863,7 +863,7 @@ static void wm_operator_reports(bContext *C, wmOperator *op, int retval, bool ca
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, true);
- BKE_report(CTX_wm_reports(C), RPT_OPERATOR, buf);
+ BKE_report_format(CTX_wm_reports(C), RPT_OPERATOR, RPT_PYTHON, buf);
MEM_freeN(buf);
}
}
More information about the Bf-blender-cvs
mailing list