Allow using F12 as a shortcut
The system API says it’s reserved, but it doesn’t seem to be used for anything.
This commit is contained in:
parent
199c3b25d9
commit
a7a3ff6248
|
@ -48,7 +48,7 @@ public enum KeyboardShortcuts {
|
|||
|
||||
/**
|
||||
Remove all handlers receiving keyboard shortcuts events.
|
||||
|
||||
|
||||
This can be used to reset the handlers before re-creating them to avoid having multiple handlers for the same shortcut.
|
||||
*/
|
||||
public static func removeAllHandlers() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import Cocoa
|
||||
|
||||
extension NSMenuItem {
|
||||
private struct AssociatedKeys {
|
||||
private enum AssociatedKeys {
|
||||
static let observer = ObjectAssociation<NSObjectProtocol>()
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ extension NSMenuItem {
|
|||
|
||||
/**
|
||||
Add a keyboard shortcut to a `NSMenuItem`.
|
||||
|
||||
|
||||
This method is only recommended for dynamic shortcuts. In general, it's preferred to create a static shortcut name and use `NSMenuItem.setShortcut(for:)` instead.
|
||||
|
||||
Pass in `nil` to clear the keyboard shortcut.
|
||||
|
|
|
@ -83,18 +83,18 @@ extension KeyboardShortcuts {
|
|||
self.placeholderString = "record_shortcut".localized
|
||||
self.centersPlaceholder = true
|
||||
self.alignment = .center
|
||||
(self.cell as? NSSearchFieldCell)?.searchButtonCell = nil
|
||||
(cell as? NSSearchFieldCell)?.searchButtonCell = nil
|
||||
|
||||
self.wantsLayer = true
|
||||
self.translatesAutoresizingMaskIntoConstraints = false
|
||||
self.setContentHuggingPriority(.defaultHigh, for: .vertical)
|
||||
self.setContentHuggingPriority(.defaultHigh, for: .horizontal)
|
||||
self.widthAnchor.constraint(greaterThanOrEqualToConstant: CGFloat(minimumWidth)).isActive = true
|
||||
setContentHuggingPriority(.defaultHigh, for: .vertical)
|
||||
setContentHuggingPriority(.defaultHigh, for: .horizontal)
|
||||
widthAnchor.constraint(greaterThanOrEqualToConstant: CGFloat(minimumWidth)).isActive = true
|
||||
|
||||
// Hide the cancel button when not showing the shortcut so the placeholder text is properly centered. Must be last.
|
||||
self.cancelButton = (self.cell as? NSSearchFieldCell)?.cancelButtonCell
|
||||
self.cancelButton = (cell as? NSSearchFieldCell)?.cancelButtonCell
|
||||
|
||||
self.setStringValue(name: name)
|
||||
setStringValue(name: name)
|
||||
|
||||
setUpEvents()
|
||||
}
|
||||
|
|
|
@ -64,10 +64,18 @@ extension KeyboardShortcuts {
|
|||
|
||||
extension KeyboardShortcuts.Shortcut {
|
||||
/// System-defined keyboard shortcuts.
|
||||
static var system: [Self] { CarbonKeyboardShortcuts.system }
|
||||
static var system: [Self] {
|
||||
CarbonKeyboardShortcuts.system
|
||||
}
|
||||
|
||||
/// Check whether the keyboard shortcut is already taken by the system.
|
||||
var isTakenBySystem: Bool { Self.system.contains(self) }
|
||||
var isTakenBySystem: Bool {
|
||||
guard self != KeyboardShortcuts.Shortcut(.f12, modifiers: []) else {
|
||||
return false
|
||||
}
|
||||
|
||||
return Self.system.contains(self)
|
||||
}
|
||||
}
|
||||
|
||||
extension KeyboardShortcuts.Shortcut {
|
||||
|
|
Loading…
Reference in New Issue