diff --git a/common/notifications_manager.cpp b/common/notifications_manager.cpp index e1b93c422b..eca6c58c26 100644 --- a/common/notifications_manager.cpp +++ b/common/notifications_manager.cpp @@ -120,19 +120,11 @@ public: m_hlDismiss->Bind( wxEVT_HYPERLINK, &NOTIFICATION_PANEL::onDismiss, this ); - Bind( wxEVT_SET_FOCUS, &NOTIFICATION_PANEL::onFocusSet, this ); - SetSizer( mainSizer ); Layout(); } private: - void onFocusSet( wxFocusEvent& aEvent ) - { - // hmmph - - } - void onDetails( wxHyperlinkEvent& aEvent ) { wxString url = aEvent.GetURL(); @@ -287,6 +279,12 @@ void NOTIFICATIONS_MANAGER::Load() // failed to load the json return; } + + if( wxGetEnv( wxT( "KICAD_TEST_NOTI" ), nullptr ) ) + { + CreateOrUpdate( wxS( "test" ), wxS( "Test Notification" ), wxS( "Test please ignore" ), + wxS( "https://kicad.org" ) ); + } } @@ -301,11 +299,13 @@ void NOTIFICATIONS_MANAGER::Save() } -void NOTIFICATIONS_MANAGER::Create( const wxString& aKey, +void NOTIFICATIONS_MANAGER::CreateOrUpdate( const wxString& aKey, const wxString& aTitle, const wxString& aDescription, const wxString& aHref ) { + wxCHECK_RET( !aKey.IsEmpty(), wxS( "Notification key must not be empty" ) ); + auto it = std::find_if( m_notifications.begin(), m_notifications.end(), [&]( const NOTIFICATION& noti ) { diff --git a/include/notifications_manager.h b/include/notifications_manager.h index 83a4c8a172..c64bfa5aa1 100644 --- a/include/notifications_manager.h +++ b/include/notifications_manager.h @@ -55,14 +55,15 @@ public: NOTIFICATIONS_MANAGER(); /** - * Creates a notification with the given parameters - * @param aKey is a unique key for the notification, this allows removing + * Creates a notification with the given parameters or updates an existing one with the same key + * + * @param aKey is a unique key for the notification, this allows removing or updating the same notification * @param aTitle is the displayed title for the event * @param aDescription is the text that displays underneath the title and has slightly more info * them later programtically in case a notificaiton is no logner required * @param aHref is link to external or internal content */ - void Create( const wxString& aKey, const wxString& aTitle, const wxString& aDescription, + void CreateOrUpdate( const wxString& aKey, const wxString& aTitle, const wxString& aDescription, const wxString& aHref = wxEmptyString ); /** diff --git a/kicad/kicad_manager_frame.cpp b/kicad/kicad_manager_frame.cpp index 9b9be6c5a5..2305665d43 100644 --- a/kicad/kicad_manager_frame.cpp +++ b/kicad/kicad_manager_frame.cpp @@ -289,7 +289,7 @@ void KICAD_MANAGER_FRAME::CreatePCM() if( aUpdateCount > 0 ) { - Pgm().GetNotificationsManager().Create( + Pgm().GetNotificationsManager().CreateOrUpdate( wxS( "pcm" ), _( "PCM Updates Available" ), wxString::Format( _( "%d package update(s) avaliable" ), aUpdateCount ),