Fix some issues with Font property

Prevent out-of-bounds access
Make sure list is initialized in symbol editor frame
Don't re-init the list more frequently than necessary

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16399
This commit is contained in:
Jon Evans 2023-12-22 18:34:26 -05:00
parent 3f73bbcc4f
commit 7470ec80e4
6 changed files with 26 additions and 8 deletions

View File

@ -857,7 +857,10 @@ void EDA_TEXT::SetFontIndex( int aIdx )
std::vector<std::string> fontNames; std::vector<std::string> fontNames;
Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) ); Fontconfig()->ListFonts( fontNames, std::string( Pgm().GetLanguageTag().utf8_str() ) );
if( aIdx >= 0 && aIdx < static_cast<int>( fontNames.size() ) )
SetFont( KIFONT::FONT::GetFont( fontNames[ aIdx ], IsBold(), IsItalic() ) ); SetFont( KIFONT::FONT::GetFont( fontNames[ aIdx ], IsBold(), IsItalic() ) );
else
SetFont( nullptr );
} }
} }

View File

@ -49,6 +49,11 @@ public:
virtual void AfterCommit() {} virtual void AfterCommit() {}
/**
* Parents will call this when the user changes the UI language
*/
virtual void LanguageChanged() {}
wxPropertyGrid* GetPropertyGrid() wxPropertyGrid* GetPropertyGrid()
{ {
return m_grid; return m_grid;

View File

@ -1912,6 +1912,8 @@ void SCH_EDIT_FRAME::ShowChangedLanguage()
m_auimgr.Update(); m_auimgr.Update();
m_hierarchy->UpdateHierarchyTree(); m_hierarchy->UpdateHierarchyTree();
m_propertiesPanel->LanguageChanged();
// status bar // status bar
UpdateMsgPanel(); UpdateMsgPanel();

View File

@ -1250,6 +1250,8 @@ void SYMBOL_EDIT_FRAME::ShowChangedLanguage()
m_treePane->GetLibTree()->ShowChangedLanguage(); m_treePane->GetLibTree()->ShowChangedLanguage();
m_propertiesPanel->LanguageChanged();
// status bar // status bar
UpdateMsgPanel(); UpdateMsgPanel();

View File

@ -87,6 +87,8 @@ SCH_PROPERTIES_PANEL::SCH_PROPERTIES_PANEL( wxWindow* aParent, SCH_BASE_FRAME* a
{ {
m_colorEditorInstance = static_cast<PG_COLOR_EDITOR*>( it->second ); m_colorEditorInstance = static_cast<PG_COLOR_EDITOR*>( it->second );
} }
updateFontList();
} }
@ -102,10 +104,6 @@ void SCH_PROPERTIES_PANEL::UpdateData()
EE_SELECTION_TOOL* selectionTool = m_frame->GetToolManager()->GetTool<EE_SELECTION_TOOL>(); EE_SELECTION_TOOL* selectionTool = m_frame->GetToolManager()->GetTool<EE_SELECTION_TOOL>();
const SELECTION& selection = selectionTool->GetSelection(); const SELECTION& selection = selectionTool->GetSelection();
// TODO perhaps it could be called less often? use PROPERTIES_TOOL and catch MODEL_RELOAD?
if( SCH_EDIT_FRAME* schFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
updateLists( schFrame->Schematic() );
// Will actually just be updatePropertyValues() if selection hasn't changed // Will actually just be updatePropertyValues() if selection hasn't changed
rebuildProperties( selection ); rebuildProperties( selection );
} }
@ -209,7 +207,13 @@ void SCH_PROPERTIES_PANEL::valueChanged( wxPropertyGridEvent& aEvent )
} }
void SCH_PROPERTIES_PANEL::updateLists( const SCHEMATIC& aSchematic ) void SCH_PROPERTIES_PANEL::LanguageChanged()
{
updateFontList();
}
void SCH_PROPERTIES_PANEL::updateFontList()
{ {
wxPGChoices fonts; wxPGChoices fonts;

View File

@ -43,6 +43,8 @@ public:
void AfterCommit() override; void AfterCommit() override;
void LanguageChanged() override;
protected: protected:
wxPGProperty* createPGProperty( const PROPERTY_BASE* aProperty ) const override; wxPGProperty* createPGProperty( const PROPERTY_BASE* aProperty ) const override;
@ -51,8 +53,8 @@ protected:
void valueChanging( wxPropertyGridEvent& aEvent ) override; void valueChanging( wxPropertyGridEvent& aEvent ) override;
void valueChanged( wxPropertyGridEvent& aEvent ) override; void valueChanged( wxPropertyGridEvent& aEvent ) override;
///< Regenerates caches of list properties ///< Regenerates caches of font list property
void updateLists( const SCHEMATIC& aSchematic ); void updateFontList();
SCH_BASE_FRAME* m_frame; SCH_BASE_FRAME* m_frame;
PROPERTY_MANAGER& m_propMgr; PROPERTY_MANAGER& m_propMgr;