Skip to content

Commit 42f95e1

Browse files
author
Lei Wang
committed
add TrickerX dmg
1 parent edc2b42 commit 42f95e1

File tree

8 files changed

+42
-24
lines changed

8 files changed

+42
-24
lines changed

Codable/SourceEditorCommand.swift

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,44 @@ import XcodeKit
1313
class SourceEditorCommand: NSObject, XCSourceEditorCommand {
1414

1515
func perform(with invocation: XCSourceEditorCommandInvocation, completionHandler: @escaping (Error?) -> Void ) -> Void {
16+
1617
let textRange = invocation.buffer.selections.firstObject as! XCSourceTextRange
1718
var startLine = textRange.start.line
1819

19-
let endRegex = """
20-
.*\\{
21-
"""
22-
let isPropertyRegex = ".*(let|var)\\s+.\\w+\\s*:(?!(.*(\\(|\\{|\\=)))"
23-
let propertyRegex = "\\w+\\s*(:)"
20+
let endRegex = ".+\\s*:\\s*.*\\{"
21+
let propertyRegex = ".*(let|var)\\s+\\w+\\s*(:|=).+"
22+
let propertyNamePartRegex = "\\w+\\s*(:|=)"
23+
let propertyNameRegex = "\\w+"
2424
let uppercase = "A"..."Z"
2525

26-
var enumCase: [(key: String, value: String)] = []
26+
var openBracketCount: Int = 0
27+
let openBracketRegex = "\\}"
28+
let closeBracketRegex = "\\{"
29+
let isClosureRegex = "->"
2730

31+
var enumCase: [(key: String, value: String)] = []
32+
2833
while startLine >= 0 {
2934
guard let lineText = invocation.buffer.lines[startLine] as? String else { startLine -= 1; continue }
30-
if lineText.isMatch(endRegex) {
35+
36+
openBracketCount += lineText.match(regex: openBracketRegex).count
37+
if openBracketCount > 0 {
38+
openBracketCount -= lineText.match(regex: closeBracketRegex).count
39+
startLine -= 1
40+
continue
41+
}else if lineText.isMatch(endRegex) {
3142
break
3243
}
33-
var propertyName: String = lineText.match(regex: isPropertyRegex)
34-
if propertyRegex.isEmpty {
44+
guard !lineText.isMatch(isClosureRegex) else {
3545
startLine -= 1
3646
continue
3747
}
38-
propertyName = propertyName.match(regex: propertyRegex).replacingOccurrences(of: ":", with: "")
48+
var propertyName: String = lineText.match(regex: propertyRegex)
49+
if propertyName.isEmpty {
50+
startLine -= 1
51+
continue
52+
}
53+
propertyName = propertyName.match(regex: propertyNamePartRegex).match(regex: propertyNameRegex)
3954
var rawValue = ""
4055
var previousWordIsUppercase = false
4156
for character in propertyName {
@@ -52,9 +67,7 @@ class SourceEditorCommand: NSObject, XCSourceEditorCommand {
5267
}
5368

5469
}
55-
if !rawValue.isEmpty {
56-
enumCase.append((key: propertyName, value: rawValue))
57-
}
70+
enumCase.append((key: propertyName, value: rawValue))
5871
startLine -= 1
5972
}
6073

@@ -80,17 +93,16 @@ class SourceEditorCommand: NSObject, XCSourceEditorCommand {
8093
writeLine += 1
8194
let key = caseTuple.key
8295
let value = caseTuple.value
83-
var text = "\(indentSpaces)\(caseIndentSpaces)case \(key)"
84-
if !value.isEmpty, key != value {
85-
text += " = \"\(value)\""
96+
writeText = "\(indentSpaces)\(caseIndentSpaces)case \(key)"
97+
if key != value, !value.isEmpty {
98+
writeText += " = \"\(value)\""
8699
}
87-
writeText = text
88100
invocation.buffer.lines.insert(writeText, at: writeLine)
89101
updateSelectionIndexs.append(writeLine)
90102
}
91-
let endText = "\(indentSpaces)}"
103+
writeText = "\(indentSpaces)}"
92104
writeLine += 1
93-
invocation.buffer.lines.insert(endText, at: writeLine)
105+
invocation.buffer.lines.insert(writeText, at: writeLine)
94106

95107
let textRanges = updateSelectionIndexs.map { (index) -> XCSourceTextRange in
96108
let sourceTextRange = XCSourceTextRange()
@@ -99,7 +111,6 @@ class SourceEditorCommand: NSObject, XCSourceEditorCommand {
99111
return sourceTextRange
100112
}
101113

102-
103114
invocation.buffer.selections.setArray(textRanges)
104115

105116
completionHandler(nil)

TrickerX.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@
382382
DEVELOPMENT_TEAM = ZRW9N2A955;
383383
INFOPLIST_FILE = TrickerX/Info.plist;
384384
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
385+
MACOSX_DEPLOYMENT_TARGET = 10.12;
385386
PRODUCT_BUNDLE_IDENTIFIER = com.rayternet.TrickerX;
386387
PRODUCT_NAME = "$(TARGET_NAME)";
387388
SWIFT_VERSION = 4.0;
@@ -399,6 +400,7 @@
399400
DEVELOPMENT_TEAM = ZRW9N2A955;
400401
INFOPLIST_FILE = TrickerX/Info.plist;
401402
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
403+
MACOSX_DEPLOYMENT_TARGET = 10.12;
402404
PRODUCT_BUNDLE_IDENTIFIER = com.rayternet.TrickerX;
403405
PRODUCT_NAME = "$(TARGET_NAME)";
404406
SWIFT_VERSION = 4.0;

TrickerX.xcodeproj/xcuserdata/ray.xcuserdatad/xcschemes/Codable.xcscheme

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,19 @@
6969
debugServiceExtension = "internal"
7070
allowLocationSimulation = "YES"
7171
launchAutomaticallySubstyle = "2">
72-
<BuildableProductRunnable
73-
runnableDebuggingMode = "0">
72+
<PathRunnable
73+
runnableDebuggingMode = "0"
74+
FilePath = "/&lt;placeholder&gt;">
75+
</PathRunnable>
76+
<MacroExpansion>
7477
<BuildableReference
7578
BuildableIdentifier = "primary"
7679
BlueprintIdentifier = "71B8528C1FC834F80084F597"
7780
BuildableName = "TrickerX.app"
7881
BlueprintName = "TrickerX"
7982
ReferencedContainer = "container:TrickerX.xcodeproj">
8083
</BuildableReference>
81-
</BuildableProductRunnable>
84+
</MacroExpansion>
8285
<AdditionalOptions>
8386
</AdditionalOptions>
8487
</LaunchAction>

TrickerX/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
<string>1.0</string>
2121
<key>CFBundleVersion</key>
2222
<string>1</string>
23+
<key>LSApplicationCategoryType</key>
24+
<string>public.app-category.developer-tools</string>
2325
<key>LSMinimumSystemVersion</key>
2426
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
2527
<key>NSHumanReadableCopyright</key>

TrickerX/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Cocoa
1010

1111
class ViewController: NSViewController {
12-
12+
1313
override func viewDidLoad() {
1414
super.viewDidLoad()
1515

app/TrickerX.dmg

4.34 MB
Binary file not shown.

codable.gif

1.33 MB
Loading

0 commit comments

Comments
 (0)