Move shutdown blocker to kiplatform

This commit is contained in:
Mark Roszko 2020-09-01 10:14:51 +00:00 committed by Ian McInerney
parent 756d6a123b
commit 9f128f942c
13 changed files with 119 additions and 83 deletions

View File

@ -49,6 +49,7 @@
#include <wx/display.h> #include <wx/display.h>
#include <wx/stdpaths.h> #include <wx/stdpaths.h>
#include <wx/string.h> #include <wx/string.h>
#include <kiplatform/app.h>
#include <functional> #include <functional>
@ -186,45 +187,7 @@ EDA_BASE_FRAME::~EDA_BASE_FRAME()
ClearUndoRedoList(); ClearUndoRedoList();
if( SupportsShutdownBlockReason() ) KIPLATFORM::APP::RemoveShutdownBlockReason( this );
RemoveShutdownBlockReason();
}
bool EDA_BASE_FRAME::SupportsShutdownBlockReason()
{
#if defined( _WIN32 )
return true;
#else
return false;
#endif
}
void EDA_BASE_FRAME::RemoveShutdownBlockReason()
{
#if defined( _WIN32 )
// Windows: Destroys any block reason that may have existed
ShutdownBlockReasonDestroy( GetHandle() );
#endif
}
void EDA_BASE_FRAME::SetShutdownBlockReason( const wxString& aReason )
{
#if defined( _WIN32 )
// Windows: sets up the pretty message on the shutdown page on why it's being "blocked"
// This is used in conjunction with handling WM_QUERYENDSESSION (wxCloseEvent)
// ShutdownBlockReasonCreate does not block by itself
ShutdownBlockReasonDestroy( GetHandle() ); // Destroys any existing or nonexisting reason
if( !ShutdownBlockReasonCreate( GetHandle(), aReason.wc_str() ) )
{
// Nothing bad happens if this fails, at worst it uses a generic application is
// preventing shutdown message
}
#endif
} }

View File

@ -28,6 +28,7 @@
#include <eda_dde.h> #include <eda_dde.h>
#include <fp_lib_table.h> #include <fp_lib_table.h>
#include <kiface_i.h> #include <kiface_i.h>
#include <kiplatform/app.h>
#include <kiway_express.h> #include <kiway_express.h>
#include <macros.h> #include <macros.h>
#include <netlist_reader/netlist_reader.h> #include <netlist_reader/netlist_reader.h>
@ -167,7 +168,7 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) :
// Start the main processing loop // Start the main processing loop
m_toolManager->InvokeTool( "cvpcb.Control" ); m_toolManager->InvokeTool( "cvpcb.Control" );
SetShutdownBlockReason( _( "Symbol to footprint changes are unsaved" ) ); KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Symbol to footprint changes are unsaved" ) );
} }
@ -340,7 +341,8 @@ bool CVPCB_MAINFRAME::canCloseWindow( wxCloseEvent& aEvent )
if( m_modified ) if( m_modified )
{ {
// Shutdown blocks must be determined and vetoed as early as possible // Shutdown blocks must be determined and vetoed as early as possible
if( SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION ) if( KIPLATFORM::APP::SupportsShutdownBlockReason()
&& aEvent.GetId() == wxEVT_QUERY_END_SESSION )
{ {
return false; return false;
} }

View File

@ -333,7 +333,8 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
rfn.MakeRelativeTo( Prj().GetProjectPath() ); rfn.MakeRelativeTo( Prj().GetProjectPath() );
LoadWindowState( rfn.GetFullPath() ); LoadWindowState( rfn.GetFullPath() );
SetShutdownBlockReason( _( "Schematic file changes are unsaved" ) ); KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Schematic file changes are unsaved" ) );
if( Kiface().IsSingle() ) if( Kiface().IsSingle() )
{ {
KIPLATFORM::APP::RegisterApplicationRestart( fullFileName ); KIPLATFORM::APP::RegisterApplicationRestart( fullFileName );

View File

@ -31,6 +31,7 @@
#include <fctsys.h> #include <fctsys.h>
#include <general.h> #include <general.h>
#include <kiface_i.h> #include <kiface_i.h>
#include <kiplatform/app.h>
#include <kiway_express.h> #include <kiway_express.h>
#include <lib_edit_frame.h> #include <lib_edit_frame.h>
#include <lib_manager.h> #include <lib_manager.h>
@ -186,7 +187,7 @@ LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
m_toolManager->RunAction( ACTIONS::zoomFitScreen, true ); m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
SetShutdownBlockReason( _( "Library changes are unsaved" ) ); KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Library changes are unsaved" ) );
// Ensure the window is on top // Ensure the window is on top
Raise(); Raise();
@ -433,7 +434,7 @@ void LIB_EDIT_FRAME::setupUIConditions()
bool LIB_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent ) bool LIB_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
{ {
// Shutdown blocks must be determined and vetoed as early as possible // Shutdown blocks must be determined and vetoed as early as possible
if( SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION if( KIPLATFORM::APP::SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION
&& IsContentModified() ) && IsContentModified() )
{ {
return false; return false;

View File

@ -36,6 +36,7 @@
#include <html_messagebox.h> #include <html_messagebox.h>
#include <invoke_sch_dialog.h> #include <invoke_sch_dialog.h>
#include <kiface_i.h> #include <kiface_i.h>
#include <kiplatform/app.h>
#include <kiway.h> #include <kiway.h>
#include <lib_edit_frame.h> #include <lib_edit_frame.h>
#include <lib_view_frame.h> #include <lib_view_frame.h>
@ -291,7 +292,7 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ):
UpdateTitle(); UpdateTitle();
// Default shutdown reason until a file is loaded // Default shutdown reason until a file is loaded
SetShutdownBlockReason( _( "New schematic file is unsaved" ) ); KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New schematic file is unsaved" ) );
// Ensure the window is on top // Ensure the window is on top
Raise(); Raise();
@ -573,7 +574,7 @@ void SCH_EDIT_FRAME::HardRedraw()
bool SCH_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent ) bool SCH_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
{ {
// Shutdown blocks must be determined and vetoed as early as possible // Shutdown blocks must be determined and vetoed as early as possible
if( SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION if( KIPLATFORM::APP::SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION
&& Schematic().GetSheets().IsModified() ) && Schematic().GetSheets().IsModified() )
{ {
return false; return false;

View File

@ -564,24 +564,6 @@ public:
const wxString& GetAboutTitle() const { return m_AboutTitle; } const wxString& GetAboutTitle() const { return m_AboutTitle; }
/**
* Sets the block reason why the window/application is preventing OS shutdown.
* This should be set far ahead of any close event.
*
* This is mainly intended for Windows platforms where this is a native feature.
*/
void SetShutdownBlockReason( const wxString& reason );
/**
* Removes any shutdown block reason set
*/
void RemoveShutdownBlockReason();
/**
* Whether or not the window supports setting a shutdown block reason
*/
bool SupportsShutdownBlockReason();
/** /**
* Get if the contents of the frame have been modified since the last save. * Get if the contents of the frame have been modified since the last save.
* *

View File

@ -35,3 +35,19 @@ bool KIPLATFORM::APP::UnregisterApplicationRestart()
// Not implemented on this platform // Not implemented on this platform
return true; return true;
} }
bool KIPLATFORM::APP::SupportsShutdownBlockReason()
{
return false;
}
void KIPLATFORM::APP::RemoveShutdownBlockReason( wxWindow* aWindow )
{
}
void KIPLATFORM::APP::SetShutdownBlockReason( wxWindow* aWindow, const wxString& aReason )
{
}

View File

@ -22,6 +22,7 @@
#define KIPLATFORM_APP_H_ #define KIPLATFORM_APP_H_
class wxString; class wxString;
class wxWindow;
namespace KIPLATFORM namespace KIPLATFORM
{ {
@ -40,6 +41,29 @@ namespace KIPLATFORM
* Depending on OS, this may not be required * Depending on OS, this may not be required
*/ */
bool UnregisterApplicationRestart(); bool UnregisterApplicationRestart();
/**
* Whether or not the window supports setting a shutdown block reason
*/
bool SupportsShutdownBlockReason();
/**
* Sets the block reason why the window/application is preventing OS shutdown.
* This should be set far ahead of any close event.
*
* This is mainly intended for Windows platforms where this is a native feature.
*
* @param aWindow that will have a shutdown blocker message
* @param aReason to display why the shutdown block is occuring
*/
void SetShutdownBlockReason( wxWindow* aWindow, const wxString& aReason );
/**
* Removes any shutdown block reason set
*
* @param aWindow that has a shutdown block reason set
*/
void RemoveShutdownBlockReason( wxWindow* aWindow );
} }
} }

View File

@ -20,7 +20,9 @@
#include <kiplatform/app.h> #include <kiplatform/app.h>
#include <wx/log.h>
#include <wx/string.h> #include <wx/string.h>
#include <wx/window.h>
#include <windows.h> #include <windows.h>
#include <strsafe.h> #include <strsafe.h>
@ -45,3 +47,28 @@ bool KIPLATFORM::APP::UnregisterApplicationRestart()
// Note, this isn't required to be used on Windows if you are just closing the program // Note, this isn't required to be used on Windows if you are just closing the program
return SUCCEEDED( ::UnregisterApplicationRestart() ); return SUCCEEDED( ::UnregisterApplicationRestart() );
} }
bool KIPLATFORM::APP::SupportsShutdownBlockReason()
{
return true;
}
void KIPLATFORM::APP::RemoveShutdownBlockReason( wxWindow* aWindow )
{
// Destroys any block reason that may have existed
ShutdownBlockReasonDestroy( aWindow->GetHandle() );
}
void KIPLATFORM::APP::SetShutdownBlockReason( wxWindow* aWindow, const wxString& aReason )
{
// Sets up the pretty message on the shutdown page on why it's being "blocked"
// This is used in conjunction with handling WM_QUERYENDSESSION (wxCloseEvent)
// ShutdownBlockReasonCreate does not block by itself
ShutdownBlockReasonDestroy( aWindow->GetHandle() ); // Destroys any existing or nonexisting reason
ShutdownBlockReasonCreate( aWindow->GetHandle(), aReason.wc_str() );
}

View File

@ -35,3 +35,19 @@ bool KIPLATFORM::APP::UnregisterApplicationRestart()
// Not implemented on this platform // Not implemented on this platform
return true; return true;
} }
bool KIPLATFORM::APP::SupportsShutdownBlockReason()
{
return false;
}
void KIPLATFORM::APP::RemoveShutdownBlockReason( wxWindow* aWindow )
{
}
void KIPLATFORM::APP::SetShutdownBlockReason( wxWindow* aWindow, const wxString& aReason )
{
}

View File

@ -41,6 +41,7 @@
#include <panel_hotkeys_editor.h> #include <panel_hotkeys_editor.h>
#include <view/view.h> #include <view/view.h>
#include <confirm.h> #include <confirm.h>
#include <kiplatform/app.h>
#include <tool/selection.h> #include <tool/selection.h>
#include <tool/action_toolbar.h> #include <tool/action_toolbar.h>
#include <tool/editor_conditions.h> #include <tool/editor_conditions.h>
@ -326,7 +327,7 @@ void PL_EDITOR_FRAME::OnExit( wxCommandEvent& aEvent )
bool PL_EDITOR_FRAME::canCloseWindow( wxCloseEvent& aEvent ) bool PL_EDITOR_FRAME::canCloseWindow( wxCloseEvent& aEvent )
{ {
// Shutdown blocks must be determined and vetoed as early as possible // Shutdown blocks must be determined and vetoed as early as possible
if( SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION if( KIPLATFORM::APP::SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION
&& IsContentModified() ) && IsContentModified() )
{ {
return false; return false;
@ -882,11 +883,11 @@ void PL_EDITOR_FRAME::OnNewPageLayout()
if( GetCurrentFileName().IsEmpty() ) if( GetCurrentFileName().IsEmpty() )
{ {
// Default shutdown reason until a file is loaded // Default shutdown reason until a file is loaded
SetShutdownBlockReason( _( "New page layout file is unsaved" ) ); KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New page layout file is unsaved" ) );
} }
else else
{ {
SetShutdownBlockReason( _( "Page layout changes are unsaved" ) ); KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Page layout changes are unsaved" ) );
} }
} }

View File

@ -48,6 +48,7 @@
#include <fp_lib_table.h> #include <fp_lib_table.h>
#include <kicad_plugin.h> #include <kicad_plugin.h>
#include <kiface_i.h> #include <kiface_i.h>
#include <kiplatform/app.h>
#include <kiway.h> #include <kiway.h>
#include <panel_hotkeys_editor.h> #include <panel_hotkeys_editor.h>
#include <pcb_draw_panel_gal.h> #include <pcb_draw_panel_gal.h>
@ -246,7 +247,7 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent,
InitExitKey(); InitExitKey();
// Default shutdown reason until a file is loaded // Default shutdown reason until a file is loaded
SetShutdownBlockReason( _( "Footprint changes are unsaved" ) ); KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Footprint changes are unsaved" ) );
// Ensure the window is on top // Ensure the window is on top
Raise(); Raise();
@ -540,7 +541,7 @@ bool FOOTPRINT_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
if( IsContentModified() ) if( IsContentModified() )
{ {
// Shutdown blocks must be determined and vetoed as early as possible // Shutdown blocks must be determined and vetoed as early as possible
if( SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION ) if( KIPLATFORM::APP::SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION )
{ {
aEvent.Veto(); aEvent.Veto();
return false; return false;

View File

@ -92,6 +92,7 @@
#include <ratsnest/ratsnest_viewitem.h> #include <ratsnest/ratsnest_viewitem.h>
#include <widgets/appearance_controls.h> #include <widgets/appearance_controls.h>
#include <widgets/panel_selection_filter.h> #include <widgets/panel_selection_filter.h>
#include <kiplatform/app.h>
#include <widgets/infobar.h> #include <widgets/infobar.h>
@ -360,7 +361,7 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
ActivateGalCanvas(); ActivateGalCanvas();
// Default shutdown reason until a file is loaded // Default shutdown reason until a file is loaded
SetShutdownBlockReason( _( "New PCB file is unsaved" ) ); KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New PCB file is unsaved" ) );
// disable Export STEP item if kicad2step does not exist // disable Export STEP item if kicad2step does not exist
wxString strK2S = Pgm().GetExecutablePath(); wxString strK2S = Pgm().GetExecutablePath();
@ -796,7 +797,7 @@ void PCB_EDIT_FRAME::ResolveDRCExclusions()
bool PCB_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent ) bool PCB_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
{ {
// Shutdown blocks must be determined and vetoed as early as possible // Shutdown blocks must be determined and vetoed as early as possible
if( SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION if( KIPLATFORM::APP::SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION
&& IsContentModified() ) && IsContentModified() )
{ {
return false; return false;
@ -1045,7 +1046,7 @@ void PCB_EDIT_FRAME::onBoardLoaded()
m_toolManager->GetTool<DRC>()->LoadRules(); m_toolManager->GetTool<DRC>()->LoadRules();
SetShutdownBlockReason( _( "PCB file changes are unsaved" ) ); KIPLATFORM::APP::SetShutdownBlockReason( this, _( "PCB file changes are unsaved" ) );
} }