forked from sbarex/SourceCodeSyntaxHighlight
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSSControlView.swift
More file actions
119 lines (100 loc) · 3.68 KB
/
Copy pathCSSControlView.swift
File metadata and controls
119 lines (100 loc) · 3.68 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//
// CSSControlViewController.swift
// SyntaxHighlight
//
// Created by Sbarex on 16/11/2019.
// Copyright © 2019 sbarex. All rights reserved.
//
//
// This file is part of SyntaxHighlight.
// SyntaxHighlight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// SyntaxHighlight is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SyntaxHighlight. If not, see <http://www.gnu.org/licenses/>.
import Cocoa
class CSSControlViewController: NSViewController {
enum Mode {
case global
case format
case themeProperty
}
var mode: Mode = .global {
didSet {
afterModeChanged()
}
}
var cssCode: String = "" {
didSet {
textView?.string = cssCode
}
}
var isStandardPropertiesOverridden: Bool = false {
didSet {
overrideButton?.state = isStandardPropertiesOverridden ? .on : .off
}
}
var isEditable = true {
didSet {
if isEditable != oldValue {
updateIsEditable()
}
}
}
var handler: ((String, Bool, Bool)->Void)?
@IBOutlet weak var infoLabel: NSTextField!
@IBOutlet weak var textView: NSTextView!
@IBOutlet weak var warningMessage: NSTextField!
@IBOutlet weak var overrideButton: NSButton!
@IBOutlet weak var saveButton: NSButton!
@IBOutlet weak var cancelButton: NSButton!
@IBAction func showHelp(_ sender: Any) {
if let locBookName = Bundle.main.object(forInfoDictionaryKey: "CFBundleHelpBookName") as? String {
NSHelpManager.shared.openHelpAnchor(mode == .global ? "SyntaxHighlight_CUSTOMCSS" : "SyntaxHighlight_CUSTOMCSS_THEME", inBook: locBookName)
}
}
@IBAction func doSave(_ sender: Any) {
handler?(textView.string, isStandardPropertiesOverridden, true)
dismiss(sender)
}
@IBAction func doClose(_ sender: Any) {
handler?(textView.string, isStandardPropertiesOverridden, false)
dismiss(sender)
}
override func viewDidLoad() {
afterModeChanged()
textView?.string = cssCode
textView.font = NSFont.monospacedSystemFont(ofSize: 11, weight: NSFont.Weight.regular)
textView.textColor = NSColor.textColor
textView.backgroundColor = NSColor.textBackgroundColor
textView.isEditable = isEditable
overrideButton.state = isStandardPropertiesOverridden ? .on : .off
updateIsEditable()
}
internal func afterModeChanged() {
switch mode {
case .global, .format:
infoLabel?.stringValue = "Custom CSS style sheet:"
case .themeProperty:
infoLabel?.stringValue = "Inline CSS style:"
}
warningMessage?.isHidden = mode != .format
overrideButton?.isHidden = mode != .themeProperty
}
internal func updateIsEditable() {
textView?.isEditable = isEditable
cancelButton?.isHidden = !isEditable
saveButton?.title = isEditable ? "OK" : "Close"
overrideButton?.isEnabled = isEditable
}
@IBAction internal func handleOverrideButton(_ sender: NSButton) {
isStandardPropertiesOverridden = sender.state == .on
}
}