You may have noticed that, after you build and run the Moon Travel Planner application, the Finder uses generic icons to represent the application and its document files. In this section, you’ll add icons that inspire an interest in the moon and lunar travel. You won’t need to design any icons; just download the materials provided for this book. See the preface for details.
You’ll do the following:
An important prerequisite to adding icons
to your application is adding the application’s creator code to
the property list. You already entered the Moon Travel Planner creator
code, 'MTPP'
, in Chapter 10.
Icon Composer creates a file with a .icns
extension
in the format used by Mac OS X to store icons. You’ll only import
a thumbnail image for the Moon Travel Planner application. You’d
use the same procedure to import images of other sizes, if you had
them.
Follow these steps to create Icon Composer files for the application
and document icons provided with the Moon Travel Planner application.
These icons are in the MTP.tif
and MTPDoc.tif
files,
respectively. See the preface for details on
how to obtain the materials.
You should follow these procedures twice: once to create an Icon Composer file for the application icon, and the second time to create an Icon Composer file for the document icon:
Double-click
Icon Composer in the /Developer/Applications
directory. Icon
Composer automatically opens an untitled file for your icons.
Choose Import Image from the File menu.
Select the file that contains the application icon, as shown
in Figure 13.3. You
can select the MTP.tif
or MTPDoc.tif
file
provided with the Moon Travel Planner materials. If you created
your own icon, you can use it instead of the one provided.
Choose a data size from the Import To pop-up menu. The MTP.tif
and MTPDoc.tif
files
each contain a thumbnail icon, so you should select “Thumbnail
32 bit data” then click Open. If you have an icon
of a different size, choose the appropriate size from the pop-up menu. The MTP.icns
file
appears in the Icon Composer window, as shown in Figure 13.4.
Add any icons you’ve created in other sizes. Mac OS X requires that you add a thumbnail icon; all other sizes are optional. If you have additional smaller images to import, either repeat steps 2-4 for each image or just drag the desired image from the Finder into the appropriate box in Icon Composer. When you add any icon other than the thumbnail, you’ll see a dialog asking if you want Icon Composer to extract a mask for the image. Unless you have special masking needs, you should let Icon Composer extract the mask. Otherwise, you’ll need to add a mask for each image (other than the thumbnail) you add.
Choose Save from the File menu. Type MTP
or MTPDoc
as
the filename and save the file in the Moon Travel Planner project folder. Icon
Composer automatically appends .icns
to
the filename.
Now that you’ve created the MTP.icns
or MTPDoc.icns
file,
you need to add it to the Moon Travel Planner project, then make
the appropriate settings so the new icon replaces the generic one.
For each file, follow these steps:
Open the Moon Travel Planner project. If the Moon Travel Planner is already open, click its icon in the Dock to make it active.
Add the file to the Moon Travel Planner project. Choose
Add Files from the Project menu. In the sheet that appears, select
the MTP.icns
or MTPDoc.icns
file
and click Open. Then click Add. If you need to, drag
the MTP.icns
or MTPDoc.icns
file
reference to the Resources group.
Now that you’ve added the MTP.icns
file,
you need to make the appropriate settings so the new icon replaces
the generic one:
Open the Application Settings pane. Click the Targets tab, select Moon Travel Planner from the Targets list, and then click the Application Settings tab.
Enter MTP
as the
name of the file. Type MTP
in
the Icon File text field, as shown in Figure 13.5.
Make sure you do not add the .icns
extension; Project Builder does that for you automatically.
Now that you’ve created an Icon Composer file for a Moon Travel Planner document, and you’ve added it to your project, you need to set file type information. Follow these steps:
In the Application
Settings tab, scroll until you can see the Type Information group
box (as shown in Figure 13.6). You must add information for each document type
your application will open or save. The Moon Travel Planner application
will open a custom document type—iTin
(an itinerary
file).
We’ve made up the itinerary file type just to show you how to add a custom file type. If you create your own application that uses a custom file type, you must also define the custom file format and write functions that allow your application to store and retrieve data of that format. The Moon Travel Planner itinerary file type is just a text file.
Enter a name for the file type. In the Name field type Itinerary
.
When you provide type information, you are actually assigning values
to the CFBundleDocumentTypes
property
keys defined in Chapter 10.
The Name field is the CFBundleTypeName
property.
Enter extensions information. This is the CFBundleTypeExtensions
property.
Extensions can help the user distinguish between various types of
document files. Entering extension information is optional. Leave
the Extensions field blank; the Moon Travel Planner application
does not add an extension to document filenames. If
you provide an extension, your file-saving functions should add
the appropriate extension to the filename that the user enters in
the Save dialog.
Enter an OS type. We’re using the four-character code iTin
to
denote the itinerary file type. Type iTin
in
the “OS types” text field. This is the CFBundleTypeOSTypes
property.
Enter a filename for document icon file. Type MTPDoc
in
the “Icon file” text field. Make sure you do not
add the .icns
extension;
that’s done automatically. This is the CFBundleTypeIconFile
property.
Click Add. The document type should appear in the Document Types list, as shown in Figure 13.6.
To add another file type, click in the blank area of the Document
Types list to clear the Type Information fields. Then, repeat steps
2 through 6. The procedure for adding a generic type, such as 'TEXT'
,
is the same as the one for adding a custom type.
Let’s make sure that the application and its documents use the icons you’ve added. You’ll need to build and run the application, then check the icons in the Finder:
Click the Build button in the upper-left corner of the Moon Travel Planner project window.
Click the Run button in the upper-left corner of the project window. Look at the Dock as the Moon Travel Planner application launches. You should see the new icon as the application starts up.
Open an itinerary file. In the Moon Travel Planner application, choose Open Itinerary from the File menu, then select a file to open.
Save the itinerary file under a new name. Choose Save Itinerary As from the File menu and type a new filename.
In the Finder, navigate to the directory where you saved the itinerary file.
If you need to, click the icon view button. The saved itinerary file should appear with the custom document icon.