2017-12-20 21:59:31 +01:00
|
|
|
|
//
|
|
|
|
|
// TimelineKeyboardDelegate.swift
|
2018-08-29 07:18:24 +02:00
|
|
|
|
// NetNewsWire
|
2017-12-20 21:59:31 +01:00
|
|
|
|
//
|
|
|
|
|
// Created by Brent Simmons on 12/19/17.
|
|
|
|
|
// Copyright © 2017 Ranchero Software. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
2018-02-03 07:51:32 +01:00
|
|
|
|
import AppKit
|
2017-12-20 21:59:31 +01:00
|
|
|
|
import RSCore
|
|
|
|
|
|
|
|
|
|
// Doesn’t have any shortcuts of its own — they’re all in MainWindowKeyboardHandler.
|
|
|
|
|
|
|
|
|
|
@objc final class TimelineKeyboardDelegate: NSObject, KeyboardDelegate {
|
|
|
|
|
|
|
|
|
|
@IBOutlet weak var timelineViewController: TimelineViewController?
|
2017-12-21 06:23:48 +01:00
|
|
|
|
let shortcuts: Set<KeyboardShortcut>
|
2017-12-20 21:59:31 +01:00
|
|
|
|
|
|
|
|
|
override init() {
|
2017-12-21 06:23:48 +01:00
|
|
|
|
|
|
|
|
|
let f = Bundle.main.path(forResource: "TimelineKeyboardShortcuts", ofType: "plist")!
|
|
|
|
|
let rawShortcuts = NSArray(contentsOfFile: f)! as! [[String: Any]]
|
|
|
|
|
|
2018-01-28 03:50:48 +01:00
|
|
|
|
self.shortcuts = Set(rawShortcuts.compactMap { KeyboardShortcut(dictionary: $0) })
|
2017-12-21 06:23:48 +01:00
|
|
|
|
|
2017-12-20 21:59:31 +01:00
|
|
|
|
super.init()
|
|
|
|
|
}
|
2017-12-21 06:23:48 +01:00
|
|
|
|
|
2017-12-20 21:59:31 +01:00
|
|
|
|
func keydown(_ event: NSEvent, in view: NSView) -> Bool {
|
|
|
|
|
|
2017-12-21 06:23:48 +01:00
|
|
|
|
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
|
2017-12-20 21:59:31 +01:00
|
|
|
|
}
|
|
|
|
|
}
|