Allow textboxes to have no text. (They still have a defined box.)

Fixes https://gitlab.com/kicad/code/kicad/issues/11286
This commit is contained in:
Jeff Young 2022-04-05 16:25:03 +01:00
parent c591e19e9f
commit 0bd3341f0f
3 changed files with 32 additions and 29 deletions

View File

@ -204,20 +204,16 @@ bool DIALOG_LIB_TEXTBOX_PROPERTIES::TransferDataFromWindow()
wxString text = m_textCtrl->GetValue();
if( !text.IsEmpty() )
{
#ifdef __WXMAC__
// On macOS CTRL+Enter produces '\r' instead of '\n' regardless of EOL setting
text.Replace( "\r", "\n" );
#elif defined( __WINDOWS__ )
// On Windows, a new line is coded as \r\n. We use only \n in kicad files and in
// drawing routines so strip the \r char.
text.Replace( "\r", "" );
#endif
m_currentText->SetText( text );
}
else if( !m_currentText->IsNew() )
{
DisplayError( this, _( "Text can not be empty." ) );
return false;
}
if( m_currentText->GetTextWidth() != m_textSize.GetValue() )
m_currentText->SetTextSize( wxSize( m_textSize.GetValue(), m_textSize.GetValue() ) );

View File

@ -354,17 +354,27 @@ bool DIALOG_TEXT_PROPERTIES::TransferDataFromWindow()
// convert any text variable cross-references to their UUIDs
text = m_frame->Schematic().ConvertRefsToKIIDs( m_textCtrl->GetValue() );
if( !text.IsEmpty() )
{
#ifdef __WXMAC__
// On macOS CTRL+Enter produces '\r' instead of '\n' regardless of EOL setting
text.Replace( "\r", "\n" );
#elif defined( __WINDOWS__ )
// On Windows, a new line is coded as \r\n. We use only \n in kicad files and in
// drawing routines so strip the \r char.
text.Replace( "\r", "" );
#endif
if( m_currentItem->Type() == SCH_TEXTBOX_T )
{
// Textboxes have a defined extent and so are allowed to be empty
m_currentText->SetText( wxEmptyString );
}
else if( !text.IsEmpty() )
{
m_currentText->SetText( text );
}
else if( !m_currentItem->IsNew() )
else
{
// Other text items do not have defined extents, and so will disappear if empty
DisplayError( this, _( "Text can not be empty." ) );
return false;
}

View File

@ -313,9 +313,6 @@ bool DIALOG_TEXTBOX_PROPERTIES::TransferDataFromWindow()
if( !pushCommit )
m_item->SetFlags( IN_EDIT );
// Set the new text content
if( !m_MultiLineText->GetValue().IsEmpty() )
{
BOARD* board = m_frame->GetBoard();
wxString txt = board->ConvertCrossReferencesToKIIDs( m_MultiLineText->GetValue() );
@ -328,8 +325,8 @@ bool DIALOG_TEXTBOX_PROPERTIES::TransferDataFromWindow()
// drawing routines so strip the \r char.
txt.Replace( "\r", "" );
#endif
m_edaText->SetText( EscapeString( txt, CTX_QUOTED_STR ) );
}
m_item->SetLocked( m_cbLocked->GetValue() );