Design and implementation of high-copy version of Xcode plugin for HOKEYPOKEY-WWDC Instructor

Source: Internet
Author: User
Tags file url

When we use the Xcode IDE to share the iOS technology, it often involves comparing the performance of multiple scenarios. There are three ways to switch between different demo scenarios: 1. Split into multiple Xcode projects; 2. Split into multiple Versions branch 3. Manually comment out the block of code that is not the current run scenario. These three options are somewhat less than satisfactory in flexibility, speed and convenience. So, is there a better way? See more WWDC video of the children's shoes may notice the name: Hokey Pokey, Chinese is the meaning of magic, WWDC instructor when switching between different presentation scenarios, the shortcut key to evoke a floating window, in the floating window tick different demo code block. The author of the implementation of the code is exactly such a WWDC instructor-special Xcode plug-in high (simple) imitation (cottage) version (goods).

Online maintenance: Https://github.com/1962449521/HokeyPokey

First, the effect of Hokeypokey plug-in demonstration

The Hokeypokey menu item is installed in Xcode View, Hokeypokey. There are [hide/show], [make], [Resume] three function items, respectively, to show/destroy the Hokeypokey work window, compile the current operation file to Hokey Pokey management database, undo all Hokey Pokey operation and database of the current file. A button is placed in the upper right corner of the work window to toggle whether the window is always in front. Scattered code blocks of the same run scheme name are grouped into a list row. The selection of a scenario is achieved by double-clicking the list item. The shortcut keys for three function items, the table header of the work window provide a scenario customization, which is described later.

Second, the use of the plug-in current version should be noted

  1. Try to open only one Xcode window and open only one tab item in a Xcode window. The problem here is that when you switch the Xcode window or tab item, the Hokeypokey window does not synchronize updates, and when you double-click the list item, the result of the original file operation is written to the new code editing area.

  2. the Hokeypokey operation needs to be carried out individually (the third function item resume). When only one tab entry is open for a Xcode window, the Hokeypokey window is automatically updated based on the file's switchover. Operation granularity is a file instead of a project, so when you need to undo all hokeypokey Operations, switch to the file you have worked on, one at a time.

  3. When editing a file, you must first revoke the file's Hokeypokey change (some code is hidden), then modify it, and then compile to the Hokeypokey database (the second feature item make).

  4. The dock/normal in the upper right corner can toggle whether the Hokeypokey window is always up front

Third, about the plug-in installation and custom settings

the plugin runs as installed, downloads the plugin project from GitHub to local, uses the default settings or changes the settings file, and runs the Xcode project. Custom settings involve files that are HPKConst.h, as specific as. Can more identify signs, text cases, shortcut keys and so on. The plugin as open source welcome and hope that children shoes change, use, dissemination and more comments. But in the respect of departure please do not modify the name of the plugin, the author statement, etc.

#ifndef Hpkconst_h#defineHpkconst_h//------------start and end flags for Hokeypokey recognition#defineHpkstartstringtag @ "//Hokey "#defineHpkendstringtag @ "//Pokey "//UI copywriting------------Header and window state switching#defineHpkheadertitle4show @ "SHOW"#defineHpkheadertitle4identifier @ "IDENTIFIER"#defineHpklabel4windowdock @ "Dock"#defineHpklable4windownormal @ "Normal"//------------shortcut key Settings#defineHpkrequirekey4hideshow @YES#defineHpkkeyequivalent4hideshow @ "H"#defineHpkkeymask4hideshow Nsshiftkeymask | Nscommandkeymask#defineHpkrequirekey4make @YES#defineHpkkeyequivalent4make @ "W"#defineHpkkeymask4make Nsshiftkeymask | Nscommandkeymask#defineHpkrequirekey4resume @YES#defineHpkkeyequivalent4resume @ "x"#defineHpkkeymask4resume Nsshiftkeymask | Nscommandkeymask//do not change the following------------#defineHpkisshownkey @ "Isshow"#defineHpktitlekey @ "Identifier"#defineHpkpockyresultskey @ "Pockyresultskey"#defineHpkfileurlkey @ "Fileurlkey"#endif/* Hpkconst_h */

Iv. Requirements and functional analysis of plug-ins

1. Usage Scenarios and Requirements analysis

When technology is shared or taught, the operational scenarios for Xcode projects are differentiated and switched. It needs to be compared with the three methods mentioned at the beginning of the article to achieve a more user-friendly, time-saving purpose.

2. Functional analysis

First, the user is asked to give the formatted TextView and trigger the Hokeypokey compilation. The user uses a formatted flag that separates a textview content into blocks with a recognition start flag (such as//hokey) and a Recognition End flag (//pokey). The unique block of code that starts between identifying and ending identities for different scenarios, and other partitions are common blocks of code.

In this format premise, plug-in development of the most basic functions, can be refined to the following:

A. Extract the individual program-specific code blocks. Given a format string, extracts the string of each scheme-specific code block, the range in the initial string, and the scheme name (identity) of each code block;

B. The operational code of the corresponding scheme is derived. Given the format string and the Hokeypokey extraction results, the operational code of the corresponding scheme can be calculated when the different scheme names are selected.

C. Visualization of current scenario selection. Gives the GUI display, draws the extracted result to the list control, and gives the prompt to show whether the blocks are displayed on the UI;

D. Provide a scheme switching method. The GUI allows user interaction to switch the scheme selection state, the Xcode code editing area display, and the physical document when the list item is double-clicked.

Design and implementation of plug-in

The realization of function point A and B by adding the category method to NSString, the class design is as follows, the corresponding function A, B provides two instance methods respectively, and designs the Hpksearchresult model for storing the block result.

@interfaceHpksearchresult:nsobject@property (nonatomic, strong) NSString*title; @property (nonatomic, assign) Nsrange range; @property (nonatomic, strong) NSString*string;-(Instancetype) Initwithrange: (Nsrange) Arangestring:(NSString *) astring title: (NSString *) Atitle;@end@interfacensstring (hpktextgetter)-(Nsarray) Open closestring: (NSString*) Close;-(NSString *) Hpk_stringbysubtractsearchresults: (Nsarray) searchresults;@end

Function C, D is implemented mainly through a custom window and cocoa binding, the class is designed as follows. The title of the window WindowTitle and the contents of the list Cotentarray need to change as the current action file changes. The data source is provided by the management class Hpkpluginmain, here is simple, directly exposes the TableView, WindowTitle, Contentarray and other attributes, by the management class Hpkpluginmain direct operation. The window class binds the user's double-click action on the list to update the Hokeypokey window list and submit the action to the management class hpkpluginmain for substantive operation.

#import<Cocoa/Cocoa.h>@classHpkpluginmain;@interfaceHpkwindowcontroller:nswindowcontroller@property (weak) Hpkpluginmain*pluginmain;//plug-in management Objects@property (weak) Iboutlet Nstableview *tableview;//plug-in window main control//Copy Content Binding@property (Strong) NSString *WindowTitle, @property (strong) Iboutlet Nsarraycontroller*Contentarray;//user double-click event binding- (void) Inspect: (Nsarray *) selectedobjects;@end@interfaceHpkwindowcontroller () <NSTableViewDelegate>//Copy Content Binding@property (Strong) NSString *Headertitle4show, @property (strong) NSString*Headertitle4identifier;//Toggle window Display whether hover button@property (weak) iboutlet Nsbutton *Btndock;@end

the design of the management class is first to provide the display data as the data source of the Hokeypokey window, and the second is to handle the business logic caused by the interaction as a delegate of the Hokeypokey window. The data source aspect mainly uses two dictionaries to realize, its key value is the physical file Url,originaltextdic the original string which when compiles Hokeypokey, contentarrdic stores each file corresponding Hokeypokey extracts the result.

#import<Cocoa/Cocoa.h>@interfaceHpkpluginmain:nsobject/** * Update the Xcode display and physical document according to the user's click on the Hokey pokey window * @param editedtitle the scheme name to operate * @param isshow whether the scheme is displayed*/- (void) Refresheditorandfileattiltle: (NSString *) Editedtitle shouldshow: (BOOL) shouldshow;@end@interfaceHpkpluginmain () <NSWindowDelegate>//Hokey Pokey Database@property (nonatomic, strong) Nsmutabledictionary *Originaltextdic, @property (nonatomic, strong) Nsmutabledictionary*Contentarrdic;//Code Editing window@property (nonatomic, strong) Dvtsourcetextview *Idesourcetextview, @property (nonatomic, strong) Ideworkspacewindow*Ideworkspacewindow, @property (nonatomic, strong) Hpkwindowcontroller*windowcontroller;//hold Hokeypokey window@property (nonatomic, strong) Whukvocontroller *documentkvo;//Facebook's Kvo class- (void) Createhokeypokeymenu;//Create a menu- (void) Createhokeypokeywindow;//Create Hokeypokey window-(Nsurl *) Activedocumenturl;//returns the address of the currently edited document- (void) Refreshhokeypokeywindowwithurl: (nsurl *) URL;//Refresh the database source for the Hokeypokey window@end

Vi. points of attention and unfinished work

  Do not open the Hokeypokey window in the normal development, so as not to mistakenly operate.

  Use it only in technology sharing, scenario presentation, and before you use it, make sure you back it up before you forget it, and Xcode shuts down causing your code to be lost.

  Only one Xcode project, one tab item, is opened when used.

The current file switchover is not supported by Undo manager and can be implemented with pasteboard and virtual key values. Before closing the window, we probably forget that the Hokeypokey window has hidden content, do we need to automatically undo all Hokeypokey actions when Xcode exits? Do I need to sync when I open multiple Xcode projects or tabs at the same time? These issues will be resolved gradually in later version maintenance.

Design and implementation of high-copy version of Xcode plugin for HOKEYPOKEY-WWDC Instructor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.