42#include <wx/filedlg.h>
46#define GRID_CELL_MARGIN 4
48#define ALL_REPOSITORIES wxT( "ALL_REPOSITORIES" )
54 {
PT_FAB,
_(
"Fabrication plugins (%d)" ) },
67 SetMinSize( FromDIP( GetMinSize() ) );
69 SetDoubleBuffered(
true );
73 m_pcm->SetDialogWindow(
this );
74 m_pcm->StopBackgroundUpdate();
82 const wxString& aVersion )
86 if( wxMessageBox( wxString::Format(
_(
"Are you sure you want to update pinned package "
87 "from version %s to %s?" ),
89 _(
"Confirm update" ), wxICON_QUESTION | wxYES_NO,
this )
118 wxString::Format( wxT(
"%s \u279C %s" ),
142 [
this](
const wxString& aPackageId,
const PCM_PACKAGE_STATE aState,
const bool aPinned )
144 m_pcm->SetPinned( aPackageId, aPinned );
157 wxString label = wxGetTranslation( entry.second );
162 m_dialogNotebook->SetPageText( 0, wxString::Format(
_(
"Repository (%d)" ), 0 ) );
170 { wxID_APPLY,
_(
"Apply Pending Changes" ) },
171 { wxID_CANCEL,
_(
"Discard Pending Changes" ) } } );
204 m_pcm->SaveInstalledPackages();
205 m_pcm->SetDialogWindow(
nullptr );
206 m_pcm->RunBackgroundUpdate();
234 || wxMessageBox(
_(
"Are you sure you want to close the package manager and discard pending changes?" ),
235 _(
"Plugin and Content Manager" ), wxICON_QUESTION | wxYES_NO,
this )
245 wxCommandEvent
dummy;
255 std::vector<std::pair<wxString, wxString>> dialog_data;
256 std::vector<std::tuple<wxString, wxString, wxString>> repo_list =
m_pcm->GetRepositoryList();
258 for(
const auto& [
id, url,
name] : repo_list )
259 dialog_data.push_back( std::make_pair( url,
name ) );
261 dialog->
SetData( dialog_data );
265 dialog_data = dialog->
GetData();
266 m_pcm->SetRepositoryList( dialog_data );
269 cfg->m_PcmRepositories = std::move( dialog_data );
281 std::vector<std::tuple<wxString, wxString, wxString>> repositories =
m_pcm->GetRepositoryList();
286 for(
const auto& [
id, url,
name] : repositories )
289 if( repositories.size() > 1 )
292 if( repositories.size() > 0 )
300 idx = (int) repositories.size();
304 auto it = std::find_if( repositories.begin(), repositories.end(),
305 [&cfg](
const auto& repo )
307 return std::get<0>( repo ) == cfg->m_PcmLastSelectedRepoId;
310 if( it != repositories.end() )
311 idx = (int) std::distance( repositories.begin(), it );
316 wxStringClientData* data =
static_cast<wxStringClientData*
>(
m_choiceRepository->GetClientObject( idx ) );
338 m_pcm->DiscardAllRepositoryCaches();
353 wxFileDialog open_file_dialog(
this,
_(
"Install Package" ), wxEmptyString, wxEmptyString,
354 wxT(
"Zip files (*.zip)|*.zip" ), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
358 if( open_file_dialog.ShowModal() == wxID_CANCEL )
377 wxStringClientData* data =
static_cast<wxStringClientData*
>(
396 wxCHECK2_MSG( aRepositoryId !=
ALL_REPOSITORIES,
return, wxT(
"should have been handled higher up" ) );
401 packagesView->ClearData();
403 std::unordered_map<wxString, PCM_PACKAGE> packagesMap;
404 std::unordered_map<wxString, wxString> repoIds;
405 std::unordered_map<wxString, wxString> repoNames;
407 if(
m_pcm->CacheRepository( aRepositoryId ) )
412 for(
const PCM_PACKAGE& pkg :
m_pcm->GetRepositoryPackages( aRepositoryId ) )
417 packagesMap[pkg.identifier] = pkg;
418 repoIds[pkg.identifier] = aRepositoryId;
419 repoNames[pkg.identifier] = repoName;
433 packagesView->ClearData();
435 std::unordered_map<wxString, PCM_PACKAGE> bestPackages;
436 std::unordered_map<wxString, wxString> bestRepositoryId;
437 std::unordered_map<wxString, wxString> bestRepositoryName;
441 for(
const auto& [repo_id, repo_url, repo_name] :
m_pcm->GetRepositoryList() )
443 if( !
m_pcm->CacheRepository( repo_id ) )
446 std::unordered_map<wxString, wxBitmap> repo_bitmaps =
m_pcm->GetRepositoryPackageBitmaps( repo_id );
447 const std::vector<PCM_PACKAGE> packages =
m_pcm->GetRepositoryPackages( repo_id );
454 bool isBetter =
false;
455 auto it = bestPackages.find( pkg.identifier );
457 if( it == bestPackages.end() )
464 if( !pkg.versions.empty() && !best.
versions.empty() )
466 if( pkg.versions[0].parsed_version > best.
versions[0].parsed_version )
473 bestPackages[pkg.identifier] = pkg;
474 bestRepositoryId[pkg.identifier] = repo_id;
475 bestRepositoryName[pkg.identifier] = repo_name;
477 if( repo_bitmaps.count( pkg.identifier ) > 0 )
490 const std::unordered_map<wxString, wxString>& aPackageRepoIds,
491 const std::unordered_map<wxString, wxString>& aPackageRepoNames )
493 std::unordered_map<PCM_PACKAGE_TYPE, std::vector<PACKAGE_VIEW_DATA>> data;
494 int totalPackages = 0;
496 for(
const auto& [pkg_id, best_pkg] : aPackages )
498 const wxString& repo_id = aPackageRepoIds.at( pkg_id );
499 const wxString& repo_name = aPackageRepoNames.at( pkg_id );
508 package_data.
state =
m_pcm->GetPackageState( repo_id, pkg_id );
513 package_data.
pinned =
m_pcm->IsPackagePinned( pkg_id );
516 else if( !best_pkg.versions.empty() )
518 package_data.
swig_warning =
m_pcm->UsesSWIGRuntime( best_pkg, best_pkg.versions[0].version );
526 if( action.package.identifier != pkg_id )
529 switch( action.action )
544 data[type].emplace_back( package_data );
553 m_contentNotebook->SetPageText( i, wxString::Format( wxGetTranslation( label ), (
int) data[type].size() ) );
556 m_dialogNotebook->SetPageText( 0, wxString::Format(
_(
"Repository (%d)" ), totalPackages ) );
586 m_pcm->ResolveInstalledPackageRepositories();
588 const std::vector<PCM_INSTALLATION_ENTRY> installed =
m_pcm->GetInstalledPackages();
589 std::vector<PACKAGE_VIEW_DATA> package_list;
602 package_data.
state =
m_pcm->GetPackageState( entry.repository_id,
603 entry.package.identifier );
605 package_data.
swig_warning =
m_pcm->UsesSWIGRuntime( entry.package, entry.current_version );
610 package_list.emplace_back( package_data );
616 (
int) package_list.size() ) );
635 task_manager.
Uninstall( action.package );
640 task_manager.
DownloadAndInstall( action.package, action.version, action.repository_id, isUpdate );
653 wxCommandEvent
dummy;
679 std::sort( rows.begin(), rows.end(),
680 [](
const int& a,
const int& b )
687 for(
int row : rows )
712 bool pinned =
m_pcm->IsPackagePinned( aPackageId );
717 packagesView->SetPackageState( aPackageId, aState, pinned );
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Implementing DIALOG_MANAGE_REPOSITORIES_BASE.
std::vector< std::pair< wxString, wxString > > GetData()
void SetData(const std::vector< std::pair< wxString, wxString > > &aData)
wxChoice * m_choiceRepository
wxNotebook * m_contentNotebook
WX_GRID * m_gridPendingActions
wxButton * m_sdbSizer1Cancel
wxBitmapButton * m_discardActionButton
DIALOG_PCM_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Plugin And Content Manager"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxNotebook * m_dialogNotebook
wxButton * m_sdbSizer1Apply
wxPanel * m_panelInstalledHolder
ActionCallback m_actionCallback
void OnDiscardChangesClicked(wxCommandEvent &event) override
Discards all pending changes.
std::unordered_map< wxString, wxBitmap > m_installedBitmaps
std::unordered_map< wxString, wxBitmap > m_packageBitmaps
void OnManageRepositoriesClicked(wxCommandEvent &event) override
Opens repository management dialog, saves changes to PCM.
void updatePackageState(const wxString &aPackageId, const PCM_PACKAGE_STATE aState)
Reflects new state of the package in all panels where it is displayed.
void OnApplyChangesClicked(wxCommandEvent &event) override
Enqueues current pending actions in PCM_TASK_MANAGER and runs the queue.
void OnDiscardActionClicked(wxCommandEvent &event) override
Discards selected pending actions.
void OnUpdateEventButtons(wxUpdateUIEvent &event)
Handles modification of the buttons' status.
std::unordered_map< PCM_PACKAGE_TYPE, PANEL_PACKAGES_VIEW * > m_repositoryContentPanels
void OnOpenPackageDirClicked(wxCommandEvent &event) override
Opens local directory where packages are installed in file manager.
PinCallback m_pinCallback
void renderPackageGrids(const std::unordered_map< wxString, PCM_PACKAGE > &aPackages, const std::unordered_map< wxString, wxString > &aPackageRepoIds, const std::unordered_map< wxString, wxString > &aPackageRepoNames)
Shared logic to render a given set of packages to the UI notebooks.
std::unordered_set< PCM_PACKAGE_TYPE > m_changed_package_types
void SetActivePackageType(PCM_PACKAGE_TYPE aType)
EDA_BASE_FRAME * m_parentFrame
void setRepositoryDataMulti()
Aggregates and deduplicates packages from all configured repositories.
DIALOG_PCM(EDA_BASE_FRAME *parent, std::shared_ptr< PLUGIN_CONTENT_MANAGER > pcm)
Constructor.
void updatePendingActionsTab()
Updates pending actions tab caption and content-fits the grid.
std::vector< PENDING_ACTION > m_pendingActions
void setRepositoryListFromPcm()
Sets repository choice list values.
void OnInstallFromFileClicked(wxCommandEvent &event) override
Opens file selection dialog and installs selected package archive.
void OnCloseWindow(wxCloseEvent &aEvent)
std::shared_ptr< PLUGIN_CONTENT_MANAGER > m_pcm
void OnRepositoryChoice(wxCommandEvent &event) override
Switches to another repository.
wxString m_selectedRepositoryId
PANEL_PACKAGES_VIEW * m_installedPanel
void setInstalledPackages()
Gets installed packages list from PCM and displays it on installed tab.
void OnPendingActionsCellClicked(wxGridEvent &event) override
Selects the whole row in the grid if a cell is clicked.
void setRepositoryData(const wxString &aRepositoryId)
Gets package data from PCM and displays it on repository tab.
void discardAction(int aIndex)
Discards specified pending action.
void OnRefreshClicked(wxCommandEvent &event) override
Discards current repo cache, fetches it anew and displays.
void OnCloseClicked(wxCommandEvent &event) override
Closes the window, asks user confirmation if there are pending actions.
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
The base frame for deriving all KiCad main window classes.
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
wxString m_PcmLastSelectedRepoId
Helper class that handles package (un)installation.
std::unordered_set< PCM_PACKAGE_TYPE > & GetChangedPackageTypes()
PCM_TASK_MANAGER::STATUS DownloadAndInstall(const PCM_PACKAGE &aPackage, const wxString &aVersion, const wxString &aRepositoryId, const bool isUpdate)
Enqueue package download and installation.
void RunQueue(wxWindow *aParent)
Run queue of pending actions.
PCM_TASK_MANAGER::STATUS Uninstall(const PCM_PACKAGE &aPackage)
Enqueue package uninstallation.
PCM_TASK_MANAGER::STATUS InstallFromFile(wxWindow *aParent, const wxString &aFilePath)
Installs package from an archive file on disk.
static std::vector< std::pair< PCM_PACKAGE_TYPE, wxString > > PACKAGE_TYPE_LIST
Base window classes and related definitions.
bool LaunchExternal(const wxString &aPath)
Launches the given file or folder in the host OS.
PCM_PACKAGE_STATE
Package states Package is available if it is not installed and there is a compatible version Package ...
PCM_PACKAGE_ACTION
Package actions.
PCM_PACKAGE_TYPE
Supported package types.
T * GetAppSettings(const char *aFilename)
std::vector< FAB_LAYER_COLOR > dummy
Collection of data relevant to the package display panel.
const PCM_PACKAGE package
Package installation entry.
std::vector< PACKAGE_VERSION > versions