25#include <wx/filename.h>
27#include <wx/hyperlink.h>
29#include <wx/scrolwin.h>
31#include <wx/settings.h>
32#include <wx/stattext.h>
45#include <nlohmann/json.hpp>
60 wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxSize( -1, 75 ),
62 m_hlDetails( nullptr ),
63 m_notification( aNoti ),
66 SetSizeHints( wxDefaultSize, wxDefaultSize );
68 wxBoxSizer* mainSizer;
69 mainSizer =
new wxBoxSizer( wxVERTICAL );
71 SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DLIGHT ) );
73 m_stTitle =
new wxStaticText(
this, wxID_ANY, aNoti->
title );
74 m_stTitle->Wrap( -1 );
75 m_stTitle->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT,
76 wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD,
false, wxEmptyString ) );
77 mainSizer->Add( m_stTitle, 0, wxALL | wxEXPAND, 1 );
79 m_stDescription =
new wxStaticText(
this, wxID_ANY, aNoti->
description, wxDefaultPosition,
81 m_stDescription->Wrap( -1 );
82 mainSizer->Add( m_stDescription, 0, wxALL | wxEXPAND, 1 );
84 wxBoxSizer* tailSizer;
85 tailSizer =
new wxBoxSizer( wxHORIZONTAL );
87 if( !aNoti->
href.IsEmpty() )
90 new wxHyperlinkCtrl(
this, wxID_ANY,
_(
"View Details" ), aNoti->
href,
91 wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE );
92 tailSizer->Add( m_hlDetails, 0, wxALL, 2 );
95 m_hlDismiss =
new wxHyperlinkCtrl(
this, wxID_ANY,
_(
"Dismiss" ), aNoti->
href,
96 wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE );
97 tailSizer->Add( m_hlDismiss, 0, wxALL, 2 );
99 mainSizer->Add( tailSizer, 1, wxEXPAND, 5 );
101 if( m_hlDetails !=
nullptr )
108 SetSizer( mainSizer );
115 wxString url = aEvent.GetURL();
117 if( url.StartsWith( wxS(
"kicad://" ) ) )
119 url.Replace( wxS(
"kicad://" ), wxS(
"" ) );
121 if( url == wxS(
"pcm" ) )
128 wxLaunchDefaultBrowser( aEvent.GetURL(), wxBROWSER_NEW_WINDOW );
138 m_manager->Remove( m_notification->key );
155 wxFrame( parent, wxID_ANY,
_(
"Notifications" ), pos, wxSize( 300, 150 ),
156 wxFRAME_NO_TASKBAR | wxBORDER_SIMPLE ),
159 SetSizeHints( wxDefaultSize, wxDefaultSize );
162 bSizer1 =
new wxBoxSizer( wxVERTICAL );
165 wxSize( -1, -1 ), wxVSCROLL );
176 wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER_HORIZONTAL );
192 if( !IsDescendant( aEvent.GetWindow() ) )
237 std::unordered_map<NOTIFICATION*, NOTIFICATION_PANEL*>
m_panelMap;
252 nlohmann::json saved_json;
254 std::ifstream saved_json_stream(
m_destFileName.GetFullPath().fn_str() );
258 saved_json_stream >> saved_json;
262 catch( std::exception& )
267 if( wxGetEnv( wxT(
"KICAD_TEST_NOTI" ),
nullptr ) )
269 CreateOrUpdate( wxS(
"test" ), wxS(
"Test Notification" ), wxS(
"Test please ignore" ),
270 wxS(
"https://kicad.org" ) );
277 std::ofstream jsonFileStream(
m_destFileName.GetFullPath().fn_str() );
280 jsonFileStream << std::setw( 4 ) << saveJson << std::endl;
281 jsonFileStream.flush();
282 jsonFileStream.close();
287 const wxString& aTitle,
288 const wxString& aDescription,
289 const wxString& aHref )
291 wxCHECK_RET( !aKey.IsEmpty(), wxS(
"Notification key must not be empty" ) );
296 return noti.key == aKey;
310 aKey, wxEmptyString } );
336 return noti.key == aKey;
350 list->Remove( &(*it) );
372 return dialog == evtWindow;
393 wxSize windowSize = list->GetSize();
394 list->SetPosition( aPos - windowSize );
414 return statusBar == aStatusBar;
void SetNotificationCount(int aCount)
Sets the notification count on the notifications button A value of 0 will hide the count.
void onFocusLoss(wxFocusEvent &aEvent)
void Add(NOTIFICATION *aNoti)
NOTIFICATIONS_MANAGER * m_manager
Text to be displayed when no notifications are present, this gets a Show/Hide call as needed.
wxBoxSizer * m_contentSizer
std::unordered_map< NOTIFICATION *, NOTIFICATION_PANEL * > m_panelMap
void Remove(NOTIFICATION *aNoti)
wxScrolledWindow * m_scrolledWindow
Inner content of the scrolled window, add panels here.
wxStaticText * m_noNotificationsText
NOTIFICATIONS_LIST(NOTIFICATIONS_MANAGER *aManager, wxWindow *parent, const wxPoint &pos)
void Save()
Saves notifications to disk.
void onListWindowClosed(wxCloseEvent &aEvent)
Handles removing the shown list window from our list of shown windows.
wxFileName m_destFileName
void Load()
Loads 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)
Creates 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
The cached file path to read/write notifications on disk.
void UnregisterStatusBar(KISTATUSBAR *aStatusBar)
Removes status bar from handling.
std::vector< NOTIFICATION > m_notifications
Currently shown notification lists.
void ShowList(wxWindow *aParent, wxPoint aPos)
Shows the notification list.
std::vector< NOTIFICATIONS_LIST * > m_shownDialogs
Status bars registered for updates.
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.
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(DRC_REPORT, source, date, kicad_version, violations, unconnected_items, schematic_parity, coordinate_units) struct ERC_SHEET
wxString description
Additional message displayed under title.
wxString title
Title of the notification.
wxString href
URL if any to link to for details.