Move shutdown blocker to kiplatform
This commit is contained in:
parent
756d6a123b
commit
9f128f942c
|
@ -49,6 +49,7 @@
|
|||
#include <wx/display.h>
|
||||
#include <wx/stdpaths.h>
|
||||
#include <wx/string.h>
|
||||
#include <kiplatform/app.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
|
@ -186,45 +187,7 @@ EDA_BASE_FRAME::~EDA_BASE_FRAME()
|
|||
|
||||
ClearUndoRedoList();
|
||||
|
||||
if( SupportsShutdownBlockReason() )
|
||||
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
|
||||
KIPLATFORM::APP::RemoveShutdownBlockReason( this );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <eda_dde.h>
|
||||
#include <fp_lib_table.h>
|
||||
#include <kiface_i.h>
|
||||
#include <kiplatform/app.h>
|
||||
#include <kiway_express.h>
|
||||
#include <macros.h>
|
||||
#include <netlist_reader/netlist_reader.h>
|
||||
|
@ -167,7 +168,7 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) :
|
|||
// Start the main processing loop
|
||||
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 )
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
|
|
|
@ -333,7 +333,8 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
|
|||
rfn.MakeRelativeTo( Prj().GetProjectPath() );
|
||||
LoadWindowState( rfn.GetFullPath() );
|
||||
|
||||
SetShutdownBlockReason( _( "Schematic file changes are unsaved" ) );
|
||||
KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Schematic file changes are unsaved" ) );
|
||||
|
||||
if( Kiface().IsSingle() )
|
||||
{
|
||||
KIPLATFORM::APP::RegisterApplicationRestart( fullFileName );
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <fctsys.h>
|
||||
#include <general.h>
|
||||
#include <kiface_i.h>
|
||||
#include <kiplatform/app.h>
|
||||
#include <kiway_express.h>
|
||||
#include <lib_edit_frame.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 );
|
||||
|
||||
SetShutdownBlockReason( _( "Library changes are unsaved" ) );
|
||||
KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Library changes are unsaved" ) );
|
||||
|
||||
// Ensure the window is on top
|
||||
Raise();
|
||||
|
@ -433,7 +434,7 @@ void LIB_EDIT_FRAME::setupUIConditions()
|
|||
bool LIB_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
|
||||
{
|
||||
// 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() )
|
||||
{
|
||||
return false;
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include <html_messagebox.h>
|
||||
#include <invoke_sch_dialog.h>
|
||||
#include <kiface_i.h>
|
||||
#include <kiplatform/app.h>
|
||||
#include <kiway.h>
|
||||
#include <lib_edit_frame.h>
|
||||
#include <lib_view_frame.h>
|
||||
|
@ -291,7 +292,7 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ):
|
|||
UpdateTitle();
|
||||
|
||||
// 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
|
||||
Raise();
|
||||
|
@ -573,7 +574,7 @@ void SCH_EDIT_FRAME::HardRedraw()
|
|||
bool SCH_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
|
||||
{
|
||||
// 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() )
|
||||
{
|
||||
return false;
|
||||
|
|
|
@ -564,24 +564,6 @@ public:
|
|||
|
||||
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.
|
||||
*
|
||||
|
|
|
@ -35,3 +35,19 @@ bool KIPLATFORM::APP::UnregisterApplicationRestart()
|
|||
// Not implemented on this platform
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool KIPLATFORM::APP::SupportsShutdownBlockReason()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void KIPLATFORM::APP::RemoveShutdownBlockReason( wxWindow* aWindow )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void KIPLATFORM::APP::SetShutdownBlockReason( wxWindow* aWindow, const wxString& aReason )
|
||||
{
|
||||
}
|
|
@ -22,6 +22,7 @@
|
|||
#define KIPLATFORM_APP_H_
|
||||
|
||||
class wxString;
|
||||
class wxWindow;
|
||||
|
||||
namespace KIPLATFORM
|
||||
{
|
||||
|
@ -40,6 +41,29 @@ namespace KIPLATFORM
|
|||
* Depending on OS, this may not be required
|
||||
*/
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,9 @@
|
|||
|
||||
#include <kiplatform/app.h>
|
||||
|
||||
#include <wx/log.h>
|
||||
#include <wx/string.h>
|
||||
#include <wx/window.h>
|
||||
|
||||
#include <windows.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
|
||||
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() );
|
||||
}
|
|
@ -35,3 +35,19 @@ bool KIPLATFORM::APP::UnregisterApplicationRestart()
|
|||
// Not implemented on this platform
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool KIPLATFORM::APP::SupportsShutdownBlockReason()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void KIPLATFORM::APP::RemoveShutdownBlockReason( wxWindow* aWindow )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void KIPLATFORM::APP::SetShutdownBlockReason( wxWindow* aWindow, const wxString& aReason )
|
||||
{
|
||||
}
|
|
@ -41,6 +41,7 @@
|
|||
#include <panel_hotkeys_editor.h>
|
||||
#include <view/view.h>
|
||||
#include <confirm.h>
|
||||
#include <kiplatform/app.h>
|
||||
#include <tool/selection.h>
|
||||
#include <tool/action_toolbar.h>
|
||||
#include <tool/editor_conditions.h>
|
||||
|
@ -326,7 +327,7 @@ void PL_EDITOR_FRAME::OnExit( wxCommandEvent& aEvent )
|
|||
bool PL_EDITOR_FRAME::canCloseWindow( wxCloseEvent& aEvent )
|
||||
{
|
||||
// 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() )
|
||||
{
|
||||
return false;
|
||||
|
@ -882,11 +883,11 @@ void PL_EDITOR_FRAME::OnNewPageLayout()
|
|||
if( GetCurrentFileName().IsEmpty() )
|
||||
{
|
||||
// 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
|
||||
{
|
||||
SetShutdownBlockReason( _( "Page layout changes are unsaved" ) );
|
||||
KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Page layout changes are unsaved" ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
#include <fp_lib_table.h>
|
||||
#include <kicad_plugin.h>
|
||||
#include <kiface_i.h>
|
||||
#include <kiplatform/app.h>
|
||||
#include <kiway.h>
|
||||
#include <panel_hotkeys_editor.h>
|
||||
#include <pcb_draw_panel_gal.h>
|
||||
|
@ -246,7 +247,7 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent,
|
|||
InitExitKey();
|
||||
|
||||
// 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
|
||||
Raise();
|
||||
|
@ -540,7 +541,7 @@ bool FOOTPRINT_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
|
|||
if( IsContentModified() )
|
||||
{
|
||||
// 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();
|
||||
return false;
|
||||
|
|
|
@ -92,6 +92,7 @@
|
|||
#include <ratsnest/ratsnest_viewitem.h>
|
||||
#include <widgets/appearance_controls.h>
|
||||
#include <widgets/panel_selection_filter.h>
|
||||
#include <kiplatform/app.h>
|
||||
|
||||
|
||||
#include <widgets/infobar.h>
|
||||
|
@ -360,7 +361,7 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
|
|||
ActivateGalCanvas();
|
||||
|
||||
// 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
|
||||
wxString strK2S = Pgm().GetExecutablePath();
|
||||
|
@ -796,7 +797,7 @@ void PCB_EDIT_FRAME::ResolveDRCExclusions()
|
|||
bool PCB_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
|
||||
{
|
||||
// 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() )
|
||||
{
|
||||
return false;
|
||||
|
@ -1045,7 +1046,7 @@ void PCB_EDIT_FRAME::onBoardLoaded()
|
|||
|
||||
m_toolManager->GetTool<DRC>()->LoadRules();
|
||||
|
||||
SetShutdownBlockReason( _( "PCB file changes are unsaved" ) );
|
||||
KIPLATFORM::APP::SetShutdownBlockReason( this, _( "PCB file changes are unsaved" ) );
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue