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>
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 );
193 if( !IsDescendant( aEvent.GetWindow() ) )
242 std::unordered_map<NOTIFICATION*, NOTIFICATION_PANEL*>
m_panelMap;
257 nlohmann::json saved_json;
259 std::ifstream saved_json_stream(
m_destFileName.GetFullPath().fn_str() );
263 saved_json_stream >> saved_json;
267 catch( std::exception& )
272 if( wxGetEnv( wxT(
"KICAD_TEST_NOTI" ),
nullptr ) )
274 CreateOrUpdate( wxS(
"test" ), wxS(
"Test Notification" ), wxS(
"Test please ignore" ),
275 wxS(
"https://kicad.org" ) );
282 std::ofstream jsonFileStream(
m_destFileName.GetFullPath().fn_str() );
285 jsonFileStream << std::setw( 4 ) << saveJson << std::endl;
286 jsonFileStream.flush();
287 jsonFileStream.close();
292 const wxString& aTitle,
293 const wxString& aDescription,
294 const wxString& aHref )
296 wxCHECK_RET( !aKey.IsEmpty(), wxS(
"Notification key must not be empty" ) );
301 return noti.key == aKey;
315 aKey, wxEmptyString } );
341 return noti.key == aKey;
355 list->Remove( &(*it) );
377 return dialog == evtWindow;
398 wxSize windowSize = list->GetSize();
399 list->SetPosition( aPos - windowSize );
419 return statusBar == aStatusBar;
KISTATUSBAR is a wxStatusBar suitable for Kicad manager.
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.
wxString description
Additional message displayed under title.
wxString title
Title of the notification.
wxString href
URL if any to link to for details.
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(UPDATE_REQUEST, platform, arch, current_version, lang, last_check) struct UPDATE_RESPONSE