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,40 +52,21 @@ class AddFolderWindowController : NSWindowController {
if oneAccount.accountID == preferredAccountID {
accountPopupButton.select(oneMenuItem)
}
}
}
// MARK: Private
private func addFolderIfNeeded() {
guard let menuItem = accountPopupButton.selectedItem else {
return
}
let account = menuItem.representedObject as! Account
AppDefaults.addFolderAccountID = account.accountID
let folderName = self.folderNameTextField.stringValue
if folderName.isEmpty {
return
}
account.ensureFolder(with: folderName)
}
// MARK: Actions
// MARK: - Actions
@IBAction func cancel(_ sender: Any?) {
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.cancel)
hostWindow!.endSheet(window!, returnCode: .cancel)
}
@IBAction func addFolder(_ sender: Any?) {
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK)
hostWindow!.endSheet(window!, returnCode: .OK)
}
}
// MARK: Text Field Delegate
// MARK: - Text Field Delegate
extension AddFolderWindowController: NSTextFieldDelegate {
@ -99,3 +78,24 @@ extension AddFolderWindowController: NSTextFieldDelegate {
addFolderButton.isEnabled = !folderName.isEmpty
}
}
// MARK: - Private
private extension AddFolderWindowController {
private func addFolderIfNeeded() {
guard let menuItem = accountPopupButton.selectedItem else {
return
}
let account = menuItem.representedObject as! Account
AppDefaults.addFolderAccountID = account.accountID
let folderName = self.folderNameTextField.stringValue
if folderName.isEmpty {
return
}
account.ensureFolder(with: folderName)
}
}