diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index cf8cf7165a..71340e7fa4 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -62,6 +62,7 @@ #include #include #include +#include bool SCH_EDIT_FRAME::SaveEEFile( SCH_SHEET* aSheet, bool aSaveUnderNewName ) @@ -325,6 +326,10 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in LoadProjectSettings(); SetShutdownBlockReason( _( "Schematic file changes are unsaved" ) ); + if( Kiface().IsSingle() ) + { + KIPLATFORM::APP::RegisterApplicationRestart( fullFileName ); + } if( is_new ) { diff --git a/kicad/kicad_manager_frame.cpp b/kicad/kicad_manager_frame.cpp index 95ac46086d..70905170ef 100644 --- a/kicad/kicad_manager_frame.cpp +++ b/kicad/kicad_manager_frame.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -378,6 +379,8 @@ void KICAD_MANAGER_FRAME::LoadProject( const wxFileName& aProjectFileName ) wxPostEvent( this, cmd ); PrintPrjInfo(); + + KIPLATFORM::APP::RegisterApplicationRestart( aProjectFileName.GetFullPath() ); } diff --git a/libs/kiplatform/CMakeLists.txt b/libs/kiplatform/CMakeLists.txt index 4f2c5a637b..aa0d3b2125 100644 --- a/libs/kiplatform/CMakeLists.txt +++ b/libs/kiplatform/CMakeLists.txt @@ -2,6 +2,7 @@ # Add the appropriate source files if( APPLE ) set( PLATFORM_SRCS + osx/app.mm osx/ui.mm ) @@ -13,10 +14,12 @@ if( APPLE ) ) elseif( WIN32 ) set( PLATFORM_SRCS + msw/app.cpp msw/ui.cpp ) elseif( UNIX ) set( PLATFORM_SRCS + gtk/app.cpp gtk/ui.cpp ) endif() diff --git a/libs/kiplatform/gtk/app.cpp b/libs/kiplatform/gtk/app.cpp new file mode 100644 index 0000000000..bf071c00cf --- /dev/null +++ b/libs/kiplatform/gtk/app.cpp @@ -0,0 +1,37 @@ +/* +* This program source code file is part of KiCad, a free EDA CAD application. +* +* Copyright (C) 2020 Mark Roszko +* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. +* +* This program is free software: you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation, either version 3 of the License, or (at your +* option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program. If not, see . +*/ + +#include + +#include + + +bool KIPLATFORM::APP::RegisterApplicationRestart( const wxString& aCommandLine ) +{ + // Not implemented on this platform + return true; +} + + +bool KIPLATFORM::APP::UnregisterApplicationRestart() +{ + // Not implemented on this platform + return true; +} \ No newline at end of file diff --git a/libs/kiplatform/include/kiplatform/app.h b/libs/kiplatform/include/kiplatform/app.h new file mode 100644 index 0000000000..73743a8d37 --- /dev/null +++ b/libs/kiplatform/include/kiplatform/app.h @@ -0,0 +1,46 @@ +/* +* This program source code file is part of KiCad, a free EDA CAD application. +* +* Copyright (C) 2020 Mark Roszko +* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. +* +* This program is free software: you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation, either version 3 of the License, or (at your +* option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program. If not, see . +*/ + +#ifndef KIPLATFORM_APP_H_ +#define KIPLATFORM_APP_H_ + +class wxString; + +namespace KIPLATFORM +{ + namespace APP + { + /** + * Registers the application for restart with the OS with the given command line string to pass as args + * + * @param aCommandLine is string the OS will invoke the application with + */ + bool RegisterApplicationRestart( const wxString& aCommandLine ); + + /** + * Unregisters the application from automatic restart + * + * Depending on OS, this may not be required + */ + bool UnregisterApplicationRestart(); + } +} + +#endif // KIPLATFORM_UI_H_ \ No newline at end of file diff --git a/libs/kiplatform/msw/app.cpp b/libs/kiplatform/msw/app.cpp new file mode 100644 index 0000000000..a4b3b4d408 --- /dev/null +++ b/libs/kiplatform/msw/app.cpp @@ -0,0 +1,47 @@ +/* +* This program source code file is part of KiCad, a free EDA CAD application. +* +* Copyright (C) 2020 Mark Roszko +* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. +* +* This program is free software: you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation, either version 3 of the License, or (at your +* option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program. If not, see . +*/ + +#include + +#include + +#include +#include + + +bool KIPLATFORM::APP::RegisterApplicationRestart( const wxString& aCommandLine ) +{ + HRESULT hr = S_OK; // not if registering for recovery and restart fails. + WCHAR wsCommandLine[RESTART_MAX_CMD_LINE]; + RtlZeroMemory( wsCommandLine, sizeof( wsCommandLine ) ); + + StringCchCopyW( wsCommandLine, sizeof( wsCommandLine ), aCommandLine.wc_str() ); + + hr = ::RegisterApplicationRestart( wsCommandLine, RESTART_NO_PATCH ); + + return SUCCEEDED( hr ); +} + + +bool KIPLATFORM::APP::UnregisterApplicationRestart() +{ + // Note, this isn't required to be used on Windows if you are just closing the program + return SUCCEEDED( ::UnregisterApplicationRestart() ); +} \ No newline at end of file diff --git a/libs/kiplatform/osx/app.mm b/libs/kiplatform/osx/app.mm new file mode 100644 index 0000000000..bf071c00cf --- /dev/null +++ b/libs/kiplatform/osx/app.mm @@ -0,0 +1,37 @@ +/* +* This program source code file is part of KiCad, a free EDA CAD application. +* +* Copyright (C) 2020 Mark Roszko +* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. +* +* This program is free software: you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation, either version 3 of the License, or (at your +* option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program. If not, see . +*/ + +#include + +#include + + +bool KIPLATFORM::APP::RegisterApplicationRestart( const wxString& aCommandLine ) +{ + // Not implemented on this platform + return true; +} + + +bool KIPLATFORM::APP::UnregisterApplicationRestart() +{ + // Not implemented on this platform + return true; +} \ No newline at end of file diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 51f3ee4fe7..3514e789ac 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include #include @@ -461,6 +462,11 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in wxString fullFileName( aFileSet[0] ); + if( Kiface().IsSingle() ) + { + KIPLATFORM::APP::RegisterApplicationRestart( fullFileName ); + } + // We insist on caller sending us an absolute path, if it does not, we say it's a bug. wxASSERT_MSG( wxFileName( fullFileName ).IsAbsolute(), wxT( "Path is not absolute!" ) );