Выбрать главу

Make that change and save the file. Note that by default, Eclipse does not automatically save any changed files before it builds a project. There is a preference option to save automatically before a build.[2] We’ll look at preferences later in this chapter.

There are several ways to build the project. For now select Project→Build All. The Problems view now shows a syntax error and tells us where it is. The error line is also identified in the editor with an icon in the marker bar. By default, problems are grouped by severity with different icons in the first column representing warnings and errors. If there are several items in the Problems view, clicking on an item moves the editor to the corresponding line, opening the file if necessary.

The Problems view can be filtered to show only warnings and/or errors for a particular resource or group of resources (Figure 3.8). Filters are accessed from the Problems view menu→Configure filters…. You can create multiple filters and enable and disable them as needed. Filters are “additive” so that any problem that satisfies at least one enabled filter will be shown.

Figure 3.8: Problems filter.

Problems can also be sorted along several dimensions by selecting Sort By from the Problems view menu.

3.3.2 Tasks View

The Tasks view lets you create tasks related to the project and link those tasks to specific resources. There are several ways to add a task to the list. Right-click in the Tasks view and select Add Task to bring up the dialog in Figure 3.9. Here you can enter a description of the task and its priority. You can even check the task as completed although it’s a little hard to understand why you would be adding a task that’s already completed.

Figure 3.9: Add Task dialog.

There are text boxes for entering an Element, Folder, and Location, but oddly enough you can’t enter anything there. So tasks created by this method can’t be linked to a resource. To create a task linked to a resource, hello.c for example, right-click in the marker bar on the left side of the editor window and select Add Task. Try it on the comment line that says “Copyright.” The same dialog box comes up but now it’s labeled Properties instead of Add Task, and the Element, Folder, and Location fields are filled in.

Change the description to “update copyright” and click OK. A task icon appears in the marker bar at line 6. Like Problems, Tasks can be filtered to show only a relevant subset and can be sorted along several dimensions. Your Task view should look something like Figure 3.10.

Figure 3.10: Task view.

3.3.3 Console View

The primary role of the Console view is to display program output, and output from the build tools. The Console view is connected to stdin, stdout, and stderr. Although several consoles may be open at any given time, only one is visible in the view. An icon on the tab bar lets you select the visible console.

Figure 3.11 shows two different console views (a and b). When a program is running in the console, a red rectangle icon appears that can terminate the program. Other icons remove terminated console views, clear the console, open a new console, and lock scrolling.

Figure 3.11: Console views (a and b).

The Console view only represents programs that are running on the host. Programs running on an external target will display their output in some other fashion, such as a terminal emulator window. In Chapter 6, “Device Software Development Platform,” we’ll look at an Eclipse project that makes remote programs visible in the Console view.

3.3.4 Properties View

Every object and/or resource in Eclipse has certain “properties,” the natures of which depend on the type of object. The Properties view shows the properties of any object selected in one of the other views. With the Properties view visible, click on the project name “hello” in the Project Explorer view to bring up something like Figure 3.12.

Figure 3.12: Properties view.

Click on “hello.c” in the Project Explorer view to see a slightly different set of properties. The Properties view is read-only — you can’t change anything here — and to be honest, it doesn’t tell you a whole lot. A more extensive, editable view of properties is available from an object’s context menu described later in this chapter.

Thus far we’ve explored several of the more common views available in Eclipse. Later on we’ll encounter other views more specific to the C development environment.

3.4 Menus

Like any good windowing program, Eclipse has a set of menus arrayed across the top of the main display window. Most of the items in these menus are fairly familiar, but a few deserve some additional description.

3.4.1 File Menu

This is a fairly standard file menu. Some additional items worth mentioning are:

• Convert Line Delimiters To: Changes how text lines are terminated for the selected file. Each of the three major operating systems that Eclipse supports has a different convention for how text lines are terminated:

 1. Unix (default): Line feed (0xa)

 2. Windows: Carriage return and line feed (0xd, 0xa)

 3. Mac OS/9: Carriage return (0xd)

 The changes are immediate and persist until you change the delimiter again. It’s not necessary to explicitly save the file.

• Import: Allows resources to be imported into the selected project.

• Export: Allows resources to be exported out of a project to some other location.

• Switch Workspace: Allows you to change to a different workspace. This restarts the workbench.

3.4.2 Edit Menu

The Edit menu also has many of the familiar options. Some Eclipse-and CDT-specific features include:

• Incremental Find Next/Previous: Search for expressions in the active editor. As you type the search expression, Eclipse incrementally jumps to the next/previous exact match.

• Add Bookmark: Adds a bookmark in the active file on the line where the cursor is displayed.

• Add Task: Adds a task in the active file on the line where the cursor is displayed.

• Word Completion (Alt + /): Attempts to complete the word currently being entered in the active editor.

• Quick fix: Supposedly offers suggestions on correcting certain errors when the cursor is on a line that has an error. Unfortunately, the only thing I’ve seen so far is “No suggestions available.”

• Content Assist: Opens a dialog at the current cursor location to offer assistance in the form of proposals and templates. The templates can be configured through the Window menu at Window→Preferences→C/C++→C/C++ Editor→Content Assist.

• Parameter Hints: Displays the parameter portion of a function prototype.

вернуться

2

Personally, I think that should be the default.