@@ -70,14 +70,14 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
70
70
71
71
//Connected to the languages pop up
72
72
@IBOutlet weak var languagesPopup : NSPopUpButton !
73
-
73
+
74
74
75
75
//Holds the currently selected language
76
76
var selectedLang : LangModel !
77
77
78
78
//Returns the title of the selected language in the languagesPopup
79
79
var selectedLanguageName : String
80
- {
80
+ {
81
81
return languagesPopup. titleOfSelectedItem!
82
82
}
83
83
@@ -99,8 +99,8 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
99
99
}
100
100
101
101
/**
102
- Sets the values of languagesPopup items' titles
103
- */
102
+ Sets the values of languagesPopup items' titles
103
+ */
104
104
func setLanguagesSelection( )
105
105
{
106
106
let langNames = Array ( langs. keys) . sorted ( )
@@ -110,8 +110,8 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
110
110
}
111
111
112
112
/**
113
- Sets the needed configurations for show the line numbers in the input text view
114
- */
113
+ Sets the needed configurations for show the line numbers in the input text view
114
+ */
115
115
func setupNumberedTextView( )
116
116
{
117
117
let lineNumberView = NoodleLineNumberView ( scrollView: scrollView)
@@ -124,8 +124,8 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
124
124
}
125
125
126
126
/**
127
- Updates the visible fields according to the selected language
128
- */
127
+ Updates the visible fields according to the selected language
128
+ */
129
129
func updateUIFieldsForSelectedLanguage( )
130
130
{
131
131
loadSelectedLanguageModel ( )
@@ -144,7 +144,7 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
144
144
}
145
145
146
146
/**
147
- Loads last selected language by user
147
+ Loads last selected language by user
148
148
*/
149
149
func loadLastSelectedLanguage( )
150
150
{
@@ -176,7 +176,7 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
176
176
}
177
177
178
178
}
179
-
179
+
180
180
181
181
182
182
@@ -270,7 +270,7 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
270
270
271
271
//MARK: - NSUserNotificationCenterDelegate
272
272
func userNotificationCenter( _ center: NSUserNotificationCenter ,
273
- shouldPresent notification: NSUserNotification ) -> Bool
273
+ shouldPresent notification: NSUserNotification ) -> Bool
274
274
{
275
275
return true
276
276
}
@@ -295,13 +295,13 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
295
295
}
296
296
} )
297
297
}
298
-
299
298
300
- /**
301
- Saves all the generated files in the specified path
302
299
303
- - parameter path: in which to save the files
304
- */
300
+ /**
301
+ Saves all the generated files in the specified path
302
+
303
+ - parameter path: in which to save the files
304
+ */
305
305
func saveToPath( _ path : String )
306
306
{
307
307
var error : NSError ?
@@ -331,23 +331,23 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
331
331
332
332
//MARK: - Messages
333
333
/**
334
- Shows the top right notification. Call it after saving the files successfully
335
- */
334
+ Shows the top right notification. Call it after saving the files successfully
335
+ */
336
336
func showDoneSuccessfully( )
337
337
{
338
338
let notification = NSUserNotification ( )
339
339
notification. title = " Success! "
340
340
notification. informativeText = " Your \( selectedLang. langName) model files have been generated successfully. "
341
341
notification. deliveryDate = Date ( )
342
-
342
+
343
343
let center = NSUserNotificationCenter . default
344
344
center. delegate = self
345
345
center. deliver ( notification)
346
346
}
347
347
348
348
/**
349
- Shows an NSAlert for the passed error
350
- */
349
+ Shows an NSAlert for the passed error
350
+ */
351
351
func showError( _ error: NSError ! )
352
352
{
353
353
if error == nil {
@@ -358,18 +358,18 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
358
358
}
359
359
360
360
/**
361
- Shows the passed error status message
362
- */
361
+ Shows the passed error status message
362
+ */
363
363
func showErrorStatus( _ errorMessage: String )
364
364
{
365
-
365
+
366
366
statusTextField. textColor = NSColor . red
367
367
statusTextField. stringValue = errorMessage
368
368
}
369
369
370
370
/**
371
- Shows the passed success status message
372
- */
371
+ Shows the passed success status message
372
+ */
373
373
func showSuccessStatus( _ successMessage: String )
374
374
{
375
375
@@ -381,17 +381,19 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
381
381
382
382
//MARK: - Generate files content
383
383
/**
384
- Validates the sourceText string input, and takes any needed action to generate the model classes and view them in the preview panel
385
- */
384
+ Validates the sourceText string input, and takes any needed action to generate the model classes and view them in the preview panel
385
+ */
386
386
func generateClasses( )
387
387
{
388
388
saveButton. isEnabled = false
389
389
var str = sourceText. string!
390
390
391
391
if str. characters. count == 0 {
392
- //Nothing to do, just clear any generated files
393
- files. removeAll ( keepingCapacity: false )
394
- tableView. reloadData ( )
392
+ runOnUiThread {
393
+ //Nothing to do, just clear any generated files
394
+ self . files. removeAll ( keepingCapacity: false )
395
+ self . tableView. reloadData ( )
396
+ }
395
397
return ;
396
398
}
397
399
var rootClassName = classNameField. stringValue
@@ -415,16 +417,17 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
415
417
}
416
418
self . loadSelectedLanguageModel ( )
417
419
self . files. removeAll ( keepingCapacity: false )
418
- let fileGenerator = self . prepareAndGetFilesBuilder ( )
419
- fileGenerator. addFileWithName ( & rootClassName, jsonObject: json, files: & self . files)
420
- fileGenerator. fixReferenceMismatches ( inFiles: self . files)
421
- self . files = Array ( self . files. reversed ( ) )
422
420
runOnUiThread {
421
+ let fileGenerator = self . prepareAndGetFilesBuilder ( )
422
+ fileGenerator. addFileWithName ( & rootClassName, jsonObject: json, files: & self . files)
423
+ fileGenerator. fixReferenceMismatches ( inFiles: self . files)
424
+ self . files = Array ( self . files. reversed ( ) )
423
425
self . sourceText. isEditable = true
424
426
self . showSuccessStatus ( " Valid JSON structure " )
425
427
self . saveButton. isEnabled = true
426
428
427
429
self . tableView. reloadData ( )
430
+ self . tableView. layout ( )
428
431
}
429
432
} catch let error1 as NSError {
430
433
error = error1
@@ -445,10 +448,10 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
445
448
}
446
449
447
450
/**
448
- Creates and returns an instance of FilesContentBuilder. It also configure the values from the UI components to the instance. I.e includeConstructors
449
-
450
- - returns: instance of configured FilesContentBuilder
451
- */
451
+ Creates and returns an instance of FilesContentBuilder. It also configure the values from the UI components to the instance. I.e includeConstructors
452
+
453
+ - returns: instance of configured FilesContentBuilder
454
+ */
452
455
func prepareAndGetFilesBuilder( ) -> FilesContentBuilder
453
456
{
454
457
let filesBuilder = FilesContentBuilder . instance
@@ -480,8 +483,8 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
480
483
481
484
return cell
482
485
}
483
-
484
-
486
+
487
+
485
488
486
489
}
487
490
0 commit comments