From 90eb5e9c31bceb6222bd39a5067ff96f7cb37afe Mon Sep 17 00:00:00 2001 From: qu1ck Date: Wed, 18 Jan 2023 16:14:31 -0800 Subject: [PATCH] PCM: auto reload global libs after dialog is run This adds Reset() method to KIFACE to reload global libs stored in global static vars. Also refactors some lib reload code in various frames to have common MAIL_RELOAD_LIB handler. Fixes https://gitlab.com/kicad/code/kicad/-/issues/12500 (cherry picked from commit 2975f5364728f73d0ad4eba1a6e226bc9fa1fbfb) --- common/fp_lib_table.cpp | 1 + eeschema/cross-probing.cpp | 4 ++ eeschema/dialogs/panel_sym_lib_table.cpp | 20 ++---- eeschema/eeschema.cpp | 25 +++++++- eeschema/symbol_editor/symbol_edit_frame.cpp | 21 +++++++ eeschema/symbol_lib_table.cpp | 1 + eeschema/symbol_viewer_frame.cpp | 15 +++++ eeschema/symbol_viewer_frame.h | 2 + include/kiface_base.h | 16 ++--- include/kiway.h | 5 ++ include/mail_type.h | 3 +- kicad/pcm/dialogs/dialog_pcm.cpp | 10 ++- kicad/pcm/dialogs/dialog_pcm.h | 7 +++ kicad/pcm/dialogs/panel_pcm_settings.cpp | 2 - kicad/pcm/dialogs/panel_pcm_settings_base.cpp | 6 +- kicad/pcm/dialogs/panel_pcm_settings_base.fbp | 61 ------------------- kicad/pcm/dialogs/panel_pcm_settings_base.h | 3 +- kicad/pcm/pcm_task_manager.cpp | 22 +++---- kicad/pcm/pcm_task_manager.h | 10 ++- kicad/tools/kicad_manager_control.cpp | 42 +++++++++++++ pcbnew/cross-probing.cpp | 4 ++ pcbnew/dialogs/panel_fp_lib_table.cpp | 15 +---- pcbnew/footprint_edit_frame.cpp | 2 +- pcbnew/footprint_editor_utils.cpp | 5 ++ pcbnew/footprint_viewer_frame.cpp | 5 ++ pcbnew/fp_tree_synchronizing_adapter.cpp | 4 +- pcbnew/fp_tree_synchronizing_adapter.h | 2 +- pcbnew/pcbnew.cpp | 25 +++++++- 28 files changed, 198 insertions(+), 140 deletions(-) diff --git a/common/fp_lib_table.cpp b/common/fp_lib_table.cpp index 4b57a771b7..a5d08a754a 100644 --- a/common/fp_lib_table.cpp +++ b/common/fp_lib_table.cpp @@ -596,6 +596,7 @@ bool FP_LIB_TABLE::LoadGlobalTable( FP_LIB_TABLE& aTable ) } } + aTable.Clear(); aTable.Load( fn.GetFullPath() ); SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); diff --git a/eeschema/cross-probing.cpp b/eeschema/cross-probing.cpp index 52e5662b5b..99d74d110a 100644 --- a/eeschema/cross-probing.cpp +++ b/eeschema/cross-probing.cpp @@ -947,6 +947,10 @@ void SCH_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) m_toolManager->RunAction( ACTIONS::updateSchematicFromPcb, true ); break; + case MAIL_RELOAD_LIB: + SyncView(); + break; + default:; } diff --git a/eeschema/dialogs/panel_sym_lib_table.cpp b/eeschema/dialogs/panel_sym_lib_table.cpp index 29d525af2b..f746dac117 100644 --- a/eeschema/dialogs/panel_sym_lib_table.cpp +++ b/eeschema/dialogs/panel_sym_lib_table.cpp @@ -1014,9 +1014,7 @@ size_t PANEL_SYM_LIB_TABLE::m_pageNdx = 0; void InvokeSchEditSymbolLibTable( KIWAY* aKiway, wxWindow *aParent ) { - auto* schEditor = (SCH_EDIT_FRAME*) aKiway->Player( FRAME_SCH, false ); auto* symbolEditor = (SYMBOL_EDIT_FRAME*) aKiway->Player( FRAME_SCH_SYMBOL_EDITOR, false ); - auto* symbolViewer = (SYMBOL_VIEWER_FRAME*) aKiway->Player( FRAME_SCH_VIEWER, false ); SYMBOL_LIB_TABLE* globalTable = &SYMBOL_LIB_TABLE::GetGlobalLibTable(); wxString globalTablePath = SYMBOL_LIB_TABLE::GetGlobalTableFileName(); @@ -1093,23 +1091,13 @@ void InvokeSchEditSymbolLibTable( KIWAY* aKiway, wxWindow *aParent ) } } - if( schEditor ) - schEditor->SyncView(); - if( symbolEditor ) { - // Check if the currently selected symbol library been removed or disabled. - if( !currentLib.empty() && projectTable && !projectTable->HasLibrary( currentLib, true ) ) - { - symbolEditor->SetCurLib( wxEmptyString ); - symbolEditor->emptyScreen(); - } - - symbolEditor->SyncLibraries( true ); symbolEditor->ThawLibraryTree(); - symbolEditor->RefreshLibraryTree(); } - if( symbolViewer ) - symbolViewer->ReCreateLibList(); + std::string payload = ""; + aKiway->ExpressMail( FRAME_SCH, MAIL_RELOAD_LIB, payload ); + aKiway->ExpressMail( FRAME_SCH_SYMBOL_EDITOR, MAIL_RELOAD_LIB, payload ); + aKiway->ExpressMail( FRAME_SCH_VIEWER, MAIL_RELOAD_LIB, payload ); } diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index 72dedf8761..2531e7fc18 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -135,6 +135,8 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override; + void Reset() override; + void OnKifaceEnd() override; wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, @@ -286,6 +288,8 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER int HandleJob( JOB* aJob ) override; private: + bool loadGlobalLibTable(); + std::unique_ptr m_jobHandler; } kiface( "eeschema", KIWAY::FACE_SCH ); @@ -332,11 +336,28 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) start_common( aCtlBits ); + if( !loadGlobalLibTable() ) + return false; + + m_jobHandler = std::make_unique(); + + return true; +} + + +void IFACE::Reset() +{ + loadGlobalLibTable(); +} + + +bool IFACE::loadGlobalLibTable() +{ wxFileName fn = SYMBOL_LIB_TABLE::GetGlobalTableFileName(); if( !fn.FileExists() ) { - if( !( aCtlBits & KFCTL_CLI ) ) + if( !( m_start_flags & KFCTL_CLI ) ) { DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG fpDialog( nullptr ); @@ -366,8 +387,6 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) } } - m_jobHandler = std::make_unique(); - return true; } diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index d345274b11..9db563a0e9 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -1324,6 +1324,27 @@ void SYMBOL_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) break; + case MAIL_RELOAD_LIB: + { + wxString currentLib = GetCurLib(); + SYMBOL_LIB_TABLE* libTable = Prj().SchSymbolLibTable(); + + FreezeLibraryTree(); + + // Check if the currently selected symbol library been removed or disabled. + if( !currentLib.empty() && libTable && !libTable->HasLibrary( currentLib, true ) ) + { + SetCurLib( wxEmptyString ); + emptyScreen(); + } + + SyncLibraries( true ); + ThawLibraryTree(); + RefreshLibraryTree(); + + break; + } + default: ; } diff --git a/eeschema/symbol_lib_table.cpp b/eeschema/symbol_lib_table.cpp index c92b834995..d69a30c8a4 100644 --- a/eeschema/symbol_lib_table.cpp +++ b/eeschema/symbol_lib_table.cpp @@ -635,6 +635,7 @@ bool SYMBOL_LIB_TABLE::LoadGlobalTable( SYMBOL_LIB_TABLE& aTable ) } } + aTable.Clear(); aTable.Load( fn.GetFullPath() ); SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); diff --git a/eeschema/symbol_viewer_frame.cpp b/eeschema/symbol_viewer_frame.cpp index 22d44be298..458b1499e3 100644 --- a/eeschema/symbol_viewer_frame.cpp +++ b/eeschema/symbol_viewer_frame.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -1306,3 +1307,17 @@ SELECTION& SYMBOL_VIEWER_FRAME::GetCurrentSelection() { return m_toolManager->GetTool()->GetSelection(); } + + +void SYMBOL_VIEWER_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) +{ + switch( mail.Command() ) + { + case MAIL_RELOAD_LIB: + { + ReCreateLibList(); + break; + } + default:; + } +} diff --git a/eeschema/symbol_viewer_frame.h b/eeschema/symbol_viewer_frame.h index 3cc98c2e57..383e27fba6 100644 --- a/eeschema/symbol_viewer_frame.h +++ b/eeschema/symbol_viewer_frame.h @@ -142,6 +142,8 @@ public: SELECTION& GetCurrentSelection() override; + void KiwayMailIn( KIWAY_EXPRESS& mail ) override; + protected: void setupUIConditions() override; diff --git a/include/kiface_base.h b/include/kiface_base.h index 7533cf5433..d7ea9b418d 100644 --- a/include/kiface_base.h +++ b/include/kiface_base.h @@ -52,6 +52,8 @@ public: virtual wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId, KIWAY* aKIWAY, int aCtlBits = 0 ) override = 0; + virtual void Reset() override{}; + virtual void* IfaceOrAddress( int aDataId ) override = 0; /** @@ -63,9 +65,9 @@ public: * #FACE_PL_EDITOR, #FACE_PCB_CALCULATOR, #FACE_BMP2CMP) */ KIFACE_BASE( const char* aKifaceName, KIWAY::FACE_T aId ) : + m_start_flags( 0 ), m_id( aId ), - m_bm( aKifaceName ), - m_start_flags( 0 ) + m_bm( aKifaceName ) { } @@ -119,12 +121,12 @@ public: aActions.push_back( action ); } +protected: + int m_start_flags; ///< flags provided in OnKifaceStart() + private: - KIWAY::FACE_T m_id; - - BIN_MOD m_bm; - - int m_start_flags; ///< flags provided in OnKifaceStart() + KIWAY::FACE_T m_id; + BIN_MOD m_bm; }; diff --git a/include/kiway.h b/include/kiway.h index def73ba60e..28e02d588e 100644 --- a/include/kiway.h +++ b/include/kiway.h @@ -184,6 +184,11 @@ struct KIFACE */ virtual void OnKifaceEnd() = 0; + /** + * Reloads global state. + */ + virtual void Reset() = 0; + /** * Create a wxWindow for the current project. * diff --git a/include/mail_type.h b/include/mail_type.h index d64231a2a4..d5efa0e978 100644 --- a/include/mail_type.h +++ b/include/mail_type.h @@ -52,7 +52,8 @@ enum MAIL_T MAIL_SCH_REFRESH, // Tell the schematic editor to refresh the display. MAIL_LIB_EDIT, MAIL_FP_EDIT, - MAIL_RELOAD_LIB //Reload Library List if one was added + MAIL_RELOAD_LIB, // Reload Library List if one was added + MAIL_RELOAD_PLUGINS // Reload python plugins }; #endif // MAIL_TYPE_H_ diff --git a/kicad/pcm/dialogs/dialog_pcm.cpp b/kicad/pcm/dialogs/dialog_pcm.cpp index dd158941ba..eaa7f88847 100644 --- a/kicad/pcm/dialogs/dialog_pcm.cpp +++ b/kicad/pcm/dialogs/dialog_pcm.cpp @@ -292,13 +292,12 @@ void DIALOG_PCM::OnInstallFromFileClicked( wxCommandEvent& event ) PCM_TASK_MANAGER task_manager( m_pcm ); task_manager.InstallFromFile( this, open_file_dialog.GetPath() ); + m_changed_package_types.merge( task_manager.GetChangedPackageTypes() ); + setInstalledPackages(); if( !m_selectedRepositoryId.IsEmpty() ) setRepositoryData( m_selectedRepositoryId ); - - if( task_manager.ColorSettingsChanged() ) - Pgm().GetSettingsManager().ReloadColorSettings(); } @@ -468,6 +467,8 @@ void DIALOG_PCM::OnApplyChangesClicked( wxCommandEvent& event ) task_manager.RunQueue( this ); + m_changed_package_types.merge( task_manager.GetChangedPackageTypes() ); + m_sdbSizer1OK->Enable(); m_sdbSizer1Apply->Enable(); m_sdbSizer1Cancel->Enable(); @@ -478,9 +479,6 @@ void DIALOG_PCM::OnApplyChangesClicked( wxCommandEvent& event ) if( !m_selectedRepositoryId.IsEmpty() ) setRepositoryData( m_selectedRepositoryId ); - - if( task_manager.ColorSettingsChanged() ) - Pgm().GetSettingsManager().ReloadColorSettings(); } diff --git a/kicad/pcm/dialogs/dialog_pcm.h b/kicad/pcm/dialogs/dialog_pcm.h index 79cb0329e4..0f68c3836e 100644 --- a/kicad/pcm/dialogs/dialog_pcm.h +++ b/kicad/pcm/dialogs/dialog_pcm.h @@ -73,6 +73,12 @@ public: ///< Handles modification of the buttons' status void OnUpdateEventButtons( wxUpdateUIEvent& event ); + ///< Returns types of packages that were installed/uninstalled + const std::unordered_set& GetChangedPackageTypes() const + { + return m_changed_package_types; + }; + private: /** * @brief Gets package data from PCM and displays it on repository tab @@ -105,6 +111,7 @@ private: std::unordered_map m_packageBitmaps; std::unordered_map m_installedBitmaps; wxBitmap m_defaultBitmap; + std::unordered_set m_changed_package_types; struct PENDING_ACTION { diff --git a/kicad/pcm/dialogs/panel_pcm_settings.cpp b/kicad/pcm/dialogs/panel_pcm_settings.cpp index e35a016434..45ea0a63a1 100644 --- a/kicad/pcm/dialogs/panel_pcm_settings.cpp +++ b/kicad/pcm/dialogs/panel_pcm_settings.cpp @@ -35,8 +35,6 @@ PANEL_PCM_SETTINGS::PANEL_PCM_SETTINGS( wxWindow* parent ) : PANEL_PCM_SETTINGS_ int minWidth = m_libPrefix->GetTextExtent( wxT( "XXX.XXX" ) ).GetWidth(); m_libPrefix->SetMinSize( wxSize( minWidth, minSize.GetHeight() ) ); - - m_libHelp->SetFont( KIUI::GetInfoFont( this ).Italic() ); } diff --git a/kicad/pcm/dialogs/panel_pcm_settings_base.cpp b/kicad/pcm/dialogs/panel_pcm_settings_base.cpp index 9a766694a9..d156d364fd 100644 --- a/kicad/pcm/dialogs/panel_pcm_settings_base.cpp +++ b/kicad/pcm/dialogs/panel_pcm_settings_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b) +// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -71,10 +71,6 @@ PANEL_PCM_SETTINGS_BASE::PANEL_PCM_SETTINGS_BASE( wxWindow* parent, wxWindowID i bSizer3->Add( bSizer2, 0, wxEXPAND, 5 ); - m_libHelp = new wxStaticText( this, wxID_ANY, _("After packages are (un)installed KiCad may need to be restarted to reflect changes in the global library table."), wxDefaultPosition, wxDefaultSize, 0 ); - m_libHelp->Wrap( -1 ); - bSizer3->Add( m_libHelp, 0, wxALL, 5 ); - bSizer1->Add( bSizer3, 1, wxEXPAND|wxTOP|wxLEFT, 5 ); diff --git a/kicad/pcm/dialogs/panel_pcm_settings_base.fbp b/kicad/pcm/dialogs/panel_pcm_settings_base.fbp index aa6a653661..744a4dd28b 100644 --- a/kicad/pcm/dialogs/panel_pcm_settings_base.fbp +++ b/kicad/pcm/dialogs/panel_pcm_settings_base.fbp @@ -673,67 +673,6 @@ - - 5 - wxALL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - After packages are (un)installed KiCad may need to be restarted to reflect changes in the global library table. - 0 - - 0 - - - 0 - - 1 - m_libHelp - 1 - - - protected - 1 - - Resizable - 1 - - - ; ; forward_declare - 0 - - - - - -1 - - diff --git a/kicad/pcm/dialogs/panel_pcm_settings_base.h b/kicad/pcm/dialogs/panel_pcm_settings_base.h index f4549c1776..c3bd290dc0 100644 --- a/kicad/pcm/dialogs/panel_pcm_settings_base.h +++ b/kicad/pcm/dialogs/panel_pcm_settings_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b) +// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -42,7 +42,6 @@ class PANEL_PCM_SETTINGS_BASE : public wxPanel wxCheckBox* m_libAutoRemove; wxStaticText* m_staticText1; wxTextCtrl* m_libPrefix; - wxStaticText* m_libHelp; public: diff --git a/kicad/pcm/pcm_task_manager.cpp b/kicad/pcm/pcm_task_manager.cpp index 4bdab11571..8b9b789e1e 100644 --- a/kicad/pcm/pcm_task_manager.cpp +++ b/kicad/pcm/pcm_task_manager.cpp @@ -212,17 +212,16 @@ void PCM_TASK_MANAGER::installDownloadedPackage( const PCM_PACKAGE& aPackage, if( extract( aFilePath.GetFullPath(), aPackage.identifier, true ) ) { m_pcm->MarkInstalled( aPackage, pkgver->version, aRepositoryId ); - // TODO register libraries. } else { // Cleanup possibly partially extracted package deletePackageDirectories( aPackage.identifier ); } - } - if( aPackage.type == PCM_PACKAGE_TYPE::PT_COLORTHEME ) - m_color_themes_changed.store( true ); + std::unique_lock lock( m_changed_package_types_guard ); + m_changed_package_types.insert( aPackage.type ); + } m_reporter->PCMReport( wxString::Format( _( "Removing downloaded archive '%s'." ), aFilePath.GetFullName() ), @@ -431,7 +430,8 @@ void PCM_TASK_MANAGER::InstallFromFile( wxWindow* aParent, const wxString& aFile aParent->Raise(); - m_color_themes_changed.store( package.type == PCM_PACKAGE_TYPE::PT_COLORTHEME ); + std::unique_lock lock( m_changed_package_types_guard ); + m_changed_package_types.insert( package.type ); } @@ -560,8 +560,8 @@ void PCM_TASK_MANAGER::Uninstall( const PCM_PACKAGE& aPackage ) m_pcm->MarkUninstalled( aPackage ); - if( aPackage.type == PCM_PACKAGE_TYPE::PT_COLORTHEME ) - m_color_themes_changed.store( true ); + std::unique_lock lock( m_changed_package_types_guard ); + m_changed_package_types.insert( aPackage.type ); m_reporter->PCMReport( wxString::Format( _( "Package %s uninstalled" ), aPackage.identifier ), @@ -589,8 +589,6 @@ void PCM_TASK_MANAGER::RunQueue( wxWindow* aParent ) std::condition_variable condvar; bool download_complete = false; - m_color_themes_changed.store( false ); - std::thread download_thread( [&]() { @@ -653,9 +651,3 @@ void PCM_TASK_MANAGER::RunQueue( wxWindow* aParent ) aParent->Raise(); } - - -bool PCM_TASK_MANAGER::ColorSettingsChanged() const -{ - return m_color_themes_changed.load(); -} \ No newline at end of file diff --git a/kicad/pcm/pcm_task_manager.h b/kicad/pcm/pcm_task_manager.h index 370a382ca7..61c41252fb 100644 --- a/kicad/pcm/pcm_task_manager.h +++ b/kicad/pcm/pcm_task_manager.h @@ -105,9 +105,12 @@ public: void InstallFromFile( wxWindow* aParent, const wxString& aFilePath ); /** - * @return true if color settings were installed or uninstalled by the most recent action + * @return types of packages that were installed/uninstalled by the task manager */ - bool ColorSettingsChanged() const; + std::unordered_set& GetChangedPackageTypes() + { + return m_changed_package_types; + }; private: /** @@ -155,7 +158,8 @@ private: SYNC_QUEUE m_download_queue; SYNC_QUEUE m_install_queue; std::shared_ptr m_pcm; - std::atomic_bool m_color_themes_changed; + std::mutex m_changed_package_types_guard; + std::unordered_set m_changed_package_types; }; diff --git a/kicad/tools/kicad_manager_control.cpp b/kicad/tools/kicad_manager_control.cpp index a1978bcf21..f70f93e0e7 100644 --- a/kicad/tools/kicad_manager_control.cpp +++ b/kicad/tools/kicad_manager_control.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -900,6 +901,47 @@ int KICAD_MANAGER_CONTROL::ShowPluginManager( const TOOL_EVENT& aEvent ) DIALOG_PCM pcm( m_frame, m_frame->GetPcm() ); pcm.ShowModal(); + const std::unordered_set& changed = pcm.GetChangedPackageTypes(); + + if( changed.count( PCM_PACKAGE_TYPE::PT_PLUGIN ) ) + { + std::string payload = ""; + m_frame->Kiway().ExpressMail( FRAME_PCB_EDITOR, MAIL_RELOAD_PLUGINS, payload ); + } + + KICAD_SETTINGS* settings = Pgm().GetSettingsManager().GetAppSettings(); + + if( changed.count( PCM_PACKAGE_TYPE::PT_LIBRARY ) + && ( settings->m_PcmLibAutoAdd || settings->m_PcmLibAutoRemove ) ) + { + // Reset project tables + Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, nullptr ); + Prj().SetElem( PROJECT::ELEM_FPTBL, nullptr ); + + KIWAY& kiway = m_frame->Kiway(); + + // Reset state containing global lib tables + KIFACE* kiface; + + if( kiface = kiway.KiFACE( KIWAY::FACE_SCH, false ) ) + kiface->Reset(); + + if( kiface = kiway.KiFACE( KIWAY::FACE_PCB, false ) ) + kiface->Reset(); + + // Reload lib tables + std::string payload = ""; + + kiway.ExpressMail( FRAME_FOOTPRINT_EDITOR, MAIL_RELOAD_LIB, payload ); + kiway.ExpressMail( FRAME_FOOTPRINT_VIEWER, MAIL_RELOAD_LIB, payload ); + kiway.ExpressMail( FRAME_CVPCB, MAIL_RELOAD_LIB, payload ); + kiway.ExpressMail( FRAME_SCH_SYMBOL_EDITOR, MAIL_RELOAD_LIB, payload ); + kiway.ExpressMail( FRAME_SCH_VIEWER, MAIL_RELOAD_LIB, payload ); + } + + if( changed.count( PCM_PACKAGE_TYPE::PT_COLORTHEME ) ) + Pgm().GetSettingsManager().ReloadColorSettings(); + return 0; } diff --git a/pcbnew/cross-probing.cpp b/pcbnew/cross-probing.cpp index d29ad605f6..1989ab677e 100644 --- a/pcbnew/cross-probing.cpp +++ b/pcbnew/cross-probing.cpp @@ -663,6 +663,10 @@ void PCB_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) break; } + case MAIL_RELOAD_PLUGINS: + GetToolManager()->RunAction( PCB_ACTIONS::pluginsReload, true ); + break; + // many many others. default: ; diff --git a/pcbnew/dialogs/panel_fp_lib_table.cpp b/pcbnew/dialogs/panel_fp_lib_table.cpp index bcacb544cb..792b06bdd1 100644 --- a/pcbnew/dialogs/panel_fp_lib_table.cpp +++ b/pcbnew/dialogs/panel_fp_lib_table.cpp @@ -1130,19 +1130,8 @@ void InvokePcbLibTableEditor( KIWAY* aKiway, wxWindow* aCaller ) } } - auto editor = (FOOTPRINT_EDIT_FRAME*) aKiway->Player( FRAME_FOOTPRINT_EDITOR, false ); - - if( editor ) - { - editor->SyncLibraryTree( true ); - editor->RefreshLibraryTree(); - } - - auto viewer = (FOOTPRINT_VIEWER_FRAME*) aKiway->Player( FRAME_FOOTPRINT_VIEWER, false ); - - if( viewer ) - viewer->ReCreateLibraryList(); - std::string payload = ""; + aKiway->ExpressMail( FRAME_FOOTPRINT_EDITOR, MAIL_RELOAD_LIB, payload ); + aKiway->ExpressMail( FRAME_FOOTPRINT_VIEWER, MAIL_RELOAD_LIB, payload ); aKiway->ExpressMail( FRAME_CVPCB, MAIL_RELOAD_LIB, payload ); } diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index b2ab41c995..564862f0ec 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -990,7 +990,7 @@ void FOOTPRINT_EDIT_FRAME::SyncLibraryTree( bool aProgress ) } // Sync the LIB_TREE to the FOOTPRINT_INFO list - adapter->Sync(); + adapter->Sync( fpTable ); m_treePane->GetLibTree()->Unselect(); m_treePane->GetLibTree()->Regenerate( true ); diff --git a/pcbnew/footprint_editor_utils.cpp b/pcbnew/footprint_editor_utils.cpp index 1715b5e931..7c9e0e4757 100644 --- a/pcbnew/footprint_editor_utils.cpp +++ b/pcbnew/footprint_editor_utils.cpp @@ -359,6 +359,11 @@ void FOOTPRINT_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) break; + case MAIL_RELOAD_LIB: + SyncLibraryTree( true ); + RefreshLibraryTree(); + break; + default: break; } diff --git a/pcbnew/footprint_viewer_frame.cpp b/pcbnew/footprint_viewer_frame.cpp index 38e2fd484e..ff9bc9c511 100644 --- a/pcbnew/footprint_viewer_frame.cpp +++ b/pcbnew/footprint_viewer_frame.cpp @@ -1086,6 +1086,11 @@ void FOOTPRINT_VIEWER_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) break; } + case MAIL_RELOAD_LIB: + { + ReCreateLibraryList(); + break; + } default: ; diff --git a/pcbnew/fp_tree_synchronizing_adapter.cpp b/pcbnew/fp_tree_synchronizing_adapter.cpp index 7b9ab9d214..a5d3d71639 100644 --- a/pcbnew/fp_tree_synchronizing_adapter.cpp +++ b/pcbnew/fp_tree_synchronizing_adapter.cpp @@ -68,8 +68,10 @@ bool FP_TREE_SYNCHRONIZING_ADAPTER::IsContainer( const wxDataViewItem& aItem ) c #define PROGRESS_INTERVAL_MILLIS 33 // 30 FPS refresh rate -void FP_TREE_SYNCHRONIZING_ADAPTER::Sync() +void FP_TREE_SYNCHRONIZING_ADAPTER::Sync( FP_LIB_TABLE* aLibs ) { + m_libs = aLibs; + // Process already stored libraries for( auto it = m_tree.m_Children.begin(); it != m_tree.m_Children.end(); ) { diff --git a/pcbnew/fp_tree_synchronizing_adapter.h b/pcbnew/fp_tree_synchronizing_adapter.h index 4562d01bc6..a61f85e691 100644 --- a/pcbnew/fp_tree_synchronizing_adapter.h +++ b/pcbnew/fp_tree_synchronizing_adapter.h @@ -38,7 +38,7 @@ public: bool IsContainer( const wxDataViewItem& aItem ) const override; - void Sync(); + void Sync( FP_LIB_TABLE* aLibs ); int GetLibrariesCount() const override; diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index c2ea27857e..aa325f6f1f 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -81,6 +81,8 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override; + void Reset() override; + void OnKifaceEnd() override; wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, @@ -286,6 +288,8 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER int HandleJob( JOB* aJob ) override; private: + bool loadGlobalLibTable(); + std::unique_ptr m_jobHandler; } kiface( "pcbnew", KIWAY::FACE_PCB ); @@ -347,11 +351,28 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) start_common( aCtlBits ); + if( !loadGlobalLibTable() ) + return false; + + m_jobHandler = std::make_unique(); + + return true; +} + + +void IFACE::Reset() +{ + loadGlobalLibTable(); +} + + +bool IFACE::loadGlobalLibTable() +{ wxFileName fn = FP_LIB_TABLE::GetGlobalTableFileName(); if( !fn.FileExists() ) { - if( !( aCtlBits & KFCTL_CLI ) ) + if( !( m_start_flags & KFCTL_CLI ) ) { DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG fpDialog( nullptr ); @@ -382,8 +403,6 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) } } - m_jobHandler = std::make_unique(); - return true; }