Merge pull request #571 from vincode-io/Issue-517

Added ability to move between timeline and detail using arrows.  Issue #267
This commit is contained in:
Brent Simmons
2019-03-04 11:33:09 -08:00
committed by GitHub
8 changed files with 108 additions and 1 deletions

View File

@@ -63,6 +63,17 @@ final class DetailViewController: NSViewController, WKUIDelegate {
override func scrollPageDown(_ sender: Any?) {
currentWebViewController.scrollPageDown(sender)
}
// MARK: - Navigation
func focus() {
guard let window = currentWebViewController.view.window else {
return
}
window.makeFirstResponderUnlessDescendantIsFirstResponder(currentWebViewController.view)
}
}
// MARK: - DetailWebViewControllerDelegate

View File

@@ -11,6 +11,17 @@ import WebKit
final class DetailWebView: WKWebView {
weak var keyboardDelegate: KeyboardDelegate?
// MARK: - NSResponder
override func keyDown(with event: NSEvent) {
if keyboardDelegate?.keydown(event, in: self) ?? false {
return
}
super.keyDown(with: event)
}
// MARK: NSView
override func willOpenMenu(_ menu: NSMenu, with event: NSEvent) {

View File

@@ -27,7 +27,9 @@ final class DetailWebViewController: NSViewController, WKUIDelegate {
}
}
}
private let keyboardDelegate = DetailKeyboardDelegate()
private struct MessageName {
static let mouseDidEnter = "mouseDidEnter"
static let mouseDidExit = "mouseDidExit"
@@ -52,6 +54,7 @@ final class DetailWebViewController: NSViewController, WKUIDelegate {
webview = DetailWebView(frame: NSRect.zero, configuration: configuration)
webview.uiDelegate = self
webview.navigationDelegate = self
webview.keyboardDelegate = keyboardDelegate
webview.translatesAutoresizingMaskIntoConstraints = false
if let userAgent = UserAgent.fromInfoPlist() {
webview.customUserAgent = userAgent

View File

@@ -0,0 +1,40 @@
//
// DetailKeyboardDelegate.swift
// NetNewsWire
//
// Created by Maurice Parker on 3/1/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import AppKit
import RSCore
@objc final class DetailKeyboardDelegate: NSObject, KeyboardDelegate {
let shortcuts: Set<KeyboardShortcut>
override init() {
let f = Bundle.main.path(forResource: "DetailKeyboardShortcuts", ofType: "plist")!
let rawShortcuts = NSArray(contentsOfFile: f)! as! [[String: Any]]
self.shortcuts = Set(rawShortcuts.compactMap { KeyboardShortcut(dictionary: $0) })
super.init()
}
func keydown(_ event: NSEvent, in view: NSView) -> Bool {
if MainWindowKeyboardHandler.shared.keydown(event, in: view) {
return true
}
let key = KeyboardKey(with: event)
guard let matchingShortcut = KeyboardShortcut.findMatchingShortcut(in: shortcuts, key: key) else {
return false
}
matchingShortcut.perform(with: view)
return true
}
}

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>key</key>
<string>[leftarrow]</string>
<key>action</key>
<string>navigateToTimeline:</string>
</dict>
</array>
</plist>

View File

@@ -331,6 +331,10 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
sidebarViewController?.focus()
}
@IBAction func navigateToDetail(_ sender: Any?) {
detailViewController?.focus()
}
@IBAction func goToPreviousSubscription(_ sender: Any?) {
sidebarViewController?.outlineView.selectPreviousRow(sender)
}

View File

@@ -8,5 +8,11 @@
<key>action</key>
<string>navigateToSidebar:</string>
</dict>
<dict>
<key>key</key>
<string>[rightarrow]</string>
<key>action</key>
<string>navigateToDetail:</string>
</dict>
</array>
</plist>