|
|
NSDocument Woes
|
|
|
|
Mac Elite
Join Date: May 2001
Location: Up north
Status:
Offline
|
|
Got a document based application.
It's an interface for an old school Fortran program.
User edits or creates an input file, they click the process button, a tmp file is created, and passed off to the command line fortran program, the fortran program creates a tmp output file.
Everything works, except I can't get the output document to show it's self after it's been allocated and initialized back in the input document.
The code, called from within the InputDocument class, just after the input file has been processed.
if (![m_outputFilePath isEqualToString:@""]) {
if ([[NSFileManager defaultManager] fileExistsAtPath:m_outputFilePath]) {
// do something like open the document setting it as a temporary document
m_outputDocument = [[OutputFile alloc] initWithContentsOfFile:m_outputFilePath ofType:@""];
// mark as a temporary file that needs to be saved (it's like an untitled document)
[m_outputDocument setTmpNeedsSave];
// we are done with the tmp file get rid of it
[[NSFileManager defaultManager] removeFileAtPath:m_outputFilePath handler:nil];
}
}
I know the output document object is getting it's data, I have verified that, but, I can't for the life of me figure out how to get it to show it's self.
Is there any way that I could tell NSApp to open the document? Like, [NSApp application:NSApp openFile:theFilePath]?? It doesn't work, it complains about selectors..
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
You don't normally allocate documents yourself, I think. To open documents, you can use NSDocumentController's openDocumentWithContentsOfFile:display:.
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Mac Elite
Join Date: May 2001
Location: Up north
Status:
Offline
|
|
Originally posted by Chuckit:
You don't normally allocate documents yourself, I think. To open documents, you can use NSDocumentController's openDocumentWithContentsOfFile:display:.
Ya, I was lazy when I started this and don't have a document controller or app controller. It looks like I should have, anyways, I am adding them, I'll see if that can do it.
On an interesting note, I sort of got it to work, by getting the window from the output document, then calling makeKeyAndOrderFront. That however doesn't work well, it crashes moments later.
I thought I liked Cocoa, and sometimes I do, but othertimes I feel there is almost too much abstraction. It's not really clear at times what paths the program is taking.. it's very different from programming cli programs, there, you have main, and you control the entire flow of your program. But, I see why this sort of abstraction is necessary for cocoa apps, it's just hard to wrap my head around sometimes.
Ack.. just had to let out some frustration.
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status:
Offline
|
|
You don't need to create an NSDocumentController subclass, Cocoa uses a singleton instance. So, basically, you just need to do something like this:
Code:
NSDocument *newDocument = [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfFile: pathToFile display: YES];
pathToFile is an NSString containing the filesystem path, and newDocument is the created NSDocument or nil if it couldn't be created.
|
Geekspiff - generating spiffdiddlee software since before you began paying attention.
|
|
|
|
|
|
|
|
Mac Elite
Join Date: May 2001
Location: Up north
Status:
Offline
|
|
Originally posted by smeger:
You don't need to create an NSDocumentController subclass, Cocoa uses a singleton instance. So, basically, you just need to do something like this:
Code:
NSDocument *newDocument = [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfFile: pathToFile display: YES];
pathToFile is an NSString containing the filesystem path, and newDocument is the created NSDocument or nil if it couldn't be created.
Thanks
I didn't notice the sharedController earlier last night. Anyways, it works great now. Now I just need to figure out how to dynamically create button and text fields to make the Fortran input file easy to read.
I would like to do something similar to the way one edits plists in expert view in project builder, would NSTableView be appropriate? Any other ideas?
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status:
Offline
|
|
That's NSOutlineView, which is a subclass of NSTableView. NSOutlineView is slightly tricky to use - there are tutorials and sample code on the web, but I don't remember where I saw 'em - maybe http://www.cocoadev.com/ ?
|
Geekspiff - generating spiffdiddlee software since before you began paying attention.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|