mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Add a confirmation alert for the delete context menu so that it matches other delete functionality.
This commit is contained in:
42
Mac/MainWindow/Sidebar/SidebarDeleteItemsAlert.swift
Normal file
42
Mac/MainWindow/Sidebar/SidebarDeleteItemsAlert.swift
Normal file
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// SidebarDeleteItemsAlert.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Maurice Parker on 10/23/20.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import AppKit
|
||||
import RSTree
|
||||
import Account
|
||||
|
||||
enum SidebarDeleteItemsAlert {
|
||||
|
||||
/// Builds a delete confirmation dialog for the supplied nodes
|
||||
static func build(_ nodes: [Node]) -> NSAlert {
|
||||
let alert = NSAlert()
|
||||
alert.alertStyle = .warning
|
||||
|
||||
if nodes.count == 1 {
|
||||
if let folder = nodes.first?.representedObject as? Folder {
|
||||
alert.messageText = NSLocalizedString("Delete Folder", comment: "Delete Folder")
|
||||
let localizedInformativeText = NSLocalizedString("Are you sure you want to delete the “%@” folder?", comment: "Folder delete text")
|
||||
alert.informativeText = NSString.localizedStringWithFormat(localizedInformativeText as NSString, folder.nameForDisplay) as String
|
||||
} else if let feed = nodes.first?.representedObject as? Feed {
|
||||
alert.messageText = NSLocalizedString("Delete Feed", comment: "Delete Feed")
|
||||
let localizedInformativeText = NSLocalizedString("Are you sure you want to delete the “%@” feed?", comment: "Feed delete text")
|
||||
alert.informativeText = NSString.localizedStringWithFormat(localizedInformativeText as NSString, feed.nameForDisplay) as String
|
||||
}
|
||||
} else {
|
||||
alert.messageText = NSLocalizedString("Delete Items", comment: "Delete Items")
|
||||
let localizedInformativeText = NSLocalizedString("Are you sure you want to delete the %d selected items?", comment: "Items delete text")
|
||||
alert.informativeText = NSString.localizedStringWithFormat(localizedInformativeText as NSString, nodes.count) as String
|
||||
}
|
||||
|
||||
alert.addButton(withTitle: NSLocalizedString("Delete", comment: "Delete Account"))
|
||||
alert.addButton(withTitle: NSLocalizedString("Cancel", comment: "Cancel Delete Account"))
|
||||
|
||||
return alert
|
||||
}
|
||||
|
||||
}
|
||||
@@ -72,13 +72,18 @@ extension SidebarViewController {
|
||||
}
|
||||
|
||||
@objc func deleteFromContextualMenu(_ sender: Any?) {
|
||||
|
||||
guard let menuItem = sender as? NSMenuItem, let objects = menuItem.representedObject as? [AnyObject] else {
|
||||
return
|
||||
}
|
||||
|
||||
let nodes = objects.compactMap { treeController.nodeInTreeRepresentingObject($0) }
|
||||
deleteNodes(nodes)
|
||||
|
||||
let alert = SidebarDeleteItemsAlert.build(nodes)
|
||||
alert.beginSheetModal(for: view.window!) { [weak self] result in
|
||||
if result == NSApplication.ModalResponse.alertFirstButtonReturn {
|
||||
self?.deleteNodes(nodes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc func renameFromContextualMenu(_ sender: Any?) {
|
||||
|
||||
@@ -236,28 +236,8 @@ protocol SidebarDelegate: class {
|
||||
return
|
||||
}
|
||||
|
||||
let alert = NSAlert()
|
||||
alert.alertStyle = .warning
|
||||
let alert = SidebarDeleteItemsAlert.build(availableSelectedNodes)
|
||||
|
||||
if availableSelectedNodes.count == 1 {
|
||||
if let folder = availableSelectedNodes.first?.representedObject as? Folder {
|
||||
alert.messageText = NSLocalizedString("Delete Folder", comment: "Delete Folder")
|
||||
let localizedInformativeText = NSLocalizedString("Are you sure you want to delete the “%@” folder?", comment: "Folder delete text")
|
||||
alert.informativeText = NSString.localizedStringWithFormat(localizedInformativeText as NSString, folder.nameForDisplay) as String
|
||||
} else if let feed = availableSelectedNodes.first?.representedObject as? Feed {
|
||||
alert.messageText = NSLocalizedString("Delete Feed", comment: "Delete Feed")
|
||||
let localizedInformativeText = NSLocalizedString("Are you sure you want to delete the “%@” feed?", comment: "Feed delete text")
|
||||
alert.informativeText = NSString.localizedStringWithFormat(localizedInformativeText as NSString, feed.nameForDisplay) as String
|
||||
}
|
||||
} else {
|
||||
alert.messageText = NSLocalizedString("Delete Items", comment: "Delete Items")
|
||||
let localizedInformativeText = NSLocalizedString("Are you sure you want to delete the %d selected items?", comment: "Items delete text")
|
||||
alert.informativeText = NSString.localizedStringWithFormat(localizedInformativeText as NSString, availableSelectedNodes.count) as String
|
||||
}
|
||||
|
||||
alert.addButton(withTitle: NSLocalizedString("Delete", comment: "Delete Account"))
|
||||
alert.addButton(withTitle: NSLocalizedString("Cancel", comment: "Cancel Delete Account"))
|
||||
|
||||
alert.beginSheetModal(for: view.window!) { [weak self] result in
|
||||
if result == NSApplication.ModalResponse.alertFirstButtonReturn {
|
||||
guard let self = self else { return }
|
||||
@@ -269,7 +249,6 @@ protocol SidebarDelegate: class {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@IBAction func doubleClickedSidebar(_ sender: Any?) {
|
||||
|
||||
@@ -297,6 +297,8 @@
|
||||
5183CCE8226F68D90010922C /* AccountRefreshTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCE7226F68D90010922C /* AccountRefreshTimer.swift */; };
|
||||
518651B223555EB20078E021 /* NNW3Document.swift in Sources */ = {isa = PBXBuildFile; fileRef = 518651AB23555EB20078E021 /* NNW3Document.swift */; };
|
||||
518651DA235621840078E021 /* ImageTransition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 518651D9235621840078E021 /* ImageTransition.swift */; };
|
||||
51868BF1254386630011A17B /* SidebarDeleteItemsAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51868BF0254386630011A17B /* SidebarDeleteItemsAlert.swift */; };
|
||||
51868BF2254386630011A17B /* SidebarDeleteItemsAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51868BF0254386630011A17B /* SidebarDeleteItemsAlert.swift */; };
|
||||
5186A635235EF3A800C97195 /* VibrantLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5186A634235EF3A800C97195 /* VibrantLabel.swift */; };
|
||||
518B2EE82351B45600400001 /* NetNewsWire_iOSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 840D61952029031D009BC708 /* NetNewsWire_iOSTests.swift */; };
|
||||
518C3193237B00D9004D740F /* DetailIconSchemeHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5141E7552374A2890013FF27 /* DetailIconSchemeHandler.swift */; };
|
||||
@@ -1618,6 +1620,7 @@
|
||||
5183CCE7226F68D90010922C /* AccountRefreshTimer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountRefreshTimer.swift; sourceTree = "<group>"; };
|
||||
518651AB23555EB20078E021 /* NNW3Document.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NNW3Document.swift; sourceTree = "<group>"; };
|
||||
518651D9235621840078E021 /* ImageTransition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageTransition.swift; sourceTree = "<group>"; };
|
||||
51868BF0254386630011A17B /* SidebarDeleteItemsAlert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarDeleteItemsAlert.swift; sourceTree = "<group>"; };
|
||||
5186A634235EF3A800C97195 /* VibrantLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VibrantLabel.swift; sourceTree = "<group>"; };
|
||||
518B2ED22351B3DD00400001 /* NetNewsWire-iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "NetNewsWire-iOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
518B2EE92351B4C200400001 /* NetNewsWire_iOSTests_target.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = NetNewsWire_iOSTests_target.xcconfig; sourceTree = "<group>"; };
|
||||
@@ -3111,6 +3114,7 @@
|
||||
children = (
|
||||
84AD1EA92031617300BC20B7 /* PasteboardFolder.swift */,
|
||||
848D578D21543519005FFAD5 /* PasteboardWebFeed.swift */,
|
||||
51868BF0254386630011A17B /* SidebarDeleteItemsAlert.swift */,
|
||||
84AD1EBB2032AF5C00BC20B7 /* SidebarOutlineDataSource.swift */,
|
||||
849A97601ED9EB96007D329B /* SidebarOutlineView.swift */,
|
||||
849A97821ED9EC63007D329B /* SidebarStatusBarView.swift */,
|
||||
@@ -4943,6 +4947,7 @@
|
||||
65ED4030235DEF6C0081F399 /* SmallIconProvider.swift in Sources */,
|
||||
510C417E24E5D1AE008226FD /* ExtensionFeedAddRequest.swift in Sources */,
|
||||
65ED4031235DEF6C0081F399 /* ArticleExtractor.swift in Sources */,
|
||||
51868BF2254386630011A17B /* SidebarDeleteItemsAlert.swift in Sources */,
|
||||
65ED4032235DEF6C0081F399 /* FetchRequestQueue.swift in Sources */,
|
||||
65ED4033235DEF6C0081F399 /* SidebarKeyboardDelegate.swift in Sources */,
|
||||
65ED4034235DEF6C0081F399 /* AccountsPreferencesViewController.swift in Sources */,
|
||||
@@ -5162,6 +5167,7 @@
|
||||
84BBB12E20142A4700F054F5 /* InspectorWindowController.swift in Sources */,
|
||||
51EF0F7A22771B890050506E /* ColorHash.swift in Sources */,
|
||||
84E46C7D1F75EF7B005ECFB3 /* AppDefaults.swift in Sources */,
|
||||
51868BF1254386630011A17B /* SidebarDeleteItemsAlert.swift in Sources */,
|
||||
D5907D972004B7EB005947E5 /* Account+Scriptability.swift in Sources */,
|
||||
841ABA4E20145E7300980E11 /* NothingInspectorViewController.swift in Sources */,
|
||||
842E45CE1ED8C308000A8B52 /* AppNotifications.swift in Sources */,
|
||||
|
||||
Reference in New Issue
Block a user