1. Trang chủ
  2. » Công Nghệ Thông Tin

Lập trình Wrox Professional Xcode 3 cho Mac OS part 11 pps

8 296 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 8
Dung lượng 2,56 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

WINDOWS AND PANES Editing in Xcode occurs in an editor pane.. An editor pane can be part of a multi - pane window, like the project window in the Default style, or it can be the sole co

Trang 1

Editing Text

WHAT'S IN THIS CHAPTER?

Understanding editing windows and panes Navigating text and jumping between fi les effi ciently Editing and reformatting text

Using syntax - aware display and completion features Editing other types of fi les (Rich Text Format, property lists)

In the introduction, I mentioned that Xcode doesn ’ t really do much of the actual development work Most of the heavy lifting is performed by external tools — compilers, linkers,

debuggers, and others — that are not part of the Xcode application, but Xcode does provide one critical tool that is integral to every developer ’ s workfl ow: the text editor You will spend far more time editing source fi les than doing almost any other single task Learning how to edit effi ciently and navigate your source fi les quickly will greatly enrich your productivity

If you ’ ve spent any time at all using Mac OS X, you ’ re familiar with the basic text editing concepts and commands This chapter explores the powerful, and some obscure, extensions that Xcode adds to the core text editing facilities It shows you a variety of techniques and shortcuts for navigating, editing, and reformatting text Xcode also supplies a rich set of language - aware code formatting, coloring, and auto - completion features that make writing source code much more productive Finally, this chapter touches on a number of ancillary topics like fi le encoding, localization, the spelling checker, and printing

Xcode has, what seems like, a thousand features to aid your development, but this also means that there are a thousand features to learn — some of which are rather obscure The more you learn about the ins and outs of the text editor, the more productive you ’ ll be, but you can ’ t learn them all in one sitting Here ’ s how I suggest you approach this chapter:

Trang 2

Skim this and the next chapter to get a general idea of what the Xcode editor has to offer.

Learn to use:

The Functions menu (see “ Jumping to Functions, Breakpoints, and Bookmarks ” ) The Jump to Defi nition and Documentation shortcuts (see the “ Most Productive Shortcuts ” sidebar)

The Jump to Counterpart command (Option+Command+up arrow) The code completion feature (see “ Code Completion ” in Chapter 7) Once you become comfortable with those, return to this chapter to explore more advanced features

WINDOWS AND PANES

Editing in Xcode occurs in an editor pane An editor pane can be part of a multi - pane window, like

the project window in the Default style, or it can be the sole content of a separate editor window

Figure 6 - 1 shows a fi le being edited in three panes: once in the project window, again in the editor

pane of the project fi nd window, and again in an independent editor window

FIGURE 6-1

Editing Panes

Xcode editing panes are homogeneous The features, functions, and capabilities are identical

regardless of where they appear This imparts one extremely useful feature: No matter where a

source fi le appears in Xcode, you have the full power of the Xcode editor at your disposal

Trang 3

The text of a fi le that appears in a search window, the debugger, or the object browser can all be edited immediately without any need to locate the fi le or open another window The same fi le can appear in multiple editing panes at once Changes made to one are refl ected in all

Opening a File in a Separate Window

To edit a fi le in a separate editor window, double - click the source fi le item in the project window

If the fi le already appears in an editing pane of another window, you can force it to open in a new window by choosing the Open in Separate Editor command This command can be accessed from the File menu by holding down the Option key (Option + Command + O) or by Right/Control+clicking

a source fi le in the project group Selecting this command while an edit pane is active opens another window containing the same fi le

Editor Panes in Multi - Pane Windows

The editor pane of a multi - pane window usually tracks some other selection in the window For example, selecting a class in the class browser displays the source of the class ’ s header in its editor pane Clicking a line found in the Project Find window displays the fi le where the line was found in that window ’ s editor pane, and so on

The Project Window ’ s Editor Pane

The editor pane of the project window is no exception, but the behavior is a little more complex

When you ’ re using the Default and All - In - One Xcode styles, the project source list shares a window with the details list and an editor pane Figure 6 - 2 shows all three panes visible at once

FIGURE 6-2

Selecting a single fi le in either the Groups & Files list or the details list immediately brings the contents of that fi le into the editor pane — that is, if the editor pane is visible As you saw in Chapter 3, the details list and the editor pane share the same area in the project window You can

Trang 4

adjust the division between the two by using the divider bar, the View ➪ Zoom Editor In/Out

command, or the Editor button in the toolbar

The Editor toolbar button is shown in Figure 6 - 2, but is not part of the default project window toolbar Choose View ➪ Customize Toolbar to add an Editor button to your toolbar

All three confi gurations of the details list and editor pane are shown in Figure 6 - 3 On the left, only

the details list is visible On the right, only the editor pane is visible In the center, both share the

same area The divider between them can be dragged to the top to fi ll the area with the editor pane,

to the bottom to hide it, or anywhere in between Double - clicking the divider alternately collapses

the editor pane so it is completely hidden, or restores it to its previous location — which could be

at the top, completely hiding the details list

FIGURE 6-3

The View ➪ Zoom Editor In/Out command (Command+Shift+E) is the complement to double

-clicking the divider bar Instead of alternately collapsing and restoring the details pane, it alternately

expands or restores the editor pane When the editor pane is hidden or shares the area with the

detail window (left and center in Figure 6 - 3), the Zoom Editor In command expands the editor

pane so that the details list is completely hidden When the editor pane is expanded, the command

changes to Zoom Editor Out and restores the previous position of the divider bar The Editor button

in the toolbar is equivalent to the Zoom Editor In/Out command in the menu

Holding down the Option key turns the command into Zoom Editor In/Out Fully When used in a

multi - pane window like the project window, Zoom Editor In Fully collapses all other panes This

would be equivalent to expanding the editor, and then collapsing the Groups & Files list so only the

editor pane is visible Zoom Editor Out Fully runs the editor pane back down and re - expands

the Groups & Files list Using the All - In - One window style, this is a quick way of pushing

everything else aside in order to see the code, and may be more convenient than opening the fi le

in a separate window

Normally, the division between the details list and the editor pane stays put until you change it

When the editor pane is collapsed, this requires two commands to edit the contents of a fi le You

Trang 5

must fi rst select the fi le in a list, and then resize the divider or use the Zoom Editor In command before the editor pane is visible If you fi nd yourself doing this often, enable the Automatically Open/Close Attached Editor option in the General pane of the Xcode Preferences Checking this option causes the editor pane to expand automatically whenever a single source fi le is selected in the Groups & Files or details list

Using a Group Editor Window

Xcode, like most document - based applications, creates a new window for every fi le you open in

a separate window If that statement sounds ridiculously obvious, bear with me It can, however,

restrict all fi les to a single separate editing window This mode is accessible only through the toolbar

Grouped/Ungrouped control, shown in Figure 6 - 4

FIGURE 6-4

If the control shows as Ungrouped, opening a new fi le in a separate editor creates a new window

There is no practical limit on the number of separate editor windows you can have open at a time Clicking the button toggles the mode and establishes that window as the “ group ” editing window In this mode, opening a fi le simply changes the fi le being displayed in the active pane of the group editor window; no new windows are created This mode can be used to avoid window clutter The setting of this mode does not affect any other windows that have already been created, and only one window can be designated as the group editor window at a time

Opening Files from the Filesystem

Xcode also lets you open fi les in the traditional manner by picking a fi le in the fi lesystem It will also respond to open document requests from the Finder or any other application Xcode understands the formats of many fi le types that it doesn ’ t “ own ” You can cause Xcode to open a fi le that would normally launch another application by dropping the fi le into Xcode ’ s icon in the dock, as shown

in Figure 6 - 5

Trang 6

Opening an editable fi le using the traditional File ➪ Open command (Command+O) opens

the fi le into the editor pane of the project window or a new editor window — which one you get

is somewhat diffi cult to determine in advance If Xcode has a project window open, Xcode may

open the fi le in the editor pane of the project window Otherwise, the fi le is opened in a new editor

window Opening any fi le that is already displayed in an Xcode window brings that window to the

front Although you can select multiple fi les in the open dialog box, the side effect of some display

rules, like the Grouped mode, can result in only one of the selected fi les being displayed in an

editor pane

Open Quickly by Filename or Symbol

An extremely useful command for fi nding

and opening a fi le is the File ➪ Open Quickly

(Command+Shift+D) command Enter all

or the beginning of any fi lename or symbol into

the Open Quickly dialog box fi eld, as shown in

Figure 6 - 6 Xcode locates all of the fi les with

that name or that defi ne that symbol This

includes all of the fi les in your project and all

of the frameworks to which your project links

Double - click the fi le (or select it and press

Return) in the list to open it

If you have text selected in the editor when you invoke the Open Quickly command, it ’ s used as the default search This makes it really easy to open a header fi le (select the #include fi lename, then press Command+Shift+D) or fi nd the fi le that defi nes almost any symbol

Closing and Saving Editor Panes

Close any window using the File ➪ Close (Command+W) command, or click the close button

in the window ’ s title bar File ➪ Close Project (Command+Control+W) closes the current

project and all windows that belong to that project The File ➪ Close File “ fi lename ” command

(Command+Shift+W) closes all windows currently editing the named fi le

FIGURE 6-5

FIGURE 6-6

Trang 7

TIP TO REMEMBER

Hold down the Option key and click the close button of an independent editor window, or choose File ➪ Close All This closes it and all other editor windows for that project, but not the project or any other type of window This is really useful when you ’ ve been editing for a while and have dozens of editor windows piled up

on the screen

Because Xcode enables you to edit a source fi le in multiple windows simultaneously, there isn ’ t a

one - to - one correspondence between a window and a fi le Unless you use the Close File “ fi lename ”

command, closing a window does not necessarily force you to save the changes made to that fi le

Even closing all of the visible panes where a fi le was being edited might not force the changes to be written The changes are held in memory until committed in response to another command Files that have been modifi ed but not yet saved appear grey in the project window In Figure 6 - 7, the PromiseListViewController.h , PromiseListViewController.m , and DueDatePicker.h fi les have been edited but not saved

FIGURE 6-7

Trang 8

Some actions cause the Save All window to appear automatically Closing a project forces you

to save or abandon the changes made in all unsaved project fi les You can confi gure the Build

commands in the Xcode Preferences to automatically save all unsaved fi les or prompt you for which

ones to save before building

THE EDITOR PANE

It ’ s now time to take a detailed look at the Xcode editor pane, shown in Figure 6 - 9

The editor pane has a number of controls and features In the center, naturally, is the editor with

the content of the fi le being edited Across the top edge is the navigation bar, the various functions

of which are explained later in the “ Navigating Within a File ” section Along the right edge are

the scrollbars and split pane controls On the left edge is the gutter and ribbon, explained later

in the “ Gutter ” section The line running down the right side of the main editing region is the

page guide Depending on your display preferences and the kind of fi le being edited, some of these

features may not be visible See the “ Display Options ” section to fi nd out how to enable or

disable them

FIGURE 6-8

The File ➪ Save (Command+S) command immediately writes the changes made in the active editor

pane to the fi le The File ➪ Save All (Option+Command+S) command presents a dialog box, like

the one in Figure 6 - 8, that lists all of the unsaved fi les Select the fi les to save and click the Save All/

Selected button

Ngày đăng: 04/07/2014, 06:20