mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-26 17:43:22 +01:00
Make progress on LogWindowController.
This commit is contained in:
parent
887e562716
commit
48ca636796
@ -12,48 +12,94 @@ class LogWindowController: NSWindowController {
|
||||
|
||||
@IBOutlet private var textView: NSTextView!
|
||||
private var title: String!
|
||||
private weak var log: Log?
|
||||
// private let attributes = [NSFont.Att
|
||||
public convenience init(title: String) {
|
||||
|
||||
public convenience init(title: String, log: Log) {
|
||||
|
||||
self.init(windowNibName: NSNib.Name(rawValue: "LogWindow"))
|
||||
self.log = log
|
||||
self.title = title
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(logDidAddItem(_:)), name: .LogDidAddItem, object: log)
|
||||
}
|
||||
|
||||
override func windowDidLoad() {
|
||||
|
||||
window!.title = title
|
||||
addExistingLogItems()
|
||||
}
|
||||
|
||||
public func appendLine(_ s: String) {
|
||||
// MARK: - Notifications
|
||||
|
||||
// Adds two line feeds before the text.
|
||||
@objc func logDidAddItem(_ note: Notification) {
|
||||
|
||||
guard let logItem = note.userInfo?[Log.logItemKey] as? LogItem else {
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public func setTextViewText(_ s: String) {
|
||||
|
||||
let attributedString = NSAttributedString(string: s)
|
||||
textView.textStorage?.setAttributedString(attributedString)
|
||||
|
||||
validateButtons()
|
||||
appendLogItem(logItem)
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
@IBAction func clearContents(_ sender: Any?) {
|
||||
|
||||
setTextViewText("")
|
||||
setTextViewAttributedString(NSAttributedString(string: ""))
|
||||
}
|
||||
|
||||
@IBAction func saveToFile(_ sender: Any?) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private extension LogWindowController {
|
||||
|
||||
func addExistingLogItems() {
|
||||
|
||||
guard let logItems = log?.logItems else {
|
||||
return
|
||||
}
|
||||
|
||||
let attString = NSMutableAttributedString()
|
||||
for logItem in logItems {
|
||||
let oneAttString = attributedString(for: logItem)
|
||||
attString.append(oneAttString)
|
||||
}
|
||||
|
||||
textView.textStorage?.setAttributedString(attString)
|
||||
|
||||
validateButtons()
|
||||
}
|
||||
|
||||
func setTextViewAttributedString(_ attString: NSAttributedString) {
|
||||
|
||||
textView.textStorage?.setAttributedString(attString)
|
||||
validateButtons()
|
||||
}
|
||||
|
||||
func appendAttributedString(_ attString: NSAttributedString) {
|
||||
|
||||
if !Thread.isMainThread {
|
||||
DispatchQueue.main.async {
|
||||
self.appendAttributedString(attString)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
validateButtons()
|
||||
}
|
||||
|
||||
func appendLogItem(_ logItem: LogItem) {
|
||||
|
||||
}
|
||||
|
||||
func attributedString(for logItem: LogItem) -> NSAttributedString {
|
||||
|
||||
return NSAttributedString() //TODO
|
||||
|
||||
}
|
||||
|
||||
func validateButtons() {
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user