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