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 );
192 if( !IsDescendant( aEvent.GetWindow() ) )
241 std::unordered_map<NOTIFICATION*, NOTIFICATION_PANEL*>
m_panelMap;
256 nlohmann::json saved_json;
258 std::ifstream saved_json_stream(
m_destFileName.GetFullPath().fn_str() );
262 saved_json_stream >> saved_json;
266 catch( std::exception& )
271 if( wxGetEnv( wxT(
"KICAD_TEST_NOTI" ),
nullptr ) )
273 CreateOrUpdate( wxS(
"test" ), wxS(
"Test Notification" ), wxS(
"Test please ignore" ),
274 wxS(
"https://kicad.org" ) );
281 std::ofstream jsonFileStream(
m_destFileName.GetFullPath().fn_str() );
284 jsonFileStream << std::setw( 4 ) << saveJson << std::endl;
285 jsonFileStream.flush();
286 jsonFileStream.close();
291 const wxString& aTitle,
292 const wxString& aDescription,
293 const wxString& aHref )
295 wxCHECK_RET( !aKey.IsEmpty(), wxS(
"Notification key must not be empty" ) );
300 return noti.key == aKey;
314 aKey, wxEmptyString } );
340 return noti.key == aKey;
354 list->Remove( &(*it) );
376 return dialog == evtWindow;
397 wxSize windowSize = list->GetSize();
398 list->SetPosition( aPos - windowSize );
418 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