Create separate private extension. Make misc. code formatting changes to match current thinking.
This commit is contained in:
parent
6f29497ec8
commit
1c06eb27e8
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue