/
GureumConfiguration.swift
235 lines (205 loc) · 8.79 KB
/
GureumConfiguration.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
229
230
231
232
233
234
235
//
// GureumConfiguration.swift
// Gureum
//
// Created by Jeong YunWon on 2018. 4. 19..
// Copyright © 2018 youknowone.org. All rights reserved.
//
import Foundation
import AppKit
enum GureumConfigurationName: String {
case lastHangulInputMode = "CIMLastHangulInputMode"
case lastRomanInputMode = "CIMLastRomanInputMode"
case leftCommandKeyShortcutBehavior = "CIMLeftCommandKeyShortcutBehavior"
case leftOptionKeyShortcutBehavior = "CIMLeftOptionKeyShortcutBehavior"
case leftControlKeyShortcutBehavior = "CIMLeftControlKeyShortcutBehavior"
case rightCommandKeyShortcutBehavior = "CIMRightCommandKeyShortcutBehavior"
case rightOptionKeyShortcutBehavior = "CIMRightOptionKeyShortcutBehavior"
case rightControlKeyShortcutBehavior = "CIMRightControlKeyShortcutBehavior"
case inputModeExchangeKey = "CIMInputModeExchangeKey"
case inputModeEmoticonKey = "CIMInputModeEmoticonKey"
case inputModeHanjaKey = "CIMInputModeHanjaKey"
case inputModeEnglishKey = "CIMInputModeEnglishKey"
case inputModeKoreanKey = "CIMInputModeKoreanKey"
case optionKeyBehavior = "CIMOptionKeyBehavior"
case enableCapslockToToggleInputMode = "EnableCapslockToToggleInputMode"
case autosaveDefaultInputMode = "CIMAutosaveDefaultInputMode"
case romanModeByEscapeKey = "CIMRomanModeByEscapeKey"
case showsInputForHanjaCandidates = "CIMShowsInputForHanjaCandidates"
case skippedVersion = "SkippedVersion"
case hangulWonCurrencySymbolForBackQuote = "HangulWonCurrencySymbolForBackQuote"
case hangulAutoReorder = "HangulAutoReorder"
case hangulNonChoseongCombination = "HangulNonChoseongCombination"
}
@objc public class GureumConfiguration: UserDefaults {
public typealias Shortcut = (UInt, NSEvent.ModifierFlags)
public class func convertShortcutToConfiguration(_ shortcut: Shortcut?) -> [String: Any] {
guard let shortcut = shortcut else {
return [:]
}
return ["modifier": shortcut.1.rawValue, "keyCode": shortcut.0]
}
public 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))
}
init() {
super.init(suiteName: "org.youknowone.Gureum")!
self.register(defaults: [
GureumConfigurationName.inputModeExchangeKey.rawValue: GureumConfiguration.convertShortcutToConfiguration((0x31, .shift)),
GureumConfigurationName.inputModeEmoticonKey.rawValue: GureumConfiguration.convertShortcutToConfiguration((0x24, [.shift, .option])),
GureumConfigurationName.inputModeHanjaKey.rawValue: GureumConfiguration.convertShortcutToConfiguration((0x24, .option)),
GureumConfigurationName.optionKeyBehavior.rawValue: 0,
GureumConfigurationName.autosaveDefaultInputMode.rawValue: true,
GureumConfigurationName.romanModeByEscapeKey.rawValue: false,
GureumConfigurationName.showsInputForHanjaCandidates.rawValue: true,
GureumConfigurationName.hangulWonCurrencySymbolForBackQuote.rawValue: true,
GureumConfigurationName.enableCapslockToToggleInputMode.rawValue: true,
GureumConfigurationName.lastHangulInputMode.rawValue: "org.youknowone.inputmethod.Gureum.han2",
GureumConfigurationName.lastRomanInputMode.rawValue: "org.youknowone.inputmethod.Gureum.qwerty",
])
}
func getShortcut(forKey key: String) -> Shortcut? {
guard let value = self.dictionary(forKey: key) else {
return nil
}
return GureumConfiguration.convertConfigurationToShortcut(value)
}
func setShortcut(_ newValue: Shortcut?, forKey key: String) {
self.set(GureumConfiguration.convertShortcutToConfiguration(newValue) , forKey: key)
}
@objc public var lastHangulInputMode: String? {
get {
return self.string(forKey: GureumConfigurationName.lastHangulInputMode.rawValue)
}
set {
return self.set(newValue, forKey: GureumConfigurationName.lastHangulInputMode.rawValue)
}
}
@objc public var lastRomanInputMode: String? {
get {
return self.string(forKey: GureumConfigurationName.lastRomanInputMode.rawValue)
}
set {
return self.set(newValue, forKey: GureumConfigurationName.lastRomanInputMode.rawValue)
}
}
@objc public var optionKeyBehavior: Int {
get {
return self.integer(forKey: GureumConfigurationName.optionKeyBehavior.rawValue)
}
set {
return self.set(newValue, forKey: GureumConfigurationName.optionKeyBehavior.rawValue)
}
}
@objc public var showsInputForHanjaCandidates: Bool {
get {
return self.bool(forKey: GureumConfigurationName.showsInputForHanjaCandidates.rawValue)
}
set {
return self.set(newValue, forKey: GureumConfigurationName.showsInputForHanjaCandidates.rawValue)
}
}
@objc public var enableCapslockToToggleInputMode: Bool {
get {
return self.bool(forKey: GureumConfigurationName.enableCapslockToToggleInputMode.rawValue)
}
set {
return self.set(newValue, forKey: GureumConfigurationName.enableCapslockToToggleInputMode.rawValue)
}
}
public var inputModeExchangeKey: Shortcut? {
get {
return getShortcut(forKey: GureumConfigurationName.inputModeExchangeKey.rawValue)
}
set {
setShortcut(newValue, forKey: GureumConfigurationName.inputModeExchangeKey.rawValue)
}
}
public var inputModeEmoticonKey: Shortcut? {
get {
return getShortcut(forKey: GureumConfigurationName.inputModeEmoticonKey.rawValue)
}
set {
setShortcut(newValue, forKey: GureumConfigurationName.inputModeEmoticonKey.rawValue)
}
}
public var inputModeHanjaKey: Shortcut? {
get {
return getShortcut(forKey: GureumConfigurationName.inputModeHanjaKey.rawValue)
}
set {
setShortcut(newValue, forKey: GureumConfigurationName.inputModeHanjaKey.rawValue)
}
}
public var inputModeEnglishKey: Shortcut? {
get {
return getShortcut(forKey: GureumConfigurationName.inputModeEnglishKey.rawValue)
}
set {
setShortcut(newValue, forKey: GureumConfigurationName.inputModeEnglishKey.rawValue)
}
}
public var inputModeKoreanKey: Shortcut? {
get {
return getShortcut(forKey: GureumConfigurationName.inputModeKoreanKey.rawValue)
}
set {
setShortcut(newValue, forKey: GureumConfigurationName.inputModeKoreanKey.rawValue)
}
}
@objc public var romanModeByEscapeKey: Bool {
get {
return self.bool(forKey: GureumConfigurationName.romanModeByEscapeKey.rawValue);
}
set {
return self.set(newValue, forKey: GureumConfigurationName.romanModeByEscapeKey.rawValue)
}
}
@objc public var autosaveDefaultInputMode: Bool {
get {
return self.bool(forKey: GureumConfigurationName.autosaveDefaultInputMode.rawValue);
}
set {
return self.set(newValue, forKey: GureumConfigurationName.autosaveDefaultInputMode.rawValue)
}
}
public var skippedVersion: String? {
get {
return self.string(forKey: GureumConfigurationName.skippedVersion.rawValue)
}
set {
return self.set(newValue, forKey: GureumConfigurationName.skippedVersion.rawValue)
}
}
public var hangulWonCurrencySymbolForBackQuote: Bool {
get {
return self.bool(forKey: GureumConfigurationName.hangulWonCurrencySymbolForBackQuote.rawValue)
}
set {
return self.set(newValue, forKey: GureumConfigurationName.hangulWonCurrencySymbolForBackQuote.rawValue)
}
}
public var hangulAutoReorder: Bool {
get {
return self.bool(forKey: GureumConfigurationName.hangulAutoReorder.rawValue)
}
set {
return self.set(newValue, forKey: GureumConfigurationName.hangulAutoReorder.rawValue)
}
}
public var hangulNonChoseongCombination: Bool {
get {
return self.bool(forKey: GureumConfigurationName.hangulNonChoseongCombination.rawValue)
}
set {
return self.set(newValue, forKey: GureumConfigurationName.hangulNonChoseongCombination.rawValue)
}
}
static let _shared = GureumConfiguration()
@objc class func shared() -> GureumConfiguration {
return _shared
}
}