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

Lập trình Wrox Professional Xcode 3 cho Mac OS part 13 pptx

6 277 0

Đ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 6
Dung lượng 1,9 MB

Nội dung

The following table lists the functions of the navigation bar controls. CONTROL FUNCTION File History Jumps to a fi le that has been edited in this pane Functions Jumps to a function, defi nition, or marker in the fi le Bookmarks Jumps to a bookmark set in the fi le Breakpoints Jumps to a breakpoint set in the fi le Class Hierarchy Jumps to related class defi nitions Included Files Jumps to an included fi le, or a fi le that includes this fi le Counterpart Jumps to the counterpart of this fi le Lock Locks or unlocks the fi le The Lock button toggles the lock (read - only) attribute of the fi le. If you lock a fi le, or the fi le was locked when it was opened, the editor will be in display - only mode. If you attempt to change the document, Xcode warns you that you cannot edit the fi le. You can override this mode in the dialog box and make changes to the document, but that does not change the permissions of the fi le and you will not be able to save changes until the fi le is made writable. Unlocking a fi le automatically switches the editor to its normal editing mode. See the option Save Files As Writable in the “ Display Options ” section of this chapter. Numerous Xcode features rely on knowledge about your program ’ s symbols and source fi les obtained from the Code Sense index. This includes features like jumping to a symbol defi nition, the Class Hierarchy menu, Included Files menus, and auto - completion — just to name a few. By default, Code Sense is enabled for all projects so this shouldn ’ t present an obstacle, but if any of these features aren ’ t working, see the “ Code Sense ” section in Chapter 7. You may need to turn on Code Sense or reindex your project. All of the other navigation controls are explained in the “ Navigating Within a File ” section, later in this chapter. DISPLAY OPTIONS The appearance of an editor pane can be customized in a number of different ways and a variety of options determine how the text itself is interpreted and displayed. The following table lists the principal display options. Display Options ❘ 99 c06.indd 99c06.indd 99 1/22/10 12:19:38 PM1/22/10 12:19:38 PM Download at getcoolebook.com 100 ❘ CHAPTER 6 EDITING TEXT DISPLAY OPTION COMMAND EFFECT Line Wrap View ➪ Text ➪ Wrap Lines Wraps lines wider than the window to the next line Show Control Characters View ➪ Text ➪ Show Control Characters Makes control characters visible Show Spaces View ➪ Text ➪ Show Spaces Makes space (ASCII 3 2) characters visible Show Issues View ➪ Message Bubbles ➪ Show Issues Shows message bubbles in the gutter Navigation Bar View ➪ Layout ➪ Show Navigation Bar Shows the navigation bar Status Bar View ➪ Layout ➪ Show Status Bar Shows the status bar Toolbar View ➪ Show Toolbar Shows the toolbar Text Wrapping The View ➪ Text ➪ Wrap Lines command toggles between wrapped and unwrapped editor modes. With line wrapping turned on, lines that exceed the width of the window are split at some convenient point and continued on the next line in the editor. When line wrapping is off, long lines simply continue off the right edge of the editor pane. If one or more lines exceed the width of the editor, a horizontal scrollbar appears at the bottom of the pane. Invisible Characters Control characters and the space character are normally invisible. Two more commands in the View ➪ Text menu, Show Control Characters (Command+Shift+6) and Show Spaces, make those characters visible. Show Control Characters is particularly useful for fi nding gremlins — illegal control characters in a source fi le. This option does not show any of the normal control characters: tab, newline, or return. Show Spaces marks the location of each ASCII space character with a spacing bracket. Select either command again to toggle them back off. The font and size of the text used for all editor panes are set in the Fonts & Colors tab of the Xcode Preferences. These settings are described in the “ Syntax Coloring ” section of Chapter 7. Global Display Options Several global settings control the appearance of editor panes for all windows. These are in the Text Editing tab of the Xcode Preferences, as shown in Figure 6 - 14. c06.indd 100c06.indd 100 1/22/10 12:19:47 PM1/22/10 12:19:47 PM Download at getcoolebook.com Editor Pane Display Options Show Gutter enables the display of the gutter in regular editor panes. Without the gutter, you cannot see or set breakpoints or fi nd where the execution of the application is currently paused. Because of this, the gutter is automatically displayed whenever you start a debugging session, and is hidden again when the debugging session ends. The editor pane in the Debugger window always shows a gutter. Show Line Numbers displays the number of each line in the gutter. The Show Gutter option must be enabled for line numbers to be visible. Show Column Position adds a column number to the fi lename of the current fi le in the history control of the navigation bar. The navigation bar must be visible for this option to have any effect. When this option is enabled, the name of the current fi le indicates both the line and column number of the current insertion point or the beginning of the text selection. If the option is disabled, only the fi le ’ s name and line number are displayed. The code folding ribbon is described in the “ Code Folding ” section of Chapter 7. The Code Focus option actively highlights the code block your cursor is currently hovering over. You may fi nd it amazingly useful or merely annoying — perhaps both. Turning on the Show Page Guide option causes a vertical line to be drawn at the column number specifi ed in the Display at Column fi eld. Some coding styles require all program text to fi t within a certain number of columns. If you are adhering to such a coding style, or are formatting text for a fi xed - width output device, the page guide is very useful. Note that the page guide is based on the em - width of the font (traditionally, the width of a capital M ) and is only accurate when you ’ re using fi xed - width fonts. FIGURE 6-14 Display Options ❘ 101 c06.indd 101c06.indd 101 1/22/10 12:19:48 PM1/22/10 12:19:48 PM Download at getcoolebook.com 102 ❘ CHAPTER 6 EDITING TEXT Editing Options The Editing Options consist of Insert Opening Bracket and Select to Matching Brace options. The Insert Opening Bracket option is a gift to Objective - C programmers. Objective - C statements are enclosed between square brackets, and can be nested like this: [self setDelegate:[[[MyDelegate alloc] init] autorelease]]; A persistent problem for Objective - C programmers is the situations where they have failed to insert enough opening braces at the beginning of the statement and end up with mismatch brackets at the end, like this statement: [[MyObject alloc] init] autorelease]; Turning the Insert Opening Bracket option on automatically inserts the missing opening bracket whenever the programmer types an unbalanced closing bracket. The Select to Matching Brace option is useful in structured languages that use braces, brackets, parentheses, and quotes to delimit blocks of text or code. With this option enabled, double - clicking any of the following characters selects the block of code/text enclosed by it and its matching delimiter: { [ ( ' " ) ] } For example, double - clicking a single or double quote selects a string. Double - clicking an open parenthesis selects the parenthetical statement it encloses. Double - clicking a curly brace selects an entire block of code. The editor takes nested delimiters into account. The Omit Braces in Selection option refi nes this feature by determining whether the text selected will include the delimiters in the selection, or just the text between the delimiters. Save Options The Save Options are an eclectic set of options that deal with fi le permissions and line endings. The Save Files as Writable option causes Xcode to set the POSIX write permission of a fi le when it is saved. With this option off, Xcode preserves the POSIX write permissions the fi le had before it was saved. That is, if the fi le were read - only it will be left read - only. When opening a read - only fi le, Xcode puts the editor pane in display - only mode. Any attempt to change the fi le is met with a warning, as shown in Figure 6 - 15. This is mostly to prevent you from trying to edit read - only fi les that belong to frameworks. c06.indd 102c06.indd 102 1/22/10 12:19:49 PM1/22/10 12:19:49 PM Download at getcoolebook.com Clicking the Allow Editing button puts the editor pane in its normal editing mode, but it does not change the permissions of the underlying fi le. In this state, Xcode refuses to save the fi le from the Save All window. However, you can save the fi le by using the File ➪ Save command directly or by starting a Build with the Always Save option selected. Xcode temporarily makes the fi le writable, writes the changes, and then restores the read - only permissions of the fi le. The editor pane remains editable. Set the Save Files as Writable option and Xcode will not restore the read - only permissions after a save, leaving the fi le writable. After the save, the fi le will behave like any other writable fi le. This behavior applies to the POSIX write permissions for the fi le. The other method of making a fi le unwritable is to set its POSIX immutable fl ag. (On an HFS fi lesystem, this fl ag is synonymous with the HFS locked attribute.) You can set or clear this fl ag by using the Lock button in the navigation bar, or in the Get Info window for the fi le in the Finder. The POSIX immutable fl ag is never overwritten by Xcode, making it a more secure method of preventing changes to a fi le than merely denying write permission. A locked fi le behaves the same as a fi le that lacks write privileges, except that File ➪ Save does not change the status of the immutable fl ag or write to the fi le. Instead, Xcode displays a simple error dialog box explaining that it cannot write to the fi le. To make changes to the fi le, you must fi rst click the Lock control in the navigation bar to unlock the fi le. File Encoding The remaining options in the Text Editing tab deal with line endings and character encoding. Under Line Encodings, the For New Files option determines the line endings for fi les created in Xcode. The choices are to end each line with a single LF character (Mac OS X or UNIX format), a single CR (Mac OS 9 and earlier format), or a CR+LF sequence (Microsoft DOS format). Unless you have some specifi c reason to use CR or CRLF line endings, all text fi les should be written using LF. The For Existing Files option determines the line encoding for fi les that are saved in Xcode. If this option is set to something other than Preserve, any fi le saved in Xcode will have its line encoding automatically converted into the selected format. The Preserve setting saves the fi le in whatever line encoding format it had when it was opened. Use the Default File Encoding option to choose the character encoding that will be used for any fi le where Xcode does not know its character encoding. This applies to existing text fi les being added to a project, or any text fi le opened in Xcode that does not belong to an open project. If an FIGURE 6-15 Display Options ❘ 103 c06.indd 103c06.indd 103 1/22/10 12:19:49 PM1/22/10 12:19:49 PM Download at getcoolebook.com 104 ❘ CHAPTER 6 EDITING TEXT open project contains a source fi le item that refers to the fi le being opened, the character encoding recorded in that source item is used. NAVIGATION WITHIN A FILE You ’ ll probably spend more time moving around in your source code than you ’ ll spend writing it. Programming just isn ’ t a linear activity. One rarely sits down and types out a function of any consequence from start to fi nish. Knowing how to move around your source code quickly and decisively will greatly enhance your effi cacy. Cursor Movement Start with just moving around in a single source fi le. The following table lists the key combinations that simply move the cursor around in the text. All of the key combinations in this chapter are based on the key binding set named “ Xcode Defaults. ” This is the default set when Xcode is installed. Key bindings — the mapping of key combinations to actions — are extremely fl exible and can be customized extensively. Xcode includes key binding sets that approximate the key combinations used in BBEdit, Metrowerks ’ CodeWarrior, and the venerable MPW system. You are also free to devise your own key binding sets. See Chapter 23 for a complete description of key bindings and how to alter them. If you have changed the key bindings in the Xcode Preferences, you may want to set them back to the Xcode Default set while working through this chapter. KEY COMBINATION CURSOR MOVEMENT Right arrow, Control + F Next character Command + right arrow, Control+ E End of line Option + right arrow End of next word Control + right arrow End of next subword Left arrow, Control + B Previous character Command + left arrow, Control + A Beginning of line Option + left arrow Beginning of previous word Control + left arrow Beginning of previous subword Up arrow, Control + P One line up Command + up arrow Beginning of document c06.indd 104c06.indd 104 1/22/10 12:19:50 PM1/22/10 12:19:50 PM Download at getcoolebook.com . created in Xcode. The choices are to end each line with a single LF character (Mac OS X or UNIX format), a single CR (Mac OS 9 and earlier format), or a CR+LF sequence (Microsoft DOS format) The Save Files as Writable option causes Xcode to set the POSIX write permission of a fi le when it is saved. With this option off, Xcode preserves the POSIX write permissions the fi le had before. to a project, or any text fi le opened in Xcode that does not belong to an open project. If an FIGURE 6-15 Display Options ❘ 1 03 c06.indd 103c06.indd 1 03 1/22/10 12:19:49 PM1/22/10 12:19:49 PM Download

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