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
This commit is contained in:
Ivan Vučica 2015-05-10 19:10:56 +00:00
parent 1a8e5a320b
commit d3861e224c
3 changed files with 24 additions and 4 deletions

View file

@ -1,3 +1,15 @@
2015-05-10 Ivan Vucica <ivan@vucica.net>
* 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 <FredKiefer@gmx.de>
* Headers/AppKit/NSColor.h,

View file

@ -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

View file

@ -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"));