Create separate private extension. Make misc. code formatting changes to match current thinking.

This commit is contained in:
Brent Simmons 2019-10-23 22:33:21 -07:00
parent 6f29497ec8
commit 1c06eb27e8
1 changed files with 28 additions and 28 deletions

View File

@ -15,17 +15,15 @@ class AddFolderWindowController : NSWindowController {
@IBOutlet var folderNameTextField: NSTextField!
@IBOutlet var accountPopupButton: NSPopUpButton!
@IBOutlet var addFolderButton: NSButton!
var hostWindow: NSWindow?
private var hostWindow: NSWindow?
convenience init() {
self.init(windowNibName: NSNib.Name("AddFolderSheet"))
}
// MARK: API
// MARK: - API
func runSheetOnWindow(_ w: NSWindow) {
hostWindow = w
hostWindow!.beginSheet(window!) { (returnCode: NSApplication.ModalResponse) -> Void in
@ -35,7 +33,7 @@ class AddFolderWindowController : NSWindowController {
}
}
// MARK: NSViewController
// MARK: - NSViewController
override func windowDidLoad() {
let preferredAccountID = AppDefaults.addFolderAccountID
@ -54,11 +52,36 @@ class AddFolderWindowController : NSWindowController {
if oneAccount.accountID == preferredAccountID {
accountPopupButton.select(oneMenuItem)
}
}
}
// MARK: Private
// MARK: - Actions
@IBAction func cancel(_ sender: Any?) {
hostWindow!.endSheet(window!, returnCode: .cancel)
}
@IBAction func addFolder(_ sender: Any?) {
hostWindow!.endSheet(window!, returnCode: .OK)
}
}
// MARK: - Text Field Delegate
extension AddFolderWindowController: NSTextFieldDelegate {
func controlTextDidChange(_ obj: Notification) {
guard let folderName = (obj.object as? NSTextField)?.stringValue else {
addFolderButton.isEnabled = false
return
}
addFolderButton.isEnabled = !folderName.isEmpty
}
}
// MARK: - Private
private extension AddFolderWindowController {
private func addFolderIfNeeded() {
guard let menuItem = accountPopupButton.selectedItem else {
@ -75,27 +98,4 @@ class AddFolderWindowController : NSWindowController {
account.ensureFolder(with: folderName)
}
// 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
extension AddFolderWindowController: NSTextFieldDelegate {
func controlTextDidChange(_ obj: Notification) {
guard let folderName = (obj.object as? NSTextField)?.stringValue else {
addFolderButton.isEnabled = false
return
}
addFolderButton.isEnabled = !folderName.isEmpty
}
}