Get translation for 3d viewer appearance manager tooltips later

The translation database isn't setup during static variable
initialization, so we can't do translations until just before the
strings are used.
This commit is contained in:
Ian McInerney 2023-08-23 23:48:35 +01:00
parent f62775de40
commit 72daeddca3
2 changed files with 63 additions and 47 deletions

View File

@ -399,9 +399,9 @@ void APPEARANCE_CONTROLS_3D::rebuildLayers()
[&]( const std::unique_ptr<APPEARANCE_SETTING_3D>& aSetting ) [&]( const std::unique_ptr<APPEARANCE_SETTING_3D>& aSetting )
{ {
wxBoxSizer* sizer = new wxBoxSizer( wxHORIZONTAL ); wxBoxSizer* sizer = new wxBoxSizer( wxHORIZONTAL );
int layer = aSetting->id; int layer = aSetting->m_Id;
aSetting->visible = visibleLayers.test( layer ); aSetting->m_Visible = visibleLayers.test( layer );
if( colors.count( layer ) ) if( colors.count( layer ) )
{ {
@ -411,7 +411,7 @@ void APPEARANCE_CONTROLS_3D::rebuildLayers()
swatch->SetToolTip( _( "Left double click or middle click to change color" ) ); swatch->SetToolTip( _( "Left double click or middle click to change color" ) );
sizer->Add( swatch, 0, wxALIGN_CENTER_VERTICAL, 0 ); sizer->Add( swatch, 0, wxALIGN_CENTER_VERTICAL, 0 );
aSetting->ctl_color = swatch; aSetting->m_Ctl_color = swatch;
swatch->Bind( COLOR_SWATCH_CHANGED, swatch->Bind( COLOR_SWATCH_CHANGED,
[this]( wxCommandEvent& event ) [this]( wxCommandEvent& event )
@ -429,9 +429,9 @@ void APPEARANCE_CONTROLS_3D::rebuildLayers()
sizer->AddSpacer( 5 ); sizer->AddSpacer( 5 );
wxStaticText* label = new wxStaticText( m_windowLayers, layer, aSetting->label ); wxStaticText* label = new wxStaticText( m_windowLayers, layer, aSetting->GetLabel() );
label->Wrap( -1 ); label->Wrap( -1 );
label->SetToolTip( aSetting->tooltip ); label->SetToolTip( aSetting->GetTooltip() );
if( layer == LAYER_3D_BACKGROUND_TOP || layer == LAYER_3D_BACKGROUND_BOTTOM ) if( layer == LAYER_3D_BACKGROUND_TOP || layer == LAYER_3D_BACKGROUND_BOTTOM )
{ {
@ -442,7 +442,7 @@ void APPEARANCE_CONTROLS_3D::rebuildLayers()
BITMAP_TOGGLE* btn_visible = new BITMAP_TOGGLE( m_windowLayers, layer, BITMAP_TOGGLE* btn_visible = new BITMAP_TOGGLE( m_windowLayers, layer,
KiBitmap( BITMAPS::visibility ), KiBitmap( BITMAPS::visibility ),
KiBitmap( BITMAPS::visibility_off ), KiBitmap( BITMAPS::visibility_off ),
aSetting->visible ); aSetting->m_Visible );
btn_visible->Bind( TOGGLE_CHANGED, btn_visible->Bind( TOGGLE_CHANGED,
[this]( wxCommandEvent& aEvent ) [this]( wxCommandEvent& aEvent )
@ -455,10 +455,10 @@ void APPEARANCE_CONTROLS_3D::rebuildLayers()
} ); } );
wxString tip; wxString tip;
tip.Printf( _( "Show or hide %s" ), aSetting->label.Lower() ); tip.Printf( _( "Show or hide %s" ), aSetting->GetLabel().Lower() );
btn_visible->SetToolTip( tip ); btn_visible->SetToolTip( tip );
aSetting->ctl_visibility = btn_visible; aSetting->m_Ctl_visibility = btn_visible;
sizer->Add( btn_visible, 0, wxALIGN_CENTER_VERTICAL, 0 ); sizer->Add( btn_visible, 0, wxALIGN_CENTER_VERTICAL, 0 );
} }
@ -474,17 +474,12 @@ void APPEARANCE_CONTROLS_3D::rebuildLayers()
m_layerSettings.emplace_back( std::make_unique<APPEARANCE_SETTING_3D>( s_setting ) ); m_layerSettings.emplace_back( std::make_unique<APPEARANCE_SETTING_3D>( s_setting ) );
std::unique_ptr<APPEARANCE_SETTING_3D>& setting = m_layerSettings.back(); std::unique_ptr<APPEARANCE_SETTING_3D>& setting = m_layerSettings.back();
// Because s_render_rows is created static, we must explicitly call wxGetTranslation if( setting->m_Spacer )
// for texts which are internationalized (tool tips and item names)
setting->tooltip = wxGetTranslation( s_setting.tooltip );
setting->label = wxGetTranslation( s_setting.label );
if( setting->spacer )
m_layersOuterSizer->AddSpacer( m_pointSize ); m_layersOuterSizer->AddSpacer( m_pointSize );
else else
appendLayer( setting ); appendLayer( setting );
m_layerSettingsMap[setting->id] = setting.get(); m_layerSettingsMap[setting->m_Id] = setting.get();
} }
m_sizerOuter->Layout(); m_sizerOuter->Layout();
@ -498,14 +493,14 @@ void APPEARANCE_CONTROLS_3D::UpdateLayerCtls()
for( std::unique_ptr<APPEARANCE_SETTING_3D>& setting : m_layerSettings ) for( std::unique_ptr<APPEARANCE_SETTING_3D>& setting : m_layerSettings )
{ {
if( setting->spacer ) if( setting->m_Spacer )
continue; continue;
if( setting->ctl_visibility ) if( setting->m_Ctl_visibility )
setting->ctl_visibility->SetValue( visibleLayers.test( setting->id ) ); setting->m_Ctl_visibility->SetValue( visibleLayers.test( setting->m_Id ) );
if( setting->ctl_color ) if( setting->m_Ctl_color )
setting->ctl_color->SetSwatchColor( colors[ setting->id ], false ); setting->m_Ctl_color->SetSwatchColor( colors[ setting->m_Id ], false );
} }
} }

View File

@ -28,6 +28,7 @@
#include <3d_canvas/board_adapter.h> #include <3d_canvas/board_adapter.h>
#include <dialogs/appearance_controls_3D_base.h> #include <dialogs/appearance_controls_3D_base.h>
#include <tool/tool_action.h> #include <tool/tool_action.h>
#include <wx/intl.h>
class BITMAP_TOGGLE; class BITMAP_TOGGLE;
@ -46,47 +47,67 @@ public:
/** /**
* Container for an appearance setting (can control a layer class, object type, etc.) * Container for an appearance setting (can control a layer class, object type, etc.)
*/ */
struct APPEARANCE_SETTING_3D class APPEARANCE_SETTING_3D
{ {
int id; public:
wxString label; int m_Id;
wxString tooltip; bool m_Visible;
bool visible; bool m_Spacer;
bool spacer;
BITMAP_TOGGLE* ctl_visibility; BITMAP_TOGGLE* m_Ctl_visibility;
COLOR_SWATCH* ctl_color; COLOR_SWATCH* m_Ctl_color;
APPEARANCE_SETTING_3D( const wxString& aLabel, int aId, const wxString& aTooltip ) : APPEARANCE_SETTING_3D( const wxString& aLabel, int aId, const wxString& aTooltip ) :
id( aId ), m_Id( aId ),
label( aLabel ), m_Visible( true ),
tooltip( aTooltip ), m_Spacer( false ),
visible( true ), m_Ctl_visibility( nullptr ),
spacer( false ), m_Ctl_color( nullptr ),
ctl_visibility( nullptr ), m_tooltip( aTooltip ),
ctl_color( nullptr ) m_label( aLabel )
{ {
} }
APPEARANCE_SETTING_3D( const wxString& aLabel, int aId, const TOOL_ACTION& aAction ) : APPEARANCE_SETTING_3D( const wxString& aLabel, int aId, const TOOL_ACTION& aAction ) :
id( aId ), m_Id( aId ),
label( aLabel ), m_Visible( true ),
tooltip( aAction.GetTooltip( true ) ), m_Spacer( false ),
visible( true ), m_Ctl_visibility( nullptr ),
spacer( false ), m_Ctl_color( nullptr ),
ctl_visibility( nullptr ), m_label( aLabel ),
ctl_color( nullptr ) m_action( &aAction )
{ {
} }
APPEARANCE_SETTING_3D() : APPEARANCE_SETTING_3D() :
id( -1 ), m_Id( -1 ),
visible( false ), m_Visible( false ),
spacer( true ), m_Spacer( true ),
ctl_visibility( nullptr ), m_Ctl_visibility( nullptr ),
ctl_color( nullptr ) m_Ctl_color( nullptr )
{ {
} }
wxString GetTooltip() const
{
if( m_tooltip.has_value() )
return wxGetTranslation( m_tooltip.value() );
else if( m_action.has_value() )
return m_action.value()->GetTooltip( true );
else
return wxEmptyString;
}
wxString GetLabel() const
{
return wxGetTranslation( m_label );
}
private:
wxString m_label;
std::optional<wxString> m_tooltip;
std::optional<const TOOL_ACTION*> m_action;
}; };
APPEARANCE_CONTROLS_3D( EDA_3D_VIEWER_FRAME* aParent, wxWindow* aFocusOwner ); APPEARANCE_CONTROLS_3D( EDA_3D_VIEWER_FRAME* aParent, wxWindow* aFocusOwner );