Formatting and better use of common code.

This commit is contained in:
Jeff Young 2025-02-02 11:31:10 +00:00
parent d96479dd34
commit 72a59c547c
3 changed files with 42 additions and 73 deletions

View File

@ -36,19 +36,19 @@
#include <notifications_manager.h> #include <notifications_manager.h>
#include <widgets/kistatusbar.h> #include <widgets/kistatusbar.h>
#include <widgets/ui_common.h>
#include <json_common.h> #include <json_common.h>
#include "core/wx_stl_compat.h" #include <core/wx_stl_compat.h>
#include <core/json_serializers.h>
#include <core/kicad_algo.h>
#include <algorithm> #include <algorithm>
#include <fstream> #include <fstream>
#include <map> #include <map>
#include <core/json_serializers.h>
#include <optional> #include <optional>
#include <string>
#include <tuple> #include <tuple>
#include <vector> #include <vector>
#include <wx/string.h>
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( NOTIFICATION, title, description, href, key, date ) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( NOTIFICATION, title, description, href, key, date )
@ -57,8 +57,7 @@ class NOTIFICATION_PANEL : public wxPanel
{ {
public: public:
NOTIFICATION_PANEL( wxWindow* aParent, NOTIFICATIONS_MANAGER* aManager, NOTIFICATION* aNoti ) : NOTIFICATION_PANEL( wxWindow* aParent, NOTIFICATIONS_MANAGER* aManager, NOTIFICATION* aNoti ) :
wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxSize( -1, 75 ), wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxSize( -1, 75 ), wxBORDER_SIMPLE ),
wxBORDER_SIMPLE ),
m_hlDetails( nullptr ), m_hlDetails( nullptr ),
m_notification( aNoti ), m_notification( aNoti ),
m_manager( aManager ) m_manager( aManager )
@ -72,13 +71,10 @@ public:
m_stTitle = new wxStaticText( this, wxID_ANY, aNoti->title ); m_stTitle = new wxStaticText( this, wxID_ANY, aNoti->title );
m_stTitle->Wrap( -1 ); m_stTitle->Wrap( -1 );
m_stTitle->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT, m_stTitle->SetFont( KIUI::GetControlFont( this ).Bold() );
wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false,
wxEmptyString ) );
mainSizer->Add( m_stTitle, 0, wxALL | wxEXPAND, 1 ); mainSizer->Add( m_stTitle, 0, wxALL | wxEXPAND, 1 );
m_stDescription = new wxStaticText( this, wxID_ANY, aNoti->description, wxDefaultPosition, m_stDescription = new wxStaticText( this, wxID_ANY, aNoti->description );
wxDefaultSize, 0 );
m_stDescription->Wrap( -1 ); m_stDescription->Wrap( -1 );
mainSizer->Add( m_stDescription, 0, wxALL | wxEXPAND, 1 ); mainSizer->Add( m_stDescription, 0, wxALL | wxEXPAND, 1 );
@ -87,22 +83,17 @@ public:
if( !aNoti->href.IsEmpty() ) if( !aNoti->href.IsEmpty() )
{ {
m_hlDetails = m_hlDetails = new wxHyperlinkCtrl( this, wxID_ANY, _( "View Details" ), aNoti->href );
new wxHyperlinkCtrl( this, wxID_ANY, _( "View Details" ), aNoti->href,
wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE );
tailSizer->Add( m_hlDetails, 0, wxALL, 2 ); tailSizer->Add( m_hlDetails, 0, wxALL, 2 );
} }
m_hlDismiss = new wxHyperlinkCtrl( this, wxID_ANY, _( "Dismiss" ), aNoti->href, m_hlDismiss = new wxHyperlinkCtrl( this, wxID_ANY, _( "Dismiss" ), aNoti->href );
wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE );
tailSizer->Add( m_hlDismiss, 0, wxALL, 2 ); tailSizer->Add( m_hlDismiss, 0, wxALL, 2 );
mainSizer->Add( tailSizer, 1, wxEXPAND, 5 ); mainSizer->Add( tailSizer, 1, wxEXPAND, 5 );
if( m_hlDetails != nullptr ) if( m_hlDetails != nullptr )
{
m_hlDetails->Bind( wxEVT_HYPERLINK, &NOTIFICATION_PANEL::onDetails, this ); m_hlDetails->Bind( wxEVT_HYPERLINK, &NOTIFICATION_PANEL::onDetails, this );
}
m_hlDismiss->Bind( wxEVT_HYPERLINK, &NOTIFICATION_PANEL::onDismiss, this ); m_hlDismiss->Bind( wxEVT_HYPERLINK, &NOTIFICATION_PANEL::onDismiss, this );
@ -140,11 +131,12 @@ private:
} ); } );
} }
wxStaticText* m_stTitle; private:
wxStaticText* m_stDescription; wxStaticText* m_stTitle;
wxHyperlinkCtrl* m_hlDetails; wxStaticText* m_stDescription;
wxHyperlinkCtrl* m_hlDismiss; wxHyperlinkCtrl* m_hlDetails;
NOTIFICATION* m_notification; wxHyperlinkCtrl* m_hlDismiss;
NOTIFICATION* m_notification;
NOTIFICATIONS_MANAGER* m_manager; NOTIFICATIONS_MANAGER* m_manager;
}; };
@ -172,9 +164,10 @@ public:
m_contentSizer->Fit( m_scrolledWindow ); m_contentSizer->Fit( m_scrolledWindow );
bSizer1->Add( m_scrolledWindow, 1, wxEXPAND | wxALL, 0 ); bSizer1->Add( m_scrolledWindow, 1, wxEXPAND | wxALL, 0 );
m_noNotificationsText = new wxStaticText( m_noNotificationsText = new wxStaticText( m_scrolledWindow, wxID_ANY,
m_scrolledWindow, wxID_ANY, _( "There are no notifications available" ), _( "There are no notifications available" ),
wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER_HORIZONTAL ); wxDefaultPosition, wxDefaultSize,
wxALIGN_CENTER_HORIZONTAL );
m_noNotificationsText->Wrap( -1 ); m_noNotificationsText->Wrap( -1 );
m_contentSizer->Add( m_noNotificationsText, 1, wxALL | wxEXPAND, 5 ); m_contentSizer->Add( m_noNotificationsText, 1, wxALL | wxEXPAND, 5 );
@ -277,7 +270,7 @@ void NOTIFICATIONS_MANAGER::Load()
if( wxGetEnv( wxT( "KICAD_TEST_NOTI" ), nullptr ) ) if( wxGetEnv( wxT( "KICAD_TEST_NOTI" ), nullptr ) )
{ {
CreateOrUpdate( wxS( "test" ), wxS( "Test Notification" ), wxS( "Test please ignore" ), CreateOrUpdate( wxS( "test" ), wxS( "Test Notification" ), wxS( "Test please ignore" ),
wxS( "https://kicad.org" ) ); wxS( "https://kicad.org" ) );
} }
} }
@ -324,15 +317,11 @@ void NOTIFICATIONS_MANAGER::CreateOrUpdate( const wxString& aKey,
{ {
// update dialogs // update dialogs
for( NOTIFICATIONS_LIST* list : m_shownDialogs ) for( NOTIFICATIONS_LIST* list : m_shownDialogs )
{
list->Add( &m_notifications.back() ); list->Add( &m_notifications.back() );
}
} }
for( KISTATUSBAR* statusBar : m_statusBars ) for( KISTATUSBAR* statusBar : m_statusBars )
{
statusBar->SetNotificationCount( m_notifications.size() ); statusBar->SetNotificationCount( m_notifications.size() );
}
Save(); Save();
} }
@ -347,18 +336,14 @@ void NOTIFICATIONS_MANAGER::Remove( const wxString& aKey )
} ); } );
if( it == m_notifications.end() ) if( it == m_notifications.end() )
{
return; return;
}
if( m_shownDialogs.size() > 0 ) if( m_shownDialogs.size() > 0 )
{ {
// update dialogs // update dialogs
for( NOTIFICATIONS_LIST* list : m_shownDialogs ) for( NOTIFICATIONS_LIST* list : m_shownDialogs )
{
list->Remove( &(*it) ); list->Remove( &(*it) );
}
} }
m_notifications.erase( it ); m_notifications.erase( it );
@ -366,9 +351,7 @@ void NOTIFICATIONS_MANAGER::Remove( const wxString& aKey )
Save(); Save();
for( KISTATUSBAR* statusBar : m_statusBars ) for( KISTATUSBAR* statusBar : m_statusBars )
{
statusBar->SetNotificationCount( m_notifications.size() ); statusBar->SetNotificationCount( m_notifications.size() );
}
} }
@ -376,11 +359,10 @@ void NOTIFICATIONS_MANAGER::onListWindowClosed( wxCloseEvent& aEvent )
{ {
NOTIFICATIONS_LIST* evtWindow = dynamic_cast<NOTIFICATIONS_LIST*>( aEvent.GetEventObject() ); NOTIFICATIONS_LIST* evtWindow = dynamic_cast<NOTIFICATIONS_LIST*>( aEvent.GetEventObject() );
m_shownDialogs.erase( std::remove_if( m_shownDialogs.begin(), m_shownDialogs.end(), alg::delete_if( m_shownDialogs, [&]( NOTIFICATIONS_LIST* dialog )
[&]( NOTIFICATIONS_LIST* dialog ) {
{ return dialog == evtWindow;
return dialog == evtWindow; } );
} ) );
aEvent.Skip(); aEvent.Skip();
} }
@ -391,9 +373,7 @@ void NOTIFICATIONS_MANAGER::ShowList( wxWindow* aParent, wxPoint aPos )
NOTIFICATIONS_LIST* list = new NOTIFICATIONS_LIST( this, aParent, aPos ); NOTIFICATIONS_LIST* list = new NOTIFICATIONS_LIST( this, aParent, aPos );
for( NOTIFICATION& job : m_notifications ) for( NOTIFICATION& job : m_notifications )
{
list->Add( &job ); list->Add( &job );
}
m_shownDialogs.push_back( list ); m_shownDialogs.push_back( list );
@ -418,9 +398,8 @@ void NOTIFICATIONS_MANAGER::RegisterStatusBar( KISTATUSBAR* aStatusBar )
void NOTIFICATIONS_MANAGER::UnregisterStatusBar( KISTATUSBAR* aStatusBar ) void NOTIFICATIONS_MANAGER::UnregisterStatusBar( KISTATUSBAR* aStatusBar )
{ {
m_statusBars.erase( std::remove_if( m_statusBars.begin(), m_statusBars.end(), alg::delete_if( m_statusBars, [&]( KISTATUSBAR* statusBar )
[&]( KISTATUSBAR* statusBar ) {
{ return statusBar == aStatusBar;
return statusBar == aStatusBar; } );
} ) );
} }

View File

@ -50,8 +50,6 @@ public:
class KICOMMON_API NOTIFICATIONS_MANAGER class KICOMMON_API NOTIFICATIONS_MANAGER
{ {
friend class NOTIFICATION_LIST;
public: public:
NOTIFICATIONS_MANAGER(); NOTIFICATIONS_MANAGER();
@ -66,7 +64,7 @@ public:
* @param aHref is link to external or internal content. * @param aHref is link to external or internal content.
*/ */
void CreateOrUpdate( const wxString& aKey, const wxString& aTitle, const wxString& aDescription, void CreateOrUpdate( const wxString& aKey, const wxString& aTitle, const wxString& aDescription,
const wxString& aHref = wxEmptyString ); const wxString& aHref = wxEmptyString );
/** /**
* Remove a notification by key. * Remove a notification by key.
@ -106,6 +104,7 @@ private:
*/ */
void onListWindowClosed( wxCloseEvent& aEvent ); void onListWindowClosed( wxCloseEvent& aEvent );
private:
/// Current stack of notifications. /// Current stack of notifications.
std::vector<NOTIFICATION> m_notifications; std::vector<NOTIFICATION> m_notifications;
@ -113,10 +112,10 @@ private:
std::vector<NOTIFICATIONS_LIST*> m_shownDialogs; std::vector<NOTIFICATIONS_LIST*> m_shownDialogs;
/// Status bars registered for updates. /// Status bars registered for updates.
std::vector<KISTATUSBAR*> m_statusBars; std::vector<KISTATUSBAR*> m_statusBars;
/// The cached file path to read/write notifications on disk. /// The cached file path to read/write notifications on disk.
wxFileName m_destFileName; wxFileName m_destFileName;
}; };
#endif #endif

View File

@ -210,8 +210,8 @@ KICAD_MANAGER_FRAME::KICAD_MANAGER_FRAME( wxWindow* parent, const wxString& titl
m_auimgr.SetManagedWindow( this ); m_auimgr.SetManagedWindow( this );
m_auimgr.SetFlags( wxAUI_MGR_LIVE_RESIZE ); m_auimgr.SetFlags( wxAUI_MGR_LIVE_RESIZE );
m_auimgr.AddPane( m_mainToolBar, EDA_PANE().VToolbar().Name( "MainToolbar" ).Left() m_auimgr.AddPane( m_mainToolBar,
.Layer( 2 ) ); EDA_PANE().VToolbar().Name( "MainToolbar" ).Left().Layer( 2 ) );
// BestSize() does not always set the actual pane size of m_leftWin to the required value. // BestSize() does not always set the actual pane size of m_leftWin to the required value.
// It happens when m_leftWin is too large (roughly > 1/3 of the kicad manager frame width. // It happens when m_leftWin is too large (roughly > 1/3 of the kicad manager frame width.
@ -240,13 +240,9 @@ KICAD_MANAGER_FRAME::KICAD_MANAGER_FRAME( wxWindow* parent, const wxString& titl
m_notebook->SetTabCtrlHeight( 0 ); m_notebook->SetTabCtrlHeight( 0 );
m_notebook->Thaw(); m_notebook->Thaw();
m_auimgr.AddPane( m_notebook, EDA_PANE() m_auimgr.AddPane( m_notebook,
.Canvas() EDA_PANE().Canvas().Name( "Editors" ).Center().Caption( EDITORS_CAPTION )
.Name( "Editors" ) .PaneBorder( false ).MinSize( m_notebook->GetBestSize() ) );
.Center()
.Caption( EDITORS_CAPTION )
.PaneBorder( false )
.MinSize( m_notebook->GetBestSize() ) );
m_auimgr.Update(); m_auimgr.Update();
@ -333,20 +329,15 @@ void KICAD_MANAGER_FRAME::onNotebookPageCountChanged( wxAuiNotebookEvent& evt )
void KICAD_MANAGER_FRAME::onNotebookPageCloseRequest( wxAuiNotebookEvent& evt ) void KICAD_MANAGER_FRAME::onNotebookPageCloseRequest( wxAuiNotebookEvent& evt )
{ {
wxAuiNotebook* ctrl = (wxAuiNotebook*) evt.GetEventObject(); wxAuiNotebook* notebook = (wxAuiNotebook*) evt.GetEventObject();
wxWindow* page = notebook->GetPage( evt.GetSelection() );
wxWindow* pageWindow = ctrl->GetPage( evt.GetSelection() ); if( PANEL_NOTEBOOK_BASE* panel = dynamic_cast<PANEL_NOTEBOOK_BASE*>( page ) )
PANEL_NOTEBOOK_BASE* panel = dynamic_cast<PANEL_NOTEBOOK_BASE*>( pageWindow );
if( panel )
{ {
if( panel->GetClosable() ) if( panel->GetClosable() )
{ {
if( !panel->GetCanClose() ) if( !panel->GetCanClose() )
{
evt.Veto(); evt.Veto();
}
CallAfter( CallAfter(
[this]() [this]()
@ -444,8 +435,8 @@ void KICAD_MANAGER_FRAME::setupUIConditions()
activeProjectCond.Enable( activeProject ); activeProjectCond.Enable( activeProject );
manager->SetConditions( ACTIONS::saveAs, activeProjectCond ); manager->SetConditions( ACTIONS::saveAs, activeProjectCond );
manager->SetConditions( KICAD_MANAGER_ACTIONS::closeProject, activeProjectCond ); manager->SetConditions( KICAD_MANAGER_ACTIONS::closeProject, activeProjectCond );
manager->SetConditions( KICAD_MANAGER_ACTIONS::newJobsetFile, activeProjectCond ); manager->SetConditions( KICAD_MANAGER_ACTIONS::newJobsetFile, activeProjectCond );
manager->SetConditions( KICAD_MANAGER_ACTIONS::openJobsetFile, activeProjectCond ); manager->SetConditions( KICAD_MANAGER_ACTIONS::openJobsetFile, activeProjectCond );
// These are just here for text boxes, search boxes, etc. in places such as the standard // These are just here for text boxes, search boxes, etc. in places such as the standard