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 > Cocoa AppKit - need HELP

Cocoa AppKit - need HELP
Thread Tools
Forum Regular
Join Date: Mar 2001
Status: Offline
Reply With Quote
Apr 14, 2001, 01:40 AM
 
Hi,

I am relatively new to Object Oriented Programming, and totally new to Cocoa.

I realize that Cocoa AppKit is really powerful and useful, but I am disappointed, disoriented.

With Project Builder, I have started a new Document Based Cocoa Application, and I can understand the basis of the structure, but there is some things I were not able to find.

If I have understood, the main.m source file instantiate NSApplication and loads the main NIB file owned by NSApplication. When I compile and launch the App, I have an instance of MyDocument that is created and the MyDocument NIB owned by MyDocument is loaded. Who instantiated MyDocument ?

I think there is something like NSApplication or NSDocumentController that do an "newDocument" action at startup.

But if I want to make a "Read Only Document App", I do not want a new document created at startup, but something like "openDocument" instead with an Open dialog window.

Moreover I want to understand how and where the Application instantiate MyDocument. How does it even knows that MyDocument.h still exists ? It is said nowhere in main.m nor MainMenu.nib, nor in "Build Settings" nor in "Application Settings". Is the "MyDocument" name reserved ?

Thanks
Imagine that my signature is here...
     
Senior User
Join Date: Mar 2000
Location: Ithaca, NY
Status: Offline
Reply With Quote
Apr 15, 2001, 04:43 PM
 
When an NSDocument based app launches, the application will look in the Info.plist file in the CFBundleDocumentTypes key to see what types of documents the app can handle. For each type in that array, you can specify under the NSDocumentClass key the name of the class that should handle opening up files of that type. In Project Builder, display the target for the app and look at the Application Settings tab. Down at the bottom, you should see the list of document types with the MyDocument class specified as the class to open up the one type that is included by default when a document based project is created. You can click on the Expert button at the top to see the actual structure of the property list.

So anyway, when the app launches, by default, it will open up a new document using the specified NSDocument subclass. (I don't know how it chooses which one to use when there are multiple types present, though) The document is made by a call to NSDocumentController's -makeUntitledDocumentOfType: method. The newDocument: method is just an action method that you can hook up to menu items and such, and it will do the same thing that happens at an app's startup time by default. If you want to override the behavior so that it doesn't open a new document, you can implement the application delegate method -(BOOL)applicationShouldOpenUntitledFile to return NO. NSApplication will ask its delegate via this method whether it should open an untitled file when requested to do so, and it will not go through with it if this method returns NO.
     
Forum Regular
Join Date: Mar 2001
Status: Offline
Reply With Quote
Apr 16, 2001, 01:16 AM
 
Thank you !!!

I progress, slowly but surely
Imagine that my signature is here...
     
   
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:17 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2