26#include <wx/statusbr.h>
28#include <wx/stattext.h>
29#include <wx/tokenzr.h>
30#include <fmt/format.h>
44#include <wx/dcclient.h>
60 GetSizer()->Fit(
this );
69 EndModal( wxID_CLEAR );
79 wxStatusBar( parent, id ),
105 if( showNotification )
108 SetFieldsCount( aNumberFields + extraFields );
123 int* styles =
new int[aNumberFields + extraFields];
125 for(
int i = 0; i < aNumberFields + extraFields; i++ )
126 styles[i] = wxSB_FLAT;
128 SetStatusStyles( aNumberFields + extraFields, styles );
131 m_backgroundTxt =
new wxStaticText(
this, wxID_ANY, wxT(
"" ), wxDefaultPosition,
132 wxDefaultSize, wxALIGN_RIGHT | wxST_NO_AUTORESIZE );
135 wxGA_HORIZONTAL | wxGA_SMOOTH );
139 m_backgroundStopButton =
new wxButton(
this, wxID_ANY,
"X", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
142 if( showNotification )
145 wxDefaultSize, wxBU_EXACTFIT );
158 wxDefaultSize, wxBU_EXACTFIT );
238 pos.x += r.GetWidth();
253 pos.x += r.GetWidth();
268 constexpr int padding = 5;
273 if( sbField >= 0 && sbField < GetFieldsCount() )
280 if( r.GetHeight() > textHeight )
281 y += ( r.GetHeight() - textHeight ) / 2;
290 if( sbField >= 0 && sbField < GetFieldsCount() )
295 int w = r.GetWidth();
296 int h = r.GetHeight();
297 wxSize buttonSize( 0, 0 );
304 buttonSize.x += padding;
314 if( sbField >= 0 && sbField < GetFieldsCount() )
331 if( sbField >= 0 && sbField < GetFieldsCount() )
336 int h = r.GetHeight();
371 if( aAmount > range )
400 SetStatusText( wxEmptyString, adjacentField );
463 if( !
text.empty() && r.GetWidth() > 4 )
465 wxClientDC dc(
this );
467 text = wxControl::Ellipsize(
text, dc, wxELLIPSIZE_END, std::max( 0, r.GetWidth() - margin ) );
480 cnt = fmt::format(
"{}", aCount );
494 wxStringTokenizer tokenizer( aMessages, wxS(
"\n" ), wxTOKEN_STRTOK );
496 while( tokenizer.HasMoreTokens() )
499 msg.
message = tokenizer.GetNextToken();
511 wxLogTrace(
traceLibraries,
"KISTATUSBAR::AddWarningMessages: this=%p, count=%zu",
512 this, aMessages.size() );
514 if( aMessages.empty() )
517 size_t totalMessageCount = 0;
524 totalMessageCount += messages.size();
527 wxLogTrace(
traceLibraries,
" -> total messages now=%zu", totalMessageCount );
530 wxLogTrace(
traceLibraries,
" -> calling CallAfter for updateWarningUI" );
542 count += messages.size();
550 wxLogTrace(
traceLibraries,
"KISTATUSBAR::updateWarningUI: this=%p, m_warningButton=%p",
555 wxLogTrace(
traceLibraries,
" -> no warning button, returning early" );
565 for(
const std::vector<LOAD_MESSAGE>& messages :
m_warningMessages | std::views::values )
566 messageCount += messages.size();
569 wxLogTrace(
traceLibraries,
" -> message count=%zu, showing button=%s",
570 messageCount, messageCount > 0 ?
"true" :
"false" );
576 if( messageCount > 0 )
578 m_warningButton->SetToolTip( wxString::Format(
_(
"View %zu message(s)" ), messageCount ) );
581 wxString badgeText = messageCount > 99
583 : wxString::Format( wxS(
"%zu" ), messageCount );
604 if( aSource.IsEmpty() )
617 std::unordered_map<wxString, std::vector<LOAD_MESSAGE>> messages;
623 if( messages.empty() )
628 for(
const std::vector<LOAD_MESSAGE>& source : std::views::values( messages ) )
640 wxString etext = aText;
644 if( GetFieldRect( aFieldId, fieldRect ) )
645 width = fieldRect.GetWidth();
649 wxClientDC dc(
this );
653 etext = wxControl::Ellipsize( etext, dc, wxELLIPSIZE_MIDDLE, width - margin );
656 SetStatusText( etext, aFieldId );
712 wxStatusBar::SetStatusWidths( aSize, aWidths );
714 for(
int i = 0; ( i < aSize ) && ( i < static_cast<int>(
m_fieldWidths.size() ) ); i++ )
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
void ShowList(wxWindow *aParent, wxPoint aPos)
Shows the background job list.
wxStdDialogButtonSizer * m_sdbSizer
WX_HTML_REPORT_BOX * m_Reporter
DIALOG_HTML_REPORTER(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Report"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
BITMAP_BUTTON * m_notificationsButton
void AddWarningMessages(const wxString &aSource, const wxString &aMessages)
Add warning/error messages (not thread-safe, use the std::vector<LOAD_MESSAGE> variant from other thr...
void onLoadWarningsIconClick(wxCommandEvent &aEvent)
std::optional< int > fieldIndex(FIELD aField) const
void SetBackgroundStatusText(const wxString &aTxt)
Set the status text that displays next to the progress bar.
BITMAP_BUTTON * m_warningButton
wxString m_backgroundRawText
Unellipsized background status text.
std::unordered_map< wxString, std::vector< LOAD_MESSAGE > > m_warningMessages
size_t GetLoadWarningCount() const
Get current message count (thread-safe).
void onBackgroundProgressClick(wxMouseEvent &aEvent)
KISTATUSBAR(int aNumberFields, wxWindow *parent, wxWindowID id, STYLE_FLAGS aFlags=DEFAULT_STYLE)
void updateAuxFieldWidths()
void onSize(wxSizeEvent &aEvent)
void ClearWarningMessages(const wxString &aSource=wxEmptyString)
Clears all warning messages from the given source (or all sources if aSource is empty)
wxString m_savedStatusText
Saved text from adjacent field during background jobs.
std::mutex m_warningMutex
Protects m_warningMessages.
void updateBackgroundText()
void SetBackgroundProgress(int aAmount)
Set the current progress of the progress bar.
wxGauge * m_backgroundProgressBar
wxButton * m_backgroundStopButton
void updateWarningUI()
Update warning button visibility and badge (main thread only)
void SetEllipsedTextField(const wxString &aText, int aFieldId)
Set the text in a field using wxELLIPSIZE_MIDDLE option to adjust the text size to the field size.
virtual void SetStatusWidths(int aSize, const int *aWidths) override
std::vector< int > m_fieldWidths
void HideBackgroundProgressBar()
Hide the background progress bar.
void onNotificationsIconClick(wxCommandEvent &aEvent)
void SetBackgroundProgressMax(int aAmount)
Set the max progress of the progress bar.
wxStaticText * m_backgroundTxt
void ShowBackgroundProgressBar(bool aCancellable=false)
Show the background progress bar.
void SetNotificationCount(int aCount)
Set the notification count on the notifications button.
void ShowList(wxWindow *aParent, wxPoint aPos)
Show the notification list.
virtual BACKGROUND_JOBS_MONITOR & GetBackgroundJobMonitor() const
virtual NOTIFICATIONS_MANAGER & GetNotificationsManager() const
void onClearButtonClick(wxCommandEvent &aEvent)
KISTATUSBAR * m_statusBar
STATUSBAR_WARNING_REPORTER_DIALOG(wxWindow *aParent, KISTATUSBAR *aStatusBar)
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
void Flush()
Build the HTML messages page.
const wxChar *const traceLibraries
Flag to enable library table and library manager tracing.
KICOMMON_API wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
PGM_BASE & Pgm()
The global program "get" accessor.
KISTATUSBAR is a wxStatusBar suitable for Kicad manager.
wxLogTrace helper definitions.
Functions to provide common constants and other functions to assist in making a consistent UI.