On-the-fly translations for Grid and Zoom menus.

Fixes https://gitlab.com/kicad/code/kicad/issues/10961
This commit is contained in:
Jeff Young 2022-02-25 17:35:51 +00:00
parent 6d8507d44f
commit 107067ad05
6 changed files with 39 additions and 15 deletions

View File

@ -146,20 +146,21 @@ void CONDITIONAL_MENU::Evaluate( SELECTION& aSelection )
switch( entry.Type() ) switch( entry.Type() )
{ {
case ENTRY::ACTION: case ENTRY::ACTION:
menuItem = Add( *entry.Action(), entry.IsCheckmarkEntry() ); Add( *entry.Action(), entry.IsCheckmarkEntry() );
menu_count++; menu_count++;
break; break;
case ENTRY::MENU: case ENTRY::MENU:
menuItem = Add( entry.Menu() ); entry.Menu()->UpdateTitle();
Add( entry.Menu() );
menu_count++; menu_count++;
break; break;
case ENTRY::WXITEM: case ENTRY::WXITEM:
menuItem = new wxMenuItem( this, menuItem = new wxMenuItem( this,
entry.wxItem()->GetId(), entry.wxItem()->GetId(),
entry.wxItem()->GetItemLabel(), wxGetTranslation( entry.wxItem()->GetItemLabel() ),
entry.wxItem()->GetHelp(), wxGetTranslation( entry.wxItem()->GetHelp() ),
entry.wxItem()->GetKind() ); entry.wxItem()->GetKind() );
if( !!entry.GetIcon() ) if( !!entry.GetIcon() )
@ -173,7 +174,7 @@ void CONDITIONAL_MENU::Evaluate( SELECTION& aSelection )
case ENTRY::SEPARATOR: case ENTRY::SEPARATOR:
if( menu_count ) if( menu_count )
menuItem = AppendSeparator(); AppendSeparator();
menu_count = 0; menu_count = 0;
break; break;

View File

@ -37,7 +37,7 @@ GRID_MENU::GRID_MENU( EDA_DRAW_FRAME* aParent ) :
ACTION_MENU( true ), ACTION_MENU( true ),
m_parent( aParent ) m_parent( aParent )
{ {
SetTitle( _( "Grid" ) ); UpdateTitle();
SetIcon( BITMAPS::grid_select ); SetIcon( BITMAPS::grid_select );
APP_SETTINGS_BASE* settings = m_parent->config(); APP_SETTINGS_BASE* settings = m_parent->config();
@ -59,6 +59,12 @@ OPT_TOOL_EVENT GRID_MENU::eventHandler( const wxMenuEvent& aEvent )
} }
void GRID_MENU::UpdateTitle()
{
SetTitle( _( "Grid" ) );
}
void GRID_MENU::update() void GRID_MENU::update()
{ {
APP_SETTINGS_BASE* settings = m_parent->config(); APP_SETTINGS_BASE* settings = m_parent->config();

View File

@ -38,13 +38,8 @@ ZOOM_MENU::ZOOM_MENU( EDA_DRAW_FRAME* aParent ) :
ACTION_MENU( true ), ACTION_MENU( true ),
m_parent( aParent ) m_parent( aParent )
{ {
SetTitle( _( "Zoom" ) ); UpdateTitle();
SetIcon( BITMAPS::zoom_selection ); SetIcon( BITMAPS::zoom_selection );
int i = ID_POPUP_ZOOM_LEVEL_START + 1; // 0 reserved for menus which support auto-zoom
for( double factor : m_parent->config()->m_Window.zoom_factors )
Append( i++, wxString::Format( _( "Zoom: %.2f" ), factor ), wxEmptyString, wxITEM_CHECK );
} }
@ -56,17 +51,30 @@ OPT_TOOL_EVENT ZOOM_MENU::eventHandler( const wxMenuEvent& aEvent )
} }
void ZOOM_MENU::UpdateTitle()
{
SetTitle( _( "Zoom" ) );
}
void ZOOM_MENU::update() void ZOOM_MENU::update()
{ {
Clear();
int ii = ID_POPUP_ZOOM_LEVEL_START + 1; // 0 reserved for menus which support auto-zoom
for( double factor : m_parent->config()->m_Window.zoom_factors )
Append( ii++, wxString::Format( _( "Zoom: %.2f" ), factor ), wxEmptyString, wxITEM_CHECK );
double zoom = m_parent->GetCanvas()->GetGAL()->GetZoomFactor(); double zoom = m_parent->GetCanvas()->GetGAL()->GetZoomFactor();
const std::vector<double>& zoomList = m_parent->config()->m_Window.zoom_factors; const std::vector<double>& zoomList = m_parent->config()->m_Window.zoom_factors;
for( size_t i = 0; i < zoomList.size(); ++i ) for( size_t jj = 0; jj < zoomList.size(); ++jj )
{ {
// Search for a value near the current zoom setting: // Search for a value near the current zoom setting:
double rel_error = std::fabs( zoomList[i] - zoom ) / zoom; double rel_error = std::fabs( zoomList[jj] - zoom ) / zoom;
// IDs start with 1 (leaving 0 for auto-zoom) // IDs start with 1 (leaving 0 for auto-zoom)
Check( ID_POPUP_ZOOM_LEVEL_START + i + 1, rel_error < 0.1 ); Check( ID_POPUP_ZOOM_LEVEL_START + jj + 1, rel_error < 0.1 );
} }
} }

View File

@ -156,6 +156,11 @@ public:
*/ */
void UpdateAll(); void UpdateAll();
/**
* Used by some menus to just-in-time translate their titles.
*/
virtual void UpdateTitle() {}
/** /**
* Clear the dirty flag on the menu and all descendants. * Clear the dirty flag on the menu and all descendants.
*/ */

View File

@ -35,6 +35,8 @@ class GRID_MENU : public ACTION_MENU
public: public:
GRID_MENU( EDA_DRAW_FRAME* aParent ); GRID_MENU( EDA_DRAW_FRAME* aParent );
void UpdateTitle() override;
static void BuildChoiceList( wxArrayString* aGridsList, APP_SETTINGS_BASE* aCfg, static void BuildChoiceList( wxArrayString* aGridsList, APP_SETTINGS_BASE* aCfg,
EDA_DRAW_FRAME* aParent ); EDA_DRAW_FRAME* aParent );

View File

@ -34,6 +34,8 @@ class ZOOM_MENU : public ACTION_MENU
public: public:
ZOOM_MENU( EDA_DRAW_FRAME* aParent ); ZOOM_MENU( EDA_DRAW_FRAME* aParent );
void UpdateTitle() override;
private: private:
ACTION_MENU* create() const override ACTION_MENU* create() const override
{ {