Skip to content

Commit 3425360

Browse files
authored
Merge pull request #120 from DeveloperAcademy-POSTECH/fix/#118
[#118] 추가 버그 픽스
2 parents 469d1cb + 59d3780 commit 3425360

File tree

7 files changed

+98
-54
lines changed

7 files changed

+98
-54
lines changed

LabDuck/Model/KPBoard.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ struct KPBoard: Identifiable {
9191
}
9292

9393
public func getTag(_ name: String) -> KPTag? {
94-
self.allTags.first(where: { $0.name == name })
94+
let name = name.trimmingCharacters(in: .whitespacesAndNewlines)
95+
return self.allTags.first(where: { $0.name == name })
9596
}
9697

9798
public func getTag(_ id: KPTag.ID) -> KPTag? {
@@ -121,6 +122,16 @@ struct KPBoard: Identifiable {
121122
}
122123
}
123124

125+
public mutating func createTag(_ name: String, _ color: KPTagColor) -> KPTag {
126+
if let tag = getTag(name) {
127+
return tag
128+
} else {
129+
let tag = KPTag(id: UUID(), name: name, colorTheme: color)
130+
self.allTags.append(tag)
131+
return tag
132+
}
133+
}
134+
124135
public mutating func deleteTag(_ tagID: KPTag.ID) {
125136
self.allTags.removeAll(where: { $0.id == tagID })
126137
}

LabDuck/Model/KPBoardDocument.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,20 @@ extension KPBoardDocument {
396396
}
397397
}
398398

399+
func changeViewType(to viewType: KPBoard.BoardViewType, animation: Animation? = .default) {
400+
withAnimation(animation) {
401+
self.board.viewType = viewType
402+
}
403+
}
404+
399405
}
400406

401407
// MARK: - 태그
402408
extension KPBoardDocument {
403409
// tag를 새로 만들 때 사용.
404410
// 보드에 해당 tag가 있으면 무시. 아니면 새로 생성.
405411
func createTag(_ name: String, undoManager: UndoManager?, animation: Animation? = .default) {
412+
let name = name.trimmingCharacters(in: .whitespacesAndNewlines)
406413
if let tag = self.board.getTag(name) {
407414
print("Already there : \(tag)")
408415
} else {
@@ -416,6 +423,21 @@ extension KPBoardDocument {
416423
}
417424
}
418425

426+
func createTag(_ name: String, color: KPTagColor, undoManager: UndoManager?, animation: Animation? = .default) {
427+
let name = name.trimmingCharacters(in: .whitespacesAndNewlines)
428+
if let tag = self.board.getTag(name) {
429+
print("Already there : \(tag)")
430+
} else {
431+
let tag = withAnimation(animation) {
432+
self.board.createTag(name, color)
433+
}
434+
435+
undoManager?.registerUndo(withTarget: self) { doc in
436+
doc.deleteTag(tagID: tag.id, undoManager: undoManager)
437+
}
438+
}
439+
}
440+
419441
// tag를 삭제할 때 사용.
420442
// 보드에 해당 tag가 없으면 무시. 아니면 지우기
421443
func deleteTag(tagID: KPTag.ID, undoManager: UndoManager?, animation: Animation? = .default) {

LabDuck/Util/CSVConvertManager.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ class CSVConvertManager {
3939
} else if writableKeyPath(from: key, type: [KPTag.ID].self) != nil {
4040
let values = value.components(separatedBy: ",")
4141
values
42+
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
4243
.filter { name in
43-
!name.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
44+
!name.isEmpty
4445
}
4546
.forEach { name in
4647
if let tag = board.getTag(name) {

LabDuck/View/MainView.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ struct MainDocumentView: View {
1919

2020
}
2121
var body: some View {
22-
MainView(board: $document.board)
22+
MainView(board: document.board)
2323
}
2424
}
2525

2626
struct MainView: View {
2727
@EnvironmentObject var document: KPBoardDocument
2828
@Environment(\.undoManager) var undoManager
29-
@Binding var board: KPBoard
29+
var board: KPBoard
30+
@State private var viewType: KPBoard.BoardViewType = .table
3031
// @State private var uniqueTags: [KPTag] = []
3132

3233
// MARK: - Zoom
@@ -141,7 +142,7 @@ struct MainView: View {
141142
}
142143

143144
ToolbarItem(placement: .principal) {
144-
Picker("View", selection: $board.viewType) {
145+
Picker("View", selection: $viewType) {
145146
ForEach(KPBoard.BoardViewType.allCases, id: \.self) { view in
146147
Text(view.rawValue).tag(view)
147148
}
@@ -179,11 +180,24 @@ struct MainView: View {
179180
.navigationTitle("\(board.title)")
180181
.toolbarBackground(Color(hex: 0xEAEAEA))
181182
}
183+
.onAppear {
184+
self.viewType = self.board.viewType
185+
}
186+
.onChange(of: self.viewType) { oldValue, newValue in
187+
self.document.changeViewType(to: newValue)
188+
}
182189
}
183190

184191
var trackWheelScrollPublisher = NSApp.publisher(for: \.currentEvent)
185192
.eraseToAnyPublisher()
186-
.filter { event in event?.type == .scrollWheel }
193+
.filter { event in
194+
if event?.type == .scrollWheel {
195+
if let window = NSApp.keyWindow, event?.window == window {
196+
return true
197+
}
198+
}
199+
return false
200+
}
187201

188202
private func calculateCenterCoordinate(_ size: CGSize) -> CGPoint {
189203
let scaledWidth = size.width * scaleValue

0 commit comments

Comments
 (0)