mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-09 16:48:45 +01:00
Add initial context menu items for feeds.
This commit is contained in:
parent
1eb8da7749
commit
c03c444997
@ -278,6 +278,17 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
|
||||||
|
guard let node = coordinator.nodeFor(indexPath), !(node.representedObject is PseudoFeed) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if node.representedObject is Feed {
|
||||||
|
return makeFeedContextMenu(indexPath: indexPath, includeDeleteRename: true)
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
coordinator.selectFeed(indexPath)
|
coordinator.selectFeed(indexPath)
|
||||||
}
|
}
|
||||||
@ -592,32 +603,56 @@ private extension MasterFeedViewController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func delete(indexPath: IndexPath) {
|
func makeFeedContextMenu(indexPath: IndexPath, includeDeleteRename: Bool) -> UIContextMenuConfiguration {
|
||||||
|
return UIContextMenuConfiguration(identifier: nil, previewProvider: nil, actionProvider: { suggestedActions in
|
||||||
|
|
||||||
guard let undoManager = undoManager,
|
var actions = [UIAction]()
|
||||||
let deleteNode = coordinator.nodeFor(indexPath),
|
|
||||||
let deleteCommand = DeleteCommand(nodesToDelete: [deleteNode], treeController: coordinator.treeController, undoManager: undoManager, errorHandler: ErrorHandler.present(self))
|
if let homePageAction = self.homePageAction(indexPath: indexPath) {
|
||||||
else {
|
actions.append(homePageAction)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var deleteIndexPaths = [indexPath]
|
if includeDeleteRename {
|
||||||
if coordinator.isExpanded(deleteNode) {
|
actions.append(self.deleteAction(indexPath: indexPath))
|
||||||
for i in 0..<deleteNode.numberOfChildNodes {
|
actions.append(self.renameAction(indexPath: indexPath))
|
||||||
deleteIndexPaths.append(IndexPath(row: indexPath.row + 1 + i, section: indexPath.section))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pushUndoableCommand(deleteCommand)
|
let feedMsg = NSLocalizedString("Feed Menu", comment: "Feed Menu")
|
||||||
|
return UIMenu(title: feedMsg, children: actions)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
coordinator.beginUpdates()
|
|
||||||
deleteCommand.perform {
|
|
||||||
self.coordinator.treeController.rebuild()
|
|
||||||
self.coordinator.rebuildShadowTable()
|
|
||||||
self.tableView.deleteRows(at: deleteIndexPaths, with: .automatic)
|
|
||||||
self.coordinator.endUpdates()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func homePageAction(indexPath: IndexPath) -> UIAction? {
|
||||||
|
guard let node = coordinator.nodeFor(indexPath),
|
||||||
|
let feed = node.representedObject as? Feed,
|
||||||
|
let homePageURL = feed.homePageURL,
|
||||||
|
let url = URL(string: homePageURL) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let title = NSLocalizedString("Open Home Page", comment: "Open Home Page")
|
||||||
|
let action = UIAction(title: title, image: UIImage(systemName: "safari")) { action in
|
||||||
|
UIApplication.shared.open(url, options: [:])
|
||||||
|
}
|
||||||
|
return action
|
||||||
|
}
|
||||||
|
|
||||||
|
func deleteAction(indexPath: IndexPath) -> UIAction {
|
||||||
|
let title = NSLocalizedString("Delete", comment: "Delete")
|
||||||
|
let action = UIAction(title: title, image: UIImage(systemName: "trash")) { action in
|
||||||
|
self.delete(indexPath: indexPath)
|
||||||
|
}
|
||||||
|
return action
|
||||||
|
}
|
||||||
|
|
||||||
|
func renameAction(indexPath: IndexPath) -> UIAction {
|
||||||
|
let title = NSLocalizedString("Rename", comment: "Rename")
|
||||||
|
let action = UIAction(title: title, image: UIImage(systemName: "square.and.pencil")) { action in
|
||||||
|
self.rename(indexPath: indexPath)
|
||||||
|
}
|
||||||
|
return action
|
||||||
}
|
}
|
||||||
|
|
||||||
func rename(indexPath: IndexPath) {
|
func rename(indexPath: IndexPath) {
|
||||||
@ -674,4 +709,32 @@ private extension MasterFeedViewController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func delete(indexPath: IndexPath) {
|
||||||
|
|
||||||
|
guard let undoManager = undoManager,
|
||||||
|
let deleteNode = coordinator.nodeFor(indexPath),
|
||||||
|
let deleteCommand = DeleteCommand(nodesToDelete: [deleteNode], treeController: coordinator.treeController, undoManager: undoManager, errorHandler: ErrorHandler.present(self))
|
||||||
|
else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var deleteIndexPaths = [indexPath]
|
||||||
|
if coordinator.isExpanded(deleteNode) {
|
||||||
|
for i in 0..<deleteNode.numberOfChildNodes {
|
||||||
|
deleteIndexPaths.append(IndexPath(row: indexPath.row + 1 + i, section: indexPath.section))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pushUndoableCommand(deleteCommand)
|
||||||
|
|
||||||
|
coordinator.beginUpdates()
|
||||||
|
deleteCommand.perform {
|
||||||
|
self.coordinator.treeController.rebuild()
|
||||||
|
self.coordinator.rebuildShadowTable()
|
||||||
|
self.tableView.deleteRows(at: deleteIndexPaths, with: .automatic)
|
||||||
|
self.coordinator.endUpdates()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user