Auto-select reference numbers in PcbNew like we do in Eeschema.

This commit is contained in:
Jeff Young 2018-10-14 00:06:41 +01:00
parent 275d5e336f
commit 0bd0558833
5 changed files with 62 additions and 38 deletions

View File

@ -127,6 +127,34 @@ bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString )
} }
void SelectReferenceNumber( wxTextEntry* aTextEntry )
{
wxString ref = aTextEntry->GetValue();
if( ref.find_first_of( '?' ) != ref.npos )
{
aTextEntry->SetSelection( ref.find_first_of( '?' ), ref.find_last_of( '?' ) + 1 );
}
else
{
wxString num = ref;
while( !num.IsEmpty() && ( !isdigit( num.Last() ) || !isdigit( num.GetChar( 0 ) ) ) )
{
if( !isdigit( num.Last() ) )
num.RemoveLast();
if( !isdigit( num.GetChar ( 0 ) ) )
num = num.Right( num.Length() - 1);
}
aTextEntry->SetSelection( ref.Find( num ), ref.Find( num ) + num.Length() );
if( num.IsEmpty() )
aTextEntry->SetSelection( -1, -1 );
}
}
void wxStringSplit( const wxString& aText, wxArrayString& aStrings, wxChar aSplitter ) void wxStringSplit( const wxString& aText, wxArrayString& aStrings, wxChar aSplitter )
{ {
wxString tmp; wxString tmp;

View File

@ -152,33 +152,9 @@ void DIALOG_EDIT_ONE_FIELD::OnTextValueSelectButtonClick( wxCommandEvent& aEvent
void DIALOG_EDIT_ONE_FIELD::OnSetFocusText( wxFocusEvent& event ) void DIALOG_EDIT_ONE_FIELD::OnSetFocusText( wxFocusEvent& event )
{ {
if( m_fieldId == REFERENCE ) if( m_fieldId == REFERENCE )
{ SelectReferenceNumber( static_cast<wxTextEntry*>( m_TextValue ) );
if( m_text.find_first_of( '?' ) != m_text.npos )
{
m_TextValue->SetSelection( m_text.find_first_of( '?' ), m_text.find_last_of( '?' ) + 1 );
}
else else
{
wxString num = m_text;
while( !num.IsEmpty() && ( !isdigit( num.Last() ) || !isdigit( num.GetChar( 0 ) ) ) )
{
if( !isdigit( num.Last() ) )
num.RemoveLast();
if( !isdigit( num.GetChar ( 0 ) ) )
num = num.Right( num.Length() - 1);
}
m_TextValue->SetSelection( m_text.Find( num ), m_text.Find( num ) + num.Length() );
if( num.IsEmpty() )
m_TextValue->SetSelection( -1, -1 ); m_TextValue->SetSelection( -1, -1 );
}
}
else
{
m_TextValue->SetSelection( -1, -1 );
}
event.Skip(); event.Skip();
} }

View File

@ -213,6 +213,11 @@ wxSize GetTextSize( const wxString& aSingleLine, wxWindow* aWindow );
*/ */
bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString = NULL ); bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString = NULL );
/**
* Select the number (or "?") in a reference for ease of editing.
*/
void SelectReferenceNumber( wxTextEntry* aTextEntry );
/** /**
* Run a command in a child process. * Run a command in a child process.
* *

View File

@ -814,26 +814,37 @@ void DIALOG_FOOTPRINT_BOARD_EDITOR::OnUpdateUI( wxUpdateUIEvent& )
// from an OK. // from an OK.
if( m_delayedFocusRow >= 0 ) if( m_delayedFocusRow >= 0 )
{ {
if( !m_delayedErrorMessage.IsEmpty() ) // We will re-enter this routine if an error dialog is displayed, so make sure we
{ // zero out our member variables first.
// We will re-enter this routine when the error dialog is displayed, so make wxGrid* grid = m_delayedFocusGrid;
// sure we don't keep putting up more dialogs. int row = m_delayedFocusRow;
int col = m_delayedFocusColumn;
wxString msg = m_delayedErrorMessage; wxString msg = m_delayedErrorMessage;
m_delayedFocusGrid = nullptr;
m_delayedFocusRow = -1;
m_delayedFocusColumn = -1;
m_delayedErrorMessage = wxEmptyString; m_delayedErrorMessage = wxEmptyString;
if( !m_delayedErrorMessage.IsEmpty() )
{
// Do not use DisplayErrorMessage(); it screws up window order on Mac // Do not use DisplayErrorMessage(); it screws up window order on Mac
DisplayError( nullptr, msg ); DisplayError( nullptr, msg );
} }
m_delayedFocusGrid->SetFocus(); grid->SetFocus();
m_delayedFocusGrid->MakeCellVisible( m_delayedFocusRow, m_delayedFocusColumn ); grid->MakeCellVisible( row, col );
m_delayedFocusGrid->SetGridCursor( m_delayedFocusRow, m_delayedFocusColumn ); grid->SetGridCursor( row, col );
m_delayedFocusGrid->EnableCellEditControl( true ); grid->EnableCellEditControl( true );
m_delayedFocusGrid->ShowCellEditControl(); grid->ShowCellEditControl();
m_delayedFocusRow = -1; if( grid == m_itemsGrid && row == 0 && col == 0 )
m_delayedFocusColumn = -1; {
auto referenceEditor = grid->GetCellEditor( 0, 0 );
SelectReferenceNumber( dynamic_cast<wxTextEntry*>( referenceEditor->GetControl() ) );
referenceEditor->DecRef();
}
} }
} }

View File

@ -235,6 +235,10 @@ bool DIALOG_TEXT_PROPERTIES::TransferDataToWindow()
if( m_SingleLineText->IsShown() ) if( m_SingleLineText->IsShown() )
{ {
m_SingleLineText->SetValue( m_edaText->GetText() ); m_SingleLineText->SetValue( m_edaText->GetText() );
if( m_modText && m_modText->GetType() == TEXTE_MODULE::TEXT_is_REFERENCE )
SelectReferenceNumber( static_cast<wxTextEntry*>( m_SingleLineText ) );
else
m_SingleLineText->SetSelection( -1, -1 ); m_SingleLineText->SetSelection( -1, -1 );
} }
else if( m_MultiLineText->IsShown() ) else if( m_MultiLineText->IsShown() )