Previous: , Up: Implementation   [Contents][Index]


6 Preferences

The preferences panel contains a number of useful customizable options which can be used to modify the behavior of Gorm.

Some of these defaults can be safely modified from the command line by the user.

7 Basic Concepts

This chapter will explain some of the basic things you need to understand before starting work on a new application.

7.1 Getting Started

First you need to understand a few basic concepts. Gorm’s main window includes a few standard entries which must be explained before we can proceed.

They are:

7.2 What is NSOwner?

NSOwner is the class which “owns” the interface. This is, by default, NSApplication, but it can be any class you like. You can change it by selecting NSOwner in the document window and going to the “Custom Class” inspector in the inspectors window. From there, you should see all of the classes which the NSOwner can assume. We’ll discuss more about this later when we go over how to create a new application

7.3 What is NSFirst?

NSFirst is your interface to the responder chain. NSFirst is representative of the current “first responder” in the application. When you want a message, such as a changeFont: message, to go to the current first responder from, say, a menu, you connect the menu item to the NSFirst object in the document window. By doing this, it means that whichever object has first responder status at that time in the application will become the reciever of the “changeFont:” message.

7.3.1 Responders

A responder is any subclass of NSResponder. This includes NSWindow, NSView and all of the NSControl subclasses.

7.3.2 The Responder Chain

The responder chain is a sequence of objects which are called to determine where a message sent to the first responder will go. A message invoked on the first responder will be invoked on the first object in the responder chain which responds to that message.

The object which this message will be called on is determined in the method [NSApplication targetForAction:]. The call sequence is as follows, it will only proceed to the next step in each case if the current step fails to respond to the message which was invoked:

If all of the options in this list are exhausted, it then gives up and returns nil for the object which is to respond.

7.4 What is NSFont?

NSFont represents the NSFontManager object for the application. This object is a shared singleton. This means that, for any given app, there should be only one instance of the object. This object is generally added to the document window when another objec, such as a Font menu item, is added to the interface, which, in turn, requires that this object be added to the document.

7.5 The awakeFromNib method

This method is called on any custom object which is unarchived from a nib/gorm file. This method is called on all objects after the entire archive has been loaded into memory and all connections have been made. Given all of this, you should not make any assumptions at all about which objects have been called and which have not. You should not release any objects in this method.

8 Creating an Application

If you have ProjectCenter, you need to open it and create an “Application” project. Create it with the name “FirstApp”. From there you can open the MainMenu.gorm by clicking on interfaces and selecting MainMenu.gorm. If Gorm.app is properly installed, you Gorm should start up.

If you don’t have ProjectCenter, you can create the Gorm file by hand. First you need to start Gorm. You can either do this by doing ‘gopen -a Gorm.app’ from a command line prompt, or you can invoke it from the Dock or from the workspace’s file viewer.

You then need to select the ‘Document’ menu, and then ‘New Application’. This should produce a new document window, with a menu and an empty window. This should be the same as with the ProjectCenter gorm file since this is the basic starting point for an application.

For the sections below... only do one or the other, not both.

8.1 Creating A Class In Gorm

There are two ways to do this next operation. I will take you through each step by step. First click on the classes icon in the toolbar on the top of the Gorm document window. You should see the view below change to an outline view containing a list of class names. Once this happens we’re ready to create a class. Select the class you wish to subclass in the outline view. For our example we will use the simplest: NSObject. Select it by clicking on the class name once. Then go to the Classes menu in the main menu and select Create Subclass (you can also type Alt-Shift-c, which will do this as well. The new class will be created in the list with the name “NewClass”.

8.2 Using The Outline View

From here double click on the subclass name to make it editable. Type the name of the class and hit enter. For our example, please use the class name MyController. When you hit enter an alert panel will appear and warn you about breaking connections, simply select OK and continue.

This method of inputting the classes was inspired by IB in OPENSTEP 4.2/Mach which had functionality very similar to this. For users of that the transition to Gorm will be seamless.

8.2.1 Adding Outlets In The Outline View

Too add an outlet, select the round icon with the two horizontal lines in it (it sort of looks like a wall outlet. This should become depressed. Here you need to go to the Gorm Menu, under Classes select “Add Outlet/Action”. Each time you press this menu item another outlet will be added with a name similar to newOutlet, as you add more the number at the end will increase. For now add only one outlet.

To rename the outlet simply double click it and change it’s name like you did the class above to “value” for the sake of our example.

8.2.2 Adding Actions In the Outline View

The procedure to add on action is precisely the same as adding an outlet, except you must click on the button which looks like a target (a circle with a + inside). Add an action and name it “buttonPressed:” for the sake of our example.

8.3 Using The Class Edit Inspector

This way is much more inline with the “OPENSTEP/GNUstep” philosophy. For each object there is an inspector, even for Class objects.

Once you have created the class as described in the previous section “Creating a Class In Gorm”, you must skip to this section to use the inspector. In the Gorm main menu select Tools and then select “Inspectors”. This will make certain that the inspectors window is being displayed. Once the inspectors window is up move the pulldown on the top to “Attributes” a