• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting filename of just opened document...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 18:03:26 -0700

So when I open a document, the appropriate NSLog appears, but no data is loaded. I thought the self = [super should have handled the opening and loading of file contents?

Yes, your self = [super code will call through (in a default cocoa document project) that stack I showed before:

#0 -[MyDocument loadDataRepresentation:ofType:] ()
#1 0x930522f8 in -[NSDocument loadFileWrapperRepresentation:ofType:] ()
#2 0x9305261c in -[NSDocument readFromFile:ofType:] ()
#3 0x92f69fb0 in -[NSDocument initWithContentsOfFile:ofType:] ()

Do you have code in loadDataRepresentation:ofType: or some other override point that loads your files? is being called? are you confusing an untitled document with opening a document from a file? Your previous code showed some misunderstanding of Cocoa's document architecture, so I'm not sure what to assume you are doing right.

Some comments: your "something special" turns out to be setSyntaxColoringFromFileName: which is something after loading your document contents, so a subclass of NSDocumentController doesn't make sense (as I suggested earlier).

You may be able to combine your code that actually loads your file (which can be put in any of those above 4 stack frames) with your call to setSyntax... and use your document's type instead of its filename extension (actually, filename is available in frames 1,2,3 so you can easily use one of those override points).


-jim



On May 31, 2004, at 2:08 AM, Oliver Cameron wrote:

Hi,

Thanks for the detailed reply.

Someone gave me this code, but unfortunately, it opens a blank document:

- (id)initWithContentsOfFile:(NSString *)fileName ofType:(NSString *)docTypes
{
self = [super initWithContentsOfFile:fileName ofType:docTypes];
[self setSyntaxColoringFromFileName:fileName];
return self;
}

- (void)setSyntaxColoringFromFileName:(NSString *)fileName
{
if ([[fileName pathExtension] isEqualToString:@"css"])
{
NSLog(@"CSS");
}
if ([[fileName pathExtension] isEqualToString:@"html"])
{
NSLog(@"HTML");
}

So when I open a document, the appropriate NSLog appears, but no data is loaded. I thought the self = [super should have handled the opening and loading of file contents?

Thanks,
Oliver

On 31 May 2004, at 10:02, James DiPalma wrote:

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.
_______________________________________________
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.


References: 
 >Getting filename of just opened document... (From: Oliver Cameron <email@hidden>)
 >Re: Getting filename of just opened document... (From: James DiPalma <email@hidden>)
 >Re: Getting filename of just opened document... (From: Oliver Cameron <email@hidden>)

  • Prev by Date: Re: some NSThread questions
  • Next by Date: Re: 30 day trial howto?
  • Previous by thread: Re: Getting filename of just opened document...
  • Next by thread: Your own NSNotificationCenter
  • Index(es):
    • Date
    • Thread