From 62b83b3d296917b4e99599c2489a3f8373f4f4a9 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Tue, 10 Jul 2018 19:43:07 +0200 Subject: [PATCH] Fix activity log window. It did not show all the messages sent before it had been shown. --- Classes/ActivityWindowController.swift | 11 ++++++----- Classes/AppDelegate.swift | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Classes/ActivityWindowController.swift b/Classes/ActivityWindowController.swift index 2d7f4e5..bfd1997 100644 --- a/Classes/ActivityWindowController.swift +++ b/Classes/ActivityWindowController.swift @@ -12,12 +12,13 @@ class ActivityWindowController : NSWindowController, MP42Logging { @IBOutlet var logView: NSTextView! let logger: Logger + private let storage: NSTextStorage init(logger: Logger) { self.logger = logger + self.storage = NSTextStorage() super.init(window: nil) self.logger.delegate = self - _ = self.window; } required init?(coder: NSCoder) { @@ -30,20 +31,20 @@ class ActivityWindowController : NSWindowController, MP42Logging { override func windowDidLoad() { super.windowDidLoad() + + logView.layoutManager?.replaceTextStorage(storage) } func write(toLog string: String) { DispatchQueue.main.async { let attrString = NSAttributedString(string: string) - self.logView.textStorage?.append(attrString) + self.storage.append(attrString) } } @IBAction func clearLog(_ sender: Any) { logger.clear() - if let textStorage = logView.textStorage { - textStorage.deleteCharacters(in: NSMakeRange(0, textStorage.length)) - } + storage.deleteCharacters(in: NSMakeRange(0, storage.length)) } diff --git a/Classes/AppDelegate.swift b/Classes/AppDelegate.swift index 6f61bfc..ce3e18c 100644 --- a/Classes/AppDelegate.swift +++ b/Classes/AppDelegate.swift @@ -146,6 +146,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { PrefsWindowController.registerUserDefaults() _ = documentController + _ = activityWindowController logger.clear() MP42File.setGlobalLogger(logger)