From b8414174af52b44db5b9c4424363b81542630442 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 25 Nov 2020 16:25:26 +0000 Subject: [PATCH] Duplicate Eeschema's select-ref-number strategy in PCBNew. Fixes https://gitlab.com/kicad/code/kicad/issues/6504 --- common/widgets/ui_common.cpp | 4 +++ pcbnew/dialogs/dialog_text_properties.cpp | 26 +++++++++++++++++-- pcbnew/dialogs/dialog_text_properties.h | 7 +++++ .../dialogs/dialog_text_properties_base.cpp | 2 ++ .../dialogs/dialog_text_properties_base.fbp | 1 + pcbnew/dialogs/dialog_text_properties_base.h | 1 + 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/common/widgets/ui_common.cpp b/common/widgets/ui_common.cpp index cf0e4e5f80..b6601a11f6 100644 --- a/common/widgets/ui_common.cpp +++ b/common/widgets/ui_common.cpp @@ -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; diff --git a/pcbnew/dialogs/dialog_text_properties.cpp b/pcbnew/dialogs/dialog_text_properties.cpp index 047d0214a4..986af26c72 100644 --- a/pcbnew/dialogs/dialog_text_properties.cpp +++ b/pcbnew/dialogs/dialog_text_properties.cpp @@ -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( m_SingleLineText ) ); + else + m_SingleLineText->SetSelection( -1, -1 ); + + event.Skip(); +} + + bool DIALOG_TEXT_PROPERTIES::TransferDataToWindow() { if( m_SingleLineText->IsShown() ) diff --git a/pcbnew/dialogs/dialog_text_properties.h b/pcbnew/dialogs/dialog_text_properties.h index 5f8179b8e9..4ea37f7cde 100644 --- a/pcbnew/dialogs/dialog_text_properties.h +++ b/pcbnew/dialogs/dialog_text_properties.h @@ -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 diff --git a/pcbnew/dialogs/dialog_text_properties_base.cpp b/pcbnew/dialogs/dialog_text_properties_base.cpp index d257c21702..235ad0d43e 100644 --- a/pcbnew/dialogs/dialog_text_properties_base.cpp +++ b/pcbnew/dialogs/dialog_text_properties_base.cpp @@ -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 ); diff --git a/pcbnew/dialogs/dialog_text_properties_base.fbp b/pcbnew/dialogs/dialog_text_properties_base.fbp index 5a2b6b664c..197bc2d007 100644 --- a/pcbnew/dialogs/dialog_text_properties_base.fbp +++ b/pcbnew/dialogs/dialog_text_properties_base.fbp @@ -329,6 +329,7 @@ + OnSetFocusText OnOkClick diff --git a/pcbnew/dialogs/dialog_text_properties_base.h b/pcbnew/dialogs/dialog_text_properties_base.h index f4f5d05582..7d8566978e 100644 --- a/pcbnew/dialogs/dialog_text_properties_base.h +++ b/pcbnew/dialogs/dialog_text_properties_base.h @@ -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(); }