diff --git a/common/string.cpp b/common/string.cpp index 4c09c4f4a2..f0e9b719a1 100644 --- a/common/string.cpp +++ b/common/string.cpp @@ -362,6 +362,12 @@ wxString EscapeHTML( const wxString& aString ) } +bool NoPrintableChars( wxString aString ) +{ + return aString.Trim( true ).Trim( false ).IsEmpty(); +} + + char* StrPurge( char* text ) { static const char whitespace[] = " \t\n\r\f\v"; diff --git a/eeschema/tools/lib_drawing_tools.cpp b/eeschema/tools/lib_drawing_tools.cpp index db33b9af86..4db742ee08 100644 --- a/eeschema/tools/lib_drawing_tools.cpp +++ b/eeschema/tools/lib_drawing_tools.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include "ee_point_editor.h" static void* g_lastPinWeakPtr; @@ -181,7 +182,7 @@ int LIB_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) DIALOG_LIB_EDIT_TEXT dlg( m_frame, text ); - if( dlg.ShowModal() != wxID_OK ) + if( dlg.ShowModal() != wxID_OK || NoPrintableChars( text->GetText() ) ) delete text; else item = text; diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index 03356eac43..8b3e69ae41 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -24,7 +24,6 @@ #include "sch_drawing_tools.h" #include "ee_selection_tool.h" -#include "ee_point_editor.h" #include #include #include @@ -48,6 +47,7 @@ #include #include #include +#include SCH_DRAWING_TOOLS::SCH_DRAWING_TOOLS() : EE_TOOL_BASE( "eeschema.InteractiveDrawing" ), @@ -733,7 +733,7 @@ SCH_TEXT* SCH_DRAWING_TOOLS::createNewText( const VECTOR2I& aPosition, int aType DIALOG_LABEL_EDITOR dlg( m_frame, textItem ); // Must be quasi modal for syntax help - if( dlg.ShowQuasiModal() != wxID_OK || textItem->GetText().IsEmpty() ) + if( dlg.ShowQuasiModal() != wxID_OK || NoPrintableChars( textItem->GetText() ) ) { delete textItem; return nullptr; @@ -789,7 +789,7 @@ SCH_SHEET_PIN* SCH_DRAWING_TOOLS::createSheetPin( SCH_SHEET* aSheet, SCH_HIERLAB { DIALOG_SHEET_PIN_PROPERTIES dlg( m_frame, sheetPin ); - if( dlg.ShowModal() != wxID_OK || sheetPin->GetText().IsEmpty() ) + if( dlg.ShowModal() != wxID_OK || NoPrintableChars( sheetPin->GetText() ) ) { delete sheetPin; return nullptr; diff --git a/include/kicad_string.h b/include/kicad_string.h index 4eede79419..c9afd6a036 100644 --- a/include/kicad_string.h +++ b/include/kicad_string.h @@ -115,6 +115,11 @@ wxString EscapeHTML( const wxString& aString ); */ char* GetLine( FILE* aFile, char* Line, int* LineNum = NULL, int SizeLine = 255 ); +/** + * Return true if the string is empty or contains only whitespace. + */ +bool NoPrintableChars( wxString aString ); + /** * Remove leading and training spaces, tabs and end of line chars in \a text * diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index aa6419f954..6a5c146a01 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -23,14 +23,18 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "drawing_tool.h" -#include "pcb_actions.h" #include #include #include #include #include #include +#include +#include +#include +#include +#include +#include #include #include #include @@ -39,24 +43,18 @@ #include #include #include - #include #include #include #include #include #include - #include #include #include -#include -#include -#include -#include -#include #include #include +#include using SCOPED_DRAW_MODE = SCOPED_SET_RESET; @@ -99,11 +97,15 @@ protected: VIA_DIMENSION via = bds.m_ViasDimensionsList[i]; if( via.m_Drill > 0 ) + { msg.Printf( _("Via %s, drill %s" ), MessageTextFromValue( units, via.m_Diameter ), MessageTextFromValue( units, via.m_Drill ) ); + } else + { msg.Printf( _( "Via %s" ), MessageTextFromValue( units, via.m_Diameter ) ); + } int menuIdx = ID_POPUP_PCB_SELECT_VIASIZE1 + i; Append( menuIdx, msg, wxEmptyString, wxITEM_CHECK ); @@ -522,11 +524,10 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) RunMainStack( [&]() { - cancelled = !textDialog.ShowModal() - || fpText->GetText().IsEmpty(); + cancelled = !textDialog.ShowModal(); } ); - if( cancelled ) + if( cancelled || NoPrintableChars( fpText->GetText() ) ) { delete text; text = nullptr; @@ -560,7 +561,7 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) m_frame->ShowTextPropertiesDialog( pcbText ); } ); - if( pcbText->GetText().IsEmpty() ) + if( NoPrintableChars( pcbText->GetText() ) ) delete pcbText; else text = pcbText;