mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
nullptr safety
This commit is contained in:
parent
70d1950bbe
commit
57f3f22aa4
@ -544,9 +544,7 @@ long NL_3D_VIEWER_PLUGIN_IMPL::SetHitSelectionOnly( bool onlySelection )
|
|||||||
long NL_3D_VIEWER_PLUGIN_IMPL::SetActiveCommand( std::string commandId )
|
long NL_3D_VIEWER_PLUGIN_IMPL::SetActiveCommand( std::string commandId )
|
||||||
{
|
{
|
||||||
if( commandId.empty() )
|
if( commandId.empty() )
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
std::list<TOOL_ACTION*> actions = ACTION_MANAGER::GetActionList();
|
std::list<TOOL_ACTION*> actions = ACTION_MANAGER::GetActionList();
|
||||||
TOOL_ACTION* context = nullptr;
|
TOOL_ACTION* context = nullptr;
|
||||||
@ -557,10 +555,8 @@ long NL_3D_VIEWER_PLUGIN_IMPL::SetActiveCommand( std::string commandId )
|
|||||||
std::string nm = action->GetName();
|
std::string nm = action->GetName();
|
||||||
|
|
||||||
if( commandId == nm )
|
if( commandId == nm )
|
||||||
{
|
|
||||||
context = action;
|
context = action;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if( context != nullptr )
|
if( context != nullptr )
|
||||||
{
|
{
|
||||||
@ -568,27 +564,21 @@ long NL_3D_VIEWER_PLUGIN_IMPL::SetActiveCommand( std::string commandId )
|
|||||||
|
|
||||||
// Only allow command execution if the window is enabled. i.e. there is not a modal dialog
|
// Only allow command execution if the window is enabled. i.e. there is not a modal dialog
|
||||||
// currently active.
|
// currently active.
|
||||||
TOOLS_HOLDER* tools_holder = nullptr;
|
if( parent && parent->IsEnabled() )
|
||||||
|
|
||||||
if( parent->IsEnabled() && ( tools_holder = dynamic_cast<TOOLS_HOLDER*>( parent ) ) )
|
|
||||||
{
|
{
|
||||||
TOOL_MANAGER* tool_manager = tools_holder->GetToolManager();
|
TOOLS_HOLDER* tools_holder = dynamic_cast<TOOLS_HOLDER*>( parent );
|
||||||
|
TOOL_MANAGER* tool_manager = tools_holder ? tools_holder->GetToolManager() : nullptr;
|
||||||
|
|
||||||
if( tool_manager == nullptr )
|
if( !tool_manager )
|
||||||
{
|
|
||||||
return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
|
return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
|
||||||
}
|
|
||||||
|
|
||||||
// Get the selection to use to test if the action is enabled
|
// Get the selection to use to test if the action is enabled
|
||||||
SELECTION& sel = tool_manager->GetToolHolder()->GetCurrentSelection();
|
SELECTION& sel = tool_manager->GetToolHolder()->GetCurrentSelection();
|
||||||
|
|
||||||
bool runAction = true;
|
bool runAction = true;
|
||||||
|
|
||||||
if( const ACTION_CONDITIONS* aCond =
|
if( const ACTION_CONDITIONS* aCond = tool_manager->GetActionManager()->GetCondition( *context ) )
|
||||||
tool_manager->GetActionManager()->GetCondition( *context ) )
|
|
||||||
{
|
|
||||||
runAction = aCond->enableCondition( sel );
|
runAction = aCond->enableCondition( sel );
|
||||||
}
|
|
||||||
|
|
||||||
if( runAction )
|
if( runAction )
|
||||||
{
|
{
|
||||||
|
@ -432,21 +432,22 @@ long NL_SCHEMATIC_PLUGIN_IMPL::SetActiveCommand( std::string commandId )
|
|||||||
|
|
||||||
// Only allow command execution if the window is enabled. i.e. there is not a modal dialog
|
// Only allow command execution if the window is enabled. i.e. there is not a modal dialog
|
||||||
// currently active.
|
// currently active.
|
||||||
|
if( parent && parent->IsEnabled() )
|
||||||
if( parent->IsEnabled() )
|
|
||||||
{
|
{
|
||||||
TOOL_MANAGER* tool_manager = static_cast<SCH_BASE_FRAME*>( parent )->GetToolManager();
|
TOOLS_HOLDER* tools_holder = dynamic_cast<TOOLS_HOLDER*>( parent );
|
||||||
|
TOOL_MANAGER* tool_manager = tools_holder ? tools_holder->GetToolManager() : nullptr;
|
||||||
|
|
||||||
|
// Only allow for command execution if the tool manager is accessible.
|
||||||
|
if( !tool_manager )
|
||||||
|
return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
|
||||||
|
|
||||||
// Get the selection to use to test if the action is enabled
|
// Get the selection to use to test if the action is enabled
|
||||||
SELECTION& sel = tool_manager->GetToolHolder()->GetCurrentSelection();
|
SELECTION& sel = tool_manager->GetToolHolder()->GetCurrentSelection();
|
||||||
|
|
||||||
bool runAction = true;
|
bool runAction = true;
|
||||||
|
|
||||||
if( const ACTION_CONDITIONS* aCond =
|
if( const ACTION_CONDITIONS* aCond = tool_manager->GetActionManager()->GetCondition( *context ) )
|
||||||
tool_manager->GetActionManager()->GetCondition( *context ) )
|
|
||||||
{
|
|
||||||
runAction = aCond->enableCondition( sel );
|
runAction = aCond->enableCondition( sel );
|
||||||
}
|
|
||||||
|
|
||||||
if( runAction )
|
if( runAction )
|
||||||
tool_manager->RunAction( *context );
|
tool_manager->RunAction( *context );
|
||||||
|
@ -432,7 +432,8 @@ long NL_GERBVIEW_PLUGIN_IMPL::SetActiveCommand( std::string commandId )
|
|||||||
if( !parent || !parent->IsEnabled() )
|
if( !parent || !parent->IsEnabled() )
|
||||||
return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
|
return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
|
||||||
|
|
||||||
TOOL_MANAGER* tool_manager = dynamic_cast<TOOLS_HOLDER*>( parent )->GetToolManager();
|
TOOLS_HOLDER* tools_holder = dynamic_cast<TOOLS_HOLDER*>( parent );
|
||||||
|
TOOL_MANAGER* tool_manager = tools_holder ? tools_holder->GetToolManager() : nullptr;
|
||||||
|
|
||||||
// Only allow for command execution if the tool manager is accessible.
|
// Only allow for command execution if the tool manager is accessible.
|
||||||
if( !tool_manager )
|
if( !tool_manager )
|
||||||
@ -448,8 +449,7 @@ long NL_GERBVIEW_PLUGIN_IMPL::SetActiveCommand( std::string commandId )
|
|||||||
// Get the selection to use to test if the action is enabled
|
// Get the selection to use to test if the action is enabled
|
||||||
const SELECTION& sel = tool_manager->GetToolHolder()->GetCurrentSelection();
|
const SELECTION& sel = tool_manager->GetToolHolder()->GetCurrentSelection();
|
||||||
|
|
||||||
const ACTION_CONDITIONS* aCond =
|
const ACTION_CONDITIONS* aCond = tool_manager->GetActionManager()->GetCondition( *action );
|
||||||
tool_manager->GetActionManager()->GetCondition( *action );
|
|
||||||
|
|
||||||
if( !aCond )
|
if( !aCond )
|
||||||
return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
|
return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
|
||||||
|
@ -436,14 +436,14 @@ long NL_PL_EDITOR_PLUGIN_IMPL::SetActiveCommand( std::string commandId )
|
|||||||
|
|
||||||
// Only allow command execution if the window is enabled. i.e. there is not a modal dialog
|
// Only allow command execution if the window is enabled. i.e. there is not a modal dialog
|
||||||
// currently active.
|
// currently active.
|
||||||
if( parent == nullptr || !parent->IsEnabled() )
|
if( !parent || !parent->IsEnabled() )
|
||||||
return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
|
return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
|
||||||
|
|
||||||
TOOLS_HOLDER* tools_holder = dynamic_cast<TOOLS_HOLDER*>( parent );
|
TOOLS_HOLDER* tools_holder = dynamic_cast<TOOLS_HOLDER*>( parent );
|
||||||
TOOL_MANAGER* tool_manager = tools_holder ? tools_holder->GetToolManager() : nullptr;
|
TOOL_MANAGER* tool_manager = tools_holder ? tools_holder->GetToolManager() : nullptr;
|
||||||
|
|
||||||
// Only allow for command execution if the tool manager is accessible.
|
// Only allow for command execution if the tool manager is accessible.
|
||||||
if( tool_manager == nullptr )
|
if( !tool_manager )
|
||||||
return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
|
return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
|
||||||
|
|
||||||
for( std::list<TOOL_ACTION*> actions = ACTION_MANAGER::GetActionList(); const auto action : actions )
|
for( std::list<TOOL_ACTION*> actions = ACTION_MANAGER::GetActionList(); const auto action : actions )
|
||||||
|
@ -417,21 +417,22 @@ long NL_PCBNEW_PLUGIN_IMPL::SetActiveCommand( std::string commandId )
|
|||||||
|
|
||||||
// Only allow command execution if the window is enabled. i.e. there is not a modal dialog
|
// Only allow command execution if the window is enabled. i.e. there is not a modal dialog
|
||||||
// currently active.
|
// currently active.
|
||||||
|
if( parent && parent->IsEnabled() )
|
||||||
if( parent->IsEnabled() )
|
|
||||||
{
|
{
|
||||||
TOOL_MANAGER* tool_manager = static_cast<PCB_BASE_FRAME*>( parent )->GetToolManager();
|
TOOLS_HOLDER* tools_holder = dynamic_cast<TOOLS_HOLDER*>( parent );
|
||||||
|
TOOL_MANAGER* tool_manager = tools_holder ? tools_holder->GetToolManager() : nullptr;
|
||||||
|
|
||||||
|
// Only allow for command execution if the tool manager is accessible.
|
||||||
|
if( !tool_manager )
|
||||||
|
return navlib::make_result_code( navlib::navlib_errc::invalid_operation );
|
||||||
|
|
||||||
// Get the selection to use to test if the action is enabled
|
// Get the selection to use to test if the action is enabled
|
||||||
SELECTION& sel = tool_manager->GetToolHolder()->GetCurrentSelection();
|
SELECTION& sel = tool_manager->GetToolHolder()->GetCurrentSelection();
|
||||||
|
|
||||||
bool runAction = true;
|
bool runAction = true;
|
||||||
|
|
||||||
if( const ACTION_CONDITIONS* aCond =
|
if( const ACTION_CONDITIONS* aCond = tool_manager->GetActionManager()->GetCondition( *context ) )
|
||||||
tool_manager->GetActionManager()->GetCondition( *context ) )
|
|
||||||
{
|
|
||||||
runAction = aCond->enableCondition( sel );
|
runAction = aCond->enableCondition( sel );
|
||||||
}
|
|
||||||
|
|
||||||
if( runAction )
|
if( runAction )
|
||||||
tool_manager->RunAction( *context );
|
tool_manager->RunAction( *context );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user