From 1802f715728b02895407b868b63fdb8404073cee Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Wed, 1 May 2019 18:26:23 -0500 Subject: [PATCH] Implement the delete UI --- Mac/Base.lproj/Preferences.storyboard | 3 +- Mac/Preferences/Accounts/AccountsDelete.xib | 92 +++++++++++++++++++ .../AccountsDeleteWindowController.swift | 47 ++++++++++ .../AccountsPreferencesViewController.swift | 18 +++- NetNewsWire.xcodeproj/project.pbxproj | 8 ++ 5 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 Mac/Preferences/Accounts/AccountsDelete.xib create mode 100644 Mac/Preferences/Accounts/AccountsDeleteWindowController.swift diff --git a/Mac/Base.lproj/Preferences.storyboard b/Mac/Base.lproj/Preferences.storyboard index 6f440710d..69ab33c6f 100644 --- a/Mac/Base.lproj/Preferences.storyboard +++ b/Mac/Base.lproj/Preferences.storyboard @@ -351,7 +351,7 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/Mac/Preferences/Accounts/AccountsDeleteWindowController.swift b/Mac/Preferences/Accounts/AccountsDeleteWindowController.swift new file mode 100644 index 000000000..708b85897 --- /dev/null +++ b/Mac/Preferences/Accounts/AccountsDeleteWindowController.swift @@ -0,0 +1,47 @@ +// +// 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) { + self.hostWindow = hostWindow + hostWindow.beginSheet(window!) + } + + // MARK: Actions + + @IBAction func cancel(_ sender: Any) { + hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.cancel) + } + + @IBAction func create(_ sender: Any) { + + hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK) + } + +} diff --git a/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift b/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift index 6cbb40604..162d01c37 100644 --- a/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift +++ b/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift @@ -13,7 +13,9 @@ final class AccountsPreferencesViewController: NSViewController { @IBOutlet weak var tableView: NSTableView! @IBOutlet weak var detailView: NSView! + @IBOutlet weak var deleteButton: NSButton! + private var deleteController: AccountsDeleteWindowController? private var sortedAccounts = [Account]() override func viewDidLoad() { @@ -36,6 +38,12 @@ final class AccountsPreferencesViewController: NSViewController { } @IBAction func removeAccount(_ sender: Any) { + guard tableView.selectedRow != -1 else { + return + } + let account = sortedAccounts[tableView.selectedRow] + deleteController = AccountsDeleteWindowController(account: account) + deleteController!.runSheetOnWindow(view.window!) } @objc func displayNameDidChange(_ note: Notification) { @@ -89,11 +97,17 @@ extension AccountsPreferencesViewController: NSTableViewDelegate { func tableViewSelectionDidChange(_ notification: Notification) { let selectedRow = tableView.selectedRow - guard selectedRow != -1 else { + if tableView.selectedRow == -1 { + deleteButton.isEnabled = false return + } else { + deleteButton.isEnabled = true } - + let account = sortedAccounts[selectedRow] + if AccountManager.shared.defaultAccount == account { + deleteButton.isEnabled = false + } let controller = AccountsDetailViewController(account: account) showController(controller) diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index d28f8ecc3..0be744ed9 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -24,6 +24,8 @@ 5144EA3D227A37AF00D19003 /* ExportOPMLSheet.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5144EA3C227A37AF00D19003 /* ExportOPMLSheet.xib */; }; 5144EA40227A37EC00D19003 /* ImportOPMLWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5144EA3E227A37EC00D19003 /* ImportOPMLWindowController.swift */; }; 5144EA43227A380F00D19003 /* ExportOPMLWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5144EA42227A380F00D19003 /* ExportOPMLWindowController.swift */; }; + 5144EA46227A5A8700D19003 /* AccountsDeleteWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5144EA44227A5A8700D19003 /* AccountsDeleteWindowController.swift */; }; + 5144EA47227A5A8700D19003 /* AccountsDelete.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5144EA45227A5A8700D19003 /* AccountsDelete.xib */; }; 5183CCD0226E1E880010922C /* NonIntrinsicLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCCF226E1E880010922C /* NonIntrinsicLabel.swift */; }; 5183CCDA226E31A50010922C /* NonIntrinsicImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCD9226E31A50010922C /* NonIntrinsicImageView.swift */; }; 5183CCDD226F1F5C0010922C /* NavigationProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCDC226F1F5C0010922C /* NavigationProgressView.swift */; }; @@ -650,6 +652,8 @@ 5144EA3C227A37AF00D19003 /* ExportOPMLSheet.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ExportOPMLSheet.xib; sourceTree = ""; }; 5144EA3E227A37EC00D19003 /* ImportOPMLWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImportOPMLWindowController.swift; sourceTree = ""; }; 5144EA42227A380F00D19003 /* ExportOPMLWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExportOPMLWindowController.swift; sourceTree = ""; }; + 5144EA44227A5A8700D19003 /* AccountsDeleteWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountsDeleteWindowController.swift; sourceTree = ""; }; + 5144EA45227A5A8700D19003 /* AccountsDelete.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AccountsDelete.xib; sourceTree = ""; }; 5183CCCF226E1E880010922C /* NonIntrinsicLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonIntrinsicLabel.swift; sourceTree = ""; }; 5183CCD9226E31A50010922C /* NonIntrinsicImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonIntrinsicImageView.swift; sourceTree = ""; }; 5183CCDC226F1F5C0010922C /* NavigationProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationProgressView.swift; sourceTree = ""; }; @@ -1596,6 +1600,8 @@ 5144EA2E2279FAB600D19003 /* AccountsDetailViewController.swift */, 5144EA352279FC3D00D19003 /* AccountsAddLocal.xib */, 5144EA372279FC6200D19003 /* AccountsAddLocalWindowController.swift */, + 5144EA45227A5A8700D19003 /* AccountsDelete.xib */, + 5144EA44227A5A8700D19003 /* AccountsDeleteWindowController.swift */, ); path = Accounts; sourceTree = ""; @@ -2189,6 +2195,7 @@ 848362FF2262A30E00DA1D35 /* template.html in Resources */, 848363082262A3DD00DA1D35 /* Main.storyboard in Resources */, 51EF0F8E2279C9260050506E /* AccountsAdd.xib in Resources */, + 5144EA47227A5A8700D19003 /* AccountsDelete.xib in Resources */, 84C9FC8F22629E8F00D921D6 /* NetNewsWire.sdef in Resources */, 84C9FC7D22629E1200D921D6 /* AccountsDetail.xib in Resources */, 5144EA362279FC3D00D19003 /* AccountsAddLocal.xib in Resources */, @@ -2412,6 +2419,7 @@ 84B7178C201E66580091657D /* SidebarViewController+ContextualMenus.swift in Sources */, 5144EA43227A380F00D19003 /* ExportOPMLWindowController.swift in Sources */, 842611A21FCB769D0086A189 /* RSHTMLMetadata+Extension.swift in Sources */, + 5144EA46227A5A8700D19003 /* AccountsDeleteWindowController.swift in Sources */, 84A1500520048DDF0046AD9A /* SendToMarsEditCommand.swift in Sources */, D5907DB22004BB37005947E5 /* ScriptingObjectContainer.swift in Sources */, 849A978A1ED9ECEF007D329B /* ArticleStylesManager.swift in Sources */,