github

cyanzhong / xTextHandler

  • воскресенье, 26 июня 2016 г. в 03:13:09
https://github.com/cyanzhong/xTextHandler

Objective-C
Xcode Source Editor Extension Toolset (Plugins for Xcode 8)



🇨🇳中文介绍

xTextHandler

Xcode Source Editor Extension Toolset (Plugins for Xcode 8)

What is it

Xcode Source Editor Extension based tools, improve text editing experience for Xcode 8, you can extend with simple code

Features

  • Multiline Selections
  • Multiple Extensions
  • Extendable API
  • Clipboard Text Handling (if select nothing)
  • Regular Expression Matching

xEncode

image

  • Base64 Encode
  • Base64 Decode
  • URL Encode
  • URL Decode
  • Upper Case
  • Lower Case
  • Escape
  • MD5
  • SHA1
  • SHA256

xRadix

image

  • Hex
  • Bin
  • Oct
  • Dec

xColor

image

  • Hex
  • RGB
  • Preview

xSearch

image

  • Google
  • Translate
  • Developer
  • StackOverflow
  • GitHub
  • Dash
  • Dictionary

xFormat

image

  • JSON
  • XML
  • CSS
  • SQL

Thanks to: vkBeautify

Usage

  1. Install Xcode 8
  2. Build & Run
  3. Choose Xcode to debug
  4. Select text
  5. Open Editor menu to find extensions
  6. You can set a shortcut (Key-Binding) for each extension
  7. Maybe you will like this WWDC Session

How to write a new Extension

Add definition in Plist:

<dict>
    <key>XCSourceEditorCommandClassName</key>
    <string>aClassName</string>
    <key>XCSourceEditorCommandIdentifier</key>
    <string>test.extension</string>
    <key>XCSourceEditorCommandName</key>
    <string>Test Extension</string>
</dict>

Map handler via commandIdentifier in class:

// Implement your modify strategy using block (you can implement as singleton dict)
// @{ @"commandIdentifier": handlerBlock }
- (NSDictionary *)handlers {
    static NSDictionary *_instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = @{
            @"test.extension": ^NSString *(NSString *text) { return text; }
        };
    });
    return _instance;
}

* Handle with regex:

// Override performCommandWithInvocation like that
- (void)performCommandWithInvocation:(XCSourceEditorCommandInvocation *)invocation completionHandler:(void (^)(NSError * _Nullable nilOrError))completionHandler {
    [xTextModifier select:invocation pattern:@"regex" handler:self.handlers[invocation.commandIdentifier]];
    completionHandler(nil);
}

TODO

  • Error handling
  • Preferences panel
  • JavaScript for text handling

Tips

Since Xcode 8.0 beta (8S128d) is totally unstable now, you may see nothing after you build & run this project :(

Contacts

Weibo: @StackOverflowError

Twitter: @cyanapps

Email: log.e@qq.com