2017-05-27 19:43:27 +02:00
|
|
|
//
|
|
|
|
// AddFolderWindowController.swift
|
2018-08-29 07:18:24 +02:00
|
|
|
// NetNewsWire
|
2017-05-27 19:43:27 +02:00
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 8/1/15.
|
|
|
|
// Copyright © 2015 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2018-02-03 07:51:32 +01:00
|
|
|
import AppKit
|
2018-07-24 03:29:08 +02:00
|
|
|
import Articles
|
2017-09-17 21:54:08 +02:00
|
|
|
import Account
|
2017-05-27 19:43:27 +02:00
|
|
|
|
|
|
|
class AddFolderWindowController : NSWindowController {
|
|
|
|
|
|
|
|
@IBOutlet var folderNameTextField: NSTextField!
|
|
|
|
@IBOutlet var accountPopupButton: NSPopUpButton!
|
|
|
|
var hostWindow: NSWindow?
|
|
|
|
|
|
|
|
convenience init() {
|
|
|
|
|
2018-12-09 21:32:33 +01:00
|
|
|
self.init(windowNibName: NSNib.Name("AddFolderSheet"))
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: API
|
|
|
|
|
|
|
|
func runSheetOnWindow(_ w: NSWindow) {
|
|
|
|
|
|
|
|
hostWindow = w
|
2017-09-17 21:54:08 +02:00
|
|
|
hostWindow!.beginSheet(window!) { (returnCode: NSApplication.ModalResponse) -> Void in
|
2017-05-27 19:43:27 +02:00
|
|
|
|
2017-09-17 21:54:08 +02:00
|
|
|
if returnCode == NSApplication.ModalResponse.OK {
|
2017-05-27 19:43:27 +02:00
|
|
|
self.addFolderIfNeeded()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: NSViewController
|
|
|
|
|
|
|
|
override func windowDidLoad() {
|
2019-05-21 16:36:33 +02:00
|
|
|
let preferredAccountID = AppDefaults.addFolderAccountID
|
2017-05-27 19:43:27 +02:00
|
|
|
accountPopupButton.removeAllItems()
|
2019-05-21 16:36:33 +02:00
|
|
|
|
2017-05-27 19:43:27 +02:00
|
|
|
let menu = NSMenu()
|
2019-05-21 16:36:33 +02:00
|
|
|
accountPopupButton.menu = menu
|
|
|
|
|
2019-05-02 13:01:30 +02:00
|
|
|
for oneAccount in AccountManager.shared.sortedActiveAccounts {
|
2019-05-21 16:36:33 +02:00
|
|
|
|
2017-05-27 19:43:27 +02:00
|
|
|
let oneMenuItem = NSMenuItem()
|
|
|
|
oneMenuItem.title = oneAccount.nameForDisplay
|
|
|
|
oneMenuItem.representedObject = oneAccount
|
|
|
|
menu.addItem(oneMenuItem)
|
2019-05-21 16:36:33 +02:00
|
|
|
|
|
|
|
if oneAccount.accountID == preferredAccountID {
|
|
|
|
accountPopupButton.select(oneMenuItem)
|
|
|
|
}
|
|
|
|
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Private
|
|
|
|
|
|
|
|
private func addFolderIfNeeded() {
|
|
|
|
guard let menuItem = accountPopupButton.selectedItem else {
|
|
|
|
return
|
|
|
|
}
|
2019-05-21 16:36:33 +02:00
|
|
|
|
2017-05-27 19:43:27 +02:00
|
|
|
let account = menuItem.representedObject as! Account
|
2019-05-21 16:36:33 +02:00
|
|
|
AppDefaults.addFolderAccountID = account.accountID
|
2017-05-27 19:43:27 +02:00
|
|
|
|
|
|
|
let folderName = self.folderNameTextField.stringValue
|
|
|
|
if folderName.isEmpty {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-09-27 13:38:43 +02:00
|
|
|
account.addFolder(folderName) { result in
|
|
|
|
switch result {
|
|
|
|
case .success:
|
|
|
|
break
|
|
|
|
case .failure(let error):
|
|
|
|
NSApplication.shared.presentError(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Actions
|
|
|
|
|
2018-02-12 03:58:50 +01:00
|
|
|
@IBAction func cancel(_ sender: Any?) {
|
2017-05-27 19:43:27 +02:00
|
|
|
|
2017-09-17 21:54:08 +02:00
|
|
|
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.cancel)
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
|
|
|
|
2018-02-12 03:58:50 +01:00
|
|
|
@IBAction func addFolder(_ sender: Any?) {
|
2017-05-27 19:43:27 +02:00
|
|
|
|
2017-09-17 21:54:08 +02:00
|
|
|
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK)
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|