diff --git a/ChangeLog b/ChangeLog index d2638e50a..1c821e910 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,11 @@ +2007-07-25 Fred Kiefer + + * Headers/AppKit/NSApplication.h: Correct comment. + * Source/NSApplication.m: Add error presenting methods. + 2007-07-24 Fred Kiefer - * Headers/AppKit/NSApplication.h: + * Headers/AppKit/NSApplication.h, * Source/NSApplication.m: Add MacOSX 10.4 method declarations. * Source/externs.m: Define new string constant. diff --git a/Headers/AppKit/NSApplication.h b/Headers/AppKit/NSApplication.h index ee561d0d1..2679db97e 100644 --- a/Headers/AppKit/NSApplication.h +++ b/Headers/AppKit/NSApplication.h @@ -475,7 +475,7 @@ APPKIT_EXPORT NSString *NSEventTrackingRunLoopMode; #if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) /** - * Not sent yet on GNUstep. + * Ask delegate for an error replacement. */ - (NSError*) application: (NSApplication*)app willPresentError: (NSError*)error; #endif diff --git a/Source/NSApplication.m b/Source/NSApplication.m index b3d88b1d2..eb5d77000 100644 --- a/Source/NSApplication.m +++ b/Source/NSApplication.m @@ -37,6 +37,8 @@ #include #include #include +#include +#include #include #include #include @@ -57,6 +59,7 @@ #endif #include "AppKit/AppKitExceptions.h" +#include "AppKit/NSAlert.h" #include "AppKit/NSApplication.h" #include "AppKit/NSCell.h" #include "AppKit/NSCursor.h" @@ -3073,6 +3076,111 @@ image.

See Also: -applicationIconImage

NSLog (_(@"reported exception - %@"), anException); } +- (BOOL) presentError: (NSError *)error +{ + NSAlert *alert; + int result; + + error = [self willPresentError: error]; + alert = [NSAlert alertWithError: error]; + result = [alert runModal]; + + if (result != NSAlertErrorReturn) + { + // Convert result (1, 0, -1) into index (0, 1, 2) + result = 1 - result; + return [[error recoveryAttempter] attemptRecoveryFromError: error + optionIndex: result]; + } + else + { + return NO; + } +} + +struct _DelegateWrapper +{ + id delegate; + SEL selector; + NSError *error; + void *context; +}; + +- (void) presentError: (NSError*)error + modalForWindow: (NSWindow*)window + delegate: (id)delegate + didPresentSelector: (SEL)sel + contextInfo: (void*)context +{ + NSAlert *alert; + struct _DelegateWrapper *wrapper; + + error = [self willPresentError: error]; + alert = [NSAlert alertWithError: error]; + // FIXME: Who is trying to recover the error? + wrapper = malloc(sizeof(struct _DelegateWrapper)); + wrapper->delegate = delegate; + wrapper->selector = sel; + wrapper->error = error; + wrapper->context = context; + + [alert beginSheetModalForWindow: window + modalDelegate: self + didEndSelector: @selector(_didPresentError:returnCode:contextInfo:) + contextInfo: wrapper]; +} + +- (void) _didPresentError: (NSWindow*)sheet + returnCode: (int)result + contextInfo: (void*)context +{ + struct _DelegateWrapper *wrapper; + id delegate; + SEL sel; + NSError *error; + void *orgContext; + BOOL recover; + + wrapper = (struct _DelegateWrapper*)context; + delegate = wrapper->delegate; + sel = wrapper->selector; + error = wrapper->error; + orgContext = wrapper->context; + free(wrapper); + + if (result != NSAlertErrorReturn) + { + // Convert result (1, 0, -1) into index (0, 1, 2) + result = 1 - result; + recover = [[error recoveryAttempter] attemptRecoveryFromError: error + optionIndex: result]; + } + else + { + recover = NO; + } + + if ([delegate respondsToSelector: sel]) + { + void (*didEnd)(id, SEL, BOOL, void*); + + didEnd = (void (*)(id, SEL, BOOL, void*))[delegate methodForSelector: sel]; + didEnd(delegate, sel, recover, orgContext); + } +} + +- (NSError*) willPresentError: (NSError*)error +{ + if ([_delegate respondsToSelector: @selector(application:willPresentError:)]) + { + return [_delegate application: self willPresentError: error]; + } + else + { + return error; + } +} + /** * Requests the application terminates the application. First an * -applicationShouldTerminate: message is sent to the delegate, and only if