Skip to content

Commit 84cc6d9

Browse files
author
Sven
committed
优化布局
1 parent e008060 commit 84cc6d9

File tree

6 files changed

+152
-21
lines changed

6 files changed

+152
-21
lines changed

SwiftJSONModeler For Xcode.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
C94AFC01241F4AE600389AF3 /* YApiHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C94AFC00241F4AE600389AF3 /* YApiHelper.swift */; };
2222
C94AFC04241F4E8A00389AF3 /* YApiObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = C94AFC03241F4E8A00389AF3 /* YApiObject.swift */; };
2323
C961C1DE23D82A8D008D0DE6 /* ConfigViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C961C1DD23D82A8D008D0DE6 /* ConfigViewController.swift */; };
24+
C97A431324EF7954002F6065 /* Token.swift in Sources */ = {isa = PBXBuildFile; fileRef = C97A431224EF7954002F6065 /* Token.swift */; };
2425
C9CB2480241F559C00F4D5CE /* ErrorCenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9CB247F241F559C00F4D5CE /* ErrorCenter.swift */; };
2526
C9CEE26D242B382900A04EA9 /* YApiCreator.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9CEE26C242B382900A04EA9 /* YApiCreator.swift */; };
2627
C9D04F2B242F218200843DC4 /* SwiftJSONModeler_For_XcodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9D04F2A242F218200843DC4 /* SwiftJSONModeler_For_XcodeTests.swift */; };
@@ -79,6 +80,7 @@
7980
C94AFC00241F4AE600389AF3 /* YApiHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YApiHelper.swift; sourceTree = "<group>"; };
8081
C94AFC03241F4E8A00389AF3 /* YApiObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YApiObject.swift; sourceTree = "<group>"; };
8182
C961C1DD23D82A8D008D0DE6 /* ConfigViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigViewController.swift; sourceTree = "<group>"; };
83+
C97A431224EF7954002F6065 /* Token.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Token.swift; sourceTree = "<group>"; };
8284
C9CB247F241F559C00F4D5CE /* ErrorCenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorCenter.swift; sourceTree = "<group>"; };
8385
C9CEE26C242B382900A04EA9 /* YApiCreator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YApiCreator.swift; sourceTree = "<group>"; };
8486
C9D04F20242EF99F00843DC4 /* YApiRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YApiRequest.swift; sourceTree = "<group>"; };
@@ -223,6 +225,7 @@
223225
C9DE045E242C8535008A0070 /* Config.swift */,
224226
C9CB247F241F559C00F4D5CE /* ErrorCenter.swift */,
225227
C935B49B24EA24BE00E48231 /* JSONHelper.swift */,
228+
C97A431224EF7954002F6065 /* Token.swift */,
226229
);
227230
path = "SwiftJSONModeler For Xcode";
228231
sourceTree = "<group>";
@@ -388,6 +391,7 @@
388391
buildActionMask = 2147483647;
389392
files = (
390393
C92A971724E513EA00C87CCD /* YApiRequest.swift in Sources */,
394+
C97A431324EF7954002F6065 /* Token.swift in Sources */,
391395
C92A971824E513F900C87CCD /* ErrorCenter.swift in Sources */,
392396
C9E393E824EE255900D80B28 /* TokenView.swift in Sources */,
393397
C9ED9CC623D7F9B3004567A1 /* AppDelegate.swift in Sources */,

SwiftJSONModeler For Xcode.xcodeproj/xcuserdata/yibin.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,53 @@
148148
landmarkType = "7">
149149
</BreakpointContent>
150150
</BreakpointProxy>
151+
<BreakpointProxy
152+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
153+
<BreakpointContent
154+
uuid = "BB2236F1-C5FA-40C2-9773-8EA191AC6EAE"
155+
shouldBeEnabled = "Yes"
156+
ignoreCount = "0"
157+
continueAfterRunningActions = "No"
158+
filePath = "SwiftJSONModeler For Xcode/Controller/TokenViewController.swift"
159+
startingColumnNumber = "9223372036854775807"
160+
endingColumnNumber = "9223372036854775807"
161+
startingLineNumber = "41"
162+
endingLineNumber = "41"
163+
landmarkName = "setupToken()"
164+
landmarkType = "7">
165+
<Locations>
166+
<Location
167+
uuid = "BB2236F1-C5FA-40C2-9773-8EA191AC6EAE - 7669a082ef3bd75a"
168+
shouldBeEnabled = "Yes"
169+
ignoreCount = "0"
170+
continueAfterRunningActions = "No"
171+
symbolName = "SwiftJSONModeler_For_Xcode.TokenViewController.(setupToken in _CAA47979606C5E1A08E8780CD089187F)() -&gt; ()"
172+
moduleName = "SwiftJSONModeler For Xcode"
173+
usesParentBreakpointCondition = "Yes"
174+
urlString = "file:///Users/yibin/Desktop/SwiftJSONModeler/SwiftJSONModeler%20For%20Xcode/Controller/TokenViewController.swift"
175+
startingColumnNumber = "9223372036854775807"
176+
endingColumnNumber = "9223372036854775807"
177+
startingLineNumber = "41"
178+
endingLineNumber = "41"
179+
offsetFromSymbolStart = "65">
180+
</Location>
181+
<Location
182+
uuid = "BB2236F1-C5FA-40C2-9773-8EA191AC6EAE - 3f77a0dd0ae2dde1"
183+
shouldBeEnabled = "Yes"
184+
ignoreCount = "0"
185+
continueAfterRunningActions = "No"
186+
symbolName = "closure #1 (SwiftJSONModeler_For_Xcode.Token) -&gt; () in SwiftJSONModeler_For_Xcode.TokenViewController.(setupToken in _CAA47979606C5E1A08E8780CD089187F)() -&gt; ()"
187+
moduleName = "SwiftJSONModeler For Xcode"
188+
usesParentBreakpointCondition = "Yes"
189+
urlString = "file:///Users/yibin/Desktop/SwiftJSONModeler/SwiftJSONModeler%20For%20Xcode/Controller/TokenViewController.swift"
190+
startingColumnNumber = "9223372036854775807"
191+
endingColumnNumber = "9223372036854775807"
192+
startingLineNumber = "41"
193+
endingLineNumber = "41"
194+
offsetFromSymbolStart = "49">
195+
</Location>
196+
</Locations>
197+
</BreakpointContent>
198+
</BreakpointProxy>
151199
</Breakpoints>
152200
</Bucket>

SwiftJSONModeler For Xcode/Base.lproj/Main.storyboard

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@
774774
<constraint firstAttribute="width" constant="80" id="cy3-XY-hR7"/>
775775
</constraints>
776776
<textFieldCell key="cell" lineBreakMode="clipping" title="前缀:" id="n9e-oo-TZ5">
777-
<font key="font" metaFont="system" size="16"/>
777+
<font key="font" metaFont="label" size="16"/>
778778
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
779779
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
780780
</textFieldCell>
@@ -796,7 +796,7 @@
796796
<constraint firstAttribute="width" constant="80" id="dew-vC-605"/>
797797
</constraints>
798798
<textFieldCell key="cell" lineBreakMode="clipping" title="后缀:" id="pft-UG-a8v">
799-
<font key="font" metaFont="system" size="16"/>
799+
<font key="font" metaFont="label" size="16"/>
800800
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
801801
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
802802
</textFieldCell>
@@ -892,7 +892,7 @@
892892
<constraint firstAttribute="width" constant="80" id="r76-oI-ssb"/>
893893
</constraints>
894894
<textFieldCell key="cell" lineBreakMode="clipping" title="其他设置" id="PMg-9i-jHB">
895-
<font key="font" metaFont="system" size="16"/>
895+
<font key="font" metaFont="label" size="16"/>
896896
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
897897
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
898898
</textFieldCell>
@@ -1007,7 +1007,7 @@
10071007
<constraint firstAttribute="width" constant="80" id="hqF-dk-Dsb"/>
10081008
</constraints>
10091009
<textFieldCell key="cell" lineBreakMode="clipping" title="YApi设置" id="Yyq-3e-wE2">
1010-
<font key="font" metaFont="system" size="16"/>
1010+
<font key="font" metaFont="label" size="16"/>
10111011
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
10121012
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
10131013
</textFieldCell>
@@ -1018,7 +1018,7 @@
10181018
<constraint firstAttribute="width" constant="80" id="H1x-4y-gS0"/>
10191019
</constraints>
10201020
<textFieldCell key="cell" lineBreakMode="clipping" title="备注" id="vRi-ca-vqg">
1021-
<font key="font" metaFont="system" size="16"/>
1021+
<font key="font" metaFont="label" size="16"/>
10221022
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
10231023
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
10241024
</textFieldCell>
@@ -1157,7 +1157,7 @@
11571157
</constraints>
11581158
<buttonCell key="cell" type="push" title="添加" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="NWl-tG-Nvt">
11591159
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
1160-
<font key="font" metaFont="system" size="16"/>
1160+
<font key="font" metaFont="label" size="16"/>
11611161
</buttonCell>
11621162
<connections>
11631163
<action selector="AddButtonTap:" target="dRj-c1-ovZ" id="48I-uA-w0v"/>
@@ -1222,7 +1222,7 @@
12221222
<customView translatesAutoresizingMaskIntoConstraints="NO" id="glB-I7-NIu">
12231223
<rect key="frame" x="0.0" y="0.0" width="698" height="359"/>
12241224
</customView>
1225-
<stackView distribution="fill" orientation="vertical" alignment="leading" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hgT-F4-Ywd">
1225+
<stackView distribution="fill" orientation="vertical" alignment="leading" spacing="0.0" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hgT-F4-Ywd">
12261226
<rect key="frame" x="0.0" y="0.0" width="698" height="359"/>
12271227
</stackView>
12281228
</subviews>

SwiftJSONModeler For Xcode/Controller/TokenViewController.swift

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ class TokenViewController: NSViewController {
1515
@IBOutlet weak var stackView: NSStackView!
1616
@IBOutlet weak var tokenContentView: NSView!
1717
private let tokenContentLayer = CALayer()
18-
private let rowHeight: CGFloat = 60
18+
private let rowHeight: CGFloat = 40
1919
private var dataSource: [Token] = []
2020

2121
private var tokenViews: [TokenView] = []
2222
override func viewDidLoad() {
2323
super.viewDidLoad()
2424
setupView()
25+
setupToken()
2526
}
2627

2728
override func viewWillLayout() {
@@ -35,6 +36,10 @@ class TokenViewController: NSViewController {
3536
tokenContentLayer.cornerRadius = 10
3637
tokenContentView.layer = tokenContentLayer
3738
}
39+
private func setupToken() {
40+
dataSource = getToken()
41+
dataSource.forEach { addTokenView($0) }
42+
}
3843

3944
@IBAction func AddButtonTap(_ sender: NSButton) {
4045
addToken()
@@ -44,33 +49,65 @@ class TokenViewController: NSViewController {
4449
// MARK: - 数据处理
4550
private extension TokenViewController {
4651
func addToken() {
47-
let willAddToken = Token(title: titleTextField.stringValue, token: tokenTextField.stringValue)
52+
let title = titleTextField.stringValue
53+
let token = tokenTextField.stringValue
54+
guard !title.isEmpty && !token.isEmpty else {
55+
showAlert()
56+
return
57+
}
58+
let willAddToken = Token(title: title, token: token)
4859
dataSource.append(willAddToken)
60+
updateToken()
61+
addTokenView(willAddToken)
4962
titleTextField.stringValue = ""
5063
tokenTextField.stringValue = ""
64+
}
65+
func addTokenView(_ token: Token) {
5166
let tokenView = TokenView()
5267
tokenView.heightAnchor.constraint(equalToConstant: rowHeight).isActive = true
5368
stackView.addArrangedSubview(tokenView)
5469
tokenView.widthAnchor.constraint(equalTo: stackView.widthAnchor, multiplier: 1).isActive = true
5570
tokenViews.append(tokenView)
5671
tokenView.deleteClosure = {
5772
[weak self] index in
58-
self?.deleteToken(at: index)
73+
self?.deleteTokenAddView(at: index)
5974
}
60-
tokenView.config(token: willAddToken)
75+
tokenView.config(token: token)
6176
}
62-
func deleteToken(at index: Int) -> Void {
77+
func deleteTokenAddView(at index: Int) -> Void {
6378
dataSource.remove(at: index)
79+
updateToken()
6480
let willDeleteView = tokenViews[index]
6581
tokenViews.remove(at: index)
6682
stackView.removeArrangedSubview(willDeleteView)
6783
willDeleteView.removeFromSuperview()
84+
85+
}
86+
87+
func showAlert() -> Void {
88+
let alert = NSAlert()
89+
alert.messageText = "错误"
90+
alert.informativeText = "项目名和 token不能为空"
91+
alert.alertStyle = .warning
92+
alert.addButton(withTitle: "确定")
93+
alert.beginSheetModal(for: NSApplication.shared.keyWindow!) { (modal) in
94+
95+
}
96+
97+
}
98+
}
99+
extension UserDefaults {
100+
enum Key: String {
101+
case tokens
68102
}
69103
}
70-
71104
// MARK: - 数据持久化
72105
private extension TokenViewController {
73-
// func (<#parameters#>) -> <#return type#> {
74-
// <#function body#>
75-
// }
106+
func updateToken() -> Void {
107+
Token.updateUserDefault(for: dataSource)
108+
}
109+
110+
func getToken() -> [Token] {
111+
return Token.getTokenFormUserDefault()
112+
}
76113
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// Token.swift
3+
// SwiftJSONModeler For Xcode
4+
//
5+
// Created by Sven on 2020/8/21.
6+
// Copyright © 2020 Sven. All rights reserved.
7+
//
8+
9+
import Foundation
10+
/// 格式 title:token
11+
typealias TokenDescription = String
12+
13+
struct Token: CustomStringConvertible {
14+
var title: String
15+
var token: String
16+
17+
var description: String {
18+
return "\(title):\(token)"
19+
}
20+
21+
init(title: String, token: String) {
22+
self.title = title
23+
self.token = token
24+
}
25+
/// 从字符串初始化
26+
/// - Parameter titleToken: 格式必须为 title:token
27+
init(titleToken: TokenDescription) {
28+
let string = titleToken.components(separatedBy: ":")
29+
title = string[0]
30+
token = string[1]
31+
}
32+
}
33+
/// 本地化
34+
extension Token {
35+
static func updateUserDefault(for tokens: [Token]) -> Void {
36+
let userDefault = UserDefaults.standard
37+
let value = tokens.map{ $0.description }
38+
userDefault.set(value, forKey: UserDefaults.Key.tokens.rawValue)
39+
}
40+
41+
static func getTokenFormUserDefault() -> [Token] {
42+
guard let tokenStrs = UserDefaults.standard.array(forKey: UserDefaults.Key.tokens.rawValue) as? [TokenDescription] else {
43+
return []
44+
}
45+
return tokenStrs.map { Token(titleToken: $0) }
46+
}
47+
}

SwiftJSONModeler For Xcode/View/TokenView.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88

99
import Cocoa
1010

11-
struct Token {
12-
var title: String
13-
var token: String
14-
}
15-
1611
class TokenView: NSView {
1712

1813
var buttonTag: Int {

0 commit comments

Comments
 (0)