mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Implement keyboard shortcut infrastructure and first shortcuts
This commit is contained in:
@@ -22,10 +22,15 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
|
||||
var undoableCommands = [UndoableCommand]()
|
||||
weak var coordinator: SceneCoordinator!
|
||||
|
||||
lazy var keyboardManager = KeyboardManager(type: .sidebar, coordinator: coordinator)
|
||||
override var keyCommands: [UIKeyCommand]? {
|
||||
return keyboardManager.keyCommands
|
||||
}
|
||||
|
||||
override var canBecomeFirstResponder: Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
override func viewDidLoad() {
|
||||
|
||||
super.viewDidLoad()
|
||||
@@ -253,6 +258,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
becomeFirstResponder()
|
||||
coordinator.selectFeed(indexPath)
|
||||
}
|
||||
|
||||
@@ -374,6 +380,12 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Keyboard shortcuts
|
||||
|
||||
@objc func openInBrowser(_ sender: Any?) {
|
||||
coordinator.showBrowserForCurrentFeed()
|
||||
}
|
||||
|
||||
// MARK: API
|
||||
|
||||
func updateFeedSelection() {
|
||||
@@ -651,31 +663,25 @@ private extension MasterFeedViewController {
|
||||
}
|
||||
|
||||
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
|
||||
guard coordinator.homePageURLForFeed(indexPath) != nil else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let title = NSLocalizedString("Open Home Page", comment: "Open Home Page")
|
||||
let action = UIAction(title: title, image: AppAssets.safariImage) { action in
|
||||
UIApplication.shared.open(url, options: [:])
|
||||
let action = UIAction(title: title, image: AppAssets.safariImage) { [weak self] action in
|
||||
self?.coordinator.showBrowserForFeed(indexPath)
|
||||
}
|
||||
return action
|
||||
}
|
||||
|
||||
func homePageAlertAction(indexPath: IndexPath, completionHandler: @escaping (Bool) -> Void) -> UIAlertAction? {
|
||||
guard let node = coordinator.nodeFor(indexPath),
|
||||
let feed = node.representedObject as? Feed,
|
||||
let homePageURL = feed.homePageURL,
|
||||
let url = URL(string: homePageURL) else {
|
||||
return nil
|
||||
guard coordinator.homePageURLForFeed(indexPath) != nil else {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
let title = NSLocalizedString("Open Home Page", comment: "Open Home Page")
|
||||
let action = UIAlertAction(title: title, style: .default) { action in
|
||||
UIApplication.shared.open(url, options: [:])
|
||||
let action = UIAlertAction(title: title, style: .default) { [weak self] action in
|
||||
self?.coordinator.showBrowserForFeed(indexPath)
|
||||
completionHandler(true)
|
||||
}
|
||||
return action
|
||||
|
||||
@@ -24,10 +24,15 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
|
||||
weak var coordinator: SceneCoordinator!
|
||||
var undoableCommands = [UndoableCommand]()
|
||||
|
||||
lazy var keyboardManager = KeyboardManager(type: .timeline, coordinator: coordinator)
|
||||
override var keyCommands: [UIKeyCommand]? {
|
||||
return keyboardManager.keyCommands
|
||||
}
|
||||
|
||||
override var canBecomeFirstResponder: Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
override func viewDidLoad() {
|
||||
|
||||
super.viewDidLoad()
|
||||
@@ -261,6 +266,7 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
becomeFirstResponder()
|
||||
coordinator.selectArticle(indexPath, automated: false)
|
||||
}
|
||||
|
||||
@@ -644,7 +650,7 @@ private extension MasterTimelineViewController {
|
||||
}
|
||||
let title = NSLocalizedString("Open in Browser", comment: "Open in Browser")
|
||||
let action = UIAction(title: title, image: AppAssets.safariImage) { [weak self] action in
|
||||
self?.coordinator.showBrowser(for: indexPath)
|
||||
self?.coordinator.showBrowserForArticle(indexPath)
|
||||
}
|
||||
return action
|
||||
}
|
||||
@@ -655,7 +661,7 @@ private extension MasterTimelineViewController {
|
||||
}
|
||||
let title = NSLocalizedString("Open in Browser", comment: "Open in Browser")
|
||||
let action = UIAlertAction(title: title, style: .default) { [weak self] action in
|
||||
self?.coordinator.showBrowser(for: indexPath)
|
||||
self?.coordinator.showBrowserForArticle(indexPath)
|
||||
completionHandler(true)
|
||||
}
|
||||
return action
|
||||
|
||||
21
iOS/RootSplitViewController.swift
Normal file
21
iOS/RootSplitViewController.swift
Normal file
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// RootSplitViewController.swift
|
||||
// NetNewsWire-iOS
|
||||
//
|
||||
// Created by Maurice Parker on 9/4/19.
|
||||
// Copyright © 2019 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class RootSplitViewController: UISplitViewController {
|
||||
|
||||
var coordinator: SceneCoordinator!
|
||||
|
||||
// MARK: Keyboard Shortcuts
|
||||
|
||||
@objc func openInBrowser(_ sender: Any?) {
|
||||
coordinator.showBrowserForCurrentArticle()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
||||
|
||||
private var activityManager = ActivityManager()
|
||||
|
||||
private var rootSplitViewController: UISplitViewController!
|
||||
private var rootSplitViewController: RootSplitViewController!
|
||||
private var masterNavigationController: UINavigationController!
|
||||
private var masterFeedViewController: MasterFeedViewController!
|
||||
private var masterTimelineViewController: MasterTimelineViewController?
|
||||
@@ -222,7 +222,10 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
||||
}
|
||||
|
||||
func start() -> UIViewController {
|
||||
rootSplitViewController = UISplitViewController.template()
|
||||
rootSplitViewController = RootSplitViewController()
|
||||
rootSplitViewController.coordinator = self
|
||||
rootSplitViewController.preferredDisplayMode = .automatic
|
||||
rootSplitViewController.viewControllers = [ThemedNavigationController.template()]
|
||||
rootSplitViewController.delegate = self
|
||||
|
||||
masterNavigationController = (rootSplitViewController.viewControllers.first as! UINavigationController)
|
||||
@@ -707,7 +710,29 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
||||
masterFeedViewController.present(addViewController, animated: true)
|
||||
}
|
||||
|
||||
func showBrowser(for indexPath: IndexPath) {
|
||||
func homePageURLForFeed(_ indexPath: IndexPath) -> URL? {
|
||||
guard let node = nodeFor(indexPath),
|
||||
let feed = node.representedObject as? Feed,
|
||||
let homePageURL = feed.homePageURL,
|
||||
let url = URL(string: homePageURL) else {
|
||||
return nil
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
func showBrowserForFeed(_ indexPath: IndexPath) {
|
||||
if let url = homePageURLForFeed(indexPath) {
|
||||
UIApplication.shared.open(url, options: [:])
|
||||
}
|
||||
}
|
||||
|
||||
func showBrowserForCurrentFeed() {
|
||||
if let ip = currentMasterIndexPath, let url = homePageURLForFeed(ip) {
|
||||
UIApplication.shared.open(url, options: [:])
|
||||
}
|
||||
}
|
||||
|
||||
func showBrowserForArticle(_ indexPath: IndexPath) {
|
||||
guard let preferredLink = articles[indexPath.row].preferredLink, let url = URL(string: preferredLink) else {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user