From f0e6f812ff9861f4f86206c399143ef0795df646 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 20 Mar 2021 00:01:37 +0000 Subject: [PATCH] Edit One Field improvements. 1) Accept as OK if the multiline textbox isn't shown. 2) Focus and select all in first control if multiline textbox isn't shown. 3) Make title be title caps ("Edit Sheet name Field" looked dorky). Fixes https://gitlab.com/kicad/code/kicad/issues/7940 --- common/string.cpp | 19 +++++++++++++++++++ eeschema/dialogs/dialog_edit_one_field.cpp | 5 ++++- eeschema/dialogs/dialog_lib_edit_text.cpp | 9 +++++++++ eeschema/dialogs/dialog_lib_edit_text.h | 2 ++ .../dialogs/dialog_lib_edit_text_base.cpp | 4 +++- .../dialogs/dialog_lib_edit_text_base.fbp | 3 ++- eeschema/dialogs/dialog_lib_edit_text_base.h | 1 + eeschema/tools/sch_edit_tool.cpp | 2 +- eeschema/tools/symbol_editor_edit_tool.cpp | 6 ++---- include/kicad_string.h | 5 +++++ 10 files changed, 48 insertions(+), 8 deletions(-) diff --git a/common/string.cpp b/common/string.cpp index a9fbfb4aca..7b7a75249c 100644 --- a/common/string.cpp +++ b/common/string.cpp @@ -212,6 +212,25 @@ wxString UnescapeString( const wxString& aSource ) } +wxString TitleCaps( const wxString& aString ) +{ + wxArrayString words; + wxString result; + + wxStringSplit( aString, words, ' ' ); + + for( const wxString& word : words ) + { + if( !result.IsEmpty() ) + result += wxT( " " ); + + result += word.Capitalize(); + } + + return result; +} + + int ReadDelimitedText( wxString* aDest, const char* aSource ) { std::string utf8; // utf8 but without escapes and quotes. diff --git a/eeschema/dialogs/dialog_edit_one_field.cpp b/eeschema/dialogs/dialog_edit_one_field.cpp index 16a9ba5b1b..cfc8de854a 100644 --- a/eeschema/dialogs/dialog_edit_one_field.cpp +++ b/eeschema/dialogs/dialog_edit_one_field.cpp @@ -93,7 +93,10 @@ void DIALOG_EDIT_ONE_FIELD::init() bool use_validator = m_fieldId == REFERENCE_FIELD || m_fieldId == VALUE_FIELD || m_fieldId == FOOTPRINT_FIELD - || m_fieldId == DATASHEET_FIELD; + || m_fieldId == DATASHEET_FIELD + || m_fieldId == SHEETNAME_V + || m_fieldId == SHEETFILENAME_V; + if( use_validator ) { m_StyledTextCtrl->Show( false ); diff --git a/eeschema/dialogs/dialog_lib_edit_text.cpp b/eeschema/dialogs/dialog_lib_edit_text.cpp index 0b4e569e6e..76d718093d 100644 --- a/eeschema/dialogs/dialog_lib_edit_text.cpp +++ b/eeschema/dialogs/dialog_lib_edit_text.cpp @@ -166,3 +166,12 @@ bool DIALOG_LIB_EDIT_TEXT::TransferDataFromWindow() return true; } + + +void DIALOG_LIB_EDIT_TEXT::OnTextEnter( wxCommandEvent& event ) +{ + if( IsQuasiModal() ) + EndQuasiModal( wxID_OK ); + else + EndModal( wxID_OK ); +} \ No newline at end of file diff --git a/eeschema/dialogs/dialog_lib_edit_text.h b/eeschema/dialogs/dialog_lib_edit_text.h index a6f81098cd..2a5e95dc86 100644 --- a/eeschema/dialogs/dialog_lib_edit_text.h +++ b/eeschema/dialogs/dialog_lib_edit_text.h @@ -47,6 +47,8 @@ public: DIALOG_LIB_EDIT_TEXT( SYMBOL_EDIT_FRAME* aParent, LIB_TEXT* aText ); ~DIALOG_LIB_EDIT_TEXT() override {}; + void OnTextEnter( wxCommandEvent& event ) override; + private: bool TransferDataToWindow() override; bool TransferDataFromWindow() override; diff --git a/eeschema/dialogs/dialog_lib_edit_text_base.cpp b/eeschema/dialogs/dialog_lib_edit_text_base.cpp index 1502b73411..562119793a 100644 --- a/eeschema/dialogs/dialog_lib_edit_text_base.cpp +++ b/eeschema/dialogs/dialog_lib_edit_text_base.cpp @@ -29,7 +29,7 @@ DIALOG_LIB_EDIT_TEXT_BASE::DIALOG_LIB_EDIT_TEXT_BASE( wxWindow* parent, wxWindow m_textLabel->Wrap( -1 ); bTextValueBoxSizer->Add( m_textLabel, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 ); - m_TextCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + m_TextCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); bTextValueBoxSizer->Add( m_TextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); m_StyledTextCtrl = new wxStyledTextCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN, wxEmptyString ); @@ -220,6 +220,7 @@ DIALOG_LIB_EDIT_TEXT_BASE::DIALOG_LIB_EDIT_TEXT_BASE( wxWindow* parent, wxWindow // Connect Events this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_LIB_EDIT_TEXT_BASE::OnCloseDialog ) ); m_TextCtrl->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( DIALOG_LIB_EDIT_TEXT_BASE::OnSetFocusText ), NULL, this ); + m_TextCtrl->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_LIB_EDIT_TEXT_BASE::OnTextEnter ), NULL, this ); m_StyledTextCtrl->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( DIALOG_LIB_EDIT_TEXT_BASE::OnSetFocusText ), NULL, this ); m_TextValueSelectButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_TEXT_BASE::OnTextValueSelectButtonClick ), NULL, this ); } @@ -229,6 +230,7 @@ DIALOG_LIB_EDIT_TEXT_BASE::~DIALOG_LIB_EDIT_TEXT_BASE() // Disconnect Events this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_LIB_EDIT_TEXT_BASE::OnCloseDialog ) ); m_TextCtrl->Disconnect( wxEVT_SET_FOCUS, wxFocusEventHandler( DIALOG_LIB_EDIT_TEXT_BASE::OnSetFocusText ), NULL, this ); + m_TextCtrl->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_LIB_EDIT_TEXT_BASE::OnTextEnter ), NULL, this ); m_StyledTextCtrl->Disconnect( wxEVT_SET_FOCUS, wxFocusEventHandler( DIALOG_LIB_EDIT_TEXT_BASE::OnSetFocusText ), NULL, this ); m_TextValueSelectButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_TEXT_BASE::OnTextValueSelectButtonClick ), NULL, this ); diff --git a/eeschema/dialogs/dialog_lib_edit_text_base.fbp b/eeschema/dialogs/dialog_lib_edit_text_base.fbp index cd7bc57f94..60bbcda26e 100644 --- a/eeschema/dialogs/dialog_lib_edit_text_base.fbp +++ b/eeschema/dialogs/dialog_lib_edit_text_base.fbp @@ -197,7 +197,7 @@ Resizable 1 - + wxTE_PROCESS_ENTER ; ; forward_declare 0 @@ -210,6 +210,7 @@ OnSetFocusText + OnTextEnter diff --git a/eeschema/dialogs/dialog_lib_edit_text_base.h b/eeschema/dialogs/dialog_lib_edit_text_base.h index 67e5b726e8..ae2ee82d4e 100644 --- a/eeschema/dialogs/dialog_lib_edit_text_base.h +++ b/eeschema/dialogs/dialog_lib_edit_text_base.h @@ -73,6 +73,7 @@ class DIALOG_LIB_EDIT_TEXT_BASE : public DIALOG_SHIM // Virtual event handlers, overide them in your derived class virtual void OnCloseDialog( wxCloseEvent& event ) { event.Skip(); } virtual void OnSetFocusText( wxFocusEvent& event ) { event.Skip(); } + virtual void OnTextEnter( wxCommandEvent& event ) { event.Skip(); } virtual void OnTextValueSelectButtonClick( wxCommandEvent& event ) { event.Skip(); } diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 8387fe8677..dff289fd68 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -1177,7 +1177,7 @@ void SCH_EDIT_TOOL::editFieldText( SCH_FIELD* aField ) if( aField->GetEditFlags() == 0 ) // i.e. not edited, or moved saveCopyInUndoList( aField, UNDO_REDO::CHANGED ); - wxString title = wxString::Format( _( "Edit %s Field" ), aField->GetName() ); + wxString title = wxString::Format( _( "Edit %s Field" ), TitleCaps( aField->GetName() ) ); DIALOG_SCH_EDIT_ONE_FIELD dlg( m_frame, title, aField ); diff --git a/eeschema/tools/symbol_editor_edit_tool.cpp b/eeschema/tools/symbol_editor_edit_tool.cpp index ccd88cc2a8..15926b8bb3 100644 --- a/eeschema/tools/symbol_editor_edit_tool.cpp +++ b/eeschema/tools/symbol_editor_edit_tool.cpp @@ -22,7 +22,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include #include #include #include @@ -30,7 +29,7 @@ #include #include #include -#include +#include #include #include #include @@ -43,7 +42,6 @@ #include "symbol_editor_edit_tool.h" #include // for KiROUND - SYMBOL_EDITOR_EDIT_TOOL::SYMBOL_EDITOR_EDIT_TOOL() : EE_TOOL_BASE( "eeschema.SymbolEditTool" ), m_pickerItem( nullptr ) @@ -521,7 +519,7 @@ void SYMBOL_EDITOR_EDIT_TOOL::editFieldProperties( LIB_FIELD* aField ) if( aField->GetId() == VALUE_FIELD ) caption = _( "Edit Symbol Name" ); else - caption.Printf( _( "Edit %s Field" ), aField->GetName() ); + caption.Printf( _( "Edit %s Field" ), TitleCaps( aField->GetName() ) ); DIALOG_LIB_EDIT_ONE_FIELD dlg( m_frame, caption, aField ); diff --git a/include/kicad_string.h b/include/kicad_string.h index 8f4a52218c..a16b288c9f 100644 --- a/include/kicad_string.h +++ b/include/kicad_string.h @@ -66,6 +66,11 @@ wxString UnescapeString( const wxString& aSource ); */ wxString PrettyPrintForMenu( const wxString& aString ); +/** + * Capitalize the first letter in each word. + */ +wxString TitleCaps( const wxString& aString ); + /** * Copy bytes from @a aSource delimited string segment to @a aDest buffer. *