21#include <wx/filename.h>
23#include <wx/hyperlink.h>
25#include <wx/scrolwin.h>
27#include <wx/settings.h>
28#include <wx/stattext.h>
63 wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxSize( -1, 75 ), wxBORDER_SIMPLE ),
68 SetSizeHints( wxDefaultSize, wxDefaultSize );
70 wxBoxSizer* mainSizer;
71 mainSizer =
new wxBoxSizer( wxVERTICAL );
75 SetBackgroundColour( bg );
76 SetForegroundColour( fg );
81 mainSizer->Add(
m_stTitle, 0, wxALL | wxEXPAND, 1 );
86 int margin = FromDIP( 8 ) + wxSystemSettings::GetMetric( wxSYS_VSCROLL_X, aParent );
88 m_stDescription->Wrap( std::max( FromDIP( 100 ), aParent->GetClientSize().x - margin ) );
91 wxBoxSizer* tailSizer;
92 tailSizer =
new wxBoxSizer( wxHORIZONTAL );
94 if( !aNoti->
href.IsEmpty() )
96 m_hlDetails =
new wxHyperlinkCtrl(
this, wxID_ANY,
_(
"View Details" ), aNoti->
href );
100 m_hlDismiss =
new wxHyperlinkCtrl(
this, wxID_ANY,
_(
"Dismiss" ), aNoti->
href );
103 mainSizer->Add( tailSizer, 1, wxEXPAND, 5 );
110 SetSizer( mainSizer );
113 SetMinSize( wxSize( -1, std::max( GetMinSize().y, mainSizer->GetMinSize().y ) ) );
120 wxString url = aEvent.GetURL();
122 if( url.StartsWith( wxS(
"kicad://" ) ) )
124 url.Replace( wxS(
"kicad://" ), wxS(
"" ) );
126 if( url == wxS(
"pcm" ) )
133 wxLaunchDefaultBrowser( aEvent.GetURL(), wxBROWSER_NEW_WINDOW );
161 wxFrame( parent, wxID_ANY,
_(
"Notifications" ), pos, wxSize( 300, 150 ),
162 wxFRAME_NO_TASKBAR | wxBORDER_SIMPLE ),
165 SetSizeHints( wxDefaultSize, wxDefaultSize );
168 bSizer1 =
new wxBoxSizer( wxVERTICAL );
171 wxSize( -1, -1 ), wxVSCROLL | wxBORDER_SIMPLE );
186 _(
"There are no notifications available" ),
187 wxDefaultPosition, wxDefaultSize,
188 wxALIGN_CENTER_HORIZONTAL );
214 if( IsDescendant( aEvent.GetWindow() ) )
272 std::unordered_map<NOTIFICATION*, NOTIFICATION_PANEL*>
m_panelMap;
289 nlohmann::json saved_json;
291 std::ifstream saved_json_stream(
m_destFileName.GetFullPath().fn_str() );
295 saved_json_stream >> saved_json;
299 catch( std::exception& )
304 if( wxGetEnv( wxT(
"KICAD_TEST_NOTI" ),
nullptr ) )
306 CreateOrUpdate( wxS(
"test" ), wxS(
"Test Notification" ), wxS(
"Test please ignore" ),
307 wxS(
"https://kicad.org" ) );
314 std::ofstream jsonFileStream(
m_destFileName.GetFullPath().fn_str() );
317 jsonFileStream << std::setw( 4 ) << saveJson << std::endl;
318 jsonFileStream.flush();
319 jsonFileStream.close();
324 const wxString& aTitle,
325 const wxString& aDescription,
326 const wxString& aHref )
328 wxCHECK_RET( !aKey.IsEmpty(), wxS(
"Notification key must not be empty" ) );
333 return noti.key == aKey;
341 noti->
title = aTitle;
348 aKey, wxEmptyString } );
354 list->Remove( noti );
370 return noti.key == aKey;
381 list->Remove( &(*it) );
399 return dialog == evtWindow;
427 wxSize windowSize = list->GetSize();
428 list->SetPosition( aPos - windowSize );
448 return statusBar == aStatusBar;
KISTATUSBAR is a wxStatusBar suitable for Kicad manager.
void SetNotificationCount(int aCount)
Set the notification count on the notifications button.
void onFocusLoss(wxFocusEvent &aEvent)
void Add(NOTIFICATION *aNoti)
NOTIFICATIONS_MANAGER * m_manager
wxBoxSizer * m_contentSizer
Inner content of the scrolled window, add panels here.
std::unordered_map< NOTIFICATION *, NOTIFICATION_PANEL * > m_panelMap
void Remove(NOTIFICATION *aNoti)
wxScrolledWindow * m_scrolledWindow
wxStaticText * m_noNotificationsText
Text to be displayed when no notifications are present, this gets a Show/Hide call as needed.
NOTIFICATIONS_LIST(NOTIFICATIONS_MANAGER *aManager, wxWindow *parent, const wxPoint &pos)
std::list< NOTIFICATION > m_notifications
Current stack of notifications. A list, since shown panels hold pointers to its elements.
void Save()
Save notifications to disk.
void onListWindowClosed(wxCloseEvent &aEvent)
Handle removing the shown list window from our list of shown windows.
wxFileName m_destFileName
The cached file path to read/write notifications on disk.
void Load()
Load notifications stored from disk.
void RegisterStatusBar(KISTATUSBAR *aStatusBar)
Add a status bar for handling.
void CreateOrUpdate(const wxString &aKey, const wxString &aTitle, const wxString &aDescription, const wxString &aHref=wxEmptyString)
Create a notification with the given parameters or updates an existing one with the same key.
void Remove(const wxString &aKey)
Remove a notification by key.
std::vector< KISTATUSBAR * > m_statusBars
Status bars registered for updates.
void UnregisterStatusBar(KISTATUSBAR *aStatusBar)
Remove status bar from handling.
void ShowList(wxWindow *aParent, wxPoint aPos)
Show the notification list.
std::vector< NOTIFICATIONS_LIST * > m_shownDialogs
Currently shown notification lists.
wxHyperlinkCtrl * m_hlDetails
wxStaticText * m_stDescription
NOTIFICATION * m_notification
void onDismiss(wxHyperlinkEvent &aEvent)
NOTIFICATION_PANEL(wxWindow *aParent, NOTIFICATIONS_MANAGER *aManager, NOTIFICATION *aNoti)
void onDetails(wxHyperlinkEvent &aEvent)
NOTIFICATIONS_MANAGER * m_manager
wxHyperlinkCtrl * m_hlDismiss
static wxString GetUserCachePath()
Gets the stock (install) 3d viewer plugins path.
KICOMMON_API wxFont GetControlFont(wxWindow *aWindow)
static long long g_last_closed_timer
wxString description
Additional message displayed under title.
wxString title
Title of the notification.
wxString href
URL if any to link to for details.
Functions to provide common constants and other functions to assist in making a consistent UI.
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(UPDATE_REQUEST, platform, arch, current_version, lang, last_check) struct UPDATE_RESPONSE