From 107067ad05e029b9dbf7ed21853026e59980a4f4 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 25 Feb 2022 17:35:51 +0000 Subject: [PATCH] On-the-fly translations for Grid and Zoom menus. Fixes https://gitlab.com/kicad/code/kicad/issues/10961 --- common/tool/conditional_menu.cpp | 11 ++++++----- common/tool/grid_menu.cpp | 8 +++++++- common/tool/zoom_menu.cpp | 26 +++++++++++++++++--------- include/tool/action_menu.h | 5 +++++ include/tool/grid_menu.h | 2 ++ include/tool/zoom_menu.h | 2 ++ 6 files changed, 39 insertions(+), 15 deletions(-) diff --git a/common/tool/conditional_menu.cpp b/common/tool/conditional_menu.cpp index bf15173658..70699217fe 100644 --- a/common/tool/conditional_menu.cpp +++ b/common/tool/conditional_menu.cpp @@ -146,20 +146,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() ) @@ -173,7 +174,7 @@ void CONDITIONAL_MENU::Evaluate( SELECTION& aSelection ) case ENTRY::SEPARATOR: if( menu_count ) - menuItem = AppendSeparator(); + AppendSeparator(); menu_count = 0; break; diff --git a/common/tool/grid_menu.cpp b/common/tool/grid_menu.cpp index 6d0549103b..ee55fc3600 100644 --- a/common/tool/grid_menu.cpp +++ b/common/tool/grid_menu.cpp @@ -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(); diff --git a/common/tool/zoom_menu.cpp b/common/tool/zoom_menu.cpp index d67ffce45b..12380e001f 100644 --- a/common/tool/zoom_menu.cpp +++ b/common/tool/zoom_menu.cpp @@ -38,13 +38,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 ); } @@ -56,17 +51,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& 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 ); } } diff --git a/include/tool/action_menu.h b/include/tool/action_menu.h index efe428e69f..8b281ebb03 100644 --- a/include/tool/action_menu.h +++ b/include/tool/action_menu.h @@ -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. */ diff --git a/include/tool/grid_menu.h b/include/tool/grid_menu.h index b60cdad902..2438d5b019 100644 --- a/include/tool/grid_menu.h +++ b/include/tool/grid_menu.h @@ -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 ); diff --git a/include/tool/zoom_menu.h b/include/tool/zoom_menu.h index bc807895fe..4d033e78e1 100644 --- a/include/tool/zoom_menu.h +++ b/include/tool/zoom_menu.h @@ -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 {