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 );
117 SetStatusWidths( aNumberFields + extraFields,
m_fieldWidths.data() );
119 int* styles =
new int[aNumberFields + extraFields];
121 for(
int i = 0; i < aNumberFields + extraFields; i++ )
122 styles[i] = wxSB_FLAT;
124 SetStatusStyles( aNumberFields + extraFields, styles );
127 m_backgroundTxt =
new wxStaticText(
this, wxID_ANY, wxT(
"" ), wxDefaultPosition,
128 wxDefaultSize, wxALIGN_RIGHT | wxST_NO_AUTORESIZE );
131 wxGA_HORIZONTAL | wxGA_SMOOTH );
136 wxDefaultSize, wxBU_EXACTFIT );
139 if( showNotification )
142 wxDefaultSize, wxBU_EXACTFIT );
155 wxDefaultSize, wxBU_EXACTFIT );
197 pos.x += r.GetWidth();
212 pos.x += r.GetWidth();
227 constexpr int padding = 5;
235 if( r.GetHeight() > textHeight )
236 y += ( r.GetHeight() - textHeight ) / 2;
245 int w = r.GetWidth();
246 int h = r.GetHeight();
247 wxSize buttonSize( 0, 0 );
254 buttonSize.x += padding;
310 if( aAmount > range )
339 SetStatusText( wxEmptyString, adjacentField );
394 if( !
text.empty() && r.GetWidth() > 4 )
396 wxClientDC dc(
this );
398 text = wxControl::Ellipsize(
text, dc, wxELLIPSIZE_END, std::max( 0, r.GetWidth() - margin ) );
411 cnt = fmt::format(
"{}", aCount );
425 wxStringTokenizer tokenizer( aMessages, wxS(
"\n" ), wxTOKEN_STRTOK );
427 while( tokenizer.HasMoreTokens() )
430 msg.
message = tokenizer.GetNextToken();
442 wxLogTrace(
traceLibraries,
"KISTATUSBAR::AddWarningMessages: this=%p, count=%zu",
443 this, aMessages.size() );
445 if( aMessages.empty() )
448 size_t totalMessageCount = 0;
455 totalMessageCount += messages.size();
458 wxLogTrace(
traceLibraries,
" -> total messages now=%zu", totalMessageCount );
461 wxLogTrace(
traceLibraries,
" -> calling CallAfter for updateWarningUI" );
473 count += messages.size();
481 wxLogTrace(
traceLibraries,
"KISTATUSBAR::updateWarningUI: this=%p, m_warningButton=%p",
486 wxLogTrace(
traceLibraries,
" -> no warning button, returning early" );
496 for(
const std::vector<LOAD_MESSAGE>& messages :
m_warningMessages | std::views::values )
497 messageCount += messages.size();
500 wxLogTrace(
traceLibraries,
" -> message count=%zu, showing button=%s",
501 messageCount, messageCount > 0 ?
"true" :
"false" );
507 if( messageCount > 0 )
509 m_warningButton->SetToolTip( wxString::Format(
_(
"View %zu message(s)" ), messageCount ) );
512 wxString badgeText = messageCount > 99
514 : wxString::Format( wxS(
"%zu" ), messageCount );
535 if( aSource.IsEmpty() )
548 std::unordered_map<wxString, std::vector<LOAD_MESSAGE>> messages;
554 if( messages.empty() )
559 for(
const std::vector<LOAD_MESSAGE>& source : std::views::values( messages ) )
571 wxString etext = aText;
575 if( GetFieldRect( aFieldId, fieldRect ) )
576 width = fieldRect.GetWidth();
580 wxClientDC dc(
this );
584 etext = wxControl::Ellipsize( etext, dc, wxELLIPSIZE_MIDDLE, width - margin );
587 SetStatusText( etext, aFieldId );
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.
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.