Edit One Field improvements.

1) Accept <enter> 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
This commit is contained in:
Jeff Young 2021-03-20 00:01:37 +00:00
parent b4e2db5913
commit f0e6f812ff
10 changed files with 48 additions and 8 deletions

View File

@ -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.

View File

@ -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 );

View File

@ -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 );
}

View File

@ -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;

View File

@ -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 );

View File

@ -197,7 +197,7 @@
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="style">wxTE_PROCESS_ENTER</property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
@ -210,6 +210,7 @@
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnSetFocus">OnSetFocusText</event>
<event name="OnTextEnter">OnTextEnter</event>
</object>
</object>
<object class="sizeritem" expanded="1">

View File

@ -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(); }

View File

@ -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 );

View File

@ -22,7 +22,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <tool/tool_manager.h>
#include <tool/picker_tool.h>
#include <tools/ee_selection_tool.h>
#include <tools/symbol_editor_pin_tool.h>
@ -30,7 +29,7 @@
#include <tools/symbol_editor_move_tool.h>
#include <ee_actions.h>
#include <bitmaps.h>
#include <confirm.h>
#include <kicad_string.h>
#include <symbol_edit_frame.h>
#include <dialogs/dialog_lib_edit_draw_item.h>
#include <dialogs/dialog_lib_edit_text.h>
@ -43,7 +42,6 @@
#include "symbol_editor_edit_tool.h"
#include <math/util.h> // 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 );

View File

@ -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.
*