Re: Getting filename of just opened document...
Re: Getting filename of just opened document...
- Subject: Re: Getting filename of just opened document...
- From: James DiPalma <email@hidden>
- Date: Mon, 31 May 2004 02:02:39 -0700
Try NSDocument's initWithContentsOfFile:ofType:?
It looks like you have implemented openDocument: in an openDocument:
subclass. This method is usually handled by an instance of
NSDocumentController (or a subclass). This assumption is based on using
[self fileName] in your code and by trying to figure out why you didn't
enter an infinite loop when calling NSDocumentController's
openDocument:. Guessing further, your application has an untitled
document (fileName == null) that is in your responder chain and
handling openDocument: before NSDocumentController.
I don't know what you are trying to do exactly, but I used PB to start
a new document application and (after returning [[NSData alloc] init]
in -dataRepresentationOfType:) was able to save, then load a file with
a breakpoint set at loadDataRepresentation:ofType:. This stack trace
gives you 4 places (frames 1,2,3,4) that you can override to perform
something special:
#0 -[MyDocument loadDataRepresentation:ofType:] ()
#1 0x930522f8 in -[NSDocument loadFileWrapperRepresentation:ofType:] ()
#2 0x9305261c in -[NSDocument readFromFile:ofType:] ()
#3 0x92f69fb0 in -[NSDocument initWithContentsOfFile:ofType:] ()
#4 0x92f69e24 in -[NSDocumentController
makeDocumentWithContentsOfFile:ofType:] ()
#5 0x92f69c64 in -[NSDocumentController _openDocumentFileAt:display:]
()
#6 0x930550d4 in -[NSDocumentController openDocument:] ()
-jim
On May 29, 2004, at 2:23 PM, Oliver Cameron wrote:
Hi guys,
I'm trying to do something special depending on the format of the file
a user opens. So in openDocument: I try this:
- (void)openDocument:(id)sender
{
[[NSDocumentController sharedDocumentController]
openDocument:self];
NSLog(@"%@", [self fileName]);
if ([[[self fileName] pathExtension]
isEqualToString:@"extension"])
{
// Special stuff goes here
}
}
Now the code builds fine, but when I open a document, the NSLog shows
that fileName is (null). Now, I realize that it may be null because it
doesn't know which fileName you are going to choose. But, fileName
does not appear in the run log until after I've chosen the document.
Any ideas?
Thanks,
Oliver
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.