All Manuals > LispWorks IDE User Guide > 19 The Interface Builder

19.5 Editing and saving code

As you create an interface in the Interface Builder, source code for the interface is generated. You can use the code view to examine and, if you want, edit this code. You can also save the source code to disk for use in your application. This section discusses how to edit and save the code generated by the Interface Builder, and discusses techniques which let you use the Interface Builder in the most effective way.

19.5.1 Integrating the design with your own code

As your GUI evolves from design into the implementation phase, you will need to integrate code generated by the Interface Builder with your own code to produce a working application.

At one extreme, you can attempt to specify the entire GUI for an application using the Interface Builder: even callbacks, keyboard accelerators for menu items, and so on. This way the source code for the entire GUI would be generated automatically. However, this is not the recommended approach.

Instead you should use the Interface Builder for the basic design and initial code generation only. Once you have created an interface skeleton for your window or dialog that you are happy with, augment the automatically-generated source code with hand-written code. At this stage, you will use the Editor tool, rather than the Interface Builder, to develop that window or dialog.

19.5.2 Editing code

Click the Code tab to switch to the code view. You can use this view to display and edit the code that is generated by the Interface Builder. The Interface Builder appears as shown in Displaying source code in the Interface Builder.

Displaying source code in the Interface Builder

Like the other views in the Interface Builder, an Interface: box at the top of the code view displays the name of the current interface. See 19.3.1 Interface box for details.

The rest of this view is dedicated to an editor window that displays the code generated for the interface. Like other editor windows in the LispWorks IDE, all the keyboard commands available in the built-in editor are available in the Code area.

19.5.3 Saving code

There are several ways to save the code generated by the Interface Builder into files of source code. Any files that you save are also displayed as buffers in the editor.

Choose File > Save or click to save the current interface. If it has already been saved to a file, the new version is saved to the same file. If the interface has not been saved before, you are prompted for a filename. After saving, the file is displayed in the editor.

Choose File > Save As... to save the current interface to a specific file. This command always prompts you for a filename; if the interface has not been saved before, this command is identical to File > Save, and if the interface has already been saved, this command saves a copy into the file you specify, regardless of the file it was originally saved in. After saving, the file is displayed in the editor.

Choose File > Save All to save all of the interfaces that have been modified. A dialog allows you to specify precisely which interfaces to save. Choosing this command is analogous to choosing File > Save individually for each of the interfaces you want to save. If there are any interfaces which have not been saved previously, you are prompted for filenames for each one.

Choose File > Revert to Saved to revert the current interface to the last version saved.

Choose File > Close to close the current interface. You are prompted to save any changes if you have not already done so. The interface name is removed from the History > Items submenu.

Individual interface definitions are saved in an intelligent fashion. You can specify the same filename for any number of interfaces without fear of overwriting existing data. Interface definitions which have not already been saved in a given file are added to the end of that file, and existing interface definitions are replaced by their new versions. Source code which does not relate directly to the definition of an interface is ignored. In this way, you can safely combine the definitions for several interfaces in one file, together with other source code which might be unrelated to the user interface for your application.

Conversely, when loading interfaces into the environment (using File > Open or ), you do not have to specify filenames which only contain definitions of interfaces. The Interface Builder scans a given file for interface definitions, loads the definitions that you request, and ignores any other code that is in the file. See 19.2.2 Loading existing interfaces for details on loading interfaces into the Interface Builder.

This approach to saving and loading interface definitions ensures that your working practices are not restricted in any way when you use the Interface Builder to design a GUI. You have complete control over the management of your source files, and are free to place the source code definitions for different parts of the GUI wherever you want; the Interface Builder can load and save to the files of your choice without failing to load interface definitions and without overwriting parts of the source code which do not relate directly to the GUI.


LispWorks IDE User Guide (Windows version) - 01 Dec 2021 19:38:04