@@ -12,14 +12,14 @@ import Cocoa
12
12
class SJEditorViewController : NSViewController , NSTextViewDelegate {
13
13
14
14
// MARK: Outlet files.
15
- @IBOutlet var textView : SJTextView ?
16
- @IBOutlet var messageLabel : NSTextField ?
17
- @IBOutlet var errorImageView : NSImageView ?
18
- @IBOutlet var baseClassTextField : NSTextField ?
19
- @IBOutlet var prefixClassTextField : NSTextField ?
20
- @IBOutlet var companyNameTextField : NSTextField ?
21
- @IBOutlet var authorNameTextField : NSTextField ?
22
- @IBOutlet var includeSwiftyCheckbox : NSButton ?
15
+ @IBOutlet var textView : SJTextView !
16
+ @IBOutlet var messageLabel : NSTextField !
17
+ @IBOutlet var errorImageView : NSImageView !
18
+ @IBOutlet var baseClassTextField : NSTextField !
19
+ @IBOutlet var prefixClassTextField : NSTextField !
20
+ @IBOutlet var companyNameTextField : NSTextField !
21
+ @IBOutlet var authorNameTextField : NSTextField !
22
+ @IBOutlet var includeSwiftyCheckbox : NSButton !
23
23
@IBOutlet var supportNSCodingCheckbox : NSButton !
24
24
@IBOutlet var supportSwiftyJSONCheckbox : NSButton !
25
25
@IBOutlet var supportObjectMapperCheckbox : NSButton !
@@ -49,12 +49,12 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate {
49
49
}
50
50
51
51
/**
52
- Validates and updates the textview.
52
+ Validates and updates the textview.
53
53
54
- - parameter pretty: If the JSON is to be pretty printed.
54
+ - parameter pretty: If the JSON is to be pretty printed.
55
55
56
- - returns: if the format was valid.
57
- */
56
+ - returns: if the format was valid.
57
+ */
58
58
func validateAndFormat( pretty: Bool ) -> Bool {
59
59
60
60
if textView? . string? . characters. count == 0 {
@@ -80,8 +80,8 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate {
80
80
}
81
81
82
82
/**
83
- Actual function that generates the model.
84
- */
83
+ Actual function that generates the model.
84
+ */
85
85
func generateModel( ) {
86
86
87
87
// The base class field is blank, cannot proceed without it. Possibly can have a default value in the future.
@@ -106,13 +106,24 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate {
106
106
107
107
let swiftyState = self . includeSwiftyCheckbox? . state == 1 ? true : false
108
108
let supportSwiftyState = self . supportSwiftyJSONCheckbox? . state == 1 ? true : false
109
-
109
+
110
110
let nscodingState = self . supportNSCodingCheckbox? . state == 1 ? true : false
111
-
111
+
112
112
let objectMapperState = self . includeObjectMapperCheckbox? . state == 1 ? true : false
113
113
let supportObjectMapperState = self . supportObjectMapperCheckbox? . state == 1 ? true : false
114
114
115
- let generator : ModelGenerator = ModelGenerator . init ( baseContent: JSON ( object!) , prefix: prefixClassTextField? . stringValue, baseClassName: ( baseClassTextField? . stringValue) !, authorName: authorNameTextField? . stringValue, companyName: companyNameTextField? . stringValue, type: ModelType . kClassType, filePath: filePath!, supportSwiftyJSON: supportSwiftyState, includeSwiftyJSON: swiftyState, supportObjectMapper: supportObjectMapperState, includeObjectMapper: objectMapperState, supportNSCoding: nscodingState)
115
+ let generator : ModelGenerator = ModelGenerator . init ( baseContent: JSON ( object!) , baseClassName: baseClassTextField. stringValue, filePath: filePath!)
116
+
117
+ generator. prefix = prefixClassTextField. stringValue
118
+ generator. authorName = authorNameTextField. stringValue
119
+ generator. companyName = companyNameTextField. stringValue
120
+ generator. type = ModelType . kClassType
121
+ generator. supportSwiftyJSON = supportSwiftyState
122
+ generator. includeSwiftyJSON = swiftyState
123
+ generator. supportObjectMapper = supportObjectMapperState
124
+ generator. includeObjectMapper = objectMapperState
125
+ generator. supportNSCoding = nscodingState
126
+
116
127
generator. generate ( )
117
128
} else {
118
129
let alert : NSAlert = NSAlert ( )
@@ -122,7 +133,7 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate {
122
133
}
123
134
124
135
@IBAction func recalcEnabledBoxes( sender: AnyObject ) {
125
-
136
+
126
137
let supportSwiftyState = self . supportSwiftyJSONCheckbox? . state == 1 ? true : false
127
138
let supportObjectMapperState = self . supportObjectMapperCheckbox? . state == 1 ? true : false
128
139
@@ -132,15 +143,15 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate {
132
143
else {
133
144
self . includeSwiftyCheckbox? . enabled = false
134
145
}
135
-
146
+
136
147
if supportObjectMapperState {
137
148
self . includeObjectMapperCheckbox? . enabled = true
138
149
}
139
150
else {
140
151
self . includeObjectMapperCheckbox? . enabled = false
141
152
}
142
153
}
143
-
154
+
144
155
// MARK: Internal Methods
145
156
146
157
/**
@@ -177,11 +188,11 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate {
177
188
}
178
189
179
190
/**
180
- Handle Error message that is provided by the JSON helper and extract the message and showing them accordingly.
191
+ Handle Error message that is provided by the JSON helper and extract the message and showing them accordingly.
181
192
182
- - parameters:
183
- - error: NSError that was provided.
184
- */
193
+ - parameters:
194
+ - error: NSError that was provided.
195
+ */
185
196
func handleError( error: NSError ? ) {
186
197
if let _ = error!. userInfo [ " debugDescription " ] as? String ? {
187
198
let message : String = error!. userInfo [ " NSDebugDescription " ] ! as! String
@@ -214,19 +225,19 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate {
214
225
}
215
226
216
227
/**
217
- Show that the JSON is fine with proper icon.
218
- */
228
+ Show that the JSON is fine with proper icon.
229
+ */
219
230
func correctJSONMessage( ) {
220
231
errorImageView? . image = NSImage . init ( named: " success " )
221
232
messageLabel? . stringValue = " Valid JSON! "
222
233
}
223
234
224
235
/**
225
- Show the invalid JSON error with proper error and message.
236
+ Show the invalid JSON error with proper error and message.
226
237
227
- - parameters:
228
- - message: Error message that is to be shown.
229
- */
238
+ - parameters:
239
+ - message: Error message that is to be shown.
240
+ */
230
241
func invalidJSONError( message: String ) {
231
242
errorImageView? . image = NSImage . init ( named: " failure " )
232
243
messageLabel? . stringValue = message
0 commit comments