4. Working with Files



This chapter introduces the concepts behind working with files in CodeWarrior.


Working with Files Overview

In this chapter we discuss opening, creating, saving, closing, and printing files in the CodeWarrior environment.

The topics in this chapter are:


Creating a New File

To create a new untitled window where source code may be entered, choose the New Text item from the File Menu.

After the new window appears, an insertion point is placed on the first line of the window. When you begin typing, CodeWarrior places text at this insertion point.

To learn more about text editing in the window you have just created, see "Editing Source Code."


Opening an Existing File

There are several ways to open a file with the CodeWarrior IDE:


NOTE:

You cannot open libraries or shared libraries with the CodeWarrior Editor, because of their binary format.

Opening Files with the File Menu

You can open three types of files with the CodeWarrior Editor:


Text File

To open a Text File, choose the Open command from the File Menu. The CodeWarrior Editor displays an Open dialog, as shown in Figure 4.1.

Figure 4.1 Open dialog




Click on the file you would like to open, then click the Open button. CodeWarrior then opens the file in an Editor window.

For more information about editing source code, see "Editing Source Code."


Project File

To open a Project File, choose the Open command from the File Menu. CodeWarrior displays an Open dialog, as shown in Figure 4.1.

Use the Show popup menu to modify the File List to display Text Files, Project Files, or All Files.

Click on the project file you would like to open, then click the Open button. CodeWarrior then opens the project, closing any other project you were working with.

For more information about working with CodeWarrior project files, see "Working with Projects."


Interface File

There are many different ways to open an interface file using CodeWarrior.

Here is one method. If you are editing a C++ .cpp file you can type Alt-Tab, and CodeWarrior will open a new window in the Editor displaying the corresponding .h file. For this to work, your files must have the same name with different extensions. For example, if you are editing the file myFile.cpp and you hit Alt-tab, CodeWarrior will search the Access Paths for the file called myFile.h to open with the Editor.

This method also works if you are editing the .h file and want to see the .cpp file. Just type Alt-Tab and the corresponding file will be opened for you.

Here's a different method. If you're editing any source code file, you can open an interface file mentioned anywhere in the text file with the Open File command.

First, select text in the editor window containing the name of the interface file you would like to open. An example of a file name you might see in a C source code file is stdio.h. You could select stdio.h by double-clicking on the stdio portion of the text. Then, choose the Open File command from the File Menu.

CodeWarrior then searches for the file and opens the file in an editor window.

If you're editing a source code file and want to open an interface file without selecting any text, you may choose the Open File command from the File Menu. This command will use the Access Paths specified for the project to search for the file to open.

CodeWarrior then displays a standard open file dialog, as shown in Figure 4.2.

Figure 4.2 Open Selection



Type the name of the file you wish to search for in the Open editable text field.

To search only the CodeWarrior directory structure (the paths specified in the System Include Path Pane of the Access Paths Panel panel), click on the Search only in the System Tree option to turn it on.

If you want to search both System Include Path Pane and Project Include Path Pane directory trees (all paths specified in the Access Paths panel), turn the Search only in the System Tree option off.

If no project is open, CodeWarrior will search the paths specified by the choices in both the System Include Path Pane and Project Include Path Pane.

You can also type the filename only using a partial path, or full path. For example:


math.h
Sys/types.h
/boot/develop/headers/Be/AppKit/Application.h

See "Access Paths" for more information.


Opening Files from the Project Window

There are three different ways to open files from within the Project Window, depending on the type of the file you wish to see.


TIP:

Files shown in bold typeface cannot be opened and displayed in an Editor Window. If the file was created using another application, double-clicking the file name in the File Column will cause the file to be opened in the application that created it.

File Column

If the file you wish to see appears in the File Column of the Project Window, double-click in the file name to open it.

If the file is a text file, CodeWarrior opens it in an Editor window.

If the file is any other type, CodeWarrior opens the application in which the file was created.



TIP:

To open several files from the File Column at one time, hold down the Alt-key and click each file that you want to see. Then, double-click one of the selected files.

Another way to open a file is to select it, and then press the Enter key.

For more information about the File Column see "File Column."


Group File Pop-up Menu

One way to open a source file is to click on the Group File Pop-up for a particular group so that it pops up, as shown in Figure 4.3. From this pop-up menu you may select the file in the group that you want to open.

You can open a source file by choosing it from the Group File Pop-up menu for the group that contains the file. This works even if the group is collapsed and the file is not visible in the Project window, as shown in Figure 4.3.

Figure 4.3 Group files pop-up in a project window




Interface Files Pop-up Menu



To open a header or interface file, click on the Interface File Pop-up to see a list of files. Select the file you want to open from this list, as shown in Figure 4.4.

Figure 4.4 Interface Files Pop-up Menu in a project window



Files shown in bold typeface in this pop-up cannot be opened.

Note that header files inside "<...>" are system header files located within the develop/headers folder. Files without these symbols are header files you have created and are stored in the project Access Paths Panel.


TIP:

To switch between a source file and its header file, use the same name for both files, except for the extension. For example, name your files foo.cpp and foo.h. Then use Alt -Tab to instantly switch between the two files.

Opening Files from an Editor Window

To open an interface file from a source file, click the Interface Pop-up Menu at the bottom left corner of the Editor Window as shown in Figure 5.1. This pop-up menu lists all interface files used by the source file. Select a file from this menu to open that file in an Editor Window.

An empty menu means your text file does not contain source code, or that the source file has not yet been compiled.

Saving a File

This section describes the many ways that CodeWarrior can save files. The choices are:


Saving One File

To save your changes to the current file, choose Save from the File Menu. CodeWarrior saves your file to disk.

The Save command is dimmed if the window is new and has no data, or if the contents of the active window have already been saved.

Projects are saved when they are closed (the Close command), when you quit CodeWarrior (the Quit command), or when the Save A Copy As command is selected.


NOTE:

If the file is new and untitled, CodeWarrior displays the Save As dialog, described in "Renaming and Saving a File."

Saving All Files

To save your changes to all the files currently open, press the Alt-Opt-S key combination.


TIP:

If your keyboard does not have an Option key, use Alt-Ctrl-S instead to save all open Editor Windows.

The CodeWarrior editor saves all the modified files to disk.


Renaming and Saving a File

If you want to save a new untitled file or save a file under a new name, use the Save As command under the File Menu. If the file is in the current project, CodeWarrior updates the project to use the new name.

When you choose Save As from the File Menu, the CodeWarrior editor displays the dialog shown in Figure 4.5.

Figure 4.5 Save As dialog



Choose the file location and name the file, then click the Save button.

CodeWarrior saves the file and changes the name of the editor window to the name you entered.

If the file is in the current project, CodeWarrior changes the file's entry in the project to match the saved name. If you don't want to change the project, but still want to save the file, you can read how to do this in "Backing Up Files".


Backing Up Files

If you want to save a backup copy of a file before you make some changes to the original, use the Save A Copy As command under the File Menu. CodeWarrior creates a copy of the file under a new name, but leaves the original in the editor window and does not change the project to use the new file name.

After choosing Save A Copy As from the File Menu, the CodeWarrior editor displays the dialog shown in Figure 4.5. Specify the file's save location and name the file. Click Save and CodeWarrior saves a version of the file with a new name. It does not change the file in the editor window or in the current project.

If the project window is the active window, Save A Copy As allows you to save a copy of the project using a new name




Saving as a Be, Macintosh, or DOS text file

CodeWarrior for BeOs opens text files stored in Be, Macintosh, or DOS end-of-line formats. When you save the file, CodeWarrior saves it in its original format.

To save a Be, Macintosh, or DOS text file in a different format, use the Options Pop-up Menu at the bottom-left of the window to specify the document format. For more information, refer to "Options Pop-up Menu" for more information.


Closing a File

Every Editor Window that you have opened is associated with a file on the hard disk. When you close the window, you close the file. You can close all windows or just a single Editor Window.

The topics in this section are:


Closing One File

To close a window, choose Close from the File Menu.

If you close a text file using the File Menu and have not saved your changes, CodeWarrior asks if you want to save the changes before closing the window, as shown in Figure 4.6. If you choose to close the file without saving your changes, all changes are lost.

Figure 4.6 The dialog box for unsaved changes


You can also close a window by clicking the close box of the active window. This is exactly the same as choosing the Close item in the File Menu.

If the active window is the Project Window, closing the window automatically saves the project before the window closes.

For more on saving project files, consult "Saving a Project."

The Close command also saves other properties of the window, such as the size, location, and the selected text in the active window. These options are configured with the "Syntax Styling." See "Font" for information on how to configure these options. If the appropriate options are enabled, the next time the source code file is opened, it will occupy the same position on your screen and the same text will be selected.

For more information about editor preferences, see "Font."


Closing All Files

To close all the open Editor Windows, use the Alt-Opt-W key combination.


TIP:

If your keyboard does not have an Option key, use Alt-Ctrl-W instead to close all open Editor Windows.

Close all doesn't close all CodeWarrior windows, just Editor Windows. The Find dialog and the Project Window remain open.


Printing a File

Use the print options in CodeWarrior to print open files.


Printing a Window

This menu command prints the contents of the active Editor Window. If no text is selected, the entire contents of the active window is printed.

To print all or a portion of a file, choose Print from the File Menu.

CodeWarrior displays the print dialog for your printer.





Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: support@metrowerks.com
Copyright © 1998, Metrowerks Corp. All rights reserved.

Last updated: February 15, 1998 * Chris Magnuson * John Roseborough