NetNewsWire/Mac/MainWindow/Timeline/Keyboard/TimelineKeyboardDelegate.swift

44 lines
1.1 KiB
Swift
Raw Normal View History

//
// TimelineKeyboardDelegate.swift
2018-08-29 07:18:24 +02:00
// NetNewsWire
//
// Created by Brent Simmons on 12/19/17.
// Copyright © 2017 Ranchero Software. All rights reserved.
//
import AppKit
import AppKitExtras
// Doesnt have any shortcuts of its own  theyre all in MainWindowKeyboardHandler.
@objc @MainActor final class TimelineKeyboardDelegate: NSObject, KeyboardDelegate {
@IBOutlet weak var timelineViewController: TimelineViewController?
let shortcuts: Set<KeyboardShortcut>
override init() {
let f = Bundle.main.path(forResource: "TimelineKeyboardShortcuts", 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
}
}