Borland Online And The Cobb Group Present:


August, 1994 - Vol. 1 No. 8

Launching an external text editor from the IDE

The Borland C++ 4.0 Integrated Development Environment (IDE) provides a very powerful text editor for modifying your applications' source files. However, if you've been using a different DOS or Windows editor for a long time, you may want to continue to use that editor but also use the powerful project maintenance features of the IDE.

To address this situation, you can create a new IDE tool that launches a separate DOS or Windows text editor. In this article, we'll show you how you can start your favorite editor from the IDE to make changes to your source files.

Managing editors

In the May issue of Borland C++ Developer's Journal, we showed you how to create an IDE tool that calls the GREP.COM application from inside the IDE ("Sending GREP's IDE Output to a File"). To launch an external text editor application, we'll use this same general technique to create another IDE tool.

First, you'll open the Tools dialog box and create a new tool. Next, you'll specify the name, path, and command-line arguments for the text editor application from the Tool Options dialog box. You'll also supply the name you want to appear in the Tools menu from this same dialog box.

Once you've defined the text editor tool itself, you'll use the Tool Advanced Options dialog box to tell the IDE which types of source files you'll want to edit with this tool (for example, ASM, C, or CPP files). In this same dialog box, you'll specify that the new tool is a Viewer and you'll configure it to appear on both the Tools menu and the Project window's SpeedMenu.

Finally, you'll specify the new text editor tool as the default tool for one or more of the specified file types. For example, the EditText tool (the integrated text editor) is normally the default tool for CPP, C, H, AutoDepend, ASM, DEF, HPJ, RC, RH, and KB files.

If you make the new text editor tool the default tool for a given type of file, double-clicking on a file of that type in the Project window will cause the text editor tool to open that file. To see this, let's look at an example that makes NOTEPAD.EXE the default editor for source files with a CPP extension.

Obviously, the Windows Notepad utility doesn't have the kinds of features that would make it the text editor of choice for most programmers. However, you can use this same technique to launch Word for Windows, Brief, or any other DOS or Windows text editor from the IDE.

Launch pad

Launch the Borland C++ 4.0 IDE. When the IDE's main window appears, open the project file in which you'll want to use the new text editor tool. For this example, choose Open Project... from the Project menu and then enter

\bc4\examples\windows\whello\whello.ide

in the File Name entry field of the Open Project File dialog box and click OK.

If you'd rather use the new text editor tool in all your new projects, close any open projects. By doing this, you'll ensure that the new text editor tool is part of the IDE's default project file. If you add an IDE tool to the default project file, you'll be able to use that tool from any new projects you create.

To begin adding the new text editor tool, choose Tools... from the Options menu. When the Tools dialog box appears, click New....

When the Tool Options dialog box appears, enter Notepad in the Name entry field and then enter NOTEPAD.EXE in the Path entry field. (This assumes that the NOTEPAD.EXE application is in a directory that appears in the current PATH statement of your CONFIG.SYS file. If NOTEPAD.EXE is in a different directory, enter the full directory path and filename for the application.)

In the Command Line entry field, enter $EDNAME. This parameter tells the IDE to pass the name of the current file to this tool when you run the tool.

Enter Notepad in the Menu Text entry field and then enter Edit using the Windows Notepad in the Help Hint entry field. These two entries will help you identify this tool when it appears on the Tools menu or on the Project window's SpeedMenu. When you finish, the Tool Options dialog box should resemble the one shown in Figure A.


Figure A - You use the Tool Options dialog box to configure a new IDE tool.

Click Advanced... to display the Tool Advanced Options dialog box. In the Tool Type section, select the Viewer radio button. In the Tool Usage section, select the Place On Tools Menu check box and the Place On SpeedMenu check box.

In the Applies To entry field and the Default For entry field, enter

.cpp; 

When you finish, the Tool Advanced Options dialog box should look like the one shown in Figure B. Click OK to save the settings in the Tool Advanced Options dialog box. When this dialog box closes, click OK in the Tool Options dialog box to save the new Notepad tool. When the Tools dialog box reappears, click Close.


Figure B - You use the Tool Advanced Options dialog box to tell the IDE how to use the new tool.

Now, double-click on the file whello [.cpp] in the Project window. The IDE will launch the Windows Notepad application and load it with the WHELLO.CPP source file, as shown in Figure C.


Figure C - You can make the Windows Notepad or any other DOS or Windows text editor the default editor for the IDE.

To close the Notepad edit window for the WHELLO.CPP file, choose Exit from the Notepad application's File menu. To close the IDE, choose Exit from the IDE's File menu.

The integrated editor is still there

If you change the default text editor for source files by creating a new text editor tool, the IDE won't always use that editor when it opens a file. In particular, if you create a new file by choosing New from the File menu, or if you open an existing file by choosing Open... from the File menu, the IDE will use the integrated editor to display the file.

Similarly, if you view a syntax error in a source file by double-clicking on the error in the Message window, the IDE will use the integrated editor to open the file. This happens because not all text editors accept line and column numbers (specifying the location of the error) as command-line arguments. Therefore, the IDE might not be able to position the cursor at the location of the error if it didn't use the integrated editor to view the result of error messages.

If you're running the IDE from OS/2 . . .

If you're running the Borland C++ 4.0 IDE under OS/2 2.1, you'll be able to launch an OS/2 text editor using the same technique we've shown for launching DOS or Windows editors. However, since the OS/2 applications may not exist in directories that are part of the DOS path for your WIN-OS/2 session, you'll probably need to specify the full path when you create a tool for an OS/2 text editor.

Conclusion

The integrated editor that's part of the IDE is adequate for many programmers. If the integrated editor doesn't have the features you need or want, you can use the technique we've shown here to launch a separate DOS or Windows editor application.

Return to the Borland C++ Developer's Journal index

Subscribe to the Borland C++ Developer's Journal


Copyright (c) 1996 The Cobb Group, a division of Ziff-Davis Publishing Company. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of Ziff-Davis Publishing Company is prohibited. The Cobb Group and The Cobb Group logo are trademarks of Ziff-Davis Publishing Company.