mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-23 16:20:53 +01:00
37 lines
910 B
Swift
37 lines
910 B
Swift
//
|
|
// MainWindowKeyboardHandler.swift
|
|
// NetNewsWire
|
|
//
|
|
// Created by Brent Simmons on 12/19/17.
|
|
// Copyright © 2017 Ranchero Software. All rights reserved.
|
|
//
|
|
|
|
import AppKit
|
|
import AppKitExtras
|
|
|
|
@MainActor final class MainWindowKeyboardHandler: KeyboardDelegate {
|
|
|
|
static let shared = MainWindowKeyboardHandler()
|
|
let globalShortcuts: Set<KeyboardShortcut>
|
|
|
|
init() {
|
|
|
|
let f = Bundle.main.path(forResource: "GlobalKeyboardShortcuts", ofType: "plist")!
|
|
let rawShortcuts = NSArray(contentsOfFile: f)! as! [[String: Any]]
|
|
|
|
self.globalShortcuts = Set(rawShortcuts.compactMap { KeyboardShortcut(dictionary: $0) })
|
|
}
|
|
|
|
func keydown(_ event: NSEvent, in view: NSView) -> Bool {
|
|
|
|
let key = KeyboardKey(with: event)
|
|
guard let matchingShortcut = KeyboardShortcut.findMatchingShortcut(in: globalShortcuts, key: key) else {
|
|
return false
|
|
}
|
|
|
|
matchingShortcut.perform(with: view)
|
|
return true
|
|
}
|
|
}
|
|
|