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

Fixes https://gitlab.com/kicad/code/kicad/issues/10961

(cherry picked from commit 107067ad05)
This commit is contained in:
Jeff Young 2022-02-25 17:35:51 +00:00
parent 96bd27ef0f
commit 9c2bc98fd3
6 changed files with 39 additions and 15 deletions

View File

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

View File

@ -37,7 +37,7 @@ GRID_MENU::GRID_MENU( EDA_DRAW_FRAME* aParent ) :
ACTION_MENU( true ),
m_parent( aParent )
{
SetTitle( _( "Grid" ) );
UpdateTitle();
SetIcon( BITMAPS::grid_select );
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()
{
APP_SETTINGS_BASE* settings = m_parent->config();

View File

@ -40,13 +40,8 @@ ZOOM_MENU::ZOOM_MENU( EDA_DRAW_FRAME* aParent ) :
ACTION_MENU( true ),
m_parent( aParent )
{
SetTitle( _( "Zoom" ) );
UpdateTitle();
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 );
}
@ -58,17 +53,30 @@ OPT_TOOL_EVENT ZOOM_MENU::eventHandler( const wxMenuEvent& aEvent )
}
void ZOOM_MENU::UpdateTitle()
{
SetTitle( _( "Zoom" ) );
}
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();
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:
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)
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();
/**
* Used by some menus to just-in-time translate their titles.
*/
virtual void UpdateTitle() {}
/**
* Clear the dirty flag on the menu and all descendants.
*/

View File

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

View File

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