A more nuanced method of making Board & Schematic Setup read-only.

This one still allows you to scroll to see all contents.

Fixes https://gitlab.com/kicad/code/kicad/issues/9302
This commit is contained in:
Jeff Young 2021-10-05 21:30:15 +01:00
parent 935a307674
commit 95f841a037
4 changed files with 60 additions and 30 deletions

View File

@ -27,6 +27,9 @@
#include <wx/spinctrl.h>
#include <wx/srchctrl.h>
#include <wx/stc/stc.h>
#include <wx/scrolbar.h>
#include <wx/scrolwin.h>
#include <wx/grid.h>
#include <widgets/ui_common.h>
#include <algorithm>
@ -267,4 +270,39 @@ bool KIUI::IsInputControlEditable( wxWindow* aFocus )
bool KIUI::IsModalDialogFocused()
{
return Pgm().m_ModalDialogCount > 0;
}
void KIUI::Disable( wxWindow* aWindow )
{
wxScrollBar* scrollBar = dynamic_cast<wxScrollBar*>( aWindow );
wxGrid* grid = dynamic_cast<wxGrid*>( aWindow );
wxStyledTextCtrl* scintilla = dynamic_cast<wxStyledTextCtrl*>( aWindow );
wxControl* control = dynamic_cast<wxControl*>( aWindow );
if( scrollBar )
{
// Leave a scroll bar active
}
else if( grid )
{
for( int row = 0; row < grid->GetNumberRows(); ++row )
{
for( int col = 0; col < grid->GetNumberCols(); ++col )
grid->SetReadOnly( row, col );
}
}
else if( scintilla )
{
scintilla->SetReadOnly( true );
}
else if( control )
{
control->Disable();
}
else
{
for( wxWindow* child : aWindow->GetChildren() )
Disable( child );
}
}

View File

@ -87,16 +87,8 @@ DIALOG_SCHEMATIC_SETUP::DIALOG_SCHEMATIC_SETUP( SCH_EDIT_FRAME* aFrame ) :
if( Prj().IsReadOnly() )
{
m_infoBar->ShowMessage( _( "Project is missing or read-only. "
"Settings will not be editable." ),
wxICON_WARNING );
m_formatting->Disable();
m_fieldNameTemplates->Disable();
m_severities->Disable();
m_pinMap->Disable();
m_netclasses->Disable();
m_textVars->Disable();
m_infoBar->ShowMessage( _( "Project is missing or read-only. Settings will not be "
"editable." ), wxICON_WARNING );
}
}
@ -113,6 +105,8 @@ void DIALOG_SCHEMATIC_SETUP::OnPageChange( wxBookCtrlEvent& event )
{
int page = event.GetSelection();
KIUI::Disable( m_treebook->GetPage( page ) );
// Enable the reset button only if the page is resettable
if( m_resetButton )
{

View File

@ -95,6 +95,12 @@ bool IsInputControlEditable( wxWindow* aControl );
bool IsModalDialogFocused();
/**
* Makes a window read-only. Does some extra work over wxWindow::Disable() to make sure you
* can still scroll around in sub-windows.
*/
void Disable( wxWindow* aWindow );
}
SEVERITY SeverityFromString( const wxString& aSeverity );

View File

@ -113,25 +113,15 @@ DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) :
// Connect Events
m_treebook->Connect( wxEVT_TREEBOOK_PAGE_CHANGED,
wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ),
nullptr, this );
wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ), nullptr,
this );
finishDialogSettings();
if( Prj().IsReadOnly() )
{
m_infoBar->ShowMessage( _( "Project is missing or read-only. "
"Some settings will not be editable." ),
wxICON_WARNING );
m_boardFinish->Disable();
m_maskAndPaste->Disable();
m_textAndGraphics->Disable();
m_textVars->Disable();
m_constraints->Disable();
m_tracksAndVias->Disable();
m_netclasses->Disable();
m_severities->Disable();
m_infoBar->ShowMessage( _( "Project is missing or read-only. Some settings will not "
"be editable." ), wxICON_WARNING );
}
}
@ -139,23 +129,25 @@ DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) :
DIALOG_BOARD_SETUP::~DIALOG_BOARD_SETUP()
{
m_treebook->Disconnect( wxEVT_TREEBOOK_PAGE_CHANGED,
wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ),
nullptr, this );
wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ), nullptr,
this );
}
void DIALOG_BOARD_SETUP::OnPageChange( wxBookCtrlEvent& event )
{
if( event.GetSelection() == m_physicalStackupPage )
int page = event.GetSelection();
if( page == m_physicalStackupPage )
m_physicalStackup->OnLayersOptionsChanged( m_layers->GetUILayerMask() );
else if( event.GetSelection() == m_layerSetupPage )
else if( page == m_layerSetupPage )
m_layers->SyncCopperLayers( m_physicalStackup->GetCopperLayerCount() );
else
KIUI::Disable( m_treebook->GetPage( page ) );
#ifdef __WXMAC__
// Work around an OSX bug where the wxGrid children don't get placed correctly until
// the first resize event
int page = event.GetSelection();
if( m_macHack[ page ] )
{
wxSize pageSize = m_treebook->GetPage( page )->GetSize();