Auto-select reference numbers in PcbNew like we do in Eeschema.
This commit is contained in:
parent
275d5e336f
commit
0bd0558833
|
@ -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 )
|
||||
{
|
||||
wxString tmp;
|
||||
|
|
|
@ -152,33 +152,9 @@ void DIALOG_EDIT_ONE_FIELD::OnTextValueSelectButtonClick( wxCommandEvent& aEvent
|
|||
void DIALOG_EDIT_ONE_FIELD::OnSetFocusText( wxFocusEvent& event )
|
||||
{
|
||||
if( m_fieldId == REFERENCE )
|
||||
{
|
||||
if( m_text.find_first_of( '?' ) != m_text.npos )
|
||||
{
|
||||
m_TextValue->SetSelection( m_text.find_first_of( '?' ), m_text.find_last_of( '?' ) + 1 );
|
||||
}
|
||||
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 );
|
||||
}
|
||||
}
|
||||
SelectReferenceNumber( static_cast<wxTextEntry*>( m_TextValue ) );
|
||||
else
|
||||
{
|
||||
m_TextValue->SetSelection( -1, -1 );
|
||||
}
|
||||
|
||||
event.Skip();
|
||||
}
|
||||
|
|
|
@ -213,6 +213,11 @@ wxSize GetTextSize( const wxString& aSingleLine, wxWindow* aWindow );
|
|||
*/
|
||||
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.
|
||||
*
|
||||
|
|
|
@ -814,26 +814,37 @@ void DIALOG_FOOTPRINT_BOARD_EDITOR::OnUpdateUI( wxUpdateUIEvent& )
|
|||
// from an OK.
|
||||
if( m_delayedFocusRow >= 0 )
|
||||
{
|
||||
// We will re-enter this routine if an error dialog is displayed, so make sure we
|
||||
// zero out our member variables first.
|
||||
wxGrid* grid = m_delayedFocusGrid;
|
||||
int row = m_delayedFocusRow;
|
||||
int col = m_delayedFocusColumn;
|
||||
wxString msg = m_delayedErrorMessage;
|
||||
|
||||
m_delayedFocusGrid = nullptr;
|
||||
m_delayedFocusRow = -1;
|
||||
m_delayedFocusColumn = -1;
|
||||
m_delayedErrorMessage = wxEmptyString;
|
||||
|
||||
if( !m_delayedErrorMessage.IsEmpty() )
|
||||
{
|
||||
// We will re-enter this routine when the error dialog is displayed, so make
|
||||
// sure we don't keep putting up more dialogs.
|
||||
wxString msg = m_delayedErrorMessage;
|
||||
m_delayedErrorMessage = wxEmptyString;
|
||||
|
||||
// Do not use DisplayErrorMessage(); it screws up window order on Mac
|
||||
DisplayError( nullptr, msg );
|
||||
}
|
||||
|
||||
m_delayedFocusGrid->SetFocus();
|
||||
m_delayedFocusGrid->MakeCellVisible( m_delayedFocusRow, m_delayedFocusColumn );
|
||||
m_delayedFocusGrid->SetGridCursor( m_delayedFocusRow, m_delayedFocusColumn );
|
||||
grid->SetFocus();
|
||||
grid->MakeCellVisible( row, col );
|
||||
grid->SetGridCursor( row, col );
|
||||
|
||||
m_delayedFocusGrid->EnableCellEditControl( true );
|
||||
m_delayedFocusGrid->ShowCellEditControl();
|
||||
grid->EnableCellEditControl( true );
|
||||
grid->ShowCellEditControl();
|
||||
|
||||
m_delayedFocusRow = -1;
|
||||
m_delayedFocusColumn = -1;
|
||||
if( grid == m_itemsGrid && row == 0 && col == 0 )
|
||||
{
|
||||
auto referenceEditor = grid->GetCellEditor( 0, 0 );
|
||||
SelectReferenceNumber( dynamic_cast<wxTextEntry*>( referenceEditor->GetControl() ) );
|
||||
referenceEditor->DecRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -235,7 +235,11 @@ bool DIALOG_TEXT_PROPERTIES::TransferDataToWindow()
|
|||
if( m_SingleLineText->IsShown() )
|
||||
{
|
||||
m_SingleLineText->SetValue( m_edaText->GetText() );
|
||||
m_SingleLineText->SetSelection( -1, -1 );
|
||||
|
||||
if( m_modText && m_modText->GetType() == TEXTE_MODULE::TEXT_is_REFERENCE )
|
||||
SelectReferenceNumber( static_cast<wxTextEntry*>( m_SingleLineText ) );
|
||||
else
|
||||
m_SingleLineText->SetSelection( -1, -1 );
|
||||
}
|
||||
else if( m_MultiLineText->IsShown() )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue