mac: Support external quit requests (#1099)
By no longer always returning NSTerminateCancel in applicationShouldTerminate. And implement applicationWillTerminate to ensure the cleanup code in SolveSpaceUI::Exit() is always called.
This commit is contained in:
parent
7e823df94a
commit
31a709e2c8
@ -1427,9 +1427,22 @@ void OpenInBrowser(const std::string &url) {
|
|||||||
- (IBAction)preferences:(id)sender;
|
- (IBAction)preferences:(id)sender;
|
||||||
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename;
|
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename;
|
||||||
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
|
||||||
|
|
||||||
|
@property BOOL exiting;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation SSApplicationDelegate
|
@implementation SSApplicationDelegate
|
||||||
|
|
||||||
|
@synthesize exiting;
|
||||||
|
|
||||||
|
- (id)init {
|
||||||
|
if (self = [super init]) {
|
||||||
|
self.exiting = false;
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
- (IBAction)preferences:(id)sender {
|
- (IBAction)preferences:(id)sender {
|
||||||
if (!SS.GW.showTextWindow) {
|
if (!SS.GW.showTextWindow) {
|
||||||
SolveSpace::SS.GW.MenuView(SolveSpace::Command::SHOW_TEXT_WND);
|
SolveSpace::SS.GW.MenuView(SolveSpace::Command::SHOW_TEXT_WND);
|
||||||
@ -1444,12 +1457,27 @@ void OpenInBrowser(const std::string &url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
|
||||||
[[[NSApp mainWindow] delegate] windowShouldClose:[NSApp mainWindow]];
|
if(!SS.unsaved) {
|
||||||
return NSTerminateCancel;
|
return NSTerminateNow;
|
||||||
|
} else {
|
||||||
|
[self performSelectorOnMainThread:@selector(applicationTerminatePrompt) withObject:nil
|
||||||
|
waitUntilDone:NO modes:@[NSDefaultRunLoopMode, NSModalPanelRunLoopMode]];
|
||||||
|
return NSTerminateLater;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)applicationWillTerminate:(NSNotification *)notification {
|
||||||
|
if(!exiting) {
|
||||||
|
// Prevent the Platform::ExitGui() call from SolveSpaceUI::Exit()
|
||||||
|
// triggering another terminate
|
||||||
|
exiting = true;
|
||||||
|
// Now let SS save settings etc
|
||||||
|
SS.Exit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)applicationTerminatePrompt {
|
- (void)applicationTerminatePrompt {
|
||||||
SolveSpace::SS.MenuFile(SolveSpace::Command::EXIT);
|
[NSApp replyToApplicationShouldTerminate:SS.OkayToStartNewFile()];
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@ -1488,9 +1516,11 @@ void RunGui() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ExitGui() {
|
void ExitGui() {
|
||||||
[NSApp setDelegate:nil];
|
if(!ssDelegate.exiting) {
|
||||||
|
ssDelegate.exiting = true;
|
||||||
[NSApp terminate:nil];
|
[NSApp terminate:nil];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ClearGui() {}
|
void ClearGui() {}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user