From 6d44ca21452d30a26cf18d4eb59091702787785f Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 30 Apr 2022 13:37:40 +0100 Subject: [PATCH] Ellipsize long heirarchical paths. Fixes https://gitlab.com/kicad/code/kicad/issues/11499 --- eeschema/dialogs/dialog_sheet_properties.cpp | 25 ++++--- .../dialogs/dialog_sheet_properties_base.cpp | 13 ++-- .../dialogs/dialog_sheet_properties_base.fbp | 71 +++++++++++++++++-- .../dialogs/dialog_sheet_properties_base.h | 2 + 4 files changed, 92 insertions(+), 19 deletions(-) diff --git a/eeschema/dialogs/dialog_sheet_properties.cpp b/eeschema/dialogs/dialog_sheet_properties.cpp index 75ae1d3f68..20417539dc 100644 --- a/eeschema/dialogs/dialog_sheet_properties.cpp +++ b/eeschema/dialogs/dialog_sheet_properties.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2009 Wayne Stambaugh - * Copyright (C) 2014-2021 KiCad Developers, see CHANGELOG.txt for contributors. + * Copyright (C) 2014-2022 KiCad Developers, see CHANGELOG.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 @@ -40,6 +40,7 @@ #include #include #include "panel_eeschema_color_settings.h" +#include "wx/dcclient.h" DIALOG_SHEET_PROPERTIES::DIALOG_SHEET_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_SHEET* aSheet, bool* aClearAnnotationNewItems ) : @@ -86,6 +87,7 @@ DIALOG_SHEET_PROPERTIES::DIALOG_SHEET_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_S // Set font sizes m_hierarchicalPathLabel->SetFont( KIUI::GetInfoFont( this ) ); + m_hierarchicalPath->SetFont( KIUI::GetInfoFont( this ) ); // wxFormBuilder doesn't include this event... m_grid->Connect( wxEVT_GRID_CELL_CHANGING, @@ -852,12 +854,10 @@ void DIALOG_SHEET_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event ) } // Propagate changes in sheetname to displayed hierarchical path - wxString hierarchicalPath = _( "Hierarchical path: " ); + wxString path = m_frame->GetCurrentSheet().PathHumanReadable( false ); - hierarchicalPath += m_frame->GetCurrentSheet().PathHumanReadable( false ); - - if( hierarchicalPath.Last() != '/' ) - hierarchicalPath.Append( '/' ); + if( path.Last() != '/' ) + path.Append( '/' ); wxGridCellEditor* editor = m_grid->GetCellEditor( SHEETNAME, FDC_VALUE ); wxControl* control = editor->GetControl(); @@ -871,12 +871,19 @@ void DIALOG_SHEET_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event ) m_dummySheet.SetFields( *m_fields ); m_dummySheetNameField.SetText( sheetName ); - hierarchicalPath += m_dummySheetNameField.GetShownText(); + path += m_dummySheetNameField.GetShownText(); editor->DecRef(); - if( m_hierarchicalPathLabel->GetLabel() != hierarchicalPath ) - m_hierarchicalPathLabel->SetLabel( hierarchicalPath ); + wxClientDC dc( m_hierarchicalPathLabel ); + int width = m_sizerBottom->GetSize().x - m_stdDialogButtonSizer->GetSize().x + - m_hierarchicalPathLabel->GetSize().x + - 30; + + path = wxControl::Ellipsize( path, dc, wxELLIPSIZE_START, width, wxELLIPSIZE_FLAGS_NONE ); + + if( m_hierarchicalPath->GetLabel() != path ) + m_hierarchicalPath->SetLabel( path ); // Handle a delayed focus if( m_delayedFocusRow >= 0 ) diff --git a/eeschema/dialogs/dialog_sheet_properties_base.cpp b/eeschema/dialogs/dialog_sheet_properties_base.cpp index 1eb7eff028..366cdc0e0a 100644 --- a/eeschema/dialogs/dialog_sheet_properties_base.cpp +++ b/eeschema/dialogs/dialog_sheet_properties_base.cpp @@ -186,12 +186,15 @@ DIALOG_SHEET_PROPERTIES_BASE::DIALOG_SHEET_PROPERTIES_BASE( wxWindow* parent, wx m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); mainSizer->Add( m_staticline1, 0, wxEXPAND|wxLEFT|wxRIGHT|wxTOP, 5 ); - wxBoxSizer* bSizerBottom; - bSizerBottom = new wxBoxSizer( wxHORIZONTAL ); + m_sizerBottom = new wxBoxSizer( wxHORIZONTAL ); m_hierarchicalPathLabel = new wxStaticText( this, wxID_ANY, _("Hierarchical path:"), wxDefaultPosition, wxDefaultSize, 0 ); m_hierarchicalPathLabel->Wrap( -1 ); - bSizerBottom->Add( m_hierarchicalPathLabel, 1, wxLEFT|wxALIGN_CENTER_VERTICAL, 10 ); + m_sizerBottom->Add( m_hierarchicalPathLabel, 0, wxLEFT|wxALIGN_CENTER_VERTICAL, 10 ); + + m_hierarchicalPath = new wxStaticText( this, wxID_ANY, _("path"), wxDefaultPosition, wxDefaultSize, 0 ); + m_hierarchicalPath->Wrap( -1 ); + m_sizerBottom->Add( m_hierarchicalPath, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); m_stdDialogButtonSizer = new wxStdDialogButtonSizer(); m_stdDialogButtonSizerOK = new wxButton( this, wxID_OK ); @@ -200,10 +203,10 @@ DIALOG_SHEET_PROPERTIES_BASE::DIALOG_SHEET_PROPERTIES_BASE( wxWindow* parent, wx m_stdDialogButtonSizer->AddButton( m_stdDialogButtonSizerCancel ); m_stdDialogButtonSizer->Realize(); - bSizerBottom->Add( m_stdDialogButtonSizer, 0, wxEXPAND, 5 ); + m_sizerBottom->Add( m_stdDialogButtonSizer, 0, wxEXPAND|wxALL, 5 ); - mainSizer->Add( bSizerBottom, 0, wxBOTTOM|wxEXPAND|wxTOP, 5 ); + mainSizer->Add( m_sizerBottom, 0, wxEXPAND|wxLEFT, 5 ); this->SetSizer( mainSizer ); diff --git a/eeschema/dialogs/dialog_sheet_properties_base.fbp b/eeschema/dialogs/dialog_sheet_properties_base.fbp index 354eda9203..7ff2b2569a 100644 --- a/eeschema/dialogs/dialog_sheet_properties_base.fbp +++ b/eeschema/dialogs/dialog_sheet_properties_base.fbp @@ -1240,17 +1240,17 @@ 5 - wxBOTTOM|wxEXPAND|wxTOP + wxEXPAND|wxLEFT 0 - bSizerBottom + m_sizerBottom wxHORIZONTAL - none + protected 10 wxLEFT|wxALIGN_CENTER_VERTICAL - 1 + 0 1 1 @@ -1308,9 +1308,70 @@ -1 + + 5 + wxALL|wxALIGN_CENTER_VERTICAL + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + path + 0 + + 0 + + + 0 + + 1 + m_hierarchicalPath + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + 5 - wxEXPAND + wxEXPAND|wxALL 0 0 diff --git a/eeschema/dialogs/dialog_sheet_properties_base.h b/eeschema/dialogs/dialog_sheet_properties_base.h index 458f9c1fa3..4605f49c05 100644 --- a/eeschema/dialogs/dialog_sheet_properties_base.h +++ b/eeschema/dialogs/dialog_sheet_properties_base.h @@ -62,7 +62,9 @@ class DIALOG_SHEET_PROPERTIES_BASE : public DIALOG_SHIM wxStaticText* m_pageNumberStaticText; wxTextCtrl* m_pageNumberTextCtrl; wxStaticLine* m_staticline1; + wxBoxSizer* m_sizerBottom; wxStaticText* m_hierarchicalPathLabel; + wxStaticText* m_hierarchicalPath; wxStdDialogButtonSizer* m_stdDialogButtonSizer; wxButton* m_stdDialogButtonSizerOK; wxButton* m_stdDialogButtonSizerCancel;