NetNewsWire/Mac/Preferences/Accounts/AccountsDeleteWindowController.swift
2019-05-02 06:57:45 -05:00

51 lines
1.3 KiB
Swift

//
// AccountsDeleteWindowController.swift
// NetNewsWire
//
// Created by Maurice Parker on 5/1/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import AppKit
import Account
class AccountsDeleteWindowController: NSWindowController {
@IBOutlet weak var deleteLabel: NSTextField!
private weak var hostWindow: NSWindow?
var account: Account?
convenience init(account: Account) {
self.init(windowNibName: NSNib.Name("AccountsDelete"))
self.account = account
}
override func windowDidLoad() {
let deletePrompt = NSLocalizedString("Delete", comment: "Delete")
deleteLabel.stringValue = "\(deletePrompt) \"\(account?.nameForDisplay ?? "")\"?"
}
// MARK: API
func runSheetOnWindow(_ hostWindow: NSWindow, completionHandler handler: ((NSApplication.ModalResponse) -> Void)? = nil) {
self.hostWindow = hostWindow
hostWindow.beginSheet(window!, completionHandler: handler)
}
// MARK: Actions
@IBAction func cancel(_ sender: Any) {
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.cancel)
}
@IBAction func delete(_ sender: Any) {
guard let account = account else {
return
}
AccountManager.shared.deleteAccount(account)
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK)
}
}