Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > NSDocument Woes

NSDocument Woes
Thread Tools
11011001
Mac Elite
Join Date: May 2001
Location: Up north
Status: Offline
Reply With Quote
Sep 8, 2003, 12:46 AM
 
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..
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Sep 8, 2003, 01:40 AM
 
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'."
     
11011001  (op)
Mac Elite
Join Date: May 2001
Location: Up north
Status: Offline
Reply With Quote
Sep 8, 2003, 02:01 AM
 
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.
     
smeger
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Sep 8, 2003, 08:13 AM
 
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.
     
11011001  (op)
Mac Elite
Join Date: May 2001
Location: Up north
Status: Offline
Reply With Quote
Sep 9, 2003, 01:25 AM
 
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?
     
smeger
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Sep 9, 2003, 03:40 AM
 
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.
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 09:28 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,