UI: improve reports popup
- use labels rather then menu items (items selected but did nothing) - each report gets its own icon (icons besides first were ignored) - use uiPupMenu rather then string based menu.
This commit is contained in:
@@ -350,7 +350,7 @@ struct uiLayout *uiPupMenuLayout(uiPopupMenu *head);
|
||||
|
||||
void uiPupMenuOkee(struct bContext *C, const char *opname, const char *str, ...) ATTR_PRINTF_FORMAT(3, 4);
|
||||
void uiPupMenuSaveOver(struct bContext *C, struct wmOperator *op, const char *filename);
|
||||
void uiPupMenuReports(struct bContext *C, struct ReportList *reports);
|
||||
void uiPupMenuReports(struct bContext *C, struct ReportList *reports) ATTR_NONNULL();
|
||||
void uiPupMenuInvoke(struct bContext *C, const char *idname); /* popup registered menu */
|
||||
|
||||
/* Popup Blocks
|
||||
@@ -578,6 +578,7 @@ void uiButGetStrInfo(struct bContext *C, uiBut *but, ...) ATTR_SENTINEL(0);
|
||||
#define UI_ID_FULL (UI_ID_RENAME | UI_ID_BROWSE | UI_ID_ADD_NEW | UI_ID_OPEN | UI_ID_ALONE | UI_ID_DELETE | UI_ID_LOCAL)
|
||||
|
||||
int uiIconFromID(struct ID *id);
|
||||
int uiIconFromReportType(int type);
|
||||
|
||||
uiBut *uiDefPulldownBut(uiBlock *block, uiBlockCreateFunc func, void *arg, const char *str, int x, int y, short width, short height, const char *tip);
|
||||
uiBut *uiDefMenuBut(uiBlock *block, uiMenuCreateFunc func, void *arg, const char *str, int x, int y, short width, short height, const char *tip);
|
||||
|
||||
@@ -2690,37 +2690,50 @@ void uiPupMenuSaveOver(bContext *C, wmOperator *op, const char *filename)
|
||||
void uiPupMenuReports(bContext *C, ReportList *reports)
|
||||
{
|
||||
Report *report;
|
||||
DynStr *ds;
|
||||
char *str;
|
||||
|
||||
if (!reports || !reports->list.first)
|
||||
return;
|
||||
uiPopupMenu *pup = NULL;
|
||||
uiLayout *layout;
|
||||
|
||||
if (!CTX_wm_window(C))
|
||||
return;
|
||||
|
||||
ds = BLI_dynstr_new();
|
||||
|
||||
for (report = reports->list.first; report; report = report->next) {
|
||||
int icon;
|
||||
const char *msg, *msg_next;
|
||||
|
||||
if (report->type < reports->printlevel) {
|
||||
/* pass */
|
||||
continue;
|
||||
}
|
||||
else if (report->type >= RPT_ERROR) {
|
||||
BLI_dynstr_appendf(ds, IFACE_("Error %%i%d%%t|%s"), ICON_ERROR, report->message);
|
||||
|
||||
if (pup == NULL) {
|
||||
char title[UI_MAX_DRAW_STR];
|
||||
BLI_snprintf(title, sizeof(title), "%s: %s", IFACE_("Report"), report->typestr);
|
||||
pup = uiPupMenuBegin(C, title, ICON_NONE);
|
||||
layout = uiPupMenuLayout(pup);
|
||||
}
|
||||
else if (report->type >= RPT_WARNING) {
|
||||
BLI_dynstr_appendf(ds, IFACE_("Warning %%i%d%%t|%s"), ICON_ERROR, report->message);
|
||||
}
|
||||
else if (report->type >= RPT_INFO) {
|
||||
BLI_dynstr_appendf(ds, IFACE_("Info %%i%d%%t|%s"), ICON_INFO, report->message);
|
||||
else {
|
||||
uiItemS(layout);
|
||||
}
|
||||
|
||||
/* split each newline into a label */
|
||||
msg = report->message;
|
||||
icon = uiIconFromReportType(report->type);
|
||||
do {
|
||||
char buf[UI_MAX_DRAW_STR];
|
||||
msg_next = strchr(msg, '\n');
|
||||
if (msg_next) {
|
||||
msg_next++;
|
||||
BLI_strncpy(buf, msg, MIN2(sizeof(buf), msg_next - msg));
|
||||
msg = buf;
|
||||
}
|
||||
uiItemL(layout, msg, icon);
|
||||
icon = ICON_NONE;
|
||||
} while ((msg = msg_next) && *msg);
|
||||
}
|
||||
|
||||
str = BLI_dynstr_get_cstring(ds);
|
||||
if (str[0] != '\0')
|
||||
ui_popup_menu_create(C, NULL, NULL, NULL, NULL, str);
|
||||
MEM_freeN(str);
|
||||
|
||||
BLI_dynstr_free(ds);
|
||||
if (pup) {
|
||||
uiPupMenuEnd(C, pup);
|
||||
}
|
||||
}
|
||||
|
||||
void uiPupMenuInvoke(bContext *C, const char *idname)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
/*
|
||||
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
@@ -3285,7 +3284,7 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
|
||||
uiBut *but;
|
||||
uiStyle *style = UI_GetStyle();
|
||||
int width;
|
||||
int icon = 0;
|
||||
int icon;
|
||||
|
||||
/* if the report display has timed out, don't show */
|
||||
if (!reports->reporttimer) return;
|
||||
@@ -3317,12 +3316,7 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
|
||||
|
||||
|
||||
/* icon and report message on top */
|
||||
if (report->type & RPT_ERROR_ALL)
|
||||
icon = ICON_ERROR;
|
||||
else if (report->type & RPT_WARNING_ALL)
|
||||
icon = ICON_ERROR;
|
||||
else if (report->type & RPT_INFO_ALL)
|
||||
icon = ICON_INFO;
|
||||
icon = uiIconFromReportType(report->type);
|
||||
|
||||
/* XXX: temporary operator to dump all reports to a text block, but only if more than 1 report
|
||||
* to be shown instead of icon when appropriate...
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include "BLF_translation.h"
|
||||
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_report.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
@@ -231,6 +232,19 @@ int uiIconFromID(ID *id)
|
||||
return (ptr.type) ? RNA_struct_ui_icon(ptr.type) : ICON_NONE;
|
||||
}
|
||||
|
||||
/* see: report_type_str */
|
||||
int uiIconFromReportType(int type)
|
||||
{
|
||||
if (type & RPT_ERROR_ALL)
|
||||
return ICON_ERROR;
|
||||
else if (type & RPT_WARNING_ALL)
|
||||
return ICON_ERROR;
|
||||
else if (type & RPT_INFO_ALL)
|
||||
return ICON_INFO;
|
||||
else
|
||||
return ICON_NONE;
|
||||
}
|
||||
|
||||
/********************************** Misc **************************************/
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user