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:
2014-02-09 12:00:03 +11:00
parent 52f080604b
commit 873f901e5a
4 changed files with 51 additions and 29 deletions

View File

@@ -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 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 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 */ void uiPupMenuInvoke(struct bContext *C, const char *idname); /* popup registered menu */
/* Popup Blocks /* 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) #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 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 *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); uiBut *uiDefMenuBut(uiBlock *block, uiMenuCreateFunc func, void *arg, const char *str, int x, int y, short width, short height, const char *tip);

View File

@@ -2690,37 +2690,50 @@ void uiPupMenuSaveOver(bContext *C, wmOperator *op, const char *filename)
void uiPupMenuReports(bContext *C, ReportList *reports) void uiPupMenuReports(bContext *C, ReportList *reports)
{ {
Report *report; Report *report;
DynStr *ds;
char *str;
if (!reports || !reports->list.first) uiPopupMenu *pup = NULL;
return; uiLayout *layout;
if (!CTX_wm_window(C)) if (!CTX_wm_window(C))
return; return;
ds = BLI_dynstr_new();
for (report = reports->list.first; report; report = report->next) { for (report = reports->list.first; report; report = report->next) {
int icon;
const char *msg, *msg_next;
if (report->type < reports->printlevel) { 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) { else {
BLI_dynstr_appendf(ds, IFACE_("Warning %%i%d%%t|%s"), ICON_ERROR, report->message); uiItemS(layout);
}
else if (report->type >= RPT_INFO) {
BLI_dynstr_appendf(ds, IFACE_("Info %%i%d%%t|%s"), ICON_INFO, report->message);
} }
/* 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 (pup) {
if (str[0] != '\0') uiPupMenuEnd(C, pup);
ui_popup_menu_create(C, NULL, NULL, NULL, NULL, str); }
MEM_freeN(str);
BLI_dynstr_free(ds);
} }
void uiPupMenuInvoke(bContext *C, const char *idname) void uiPupMenuInvoke(bContext *C, const char *idname)

View File

@@ -1,5 +1,4 @@
/* /*
* ***** BEGIN GPL LICENSE BLOCK ***** * ***** BEGIN GPL LICENSE BLOCK *****
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@@ -3285,7 +3284,7 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
uiBut *but; uiBut *but;
uiStyle *style = UI_GetStyle(); uiStyle *style = UI_GetStyle();
int width; int width;
int icon = 0; int icon;
/* if the report display has timed out, don't show */ /* if the report display has timed out, don't show */
if (!reports->reporttimer) return; if (!reports->reporttimer) return;
@@ -3317,12 +3316,7 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
/* icon and report message on top */ /* icon and report message on top */
if (report->type & RPT_ERROR_ALL) icon = uiIconFromReportType(report->type);
icon = ICON_ERROR;
else if (report->type & RPT_WARNING_ALL)
icon = ICON_ERROR;
else if (report->type & RPT_INFO_ALL)
icon = ICON_INFO;
/* XXX: temporary operator to dump all reports to a text block, but only if more than 1 report /* 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... * to be shown instead of icon when appropriate...

View File

@@ -44,6 +44,7 @@
#include "BLF_translation.h" #include "BLF_translation.h"
#include "BKE_context.h" #include "BKE_context.h"
#include "BKE_report.h"
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
@@ -231,6 +232,19 @@ int uiIconFromID(ID *id)
return (ptr.type) ? RNA_struct_ui_icon(ptr.type) : ICON_NONE; 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 **************************************/ /********************************** Misc **************************************/
/** /**