Skip to content

Commit 6916779

Browse files
committed
Fix upsidedown text
1 parent 3aec1d4 commit 6916779

File tree

2 files changed

+70
-63
lines changed

2 files changed

+70
-63
lines changed

JSONExport/FilePreviewCell.swift

+26-22
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,29 @@ class FilePreviewCell: NSTableCellView, NSTextViewDelegate {
2121
var file: FileRepresenter!{
2222
didSet{
2323
if file != nil{
24-
var fileName = file.className
25-
fileName += "."
26-
if file is HeaderFileRepresenter{
27-
fileName += file.lang.headerFileData.headerFileExtension
28-
}else{
29-
fileName += file.lang.fileExtension
30-
}
31-
classNameLabel.stringValue = fileName
32-
if(textView != nil){
33-
textView.string = file.toString()
34-
}
35-
36-
if file.includeConstructors{
37-
constructors.state = NSOnState
38-
}else{
39-
constructors.state = NSOffState
40-
}
41-
if file.includeUtilities{
42-
utilities.state = NSOnState
43-
}else{
44-
utilities.state = NSOffState
24+
DispatchQueue.main.async {
25+
var fileName = self.file.className
26+
fileName += "."
27+
if self.file is HeaderFileRepresenter{
28+
fileName += self.file.lang.headerFileData.headerFileExtension
29+
}else{
30+
fileName += self.file.lang.fileExtension
31+
}
32+
self.classNameLabel.stringValue = fileName
33+
if(self.textView != nil){
34+
self.textView.string = self.file.toString()
35+
}
36+
37+
if self.file.includeConstructors{
38+
self.constructors.state = NSOnState
39+
}else{
40+
self.constructors.state = NSOffState
41+
}
42+
if self.file.includeUtilities{
43+
self.utilities.state = NSOnState
44+
}else{
45+
self.utilities.state = NSOffState
46+
}
4547
}
4648
}else{
4749
classNameLabel.stringValue = ""
@@ -55,7 +57,9 @@ class FilePreviewCell: NSTableCellView, NSTextViewDelegate {
5557
super.awakeFromNib()
5658
if textView != nil{
5759
textView.delegate = self
58-
setupNumberedTextView()
60+
DispatchQueue.main.async {
61+
self.setupNumberedTextView()
62+
}
5963
}
6064
}
6165

JSONExport/ViewController.swift

+44-41
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
7070

7171
//Connected to the languages pop up
7272
@IBOutlet weak var languagesPopup: NSPopUpButton!
73-
73+
7474

7575
//Holds the currently selected language
7676
var selectedLang : LangModel!
7777

7878
//Returns the title of the selected language in the languagesPopup
7979
var selectedLanguageName : String
80-
{
80+
{
8181
return languagesPopup.titleOfSelectedItem!
8282
}
8383

@@ -99,8 +99,8 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
9999
}
100100

101101
/**
102-
Sets the values of languagesPopup items' titles
103-
*/
102+
Sets the values of languagesPopup items' titles
103+
*/
104104
func setLanguagesSelection()
105105
{
106106
let langNames = Array(langs.keys).sorted()
@@ -110,8 +110,8 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
110110
}
111111

112112
/**
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+
*/
115115
func setupNumberedTextView()
116116
{
117117
let lineNumberView = NoodleLineNumberView(scrollView: scrollView)
@@ -124,8 +124,8 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
124124
}
125125

126126
/**
127-
Updates the visible fields according to the selected language
128-
*/
127+
Updates the visible fields according to the selected language
128+
*/
129129
func updateUIFieldsForSelectedLanguage()
130130
{
131131
loadSelectedLanguageModel()
@@ -144,7 +144,7 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
144144
}
145145

146146
/**
147-
Loads last selected language by user
147+
Loads last selected language by user
148148
*/
149149
func loadLastSelectedLanguage()
150150
{
@@ -176,7 +176,7 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
176176
}
177177

178178
}
179-
179+
180180

181181

182182

@@ -270,7 +270,7 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
270270

271271
//MARK: - NSUserNotificationCenterDelegate
272272
func userNotificationCenter(_ center: NSUserNotificationCenter,
273-
shouldPresent notification: NSUserNotification) -> Bool
273+
shouldPresent notification: NSUserNotification) -> Bool
274274
{
275275
return true
276276
}
@@ -295,13 +295,13 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
295295
}
296296
})
297297
}
298-
299298

300-
/**
301-
Saves all the generated files in the specified path
302299

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+
*/
305305
func saveToPath(_ path : String)
306306
{
307307
var error : NSError?
@@ -331,23 +331,23 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
331331

332332
//MARK: - Messages
333333
/**
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+
*/
336336
func showDoneSuccessfully()
337337
{
338338
let notification = NSUserNotification()
339339
notification.title = "Success!"
340340
notification.informativeText = "Your \(selectedLang.langName) model files have been generated successfully."
341341
notification.deliveryDate = Date()
342-
342+
343343
let center = NSUserNotificationCenter.default
344344
center.delegate = self
345345
center.deliver(notification)
346346
}
347347

348348
/**
349-
Shows an NSAlert for the passed error
350-
*/
349+
Shows an NSAlert for the passed error
350+
*/
351351
func showError(_ error: NSError!)
352352
{
353353
if error == nil{
@@ -358,18 +358,18 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
358358
}
359359

360360
/**
361-
Shows the passed error status message
362-
*/
361+
Shows the passed error status message
362+
*/
363363
func showErrorStatus(_ errorMessage: String)
364364
{
365-
365+
366366
statusTextField.textColor = NSColor.red
367367
statusTextField.stringValue = errorMessage
368368
}
369369

370370
/**
371-
Shows the passed success status message
372-
*/
371+
Shows the passed success status message
372+
*/
373373
func showSuccessStatus(_ successMessage: String)
374374
{
375375

@@ -381,17 +381,19 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
381381

382382
//MARK: - Generate files content
383383
/**
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+
*/
386386
func generateClasses()
387387
{
388388
saveButton.isEnabled = false
389389
var str = sourceText.string!
390390

391391
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+
}
395397
return;
396398
}
397399
var rootClassName = classNameField.stringValue
@@ -415,16 +417,17 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
415417
}
416418
self.loadSelectedLanguageModel()
417419
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())
422420
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())
423425
self.sourceText.isEditable = true
424426
self.showSuccessStatus("Valid JSON structure")
425427
self.saveButton.isEnabled = true
426428

427429
self.tableView.reloadData()
430+
self.tableView.layout()
428431
}
429432
} catch let error1 as NSError {
430433
error = error1
@@ -445,10 +448,10 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
445448
}
446449

447450
/**
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+
*/
452455
func prepareAndGetFilesBuilder() -> FilesContentBuilder
453456
{
454457
let filesBuilder = FilesContentBuilder.instance
@@ -480,8 +483,8 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
480483

481484
return cell
482485
}
483-
484-
486+
487+
485488

486489
}
487490

0 commit comments

Comments
 (0)