PCM: Disable Download, Install buttons when they're non-functional
Fixes https://gitlab.com/kicad/code/kicad/issues/9584
This commit is contained in:
parent
80c5b1efb1
commit
00aa4f3393
|
@ -316,10 +316,7 @@ void PANEL_PACKAGES_VIEW::setPackageDetails( const PACKAGE_VIEW_DATA& aPackageDa
|
||||||
|
|
||||||
m_gridVersions->Thaw();
|
m_gridVersions->Thaw();
|
||||||
|
|
||||||
if( aPackageData.state == PPS_AVAILABLE || aPackageData.state == PPS_UNAVAILABLE )
|
updateDetailsButtons();
|
||||||
m_buttonInstall->Enable();
|
|
||||||
else
|
|
||||||
m_buttonInstall->Disable();
|
|
||||||
|
|
||||||
m_infoText->Show( true );
|
m_infoText->Show( true );
|
||||||
m_sizerVersions->Show( true );
|
m_sizerVersions->Show( true );
|
||||||
|
@ -366,6 +363,29 @@ wxString PANEL_PACKAGES_VIEW::toHumanReadableSize( const boost::optional<uint64_
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PANEL_PACKAGES_VIEW::canDownload() const
|
||||||
|
{
|
||||||
|
if( !m_currentSelected )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return m_gridVersions->GetNumberRows() == 1 || m_gridVersions->GetSelectedRows().size() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PANEL_PACKAGES_VIEW::canInstall() const
|
||||||
|
{
|
||||||
|
if( !m_currentSelected )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const PACKAGE_VIEW_DATA& packageData = m_currentSelected->GetPackageData();
|
||||||
|
|
||||||
|
if( packageData.state != PPS_AVAILABLE && packageData.state != PPS_UNAVAILABLE )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return m_gridVersions->GetNumberRows() == 1 || m_gridVersions->GetSelectedRows().size() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PANEL_PACKAGES_VIEW::SetPackageState( const wxString& aPackageId,
|
void PANEL_PACKAGES_VIEW::SetPackageState( const wxString& aPackageId,
|
||||||
const PCM_PACKAGE_STATE aState ) const
|
const PCM_PACKAGE_STATE aState ) const
|
||||||
{
|
{
|
||||||
|
@ -388,22 +408,24 @@ void PANEL_PACKAGES_VIEW::OnVersionsCellClicked( wxGridEvent& event )
|
||||||
{
|
{
|
||||||
m_gridVersions->ClearSelection();
|
m_gridVersions->ClearSelection();
|
||||||
m_gridVersions->SelectRow( event.GetRow() );
|
m_gridVersions->SelectRow( event.GetRow() );
|
||||||
|
|
||||||
|
updateDetailsButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PANEL_PACKAGES_VIEW::OnDownloadVersionClicked( wxCommandEvent& event )
|
void PANEL_PACKAGES_VIEW::OnDownloadVersionClicked( wxCommandEvent& event )
|
||||||
{
|
{
|
||||||
if( m_gridVersions->GetNumberRows() == 1 )
|
if( !canDownload() )
|
||||||
m_gridVersions->SelectRow( 0 );
|
|
||||||
|
|
||||||
const wxArrayInt selectedRows = m_gridVersions->GetSelectedRows();
|
|
||||||
|
|
||||||
if( !m_currentSelected || selectedRows.size() != 1 )
|
|
||||||
{
|
{
|
||||||
wxBell();
|
wxBell();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( m_gridVersions->GetNumberRows() == 1 )
|
||||||
|
m_gridVersions->SelectRow( 0 );
|
||||||
|
|
||||||
|
const wxArrayInt selectedRows = m_gridVersions->GetSelectedRows();
|
||||||
|
|
||||||
wxString version = m_gridVersions->GetCellValue( selectedRows[0], COL_VERSION );
|
wxString version = m_gridVersions->GetCellValue( selectedRows[0], COL_VERSION );
|
||||||
const PCM_PACKAGE& package = m_currentSelected->GetPackageData().package;
|
const PCM_PACKAGE& package = m_currentSelected->GetPackageData().package;
|
||||||
|
|
||||||
|
@ -474,17 +496,17 @@ void PANEL_PACKAGES_VIEW::OnDownloadVersionClicked( wxCommandEvent& event )
|
||||||
|
|
||||||
void PANEL_PACKAGES_VIEW::OnInstallVersionClicked( wxCommandEvent& event )
|
void PANEL_PACKAGES_VIEW::OnInstallVersionClicked( wxCommandEvent& event )
|
||||||
{
|
{
|
||||||
if( m_gridVersions->GetNumberRows() == 1 )
|
if( !canInstall() )
|
||||||
m_gridVersions->SelectRow( 0 );
|
|
||||||
|
|
||||||
const wxArrayInt selectedRows = m_gridVersions->GetSelectedRows();
|
|
||||||
|
|
||||||
if( !m_currentSelected || selectedRows.size() != 1 )
|
|
||||||
{
|
{
|
||||||
wxBell();
|
wxBell();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( m_gridVersions->GetNumberRows() == 1 )
|
||||||
|
m_gridVersions->SelectRow( 0 );
|
||||||
|
|
||||||
|
const wxArrayInt selectedRows = m_gridVersions->GetSelectedRows();
|
||||||
|
|
||||||
wxString version = m_gridVersions->GetCellValue( selectedRows[0], COL_VERSION );
|
wxString version = m_gridVersions->GetCellValue( selectedRows[0], COL_VERSION );
|
||||||
const PCM_PACKAGE& package = m_currentSelected->GetPackageData().package;
|
const PCM_PACKAGE& package = m_currentSelected->GetPackageData().package;
|
||||||
|
|
||||||
|
@ -516,6 +538,8 @@ void PANEL_PACKAGES_VIEW::OnShowAllVersionsClicked( wxCommandEvent& event )
|
||||||
wxMouseEvent dummy;
|
wxMouseEvent dummy;
|
||||||
m_currentSelected->OnClick( dummy );
|
m_currentSelected->OnClick( dummy );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateDetailsButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -586,6 +610,13 @@ void PANEL_PACKAGES_VIEW::updatePackageList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PANEL_PACKAGES_VIEW::updateDetailsButtons()
|
||||||
|
{
|
||||||
|
m_buttonDownload->Enable( canDownload() );
|
||||||
|
m_buttonInstall->Enable( canInstall() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PANEL_PACKAGES_VIEW::OnSizeInfoBox( wxSizeEvent& aEvent )
|
void PANEL_PACKAGES_VIEW::OnSizeInfoBox( wxSizeEvent& aEvent )
|
||||||
{
|
{
|
||||||
wxSize infoSize = m_infoText->GetParent()->GetClientSize();
|
wxSize infoSize = m_infoText->GetParent()->GetClientSize();
|
||||||
|
|
|
@ -87,6 +87,9 @@ private:
|
||||||
///< Updates package listing according to search term
|
///< Updates package listing according to search term
|
||||||
void updatePackageList();
|
void updatePackageList();
|
||||||
|
|
||||||
|
///< Updates buttons below the package details: Download and Install
|
||||||
|
void updateDetailsButtons();
|
||||||
|
|
||||||
///< Updates details panel
|
///< Updates details panel
|
||||||
void setPackageDetails( const PACKAGE_VIEW_DATA& aPackageData );
|
void setPackageDetails( const PACKAGE_VIEW_DATA& aPackageData );
|
||||||
|
|
||||||
|
@ -96,6 +99,12 @@ private:
|
||||||
///< Bytes to Kb/Mb/Gb string or "-" if absent
|
///< Bytes to Kb/Mb/Gb string or "-" if absent
|
||||||
wxString toHumanReadableSize( const boost::optional<uint64_t> size ) const;
|
wxString toHumanReadableSize( const boost::optional<uint64_t> size ) const;
|
||||||
|
|
||||||
|
///< Returns true if it the download operation can be performed
|
||||||
|
bool canDownload() const;
|
||||||
|
|
||||||
|
///< Returns true if the install operation can be performed
|
||||||
|
bool canInstall() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ActionCallback m_actionCallback;
|
ActionCallback m_actionCallback;
|
||||||
std::unordered_map<wxString, PANEL_PACKAGE*> m_packagePanels;
|
std::unordered_map<wxString, PANEL_PACKAGE*> m_packagePanels;
|
||||||
|
|
Loading…
Reference in New Issue