Move NSTextFieldDelegate conformance to separate extension.

Handle the optional nil case in controlTextDidChange.
This commit is contained in:
Brent Simmons
2019-10-23 22:27:08 -07:00
parent c01b2c6269
commit 6f29497ec8

View File

@@ -10,7 +10,7 @@ import AppKit
import Articles
import Account
class AddFolderWindowController : NSWindowController, NSTextFieldDelegate {
class AddFolderWindowController : NSWindowController {
@IBOutlet var folderNameTextField: NSTextField!
@IBOutlet var accountPopupButton: NSPopUpButton!
@@ -79,20 +79,23 @@ class AddFolderWindowController : NSWindowController, NSTextFieldDelegate {
// MARK: Actions
@IBAction func cancel(_ sender: Any?) {
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.cancel)
}
@IBAction func addFolder(_ sender: Any?) {
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK)
}
}
// MARK: Text Field Delegate
// MARK: Text Field Delegate
extension AddFolderWindowController: NSTextFieldDelegate {
func controlTextDidChange(_ obj: Notification) {
if let value = (obj.object as? NSTextField)?.stringValue {
addFolderButton.isEnabled = !value.isEmpty
guard let folderName = (obj.object as? NSTextField)?.stringValue else {
addFolderButton.isEnabled = false
return
}
addFolderButton.isEnabled = !folderName.isEmpty
}
}