Implemented the should quit logic on Mac OS X. The actual new quitting logic isn't in yet; that will wait for tests.

This commit is contained in:
Pietro Gagliardi 2015-05-09 10:05:24 -04:00
parent c395cdd2fd
commit 8032c24f74
2 changed files with 19 additions and 3 deletions

View File

@ -22,6 +22,10 @@ static BOOL canQuit = NO;
if (!canQuit)
complain("call to [NSApp terminate:] when not ready to terminate");
// TODO move the body of uiQuit() here
// TODO make uiQuit() just call terminate:
// TODO update the above comment
}
@end
@ -38,8 +42,12 @@ static BOOL canQuit = NO;
{
// for debugging
NSLog(@"in applicationShouldTerminate:");
canQuit = YES;
return NSTerminateNow;
if (shouldQuit()) {
canQuit = YES;
// this will call terminate:, which is the same as uiQuit()
return NSTerminateNow;
}
return NSTerminateCancel;
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)app

View File

@ -64,6 +64,12 @@ enum {
(*(item->onClicked))(uiMenuItem(item), windowFromNSWindow([NSApp keyWindow]), item->onClickedData);
}
- (IBAction)onQuitClicked:(id)sender
{
if ([[NSApp delegate] applicationShouldTerminate:NSApp] == NSTerminateNow)
[NSApp terminate:self];
}
- (void)register:(NSMenuItem *)item to:(struct menuItem *)smi
{
NSValue *v;
@ -169,7 +175,7 @@ enum {
// and finally Quit
// DON'T use @selector(terminate:) as the action; we handle termination ourselves
title = [@"Quit " stringByAppendingString:appName];
item = [[NSMenuItem alloc] initWithTitle:title action:@selector(onClicked:) keyEquivalent:@"q"];
item = [[NSMenuItem alloc] initWithTitle:title action:@selector(onQuitClicked:) keyEquivalent:@"q"];
[item setTarget:self];
[appMenu addItem:item];
self.quitItem = item;
@ -210,6 +216,8 @@ static void menuItemOnClicked(uiMenuItem *ii, void (*f)(uiMenuItem *, uiWindow *
{
struct menuItem *item = (struct menuItem *) ii;
if (item->type == typeQuit)
complain("attempt to call uiMenuItemOnClicked() on a Quit item; use uiOnShouldQuit() instead");
item->onClicked = f;
item->onClickedData = data;
}