mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-13 17:53:11 +02:00
Fix crashes when settings manager doesn't exist yet.
This commit is contained in:
parent
dafc9dd05a
commit
33c73d7db4
@ -63,33 +63,43 @@ void SPNAV_VIEWER_PLUGIN::onPollTimer( wxTimerEvent& )
|
||||
|
||||
void SPNAV_VIEWER_PLUGIN::OnPan( double x, double y, double z )
|
||||
{
|
||||
const COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
|
||||
float scale = 0.0005f * ( cfg->m_SpaceMouse.pan_speed / 5.0f );
|
||||
if( cfg->m_SpaceMouse.reverse_pan_x )
|
||||
x = -x;
|
||||
if( cfg->m_SpaceMouse.reverse_pan_y )
|
||||
y = -y;
|
||||
if( cfg->m_SpaceMouse.reverse_zoom )
|
||||
z = -z;
|
||||
if( m_camera )
|
||||
if( const COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
|
||||
{
|
||||
m_camera->Pan( SFVEC3F( x * scale, -y * scale, z * scale ) );
|
||||
m_canvas->Request_refresh();
|
||||
float scale = 0.0005f * ( cfg->m_SpaceMouse.pan_speed / 5.0f );
|
||||
|
||||
if( cfg->m_SpaceMouse.reverse_pan_x )
|
||||
x = -x;
|
||||
|
||||
if( cfg->m_SpaceMouse.reverse_pan_y )
|
||||
y = -y;
|
||||
|
||||
if( cfg->m_SpaceMouse.reverse_zoom )
|
||||
z = -z;
|
||||
|
||||
if( m_camera )
|
||||
{
|
||||
m_camera->Pan( SFVEC3F( x * scale, -y * scale, z * scale ) );
|
||||
m_canvas->Request_refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SPNAV_VIEWER_PLUGIN::OnRotate( double rx, double ry, double rz )
|
||||
{
|
||||
const COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
|
||||
float scale = 0.001f * ( cfg->m_SpaceMouse.rotate_speed / 5.0f );
|
||||
if( cfg->m_SpaceMouse.reverse_rotate )
|
||||
scale = -scale;
|
||||
if( m_camera )
|
||||
if( const COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
|
||||
{
|
||||
m_camera->RotateX( ry * scale );
|
||||
m_camera->RotateY( rx * scale );
|
||||
m_camera->RotateZ( rz * scale );
|
||||
m_canvas->Request_refresh();
|
||||
float scale = 0.001f * ( cfg->m_SpaceMouse.rotate_speed / 5.0f );
|
||||
|
||||
if( cfg->m_SpaceMouse.reverse_rotate )
|
||||
scale = -scale;
|
||||
|
||||
if( m_camera )
|
||||
{
|
||||
m_camera->RotateX( ry * scale );
|
||||
m_camera->RotateY( rx * scale );
|
||||
m_camera->RotateZ( rz * scale );
|
||||
m_canvas->Request_refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -207,18 +207,15 @@ wxImage BITMAP_STORE::getImage( BITMAPS aBitmapId, int aHeight )
|
||||
|
||||
void BITMAP_STORE::ThemeChanged()
|
||||
{
|
||||
COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
|
||||
wxString oldTheme = m_theme;
|
||||
wxString oldTheme = m_theme;
|
||||
|
||||
if( settings )
|
||||
if( COMMON_SETTINGS* settings = Pgm().GetCommonSettings() )
|
||||
{
|
||||
switch( settings->m_Appearance.icon_theme )
|
||||
{
|
||||
case ICON_THEME::LIGHT: m_theme = wxT( "light" ); break;
|
||||
case ICON_THEME::DARK: m_theme = wxT( "dark" ); break;
|
||||
case ICON_THEME::AUTO:
|
||||
m_theme = KIPLATFORM::UI::IsDarkTheme() ? wxT( "dark" ) : wxT( "light" );
|
||||
break;
|
||||
case ICON_THEME::LIGHT: m_theme = wxT( "light" ); break;
|
||||
case ICON_THEME::DARK: m_theme = wxT( "dark" ); break;
|
||||
case ICON_THEME::AUTO: m_theme = KIPLATFORM::UI::IsDarkTheme() ? wxT( "dark" ) : wxT( "light" ); break;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -247,21 +247,23 @@ bool DIALOG_SHIM::Show( bool show )
|
||||
#endif
|
||||
ret = wxDialog::Show( show );
|
||||
|
||||
wxRect savedDialogRect;
|
||||
COMMON_SETTINGS* settings = Pgm().GetSettingsManager().GetCommonSettings();
|
||||
std::string key = m_hash_key.empty() ? GetTitle().ToStdString() : m_hash_key;
|
||||
wxRect savedDialogRect;
|
||||
std::string key = m_hash_key.empty() ? GetTitle().ToStdString() : m_hash_key;
|
||||
|
||||
auto dlgIt = settings->m_dialogControlValues.find( key );
|
||||
|
||||
if( dlgIt != settings->m_dialogControlValues.end() )
|
||||
if( COMMON_SETTINGS* settings = Pgm().GetCommonSettings() )
|
||||
{
|
||||
auto geoIt = dlgIt->second.find( "__geometry" );
|
||||
auto dlgIt = settings->m_dialogControlValues.find( key );
|
||||
|
||||
if( geoIt != dlgIt->second.end() && geoIt->second.is_object() )
|
||||
if( dlgIt != settings->m_dialogControlValues.end() )
|
||||
{
|
||||
const nlohmann::json& g = geoIt->second;
|
||||
savedDialogRect.SetPosition( wxPoint( g.value( "x", 0 ), g.value( "y", 0 ) ) );
|
||||
savedDialogRect.SetSize( wxSize( g.value( "w", 500 ), g.value( "h", 300 ) ) );
|
||||
auto geoIt = dlgIt->second.find( "__geometry" );
|
||||
|
||||
if( geoIt != dlgIt->second.end() && geoIt->second.is_object() )
|
||||
{
|
||||
const nlohmann::json& g = geoIt->second;
|
||||
savedDialogRect.SetPosition( wxPoint( g.value( "x", 0 ), g.value( "y", 0 ) ) );
|
||||
savedDialogRect.SetSize( wxSize( g.value( "w", 500 ), g.value( "h", 300 ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -325,15 +327,17 @@ bool DIALOG_SHIM::Show( bool show )
|
||||
|
||||
void DIALOG_SHIM::resetSize()
|
||||
{
|
||||
COMMON_SETTINGS* settings = Pgm().GetSettingsManager().GetCommonSettings();
|
||||
std::string key = m_hash_key.empty() ? GetTitle().ToStdString() : m_hash_key;
|
||||
if( COMMON_SETTINGS* settings = Pgm().GetCommonSettings() )
|
||||
{
|
||||
std::string key = m_hash_key.empty() ? GetTitle().ToStdString() : m_hash_key;
|
||||
|
||||
auto dlgIt = settings->m_dialogControlValues.find( key );
|
||||
auto dlgIt = settings->m_dialogControlValues.find( key );
|
||||
|
||||
if( dlgIt == settings->m_dialogControlValues.end() )
|
||||
return;
|
||||
if( dlgIt == settings->m_dialogControlValues.end() )
|
||||
return;
|
||||
|
||||
dlgIt->second.erase( "__geometry" );
|
||||
dlgIt->second.erase( "__geometry" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -402,9 +406,13 @@ std::string DIALOG_SHIM::generateKey( const wxWindow* aWin ) const
|
||||
|
||||
void DIALOG_SHIM::SaveControlState()
|
||||
{
|
||||
COMMON_SETTINGS* settings = Pgm().GetSettingsManager().GetCommonSettings();
|
||||
COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
|
||||
|
||||
if( !settings )
|
||||
return;
|
||||
|
||||
std::string dialogKey = m_hash_key.empty() ? GetTitle().ToStdString() : m_hash_key;
|
||||
auto& dlgMap = settings->m_dialogControlValues[ dialogKey ];
|
||||
std::map<std::string, nlohmann::json>& dlgMap = settings->m_dialogControlValues[ dialogKey ];
|
||||
|
||||
wxRect rect( GetPosition(), GetSize() );
|
||||
nlohmann::json geom;
|
||||
@ -470,7 +478,7 @@ void DIALOG_SHIM::SaveControlState()
|
||||
|
||||
void DIALOG_SHIM::LoadControlState()
|
||||
{
|
||||
COMMON_SETTINGS* settings = Pgm().GetSettingsManager().GetCommonSettings();
|
||||
COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
|
||||
|
||||
if( !settings )
|
||||
return;
|
||||
@ -481,7 +489,7 @@ void DIALOG_SHIM::LoadControlState()
|
||||
if( dlgIt == settings->m_dialogControlValues.end() )
|
||||
return;
|
||||
|
||||
const auto& dlgMap = dlgIt->second;
|
||||
const std::map<std::string, nlohmann::json>& dlgMap = dlgIt->second;
|
||||
|
||||
std::function<void( wxWindow* )> loadFn =
|
||||
[&]( wxWindow* win )
|
||||
|
@ -112,7 +112,7 @@ wxFont getGUIFont( wxWindow* aWindow, int aRelativeSize )
|
||||
|
||||
font.SetPointSize( font.GetPointSize() + aRelativeSize );
|
||||
|
||||
if( Pgm().GetCommonSettings()->m_Appearance.apply_icon_scale_to_fonts )
|
||||
if( Pgm().GetCommonSettings() && Pgm().GetCommonSettings()->m_Appearance.apply_icon_scale_to_fonts )
|
||||
font.SetPointSize( KiROUND( KiIconScale( aWindow ) * font.GetPointSize() / 4.0 ) );
|
||||
|
||||
#ifdef __WXMAC__
|
||||
@ -368,14 +368,12 @@ void KIUI::Disable( wxWindow* aWindow )
|
||||
void KIUI::AddBitmapToMenuItem( wxMenuItem* aMenu, const wxBitmapBundle& aImage )
|
||||
{
|
||||
// Retrieve the global application show icon option:
|
||||
bool useImagesInMenus = Pgm().GetCommonSettings()->m_Appearance.use_icons_in_menus;
|
||||
bool useImagesInMenus = Pgm().GetCommonSettings() && Pgm().GetCommonSettings()->m_Appearance.use_icons_in_menus;
|
||||
|
||||
wxItemKind menu_type = aMenu->GetKind();
|
||||
|
||||
if( useImagesInMenus && menu_type != wxITEM_CHECK && menu_type != wxITEM_RADIO )
|
||||
{
|
||||
aMenu->SetBitmap( aImage );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -296,7 +296,7 @@ void WX_GRID::SetTable( wxGridTableBase* aTable, bool aTakeOwnership )
|
||||
|
||||
delete[] formBuilderColWidths;
|
||||
|
||||
EnableAlternateRowColors( Pgm().GetCommonSettings()->m_Appearance.grid_striping );
|
||||
EnableAlternateRowColors( Pgm().GetCommonSettings() && Pgm().GetCommonSettings()->m_Appearance.grid_striping );
|
||||
|
||||
Connect( wxEVT_GRID_COL_MOVE, wxGridEventHandler( WX_GRID::onGridColMove ), nullptr, this );
|
||||
Connect( wxEVT_GRID_SELECT_CELL, wxGridEventHandler( WX_GRID::onGridCellSelect ), nullptr, this );
|
||||
|
@ -330,21 +330,22 @@ int SYMBOL_EDITOR_CONTROL::OpenDirectory( const TOOL_EVENT& aEvent )
|
||||
wxFileName fileName( libItemName );
|
||||
|
||||
wxString filePath = wxEmptyString;
|
||||
wxString explorerCommand;
|
||||
|
||||
COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
|
||||
if( COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
|
||||
explorerCommand = cfg->m_System.file_explorer;
|
||||
|
||||
wxString explCommand = cfg->m_System.file_explorer;
|
||||
|
||||
if( explCommand.IsEmpty() )
|
||||
if( explorerCommand.IsEmpty() )
|
||||
{
|
||||
filePath = fileName.GetFullPath().BeforeLast( wxFileName::GetPathSeparator() );
|
||||
|
||||
if( !filePath.IsEmpty() && wxDirExists( filePath ) )
|
||||
LaunchExternal( filePath );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( !explCommand.EndsWith( "%F" ) )
|
||||
if( !explorerCommand.EndsWith( "%F" ) )
|
||||
{
|
||||
wxMessageBox( _( "Missing/malformed file explorer argument '%F' in common settings." ) );
|
||||
return 0;
|
||||
@ -355,10 +356,10 @@ int SYMBOL_EDITOR_CONTROL::OpenDirectory( const TOOL_EVENT& aEvent )
|
||||
|
||||
wxString fileArg = '"' + filePath + '"';
|
||||
|
||||
explCommand.Replace( wxT( "%F" ), fileArg );
|
||||
explorerCommand.Replace( wxT( "%F" ), fileArg );
|
||||
|
||||
if( !explCommand.IsEmpty() )
|
||||
wxExecute( explCommand );
|
||||
if( !explorerCommand.IsEmpty() )
|
||||
wxExecute( explorerCommand );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -76,15 +76,11 @@ void KICAD_MANAGER_FRAME::doReCreateMenuBar()
|
||||
fileMenu->Add( KICAD_MANAGER_ACTIONS::newProject );
|
||||
fileMenu->Add( KICAD_MANAGER_ACTIONS::newFromTemplate );
|
||||
|
||||
if( Pgm().GetCommonSettings()->m_Git.enableGit )
|
||||
{
|
||||
if( Pgm().GetCommonSettings() && Pgm().GetCommonSettings()->m_Git.enableGit )
|
||||
fileMenu->Add( KICAD_MANAGER_ACTIONS::newFromRepository );
|
||||
}
|
||||
|
||||
if( wxDir::Exists( PATHS::GetStockDemosPath() ) )
|
||||
{
|
||||
fileMenu->Add( KICAD_MANAGER_ACTIONS::openDemoProject );
|
||||
}
|
||||
|
||||
fileMenu->Add( KICAD_MANAGER_ACTIONS::openProject );
|
||||
|
||||
|
@ -630,12 +630,12 @@ int FOOTPRINT_EDITOR_CONTROL::OpenDirectory( const TOOL_EVENT& aEvent )
|
||||
fileExt = FILEEXT::KiCadFootprintFileExtension;
|
||||
|
||||
wxFileName fileName( path, libItemName, fileExt );
|
||||
wxString explorerCommand;
|
||||
|
||||
COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
|
||||
if( COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
|
||||
explorerCommand = cfg->m_System.file_explorer;
|
||||
|
||||
wxString explCommand = cfg->m_System.file_explorer;
|
||||
|
||||
if( explCommand.IsEmpty() )
|
||||
if( explorerCommand.IsEmpty() )
|
||||
{
|
||||
path = fileName.GetFullPath().BeforeLast( wxFileName::GetPathSeparator() );
|
||||
|
||||
@ -645,7 +645,7 @@ int FOOTPRINT_EDITOR_CONTROL::OpenDirectory( const TOOL_EVENT& aEvent )
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( !explCommand.EndsWith( "%F" ) )
|
||||
if( !explorerCommand.EndsWith( "%F" ) )
|
||||
{
|
||||
wxMessageBox( _( "Missing/malformed file explorer argument '%F' in common settings." ) );
|
||||
return 0;
|
||||
@ -657,10 +657,10 @@ int FOOTPRINT_EDITOR_CONTROL::OpenDirectory( const TOOL_EVENT& aEvent )
|
||||
wxString fileArg = wxEmptyString;
|
||||
fileArg << '"' << escapedFilePath << '"';
|
||||
|
||||
explCommand.Replace( wxT( "%F" ), fileArg );
|
||||
explorerCommand.Replace( wxT( "%F" ), fileArg );
|
||||
|
||||
if( !explCommand.IsEmpty() )
|
||||
wxExecute( explCommand );
|
||||
if( !explorerCommand.IsEmpty() )
|
||||
wxExecute( explorerCommand );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user