Skip to content

Commit e008060

Browse files
author
Sven
committed
feat: token 显示布局
1 parent da5c2b4 commit e008060

File tree

4 files changed

+48
-24
lines changed

4 files changed

+48
-24
lines changed

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,5 @@
148148
landmarkType = "7">
149149
</BreakpointContent>
150150
</BreakpointProxy>
151-
<BreakpointProxy
152-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
153-
<BreakpointContent
154-
uuid = "7066EC06-1947-48C9-88AF-A0E8E9942902"
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 = "35"
162-
endingLineNumber = "35"
163-
landmarkName = "setupView()"
164-
landmarkType = "7">
165-
</BreakpointContent>
166-
</BreakpointProxy>
167151
</Breakpoints>
168152
</Bucket>

SwiftJSONModeler For Xcode/Base.lproj/Main.storyboard

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,9 @@
12581258
</view>
12591259
<connections>
12601260
<outlet property="stackView" destination="hgT-F4-Ywd" id="rV5-aP-Wd4"/>
1261+
<outlet property="titleTextField" destination="u2F-7R-G6v" id="u5g-zP-GLy"/>
12611262
<outlet property="tokenContentView" destination="glB-I7-NIu" id="pJ5-fO-Jas"/>
1263+
<outlet property="tokenTextField" destination="cmb-gd-KcC" id="uFT-0w-gKh"/>
12621264
</connections>
12631265
</viewController>
12641266
<customObject id="d6U-Sm-fOC" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>

SwiftJSONModeler For Xcode/Controller/TokenViewController.swift

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import Cocoa
1010

1111
class TokenViewController: NSViewController {
1212

13+
@IBOutlet weak var titleTextField: NSTextField!
14+
@IBOutlet weak var tokenTextField: NSTextField!
1315
@IBOutlet weak var stackView: NSStackView!
1416
@IBOutlet weak var tokenContentView: NSView!
1517
private let tokenContentLayer = CALayer()
1618
private let rowHeight: CGFloat = 60
17-
private var dataSource: [(title: String, token: String)] = []
19+
private var dataSource: [Token] = []
1820

1921
private var tokenViews: [TokenView] = []
2022
override func viewDidLoad() {
@@ -32,18 +34,43 @@ class TokenViewController: NSViewController {
3234
tokenContentLayer.borderColor = NSColor.lightGray.cgColor
3335
tokenContentLayer.cornerRadius = 10
3436
tokenContentView.layer = tokenContentLayer
37+
}
3538

39+
@IBAction func AddButtonTap(_ sender: NSButton) {
40+
addToken()
41+
}
42+
}
43+
44+
// MARK: - 数据处理
45+
private extension TokenViewController {
46+
func addToken() {
47+
let willAddToken = Token(title: titleTextField.stringValue, token: tokenTextField.stringValue)
48+
dataSource.append(willAddToken)
49+
titleTextField.stringValue = ""
50+
tokenTextField.stringValue = ""
3651
let tokenView = TokenView()
3752
tokenView.heightAnchor.constraint(equalToConstant: rowHeight).isActive = true
3853
stackView.addArrangedSubview(tokenView)
3954
tokenView.widthAnchor.constraint(equalTo: stackView.widthAnchor, multiplier: 1).isActive = true
40-
stackView.layer?.borderColor = NSColor.gray.cgColor
41-
stackView.layer?.borderWidth = 1.0
55+
tokenViews.append(tokenView)
56+
tokenView.deleteClosure = {
57+
[weak self] index in
58+
self?.deleteToken(at: index)
59+
}
60+
tokenView.config(token: willAddToken)
4261
}
43-
44-
45-
46-
@IBAction func AddButtonTap(_ sender: NSButton) {
47-
62+
func deleteToken(at index: Int) -> Void {
63+
dataSource.remove(at: index)
64+
let willDeleteView = tokenViews[index]
65+
tokenViews.remove(at: index)
66+
stackView.removeArrangedSubview(willDeleteView)
67+
willDeleteView.removeFromSuperview()
4868
}
4969
}
70+
71+
// MARK: - 数据持久化
72+
private extension TokenViewController {
73+
// func (<#parameters#>) -> <#return type#> {
74+
// <#function body#>
75+
// }
76+
}

SwiftJSONModeler For Xcode/View/TokenView.swift

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

99
import Cocoa
1010

11+
struct Token {
12+
var title: String
13+
var token: String
14+
}
15+
1116
class TokenView: NSView {
1217

1318
var buttonTag: Int {
@@ -49,6 +54,12 @@ class TokenView: NSView {
4954
contentView.frame = bounds
5055
deleteButton.attributedTitle = NSAttributedString(string: "删除", attributes: [NSAttributedString.Key.foregroundColor : NSColor.red])
5156
}
57+
58+
func config(token: Token) -> Void {
59+
tokenLabel.stringValue = token.token
60+
titleLabel.stringValue = token.title
61+
}
62+
5263
@IBAction func deleteButtonTap(_ sender: NSButton) {
5364
deleteClosure(sender.tag)
5465
}

0 commit comments

Comments
 (0)