forked from glushchenko/fsnotes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProjectSettingsViewController.swift
74 lines (56 loc) · 2.06 KB
/
ProjectSettingsViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// ProjectSettingsViewController.swift
// FSNotes
//
// Created by Oleksandr Glushchenko on 11/23/18.
// Copyright © 2018 Oleksandr Glushchenko. All rights reserved.
//
import Cocoa
import Carbon.HIToolbox
class ProjectSettingsViewController: NSViewController {
private var project: Project?
@IBOutlet weak var modificationDate: NSButton!
@IBOutlet weak var creationDate: NSButton!
@IBOutlet weak var titleButton: NSButton!
@IBOutlet weak var showInAll: NSButton!
@IBOutlet weak var firstLineAsTitle: NSButton!
@IBAction func sortBy(_ sender: NSButton) {
project?.sortBy = SortBy(rawValue: sender.identifier!.rawValue)!
project?.saveSettings()
guard let vc = ViewController.shared() else {
return
}
vc.updateTable()
}
@IBAction func showNotesInMainList(_ sender: NSButton) {
project?.showInCommon = sender.state == .on
project?.saveSettings()
}
@IBAction func firstLineAsTitle(_ sender: NSButton) {
guard let project = self.project else { return }
project.firstLineAsTitle = sender.state == .on
project.saveSettings()
let notes = Storage.sharedInstance().getNotesBy(project: project)
for note in notes {
note.invalidateCache()
}
guard let vc = ViewController.shared() else { return }
vc.notesTableView.reloadData()
}
@IBAction func close(_ sender: Any) {
self.dismiss(nil)
}
override func keyDown(with event: NSEvent) {
if event.keyCode == kVK_Return || event.keyCode == kVK_Escape {
self.dismiss(nil)
}
}
public func load(project: Project) {
showInAll.state = project.showInCommon ? .on : .off
firstLineAsTitle.state = project.firstLineAsTitle ? .on : .off
modificationDate.state = project.sortBy == .modificationDate ? .on : .off
creationDate.state = project.sortBy == .creationDate ? .on : .off
titleButton.state = project.sortBy == .title ? .on : .off
self.project = project
}
}