-
-
Notifications
You must be signed in to change notification settings - Fork 124
/
Configuration.swift
228 lines (196 loc) · 7.64 KB
/
Configuration.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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
//
// Configuration.swift
// Gureum
//
// Created by Jeong YunWon on 2018. 4. 19..
// Copyright © 2018 youknowone.org. All rights reserved.
//
import AppKit
import Foundation
enum ConfigurationName: String {
case lastHangulInputMode = "LastHangulInputMode"
case lastRomanInputMode = "LastRomanInputMode"
case inputModeExchangeKey = "InputModeExchangeKey"
case inputModeEmoticonKey = "InputModeEmoticonKey"
case inputModeHanjaKey = "InputModeHanjaKey"
case inputModeEnglishKey = "InputModeEnglishKey"
case inputModeKoreanKey = "InputModeKoreanKey"
case optionKeyBehavior = "OptionKeyBehavior"
case overridingKeyboardName = "OverridingKeyboardName"
case romanModeByEscapeKey = "ExchangeToRomanModeByEscapeKey"
case showsInputForHanjaCandidates = "ShowsInputForHanjaCandidates"
case hangulWonCurrencySymbolForBackQuote = "HangulWonCurrencySymbolForBackQuote"
case hangulAutoReorder = "HangulAutoReorder"
case hangulNonChoseongCombination = "HangulNonChoseongCombination"
case hangulForceStrictCombinationRule = "HangulForceStrictCombinationRule"
}
public class Configuration: UserDefaults {
public static let sharedSuiteName = "org.youknowone.Gureum"
public static var shared = Configuration()
var enableCapslockToToggleInputMode: Bool = false
typealias Shortcut = (UInt, NSEvent.ModifierFlags)
class func convertShortcutToConfiguration(_ shortcut: Shortcut?) -> [String: Any] {
guard let shortcut = shortcut else {
return [:]
}
return ["modifier": shortcut.1.rawValue, "keyCode": shortcut.0]
}
class func convertConfigurationToShortcut(_ configuration: [String: Any]) -> Shortcut? {
guard let modifier = configuration["modifier"] as? UInt, let keyCode = configuration["keyCode"] as? UInt else {
return nil
}
return (keyCode, NSEvent.ModifierFlags(rawValue: modifier))
}
override init?(suiteName: String?) {
super.init(suiteName: suiteName)
register(defaults: [
ConfigurationName.lastHangulInputMode.rawValue: "org.youknowone.inputmethod.Gureum.han2",
ConfigurationName.lastRomanInputMode.rawValue: "org.youknowone.inputmethod.Gureum.qwerty",
ConfigurationName.inputModeEmoticonKey.rawValue: Configuration.convertShortcutToConfiguration((0x24, [.shift, .option])),
ConfigurationName.inputModeHanjaKey.rawValue: Configuration.convertShortcutToConfiguration((0x24, .option)),
ConfigurationName.optionKeyBehavior.rawValue: 0,
ConfigurationName.overridingKeyboardName.rawValue: "com.apple.keylayout.ABC",
ConfigurationName.romanModeByEscapeKey.rawValue: false,
ConfigurationName.showsInputForHanjaCandidates.rawValue: false,
ConfigurationName.hangulWonCurrencySymbolForBackQuote.rawValue: true,
ConfigurationName.hangulAutoReorder.rawValue: false,
ConfigurationName.hangulNonChoseongCombination.rawValue: false,
ConfigurationName.hangulForceStrictCombinationRule.rawValue: false,
])
}
convenience init() {
self.init(suiteName: Configuration.sharedSuiteName)!
}
public func persistentDomain() -> [String: Any] {
return persistentDomain(forName: Configuration.sharedSuiteName) ?? [:]
}
func getShortcut(forKey key: String) -> Shortcut? {
guard let value = self.dictionary(forKey: key) else {
return nil
}
return Configuration.convertConfigurationToShortcut(value)
}
func setShortcut(_ newValue: Shortcut?, forKey key: String) {
`set`(Configuration.convertShortcutToConfiguration(newValue), forKey: key)
}
var lastHangulInputMode: String {
get {
return string(forKey: ConfigurationName.lastHangulInputMode.rawValue)!
}
set {
`set`(newValue, forKey: ConfigurationName.lastHangulInputMode.rawValue)
}
}
var lastRomanInputMode: String {
get {
return string(forKey: ConfigurationName.lastRomanInputMode.rawValue)!
}
set {
`set`(newValue, forKey: ConfigurationName.lastRomanInputMode.rawValue)
}
}
var optionKeyBehavior: Int {
get {
return integer(forKey: ConfigurationName.optionKeyBehavior.rawValue)
}
set {
`set`(newValue, forKey: ConfigurationName.optionKeyBehavior.rawValue)
}
}
var overridingKeyboardName: String {
get {
return string(forKey: ConfigurationName.overridingKeyboardName.rawValue)!
}
set {
`set`(newValue, forKey: ConfigurationName.overridingKeyboardName.rawValue)
}
}
var showsInputForHanjaCandidates: Bool {
get {
return bool(forKey: ConfigurationName.showsInputForHanjaCandidates.rawValue)
}
set {
`set`(newValue, forKey: ConfigurationName.showsInputForHanjaCandidates.rawValue)
}
}
var inputModeExchangeKey: Shortcut? {
get {
return getShortcut(forKey: ConfigurationName.inputModeExchangeKey.rawValue)
}
set {
setShortcut(newValue, forKey: ConfigurationName.inputModeExchangeKey.rawValue)
}
}
var inputModeEmoticonKey: Shortcut? {
get {
return getShortcut(forKey: ConfigurationName.inputModeEmoticonKey.rawValue)
}
set {
setShortcut(newValue, forKey: ConfigurationName.inputModeEmoticonKey.rawValue)
}
}
var inputModeHanjaKey: Shortcut? {
get {
return getShortcut(forKey: ConfigurationName.inputModeHanjaKey.rawValue)
}
set {
setShortcut(newValue, forKey: ConfigurationName.inputModeHanjaKey.rawValue)
}
}
var inputModeEnglishKey: Shortcut? {
get {
return getShortcut(forKey: ConfigurationName.inputModeEnglishKey.rawValue)
}
set {
setShortcut(newValue, forKey: ConfigurationName.inputModeEnglishKey.rawValue)
}
}
var inputModeKoreanKey: Shortcut? {
get {
return getShortcut(forKey: ConfigurationName.inputModeKoreanKey.rawValue)
}
set {
setShortcut(newValue, forKey: ConfigurationName.inputModeKoreanKey.rawValue)
}
}
var romanModeByEscapeKey: Bool {
get {
return bool(forKey: ConfigurationName.romanModeByEscapeKey.rawValue)
}
set {
`set`(newValue, forKey: ConfigurationName.romanModeByEscapeKey.rawValue)
}
}
var hangulWonCurrencySymbolForBackQuote: Bool {
get {
return bool(forKey: ConfigurationName.hangulWonCurrencySymbolForBackQuote.rawValue)
}
set {
`set`(newValue, forKey: ConfigurationName.hangulWonCurrencySymbolForBackQuote.rawValue)
}
}
var hangulAutoReorder: Bool {
get {
return bool(forKey: ConfigurationName.hangulAutoReorder.rawValue)
}
set {
`set`(newValue, forKey: ConfigurationName.hangulAutoReorder.rawValue)
}
}
var hangulNonChoseongCombination: Bool {
get {
return bool(forKey: ConfigurationName.hangulNonChoseongCombination.rawValue)
}
set {
`set`(newValue, forKey: ConfigurationName.hangulNonChoseongCombination.rawValue)
}
}
var hangulForceStrictCombinationRule: Bool {
get {
return bool(forKey: ConfigurationName.hangulForceStrictCombinationRule.rawValue)
}
set {
`set`(newValue, forKey: ConfigurationName.hangulForceStrictCombinationRule.rawValue)
}
}
}