From daa905a169c0ff8a687d3ccf4b38c971a1926d14 Mon Sep 17 00:00:00 2001 From: ivucica Date: Sun, 10 May 2015 19:10:56 +0000 Subject: [PATCH] Better support for setting errors inside -dataOfType:error: and -readFromData:ofType:error:. Previously, under GNUstep, NSLocalizedFailureReasonKey was ignored when presented with +[NSAlert alertWithError]. Additionally, error set in -readFromData:ofType:error: was overwritten by two different methods in the file reading chain. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@38483 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 12 ++++++++++++ Source/NSAlert.m | 9 ++++++++- Source/NSDocument.m | 7 ++++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index b7ef8aacc..803d6c457 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2015-05-10 Ivan Vucica + + * Source/NSAlert.m (+alertWithError:): Support use of + NSLocalizedFailureReasonKey. Prefer it as the title of the error + alert's title in case it is present inside a NSError. + * Source/NSDocument.m (-fileWrapperOfType:error:): Prefer error + created by called -dataOfType:error: method; that is, do not overwrite + it. + * Source/NSDocument.m (-writeToURL:ofType:error:): Check that error is + non-nil, then apply the error message only if + -fileWrapperOfType:error: did not set its own error. + 2015-04-03 Fred Kiefer * Headers/AppKit/NSColor.h, diff --git a/Source/NSAlert.m b/Source/NSAlert.m index d418bd96d..a5a994de1 100644 --- a/Source/NSAlert.m +++ b/Source/NSAlert.m @@ -1789,10 +1789,17 @@ void NSBeginInformationalAlertSheet(NSString *title, { NSArray *options; NSUInteger count; + NSString *errorText; + + errorText = [error localizedFailureReason]; + if (errorText == nil) + { + errorText = [error localizedDescription]; + } options = [error localizedRecoveryOptions]; count = [options count]; - return [self alertWithMessageText: [error localizedDescription] + return [self alertWithMessageText: errorText defaultButton: (count > 0) ? [options objectAtIndex: 0] : nil alternateButton: (count > 1) ? [options objectAtIndex: 1] : nil otherButton: (count > 2) ? [options objectAtIndex: 2] : nil diff --git a/Source/NSDocument.m b/Source/NSDocument.m index 2f46ac46f..7008a5cd7 100644 --- a/Source/NSDocument.m +++ b/Source/NSDocument.m @@ -641,8 +641,9 @@ withContentsOfURL: (NSURL *)url if (data == nil) { - *error = create_error(0, NSLocalizedString(@"Could not create data for type.", - @"Error description")); + if (error && !(*error)) + *error = create_error(0, NSLocalizedString(@"Could not create data for type.", + @"Error description")); return nil; } return AUTORELEASE([[NSFileWrapper alloc] initRegularFileWithContents: data]); @@ -1022,7 +1023,7 @@ withContentsOfURL: (NSURL *)url error: error]; if (wrapper == nil) { - if (error) + if (error && !(*error)) { *error = create_error(0, NSLocalizedString(@"Could not write file wrapper.", @"Error description"));