[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
NSDocument fix
From: |
Wolfgang Lux |
Subject: |
NSDocument fix |
Date: |
Sun, 2 Sep 2007 18:14:42 +0200 |
And here's yet another one (the last one for today :-).
This patch fixes an issue with the setFileURL/setFileName
compatibility code
in NSDocument. The problem is that NSDocument at present assigns only
one of
the attributes _file_url and _file_name, depending on whether -
setFileName is
overridden or not. This will lead to problems for classes that override
-setFileName but not -fileName and vice versa. The patch below fixes
this by
always setting _file_url and _file_name.
In addition, the patch also ensures that the error variable is well
defined
after calling an overridden method which does not have an error
parameter,
setting the variable to nil (this is what Mac OS X seems to do in
this case
as well).
Regards
Wolfgang
--- Source/NSDocument.m (Revision 25440)
+++ Source/NSDocument.m (Arbeitskopie)
@@ -233,8 +233,12 @@
{
[self setFileURL: [NSURL fileURLWithPath: fileName]];
}
- ASSIGN(_file_name, fileName);
- [self setLastComponentOfFileName: [_file_name lastPathComponent]];
+ else
+ {
+ ASSIGN(_file_name, fileName);
+ ASSIGN(_file_url, [NSURL fileURLWithPath: fileName]);
+ [self setLastComponentOfFileName: [_file_name
lastPathComponent]];
+ }
}
- (NSString *)fileType
@@ -269,6 +273,7 @@
else
{
ASSIGN(_file_url, url);
+ ASSIGN(_file_name, url && [url isFileURL] ? [url path] : nil);
[self setLastComponentOfFileName: [[_file_url path]
lastPathComponent]];
}
}
@@ -537,6 +542,7 @@
{
if (OVERRIDDEN(dataRepresentationOfType:))
{
+ *error = nil;
return [self dataRepresentationOfType: type];
}
@@ -569,6 +575,7 @@
if (OVERRIDDEN(fileWrapperRepresentationOfType:))
{
+ *error = nil;
return [self fileWrapperRepresentationOfType: type];
}
@@ -654,6 +661,7 @@
{
if (OVERRIDDEN(loadFileWrapperRepresentation:ofType:))
{
+ *error = nil;
return [self loadFileWrapperRepresentation: wrapper ofType:
type];
}
@@ -664,7 +672,7 @@
error: error];
}
- // FIXME: Set error
+ *error = nil;
return NO;
}
@@ -678,6 +686,7 @@
if (OVERRIDDEN(readFromFile:ofType:))
{
+ *error = nil;
return [self readFromFile: [url path] ofType: type];
}
else
@@ -690,7 +699,7 @@
}
}
- // FIXME: Set error
+ *error = nil;
return NO;
}
@@ -821,6 +830,7 @@
saveOp = NSSaveToOperation;
}
+ *error = nil;
return [self writeWithBackupToFile: [url path]
ofType: type
saveOperation: saveOp];
@@ -845,7 +855,7 @@
if (![self _writeBackupForFile: newFileName
toFile: backupFilename])
{
- // FIXME: Set error.
+ *error = nil;
return NO;
}
}
@@ -891,7 +901,8 @@
if (OVERRIDDEN(writeToFile:ofType:))
{
- return [self writeToFile: [url path] ofType: type];
+ *error = nil;
+ return [self writeToFile: [url path] ofType: type];
}
wrapper = [self fileWrapperOfType: type
@@ -900,7 +911,8 @@
{
return NO;
}
-
+
+ *error = nil;
return [wrapper writeToFile: [url path] atomically: YES
updateFilenames: YES];
}
@@ -917,6 +929,7 @@
saveOp = NSSaveToOperation;
}
+ *error = nil;
return [self writeToFile: [url path]
ofType: type
originalFile: [orig path]
@@ -1249,6 +1262,7 @@
- (NSPrintOperation *)printOperationWithSettings: (NSDictionary *)
settings
error: (NSError **)error
{
+ *error = nil;
return nil;
}
- NSDocument fix,
Wolfgang Lux <=