diff --git a/common/eda_text.cpp b/common/eda_text.cpp index acd9f65495..6f5f06b433 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -493,36 +493,6 @@ void EDA_TEXT::AddRenderCacheGlyph( const SHAPE_POLY_SET& aPoly ) } -wxString EDA_TEXT::ShortenedText() const -{ - wxString tmp = GetText(); - - tmp.Replace( wxT( "\n" ), wxT( " " ) ); - tmp.Replace( wxT( "\r" ), wxT( " " ) ); - tmp.Replace( wxT( "\t" ), wxT( " " ) ); - - if( tmp.Length() > 54 ) - tmp = tmp.Left( 52 ) + wxT( "..." ); - - return tmp; -} - - -wxString EDA_TEXT::ShortenedShownText() const -{ - wxString tmp = GetShownText(); - - tmp.Replace( wxT( "\n" ), wxT( " " ) ); - tmp.Replace( wxT( "\r" ), wxT( " " ) ); - tmp.Replace( wxT( "\t" ), wxT( " " ) ); - - if( tmp.Length() > 36 ) - tmp = tmp.Left( 34 ) + wxT( "..." ); - - return tmp; -} - - int EDA_TEXT::GetInterline() const { return KiROUND( GetDrawFont()->GetInterline( GetTextHeight() ) ); diff --git a/common/widgets/ui_common.cpp b/common/widgets/ui_common.cpp index 851206fe10..7743297ac9 100644 --- a/common/widgets/ui_common.cpp +++ b/common/widgets/ui_common.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2018-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -37,6 +36,7 @@ #include #include #include +#include int KIUI::GetStdMargin() { @@ -182,6 +182,34 @@ bool KIUI::EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString ) } +wxString KIUI::EllipsizeStatusText( wxWindow* aWindow, const wxString& aString ) +{ + wxString msg = UnescapeString( aString ); + + msg.Replace( wxT( "\n" ), wxT( " " ) ); + msg.Replace( wxT( "\r" ), wxT( " " ) ); + msg.Replace( wxT( "\t" ), wxT( " " ) ); + + wxClientDC dc( aWindow ); + return wxControl::Ellipsize( msg, dc, wxELLIPSIZE_END, aWindow->GetSize().GetWidth() / 3 ); +} + + +wxString KIUI::EllipsizeMenuText( const wxString& aString ) +{ + wxString msg = UnescapeString( aString ); + + msg.Replace( wxT( "\n" ), wxT( " " ) ); + msg.Replace( wxT( "\r" ), wxT( " " ) ); + msg.Replace( wxT( "\t" ), wxT( " " ) ); + + if( msg.Length() > 36 ) + msg = msg.Left( 34 ) + wxT( "..." ); + + return msg; +} + + void KIUI::SelectReferenceNumber( wxTextEntry* aTextEntry ) { wxString ref = aTextEntry->GetValue(); diff --git a/eeschema/lib_field.cpp b/eeschema/lib_field.cpp index 8baf7df7be..0641882da4 100644 --- a/eeschema/lib_field.cpp +++ b/eeschema/lib_field.cpp @@ -455,7 +455,7 @@ void LIB_FIELD::SetName( const wxString& aName ) wxString LIB_FIELD::GetSelectMenuText( EDA_UNITS aUnits ) const { - return wxString::Format( "%s '%s'", GetName(), ShortenedShownText() ); + return wxString::Format( "%s '%s'", GetName(), KIUI::EllipsizeMenuText( GetShownText() ) ); } diff --git a/eeschema/lib_text.cpp b/eeschema/lib_text.cpp index 02bdc1272d..51f729ce40 100644 --- a/eeschema/lib_text.cpp +++ b/eeschema/lib_text.cpp @@ -422,7 +422,7 @@ const EDA_RECT LIB_TEXT::GetBoundingBox() const wxString LIB_TEXT::GetSelectMenuText( EDA_UNITS aUnits ) const { - return wxString::Format( _( "Graphic Text '%s'" ), ShortenedShownText() ); + return wxString::Format( _( "Graphic Text '%s'" ), KIUI::EllipsizeMenuText( GetShownText() ) ); } diff --git a/eeschema/lib_textbox.cpp b/eeschema/lib_textbox.cpp index 895393ab4a..3095accd0f 100644 --- a/eeschema/lib_textbox.cpp +++ b/eeschema/lib_textbox.cpp @@ -392,7 +392,7 @@ void LIB_TEXTBOX::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorGetUserUnits(); // Don't use GetShownText() here; we want to show the user the variable references - aList.emplace_back( _( "Text Box" ), UnescapeString( ShortenedText() ) ); + aList.emplace_back( _( "Text Box" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) ); aList.emplace_back( _( "Font" ), GetDrawFont()->GetName() ); diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 35c343214e..6ebff7f45f 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -671,7 +671,7 @@ void SCH_FIELD::Rotate( const VECTOR2I& aCenter ) wxString SCH_FIELD::GetSelectMenuText( EDA_UNITS aUnits ) const { - return wxString::Format( "%s '%s'", GetName(), ShortenedShownText() ); + return wxString::Format( "%s '%s'", GetName(), KIUI::EllipsizeMenuText( GetShownText() ) ); } diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index 17cd1b7a10..441cf895de 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -957,7 +957,7 @@ const EDA_RECT SCH_LABEL::GetBodyBoundingBox() const wxString SCH_LABEL::GetSelectMenuText( EDA_UNITS aUnits ) const { - return wxString::Format( _( "Label '%s'" ), ShortenedShownText() ); + return wxString::Format( _( "Label '%s'" ), KIUI::EllipsizeMenuText( GetShownText() ) ); } @@ -1411,7 +1411,7 @@ void SCH_GLOBALLABEL::CreateGraphicShape( const RENDER_SETTINGS* aRenderSettings wxString SCH_GLOBALLABEL::GetSelectMenuText( EDA_UNITS aUnits ) const { - return wxString::Format( _( "Global Label '%s'" ), ShortenedShownText() ); + return wxString::Format( _( "Global Label '%s'" ), KIUI::EllipsizeMenuText( GetShownText() ) ); } @@ -1544,7 +1544,8 @@ VECTOR2I SCH_HIERLABEL::GetSchematicTextOffset( const RENDER_SETTINGS* aSettings wxString SCH_HIERLABEL::GetSelectMenuText( EDA_UNITS aUnits ) const { - return wxString::Format( _( "Hierarchical Label '%s'" ), ShortenedShownText() ); + return wxString::Format( _( "Hierarchical Label '%s'" ), + KIUI::EllipsizeMenuText( GetShownText() ) ); } diff --git a/eeschema/sch_sheet_pin.cpp b/eeschema/sch_sheet_pin.cpp index e2a02ca88a..af11f3b032 100644 --- a/eeschema/sch_sheet_pin.cpp +++ b/eeschema/sch_sheet_pin.cpp @@ -327,7 +327,8 @@ void SCH_SHEET_PIN::GetEndPoints( std::vector& aItemList ) wxString SCH_SHEET_PIN::GetSelectMenuText( EDA_UNITS aUnits ) const { - return wxString::Format( _( "Hierarchical Sheet Pin %s" ), ShortenedShownText() ); + return wxString::Format( _( "Hierarchical Sheet Pin %s" ), + KIUI::EllipsizeMenuText( GetShownText() ) ); } diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index da928ce47d..9f544dee9a 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -383,7 +383,7 @@ wxString SCH_TEXT::GetShownText( int aDepth ) const wxString SCH_TEXT::GetSelectMenuText( EDA_UNITS aUnits ) const { - return wxString::Format( _( "Graphic Text '%s'" ), ShortenedShownText() ); + return wxString::Format( _( "Graphic Text '%s'" ), KIUI::EllipsizeMenuText( GetShownText() ) ); } @@ -475,7 +475,7 @@ void SCH_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorGetName() ); diff --git a/eeschema/sch_textbox.cpp b/eeschema/sch_textbox.cpp index 26b688311b..1a7537153a 100644 --- a/eeschema/sch_textbox.cpp +++ b/eeschema/sch_textbox.cpp @@ -390,7 +390,7 @@ void SCH_TEXTBOX::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorGetUserUnits(); // Don't use GetShownText() here; we want to show the user the variable references - aList.emplace_back( _( "Text Box" ), UnescapeString( ShortenedText() ) ); + aList.emplace_back( _( "Text Box" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) ); aList.emplace_back( _( "Font" ), GetDrawFont()->GetName() ); diff --git a/include/eda_text.h b/include/eda_text.h index 3cdf7011d8..4e91685092 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -87,11 +87,6 @@ public: */ virtual const wxString& GetText() const { return m_text; } - /** - * Returns a shortened version (max 54 characters) of the shown text - */ - wxString ShortenedText() const; - /** * Return the string actually shown after processing of the base text. * @@ -100,11 +95,6 @@ public: */ virtual wxString GetShownText( int aDepth = 0 ) const { return m_shown_text; } - /** - * Returns a shortened version (max 36 characters) of the shown text - */ - wxString ShortenedShownText() const; - /** * Indicates the ShownText has text var references which need to be processed. */ diff --git a/include/widgets/ui_common.h b/include/widgets/ui_common.h index 4b4a811182..cab2e134fd 100644 --- a/include/widgets/ui_common.h +++ b/include/widgets/ui_common.h @@ -77,6 +77,20 @@ bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString = nullptr ) */ void SelectReferenceNumber( wxTextEntry* aTextEntry ); +/** + * Ellipsize text (at the end) to be no more than 1/3 of the window width. + * + * @return shortened text ending with an ellipsis. + */ +wxString EllipsizeStatusText( wxWindow* aWindow, const wxString& aString ); + +/** + * Ellipsize text (at the end) to be no more than 36 characters. + * + * @return shortened text ending with an ellipsis. + */ +wxString EllipsizeMenuText( const wxString& aString ); + /** * Check if a input control has focus. * diff --git a/pcbnew/fp_text.cpp b/pcbnew/fp_text.cpp index d99005b2e9..40e858e47b 100644 --- a/pcbnew/fp_text.cpp +++ b/pcbnew/fp_text.cpp @@ -316,7 +316,7 @@ wxString FP_TEXT::GetSelectMenuText( EDA_UNITS aUnits ) const default: return wxString::Format( _( "Footprint Text '%s' of %s" ), - ShortenedShownText(), + KIUI::EllipsizeMenuText( GetShownText() ), static_cast( GetParent() )->GetReference() ); } } diff --git a/pcbnew/pcb_text.cpp b/pcbnew/pcb_text.cpp index 724b48ff54..f9582dc1ca 100644 --- a/pcbnew/pcb_text.cpp +++ b/pcbnew/pcb_text.cpp @@ -130,7 +130,7 @@ void PCB_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorGetUserUnits(); // Don't use GetShownText() here; we want to show the user the variable references - aList.emplace_back( _( "PCB Text" ), UnescapeString( GetText() ) ); + aList.emplace_back( _( "PCB Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) ); if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() ) aList.emplace_back( _( "Status" ), _( "Locked" ) ); @@ -233,7 +233,9 @@ void PCB_TEXT::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) wxString PCB_TEXT::GetSelectMenuText( EDA_UNITS aUnits ) const { - return wxString::Format( _( "PCB Text '%s' on %s"), ShortenedShownText(), GetLayerName() ); + return wxString::Format( _( "PCB Text '%s' on %s"), + KIUI::EllipsizeMenuText( GetShownText() ), + GetLayerName() ); } diff --git a/pcbnew/pcb_textbox.cpp b/pcbnew/pcb_textbox.cpp index 368fdc6d1a..ff83aa20e2 100644 --- a/pcbnew/pcb_textbox.cpp +++ b/pcbnew/pcb_textbox.cpp @@ -298,7 +298,7 @@ void PCB_TEXTBOX::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorGetUserUnits(); // Don't use GetShownText() here; we want to show the user the variable references - aList.emplace_back( _( "Text Box" ), UnescapeString( GetText() ) ); + aList.emplace_back( _( "Text Box" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) ); if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() ) aList.emplace_back( _( "Status" ), _( "Locked" ) );