Skip to content

Commit 080505e

Browse files
committed
Xcode 8 with <3
1 parent 11f56ff commit 080505e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1300
-3588
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ Pods
2121

2222
/video/
2323
/video
24+
/ignore

Design/XAlign.sketch

192 KB
Binary file not shown.

Scripts/install.sh

-27
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.

XAlign/XAlignPattern.h Source/XAlignPattern.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//
88

99
#import <Foundation/Foundation.h>
10-
#import "blade.h"
1110

1211
typedef enum XAlignPosition{
1312
XAlignPositionFisrt = -1,
@@ -35,21 +34,22 @@ typedef NSString * (^XAlignPatternControlBlockUS)(NSUInteger padding, NSString *
3534
@property (nonatomic, assign) XAlignPaddingMode matchMode;
3635
@property (nonatomic, assign) XAlignPaddingMode tailMode;
3736
@property (nonatomic, copy) XAlignPatternControlBlockUS control;
37+
+ (NSArray *)patterns;
3838
@end
3939

4040
@interface XAlignPatternManager : NSObject
4141

42-
AS_SINGLETON( XAlignPatternManager );
42+
+ (instancetype)sharedInstance;
4343

4444
@property (nonatomic, strong) NSMutableDictionary * specifiers;
4545

46+
+ (void)launch;
47+
4648
+ (void)setupWithRawArray:(NSArray *)array;
4749

4850
+ (NSArray *)patternGroupsWithContentsOfFile:(NSString *)name;
49-
5051
+ (NSArray *)patternGroupsWithRawArray:(NSArray *)array;
51-
5252
+ (NSArray *)patternGroupMatchWithString:(NSString *)string;
5353
+ (NSArray *)patternGroupWithDictinary:(NSDictionary *)dictionary;
5454

55-
@end
55+
@end

XAlign/XAlignPattern.m Source/XAlignPattern.m

+28-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ + (NSString *)stringWithFormat:(NSString *)format
4949

5050
@implementation XAlignPattern
5151

52+
+ (NSArray *)patterns
53+
{
54+
static NSArray * __items = nil;
55+
56+
if ( __items == nil )
57+
{
58+
NSString * patternsBundlePath = [[NSBundle mainBundle] pathForResource:@"Patterns" ofType:@"bundle"];
59+
NSString * filePath = [[NSBundle bundleWithPath:patternsBundlePath] pathForResource:@"default" ofType:@"plist"];
60+
__items = [NSArray arrayWithContentsOfFile:filePath];
61+
}
62+
63+
return __items;
64+
}
65+
5266
- (NSString *)description
5367
{
5468
return self.string;
@@ -62,7 +76,15 @@ @interface XAlignPatternManager()
6276

6377
@implementation XAlignPatternManager
6478

65-
DEF_SINGLETON( XAlignPatternManager );
79+
+ (instancetype)sharedInstance
80+
{
81+
static XAlignPatternManager * i = nil;
82+
static dispatch_once_t onceToken;
83+
dispatch_once(&onceToken, ^{
84+
i = [[[self class] alloc] init];
85+
});
86+
return i;
87+
}
6688

6789
- (id)init
6890
{
@@ -76,6 +98,11 @@ - (id)init
7698

7799
#pragma mark - setup
78100

101+
+ (void)launch
102+
{
103+
[self setupWithRawArray:[XAlignPattern patterns]];
104+
}
105+
79106
+ (void)setupWithRawArray:(NSArray *)array
80107
{
81108
[self setupSpecifiersWithRawArray:array];

SourceEditorExtension/Info.plist

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleDisplayName</key>
8+
<string>XAlign</string>
9+
<key>CFBundleExecutable</key>
10+
<string>$(EXECUTABLE_NAME)</string>
11+
<key>CFBundleIdentifier</key>
12+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>6.0</string>
15+
<key>CFBundleName</key>
16+
<string>XAlign</string>
17+
<key>CFBundlePackageType</key>
18+
<string>XPC!</string>
19+
<key>CFBundleShortVersionString</key>
20+
<string>1.0</string>
21+
<key>CFBundleVersion</key>
22+
<string>201611092325</string>
23+
<key>LSMinimumSystemVersion</key>
24+
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
25+
<key>NSExtension</key>
26+
<dict>
27+
<key>NSExtensionAttributes</key>
28+
<dict>
29+
<key>XCSourceEditorCommandDefinitions</key>
30+
<array>
31+
<dict>
32+
<key>XCSourceEditorCommandClassName</key>
33+
<string>SourceEditorCommand</string>
34+
<key>XCSourceEditorCommandIdentifier</key>
35+
<string>$(PRODUCT_BUNDLE_IDENTIFIER).SourceEditorCommand</string>
36+
<key>XCSourceEditorCommandName</key>
37+
<string>Auto Align</string>
38+
</dict>
39+
</array>
40+
<key>XCSourceEditorExtensionPrincipalClass</key>
41+
<string>SourceEditorExtension</string>
42+
</dict>
43+
<key>NSExtensionPointIdentifier</key>
44+
<string>com.apple.dt.Xcode.extension.source-editor</string>
45+
</dict>
46+
<key>NSHumanReadableCopyright</key>
47+
<string>Copyright © 2016 QFish. All rights reserved.</string>
48+
</dict>
49+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// SourceEditorCommand.h
3+
// SourceEditorExtension
4+
//
5+
// Created by QFish on 03/11/2016.
6+
// Copyright © 2016 QFish. All rights reserved.
7+
//
8+
9+
#import <XcodeKit/XcodeKit.h>
10+
11+
@interface SourceEditorCommand : NSObject <XCSourceEditorCommand>
12+
13+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//
2+
// SourceEditorCommand.m
3+
// SourceEditorExtension
4+
//
5+
// Created by QFish on 03/11/2016.
6+
// Copyright © 2016 QFish. All rights reserved.
7+
//
8+
9+
#import "SourceEditorCommand.h"
10+
#import "XAlignPattern.h"
11+
#import "NSString+XAlign.h"
12+
13+
@implementation SourceEditorCommand
14+
15+
- (void)performCommandWithInvocation:(XCSourceEditorCommandInvocation *)invocation completionHandler:(void (^)(NSError * _Nullable nilOrError))completionHandler
16+
{
17+
// Implement your command here, invoking the completion handler when done. Pass it nil on success, and an NSError on failure.
18+
19+
if ([invocation.commandIdentifier hasSuffix:@"SourceEditorCommand"])
20+
{
21+
[[self class] autoAlign:invocation];
22+
}
23+
24+
completionHandler(nil);
25+
}
26+
27+
+ (void)autoAlign:(XCSourceEditorCommandInvocation *)invocation
28+
{
29+
NSMutableArray * selections = [NSMutableArray array];
30+
31+
for ( XCSourceTextRange *range in invocation.buffer.selections )
32+
{
33+
for ( NSInteger i = range.start.line; i < range.end.line ; i++)
34+
{
35+
[selections addObject:invocation.buffer.lines[i]];
36+
}
37+
}
38+
39+
NSString * selectedString = [selections componentsJoinedByString:@""];
40+
41+
NSArray * patternGroup = [XAlignPatternManager patternGroupMatchWithString:selectedString];
42+
43+
if ( !patternGroup )
44+
return;
45+
46+
NSString * alignedString = [selectedString stringByAligningWithPatterns:patternGroup];
47+
48+
NSArray * result = [alignedString componentsSeparatedByString:@"\n"];
49+
50+
for ( XCSourceTextRange *range in invocation.buffer.selections )
51+
{
52+
for ( NSInteger i = range.start.line, j=0; i < range.end.line ; i++, j++ )
53+
{
54+
invocation.buffer.lines[i] = result[j];
55+
}
56+
}
57+
}
58+
59+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.app-sandbox</key>
6+
<true/>
7+
</dict>
8+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// SourceEditorExtension.h
3+
// SourceEditorExtension
4+
//
5+
// Created by QFish on 03/11/2016.
6+
// Copyright © 2016 QFish. All rights reserved.
7+
//
8+
9+
#import <XcodeKit/XcodeKit.h>
10+
11+
@interface SourceEditorExtension : NSObject <XCSourceEditorExtension>
12+
13+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// SourceEditorExtension.m
3+
// SourceEditorExtension
4+
//
5+
// Created by QFish on 03/11/2016.
6+
// Copyright © 2016 QFish. All rights reserved.
7+
//
8+
9+
#import "SourceEditorExtension.h"
10+
#import "XAlignPattern.h"
11+
12+
@implementation SourceEditorExtension
13+
14+
- (void)extensionDidFinishLaunching
15+
{
16+
// If your extension needs to do any work at launch, implement this optional method.
17+
[XAlignPatternManager launch];
18+
}
19+
20+
//- (NSArray <NSDictionary <XCSourceEditorCommandDefinitionKey, id> *> *)commandDefinitions
21+
//{
22+
// // If your extension needs to return a collection of command definitions that differs from those in its Info.plist, implement this optional property getter.
23+
// return @[];
24+
//}
25+
26+
@end

Test/XAlign.xcworkspace/contents.xcworkspacedata

-10
This file was deleted.

0 commit comments

Comments
 (0)