Duplicate Eeschema's select-ref-number strategy in PCBNew.

Fixes https://gitlab.com/kicad/code/kicad/issues/6504
This commit is contained in:
Jeff Young 2020-11-25 16:25:26 +00:00
parent 7a2a302117
commit b8414174af
6 changed files with 39 additions and 2 deletions

View File

@ -106,6 +106,10 @@ void KIUI::SelectReferenceNumber( wxTextEntry* aTextEntry )
{
aTextEntry->SetSelection( ref.find_first_of( '?' ), ref.find_last_of( '?' ) + 1 );
}
else if( ref.find_first_of( '*' ) != ref.npos )
{
aTextEntry->SetSelection( ref.find_first_of( '*' ), ref.find_last_of( '*' ) + 1 );
}
else
{
wxString num = ref;

View File

@ -48,8 +48,8 @@ DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, BO
m_thickness( aParent, m_ThicknessLabel, m_ThicknessCtrl, m_ThicknessUnits, true ),
m_posX( aParent, m_PositionXLabel, m_PositionXCtrl, m_PositionXUnits ),
m_posY( aParent, m_PositionYLabel, m_PositionYCtrl, m_PositionYUnits ),
m_linesThickness( aParent, m_LineThicknessLabel, m_LineThicknessCtrl,
m_LineThicknessUnits, true ),
m_linesThickness( aParent, m_LineThicknessLabel, m_LineThicknessCtrl, m_LineThicknessUnits,
true ),
m_OrientValidator( 1, &m_OrientValue )
{
wxString title;
@ -227,6 +227,28 @@ void DIALOG_TEXT_PROPERTIES::OnCharHook( wxKeyEvent& aEvent )
}
void DIALOG_TEXT_PROPERTIES::OnSetFocusText( wxFocusEvent& event )
{
#ifdef __WXGTK__
// Force an update of the text control before setting the text selection
// This is needed because GTK seems to ignore the selection on first update
//
// Note that we can't do this on OSX as it tends to provoke Apple's
// "[NSAlert runModal] may not be invoked inside of transaction begin/commit pair"
// bug. See: https://bugs.launchpad.net/kicad/+bug/1837225
if( m_fieldId == REFERENCE_FIELD || m_fieldId == VALUE_FIELD || m_fieldId == SHEETNAME_V )
m_TextCtrl->Update();
#endif
if( m_fpText->GetType() == FP_TEXT::TEXT_is_REFERENCE )
KIUI::SelectReferenceNumber( static_cast<wxTextEntry*>( m_SingleLineText ) );
else
m_SingleLineText->SetSelection( -1, -1 );
event.Skip();
}
bool DIALOG_TEXT_PROPERTIES::TransferDataToWindow()
{
if( m_SingleLineText->IsShown() )

View File

@ -43,6 +43,13 @@ public:
DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, BOARD_ITEM* aItem );
~DIALOG_TEXT_PROPERTIES();
/**
* Used to select the variant part of some text fields (for instance, the question mark
* or number in a reference).
* @param event
*/
virtual void OnSetFocusText( wxFocusEvent& event ) override;
private:
PCB_BASE_EDIT_FRAME* m_Parent;
BOARD_ITEM* m_item; // FP_TEXT, PCB_TEXT, or DIMENSION

View File

@ -265,6 +265,7 @@ DIALOG_TEXT_PROPERTIES_BASE::DIALOG_TEXT_PROPERTIES_BASE( wxWindow* parent, wxWi
// Connect Events
this->Connect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnInitDlg ) );
m_SingleLineText->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnSetFocusText ), NULL, this );
m_SingleLineText->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this );
m_SizeXCtrl->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this );
m_SizeYCtrl->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this );
@ -280,6 +281,7 @@ DIALOG_TEXT_PROPERTIES_BASE::~DIALOG_TEXT_PROPERTIES_BASE()
{
// Disconnect Events
this->Disconnect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnInitDlg ) );
m_SingleLineText->Disconnect( wxEVT_SET_FOCUS, wxFocusEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnSetFocusText ), NULL, this );
m_SingleLineText->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this );
m_SizeXCtrl->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this );
m_SizeYCtrl->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_TEXT_PROPERTIES_BASE::OnOkClick ), NULL, this );

View File

@ -329,6 +329,7 @@
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnSetFocus">OnSetFocusText</event>
<event name="OnTextEnter">OnOkClick</event>
</object>
</object>

View File

@ -82,6 +82,7 @@ class DIALOG_TEXT_PROPERTIES_BASE : public DIALOG_SHIM
// Virtual event handlers, overide them in your derived class
virtual void OnInitDlg( wxInitDialogEvent& event ) { event.Skip(); }
virtual void OnSetFocusText( wxFocusEvent& event ) { event.Skip(); }
virtual void OnOkClick( wxCommandEvent& event ) { event.Skip(); }