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

8 162 0
Lập trình Wrox Professional Xcode 3 cho Mac OS part 78 pptx

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

Thông tin tài liệu

Customizing Xcode WHAT'S IN THIS CHAPTER? Setting expert preferences Changing command key shortcuts and editor key bindings Using alternate editor applications Creating custom text macros and command scripts Making your own project, fi le, and target templates Apple is famous for developing spare and elegant software. Rare indeed is the Apple application that suffers from “ featurosis ” — a malady of ever - expanding specialized features that eventually smother an application in an incomprehensible maze of commands and options. Developers, however, are not consumers. At least they don ’ t think of themselves as consumers. Developers are professionals that expect, nay demand, that almost every aspect of the tools they use be under their control to alter, repurpose, and tweak as they see fi t. I have personally worked with a developer who, dissatisfi ed with the warnings produced by a compiler, downloaded its source code, corrected the perceived fl aw, and built his own personalized version to use. Although the wisdom of his actions are debatable, the spirit of “ if you don ’ t like the way it works, build your own ” runs deep and strong through the developer community. For this reason, Xcode is a departure from most software produced by the engineering teams at Apple. Xcode has a dizzying array of customizable options, as witnessed by the monstrous Xcode Preferences window. Using the Xcode interface, you can completely customize the keystrokes used to invoke every Xcode command and motion. The extensive set of build settings enable you to specify any of the innumerable switches passed to compilers, linkers, and other tools employed by Xcode. You can completely reorganize the build process, and even assume complete responsibility for it. You are free to use a different text editor. You can ➤ ➤ ➤ ➤ ➤ 23 c23.indd 639c23.indd 639 1/22/10 1:28:29 PM1/22/10 1:28:29 PM Download at getcoolebook.com 640 ❘ CHAPTER 23 CUSTOMIZING XCODE even alter seemingly inconsequential interface details, such as the highlight colors used by the debugger. Surprisingly, the list doesn ’ t stop there. There are scores of hidden and undocumented customizations in Xcode. Most are application settings that you can alter by editing the Xcode preferences fi le, as discussed in this chapter. You can also create your own templates and customize the Xcode application by adding your own commands. Most undocumented features are unsupported by Apple and the Xcode development team. I ’ ve tested every customization presented in this chapter, but that doesn ’ t mean they will work in future versions of Xcode. Customization features that turn out to be popular are often re - implemented and appear in future versions in a friendlier and better - supported form. Check the release notes for the feature you are looking for. XCODE PREFERENCES If you came to this chapter looking for the meaning of a particular Xcode preference setting, most of them are discussed in the chapter that the setting applies to. For example, the options in the Code Sense tab are discussed in the “ Code Sense ” section in Chapter 7. To point you in the right direction, the following table lists the tabs in the Xcode Preferences window and the chapter where those settings are explained. PREFERENCE TAB CHAPTER General 3 and 6 Code Sense 7 Building 17 Distributed Builds 17 Debugging 18 Key Bindings 23 Text Editing 6 Font & Colors 6 Indentation 6 File Types 6 c23.indd 640c23.indd 640 1/22/10 1:28:32 PM1/22/10 1:28:32 PM Download at getcoolebook.com PREFERENCE TAB CHAPTER Opening Quickly 6 Source Trees 21 SCM 21 Documentation 12 FIGURE 23 - 1 The Xcode documentation also describes the preference settings for each topic. Chapter 12 of this book provides assistance in browsing the Xcode Help documents. KEY BINDINGS The only preference tab not covered in the other chapters is Key Bindings. The Key Bindings pane, shown in Figure 23 - 1, allows you defi ne the keystroke combination associated with just about every command and action that Xcode performs. You will also see that a few actions are inaccessible in Xcode ’ s default confi guration and can only be accessed by assigning them a key binding. Key Bindings ❘ 641 c23.indd 641c23.indd 641 1/22/10 1:28:37 PM1/22/10 1:28:37 PM Download at getcoolebook.com 642 ❘ CHAPTER 23 CUSTOMIZING XCODE Key bindings are stored in sets. Use the Key Binding Sets pop - up menu to switch between any of the predefi ned sets that ship with Xcode, or any sets that you ’ ve defi ned. Choose a set and click the Apply or OK button, and the new bindings take effect immediately. If you want to create a new binding set, select a base set and click the Duplicate button. Give the key binding set a name, as shown in Figure 23 - 2. To delete the selected set, click the Delete button. You cannot edit or delete predefi ned sets. To customize one of the predefi ned sets, duplicate it and edit the new set. If you try to edit a predefi ned key binding set, Xcode offers to fi rst duplicate the set. FIGURE 23 - 2 Menu Key Bindings The Key Bindings pane has two tabs: Menu Key Bindings and Text Key Bindings. Menu key bindings, previously shown in Figure 23 - 1, bind keyboard shortcuts with the items in the Xcode menus. Menus items that are created dynamically, such as the list of recently opened projects, cannot be bound. To edit a menu key binding, fi nd the menu item in the hierarchy of menu groups and double - click its Key cell in the table. The menu item ’ s current binding turns into an editable fi eld, as shown in Figure 23 - 3. This is not a normal text edit fi eld; it captures any single keystroke or combination you press. You ’ ve used it most recently in Chapter 22 when assigning keyboard shortcuts to actions. To bind Command+P to the Xcode ➪ Preferences command, press Command+P on the keyboard. Instead of invoking the File ➪ Print command, Xcode captures the shortcut and replaces the previous key binding. Also shown in Figure 23 - 3 is a warning at the bottom of the pane that “ ~CM - P is currently bound to Print. ” This is a warning that the key binding that you chose for this command is currently assigned to another command. If you accept this key binding, the binding on the other command will be removed. This is your only warning that a confl icting key binding will be removed, so check for confl ict messages before assigning a binding and immediately enter a shortcut combination that doesn ’ t confl ict with another command before going on. Unless, of course, your intention is to reassign that shortcut to a different command, in which case that ’ s exactly what you ’ ll get. c23.indd 642c23.indd 642 1/22/10 1:28:38 PM1/22/10 1:28:38 PM Download at getcoolebook.com To accept a key binding change, click outside the edit fi eld. There is no keyboard shortcut to accept a binding, because any keystroke you press will be captured as the new binding. To remove a key binding, double - click the binding to enter edit mode and then click the grey – button to the right of the cell. Traditionally, key bindings for menu items are Command key combinations. However, you are free to assign any keystroke combination you want. Existing examples are commands like Edit ➪ Next Completion, which is bound to Control+., or Edit ➪ Select Next Placeholder, which is bound to Control+/. Be judicious in these assignments — for example, assigning the Tab key to the Xcode ➪ Quit command is not recommended. Letter keys have no sense of case in key bindings. Command+A is one key combination, and Command+Shift+A is a different key combination. The state of the Caps Lock key has no infl uence on key bindings. FIGURE 23 - 3 Key Bindings ❘ 643 c23.indd 643c23.indd 643 1/22/10 1:28:39 PM1/22/10 1:28:39 PM Download at getcoolebook.com 644 ❘ CHAPTER 23 CUSTOMIZING XCODE When editing key bindings, Xcode displays the symbols listed in the following table for special keys: SYMBOL KEY ~CM Command ~OP Option ~SH Shift ~CT Control  Left Arrow  Right Arrow  Up Arrow  Down Arrow  Tab  Esc Delete (backspace) Delete (forward)  Page Up  Page Down  Home  End  Return  Enter Space Space Text Key Bindings Text key bindings are the keystrokes that the text editor interprets as actions. By altering the text key bindings, you can change the behavior of the Xcode text editor. Editing a text key binding is almost identical to the procedure for editing menu key bindings, as you can see in Figure 23 - 4. The only signifi cant difference is that you can assign multiple key bindings to the same action. Any of the key combinations listed will invoke that action. c23.indd 644c23.indd 644 1/22/10 1:28:39 PM1/22/10 1:28:39 PM Download at getcoolebook.com To alter a key binding, double - click the Keys fi eld of the binding. Set the fi rst, or replace the existing, key combination by typing the desired combination. To add additional key combinations to the same action, click the + button to the right side of the edit fi eld, as shown in Figure 23 - 4. To delete a specifi c key combination, click the combination in the list to select it and then click the – button. FIGURE 23 - 4 Key Bindings ❘ 645 In the editor, any regular character key that is not assigned an action is inserted literally into the text — assuming the encoding of the document permits it. To give you an idea of the kind of subtle change you can make to the editor, I ’ ll step you through the process of turning off the automatic indenting that normally occurs when you press the Tab key. Pressing the Tab key in most text editors simply inserts a tab character into the text. If you look at the key bindings for Xcode, you ’ ll see that the Tab key is tied to the Insert Tab action. On the face of it, it would appear that Xcode does the same thing. In reality, Insert Tab adds an additional level of convenience; it automatically re - indents the line after inserting the tab. The insert tab action that does nothing but insert a single tab character is named, cleverly, Insert Tab Without Extra Action. Normally, the automatic re - indenting of your text is a huge convenience, but you might fi nd yourself in a situation where you just want a tab to be a tab. You can fi x this in the key bindings for the editor, as follows: 1. Open the Key Bindings tab of the Xcode Preferences. If you don ’ t have your own key bindings set already, duplicate the current key bindings set and give it a new name. c23.indd 645c23.indd 645 1/22/10 1:28:40 PM1/22/10 1:28:40 PM Download at getcoolebook.com 646 ❘ CHAPTER 23 CUSTOMIZING XCODE 2. In the Text Key Bindings table, fi nd the Insert Tab action and double - click its current binding (usually the Tab key). 3. Hold down the Option key and press the Tab key. Click outside the fi eld to set it. 4. Click the OK button to adopt the new key bindings. Editing the text key bindings changes the key combinations that Xcode will use in all text editor panes. In steps 2 and 3, you replaced the key binding for the Insert Tab action — the action with the extra features — with Option+Tab. Because the Option+Tab was previously bound to Insert Tab Without Extra Action, Xcode warned you of the confl ict (see the bottom of Figure 23 - 4) and deleted that binding when you accepted the new one. Now the Tab key (alone) has no binding. Without a special key binding, the Tab key is treated like any other character. No special reformatting or navigation is attached to inserting a single tab character any more. Alternatively, you could have accomplished the same thing by binding the Tab key to the Insert Tab Without Extra Action action. Because the Tab key represents the tab character, both are equivalent. Key bindings are global, and both the menu key bindings and text key bindings share the same table. A key combination can only be assigned to a single menu command or editor action. Keep this in mind when you ’ re assigning non - Command key combinations to menu commands and vice versa. Key bindings are stored by name in your local ~/Library/Application Support/Xcode/Key Bindings folder as .pbxkeys fi les. You can exchange key binding fi les with other users. To install a key binding fi le, quit Xcode, copy a key bindings fi le into the Key Bindings folder, launch Xcode, and select the new set from the Key Bindings Sets pop - up menu. USING AN EXTERNAL EDITOR Is customizing the editor keystrokes and command shortcuts not enough? What if your favorite editing feature isn ’ t included in Xcode ’ s editors? What if Xcode doesn ’ t even have an editor for the kind of fi le you ’ ve added? Fear not; you can elect to use a third - party editor, instead of the built - in editors provided by Xcode, for some or all of your editing needs. Although Xcode ’ s editors are powerful, Xcode has a relatively limited feature set when editing certain types of source fi les, like XML and HTML. The ability to plug a dedicated HTML editor into Xcode adds a powerful new dimension to your development environment. Xcode has several different built - in editors. What you have been exposed to most in this book is the Source Code editor. There is also a Plain Text editor, an RTF (Rich Text File) editor, an XML Properties List editor, an Xcode Confi gurations Settings File editor, an AppleScript Dictionary editor, an Image editor, a Data Model editor, and a few others. The editor that is used when you open a fi le is determined by the settings in the File Types tab of the Xcode Preferences (see Chapter 6). Each fi le type that Xcode understands is associated with an editor. This can be one of the editors built into Xcode, an external application, or the decision can be deferred to the Finder. Using an Alternate Editor Once At any time, you can open a fi le using an alternate Xcode editor. Right/Control+click the source item and choose an editor from the Open As menu. The menu contains the list of Xcode ’ s internal c23.indd 646c23.indd 646 1/22/10 1:28:41 PM1/22/10 1:28:41 PM Download at getcoolebook.com . FIGURE 23 - 3 Key Bindings ❘ 6 43 c 23. indd 643c 23. indd 6 43 1/22/10 1:28 :39 PM1/22/10 1:28 :39 PM Download at getcoolebook.com 644 ❘ CHAPTER 23 CUSTOMIZING XCODE When editing key bindings, Xcode. key binding. Key Bindings ❘ 641 c 23. indd 641c 23. indd 641 1/22/10 1:28 :37 PM1/22/10 1:28 :37 PM Download at getcoolebook.com 642 ❘ CHAPTER 23 CUSTOMIZING XCODE Key bindings are stored in sets using an alternate Xcode editor. Right/Control+click the source item and choose an editor from the Open As menu. The menu contains the list of Xcode ’ s internal c 23. indd 646c 23. indd 646 1/22/10

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

Tài liệu cùng người dùng

Tài liệu liên quan