Skip to content

Commit

Permalink
Xcode 8 with <3
Browse files Browse the repository at this point in the history
  • Loading branch information
qfish committed Nov 9, 2016
1 parent 11f56ff commit 080505e
Show file tree
Hide file tree
Showing 61 changed files with 1,300 additions and 3,588 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ Pods

/video/
/video
/ignore
Binary file added Design/XAlign.sketch
Binary file not shown.
27 changes: 0 additions & 27 deletions Scripts/install.sh

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions XAlign/XAlignPattern.h → Source/XAlignPattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

#import <Foundation/Foundation.h>
#import "blade.h"

typedef enum XAlignPosition{
XAlignPositionFisrt = -1,
Expand Down Expand Up @@ -35,21 +34,22 @@ typedef NSString * (^XAlignPatternControlBlockUS)(NSUInteger padding, NSString *
@property (nonatomic, assign) XAlignPaddingMode matchMode;
@property (nonatomic, assign) XAlignPaddingMode tailMode;
@property (nonatomic, copy) XAlignPatternControlBlockUS control;
+ (NSArray *)patterns;
@end

@interface XAlignPatternManager : NSObject

AS_SINGLETON( XAlignPatternManager );
+ (instancetype)sharedInstance;

@property (nonatomic, strong) NSMutableDictionary * specifiers;

+ (void)launch;

+ (void)setupWithRawArray:(NSArray *)array;

+ (NSArray *)patternGroupsWithContentsOfFile:(NSString *)name;

+ (NSArray *)patternGroupsWithRawArray:(NSArray *)array;

+ (NSArray *)patternGroupMatchWithString:(NSString *)string;
+ (NSArray *)patternGroupWithDictinary:(NSDictionary *)dictionary;

@end
@end
29 changes: 28 additions & 1 deletion XAlign/XAlignPattern.m → Source/XAlignPattern.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ + (NSString *)stringWithFormat:(NSString *)format

@implementation XAlignPattern

+ (NSArray *)patterns
{
static NSArray * __items = nil;

if ( __items == nil )
{
NSString * patternsBundlePath = [[NSBundle mainBundle] pathForResource:@"Patterns" ofType:@"bundle"];
NSString * filePath = [[NSBundle bundleWithPath:patternsBundlePath] pathForResource:@"default" ofType:@"plist"];
__items = [NSArray arrayWithContentsOfFile:filePath];
}

return __items;
}

- (NSString *)description
{
return self.string;
Expand All @@ -62,7 +76,15 @@ @interface XAlignPatternManager()

@implementation XAlignPatternManager

DEF_SINGLETON( XAlignPatternManager );
+ (instancetype)sharedInstance
{
static XAlignPatternManager * i = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
i = [[[self class] alloc] init];
});
return i;
}

- (id)init
{
Expand All @@ -76,6 +98,11 @@ - (id)init

#pragma mark - setup

+ (void)launch
{
[self setupWithRawArray:[XAlignPattern patterns]];
}

+ (void)setupWithRawArray:(NSArray *)array
{
[self setupSpecifiersWithRawArray:array];
Expand Down
49 changes: 49 additions & 0 deletions SourceEditorExtension/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>XAlign</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>XAlign</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>201611092325</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>XCSourceEditorCommandDefinitions</key>
<array>
<dict>
<key>XCSourceEditorCommandClassName</key>
<string>SourceEditorCommand</string>
<key>XCSourceEditorCommandIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER).SourceEditorCommand</string>
<key>XCSourceEditorCommandName</key>
<string>Auto Align</string>
</dict>
</array>
<key>XCSourceEditorExtensionPrincipalClass</key>
<string>SourceEditorExtension</string>
</dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.dt.Xcode.extension.source-editor</string>
</dict>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2016 QFish. All rights reserved.</string>
</dict>
</plist>
13 changes: 13 additions & 0 deletions SourceEditorExtension/SourceEditorCommand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// SourceEditorCommand.h
// SourceEditorExtension
//
// Created by QFish on 03/11/2016.
// Copyright © 2016 QFish. All rights reserved.
//

#import <XcodeKit/XcodeKit.h>

@interface SourceEditorCommand : NSObject <XCSourceEditorCommand>

@end
59 changes: 59 additions & 0 deletions SourceEditorExtension/SourceEditorCommand.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// SourceEditorCommand.m
// SourceEditorExtension
//
// Created by QFish on 03/11/2016.
// Copyright © 2016 QFish. All rights reserved.
//

#import "SourceEditorCommand.h"
#import "XAlignPattern.h"
#import "NSString+XAlign.h"

@implementation SourceEditorCommand

- (void)performCommandWithInvocation:(XCSourceEditorCommandInvocation *)invocation completionHandler:(void (^)(NSError * _Nullable nilOrError))completionHandler
{
// Implement your command here, invoking the completion handler when done. Pass it nil on success, and an NSError on failure.

if ([invocation.commandIdentifier hasSuffix:@"SourceEditorCommand"])
{
[[self class] autoAlign:invocation];
}

completionHandler(nil);
}

+ (void)autoAlign:(XCSourceEditorCommandInvocation *)invocation
{
NSMutableArray * selections = [NSMutableArray array];

for ( XCSourceTextRange *range in invocation.buffer.selections )
{
for ( NSInteger i = range.start.line; i < range.end.line ; i++)
{
[selections addObject:invocation.buffer.lines[i]];
}
}

NSString * selectedString = [selections componentsJoinedByString:@""];

NSArray * patternGroup = [XAlignPatternManager patternGroupMatchWithString:selectedString];

if ( !patternGroup )
return;

NSString * alignedString = [selectedString stringByAligningWithPatterns:patternGroup];

NSArray * result = [alignedString componentsSeparatedByString:@"\n"];

for ( XCSourceTextRange *range in invocation.buffer.selections )
{
for ( NSInteger i = range.start.line, j=0; i < range.end.line ; i++, j++ )
{
invocation.buffer.lines[i] = result[j];
}
}
}

@end
8 changes: 8 additions & 0 deletions SourceEditorExtension/SourceEditorExtension.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
</dict>
</plist>
13 changes: 13 additions & 0 deletions SourceEditorExtension/SourceEditorExtension.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// SourceEditorExtension.h
// SourceEditorExtension
//
// Created by QFish on 03/11/2016.
// Copyright © 2016 QFish. All rights reserved.
//

#import <XcodeKit/XcodeKit.h>

@interface SourceEditorExtension : NSObject <XCSourceEditorExtension>

@end
26 changes: 26 additions & 0 deletions SourceEditorExtension/SourceEditorExtension.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// SourceEditorExtension.m
// SourceEditorExtension
//
// Created by QFish on 03/11/2016.
// Copyright © 2016 QFish. All rights reserved.
//

#import "SourceEditorExtension.h"
#import "XAlignPattern.h"

@implementation SourceEditorExtension

- (void)extensionDidFinishLaunching
{
// If your extension needs to do any work at launch, implement this optional method.
[XAlignPatternManager launch];
}

//- (NSArray <NSDictionary <XCSourceEditorCommandDefinitionKey, id> *> *)commandDefinitions
//{
// // If your extension needs to return a collection of command definitions that differs from those in its Info.plist, implement this optional property getter.
// return @[];
//}

@end
10 changes: 0 additions & 10 deletions Test/XAlign.xcworkspace/contents.xcworkspacedata

This file was deleted.

Loading

0 comments on commit 080505e

Please sign in to comment.