No more keyboard shortcuts sounds in the popover.
This commit is contained in:
+47
-49
@@ -1,22 +1,17 @@
|
||||
import Cocoa
|
||||
import AppKit
|
||||
import Carbon
|
||||
import ServiceManagement
|
||||
import OSLog
|
||||
|
||||
fileprivate enum Metrics {
|
||||
static let contentMinWidth = 400.0
|
||||
static let contentMaxWidth = /*600.0*/ NSScreen.main!.visibleFrame.size.width * 0.7 // REVIEW: Under what circumstances can NSScreen return nil?
|
||||
static let contentMinWidth = 400.0
|
||||
static let contentMaxWidth = /*600.0*/ NSScreen.main!.visibleFrame.size.width * 0.7 // WARNING: Under what circumstances can NSScreen return nil?
|
||||
static let contentMinHeight = 160.0
|
||||
static let contentMaxHeight = /*800.0*/ NSScreen.main!.visibleFrame.size.height * 0.8 // REVIEW: Under what circumstances can NSScreen return nil?
|
||||
static let padding = 10.0
|
||||
static let buttonSpacing = 2.0
|
||||
static let contentMaxHeight = /*800.0*/ NSScreen.main!.visibleFrame.size.height * 0.8 // WARNING: Under what circumstances can NSScreen return nil?
|
||||
static let padding = 10.0
|
||||
static let buttonSpacing = 2.0
|
||||
}
|
||||
|
||||
class CmdViewController: NSViewController {
|
||||
fileprivate static let logger = Logger(
|
||||
subsystem: Bundle.main.bundleIdentifier!,
|
||||
category: String(describing: CmdViewController.self)
|
||||
)
|
||||
|
||||
private weak var cmdFile: CmdFile?
|
||||
private var timer: DispatchSourceTimer?
|
||||
private var keyboardEvents: EventMonitor?
|
||||
@@ -332,7 +327,10 @@ class CmdViewController: NSViewController {
|
||||
}
|
||||
|
||||
private func resetReloadButton() {
|
||||
reloadButton.image = systemImage("arrow.clockwise.circle.fill", .title2, .large, .init(paletteColors: [.white, .systemBlue]))
|
||||
reloadButton.image = systemImage("arrow.clockwise.circle.fill",
|
||||
.title2, .large,
|
||||
.init(paletteColors: [.white,
|
||||
.systemBlue]))
|
||||
reloadButton.action = #selector(reloadWidget)
|
||||
reloadButton.toolTip = "Reload Current"
|
||||
}
|
||||
@@ -351,51 +349,51 @@ class CmdViewController: NSViewController {
|
||||
}
|
||||
|
||||
private func setupKeyEvents() {
|
||||
keyboardEvents = LocalEventMonitor(mask: [.flagsChanged, .keyDown], handler: { [weak self] event in
|
||||
keyboardEvents = LocalEventMonitor(mask: [.flagsChanged, .keyDown],
|
||||
handler:
|
||||
{ [weak self] event in
|
||||
let modifiers = event.modifierFlags.rawValue
|
||||
let command = NSEvent.ModifierFlags.command.rawValue
|
||||
let shift = NSEvent.ModifierFlags.shift.rawValue
|
||||
let control = NSEvent.ModifierFlags.control.rawValue
|
||||
let option = NSEvent.ModifierFlags.option.rawValue
|
||||
let key = event.keyCode
|
||||
|
||||
if event.modifierFlags.contains(.shift) {
|
||||
self?.reloadButton.image = systemImage("arrow.clockwise.circle.fill", .title2, .large, .init(paletteColors: [.white, .systemCyan]))
|
||||
if modsContains(keys: OSShift, in: modifiers) {
|
||||
self?.reloadButton.image =
|
||||
systemImage("arrow.clockwise.circle.fill", .title2,
|
||||
.large,.init(paletteColors: [.white,
|
||||
.systemCyan]))
|
||||
self?.reloadButton.action = #selector(self?.reloadWidgets)
|
||||
self?.reloadButton.toolTip = "Reload All"
|
||||
} else {
|
||||
self?.reloadButton.image = systemImage("arrow.clockwise.circle.fill", .title2, .large, .init(paletteColors: [.white, .systemBlue]))
|
||||
self?.reloadButton.image =
|
||||
systemImage("arrow.clockwise.circle.fill", .title2,
|
||||
.large, .init(paletteColors: [.white,
|
||||
.systemBlue]))
|
||||
self?.reloadButton.action = #selector(self?.reloadWidget)
|
||||
self?.reloadButton.toolTip = "Reload Current"
|
||||
}
|
||||
|
||||
// NOTE: Standalone keys should go last!
|
||||
if (modifiers & command) == command,
|
||||
(modifiers & (control | shift | option)) == 0,
|
||||
event.keyCode == 12 // Q
|
||||
{
|
||||
self?.terminateApp()
|
||||
} else if (modifiers & command) == command,
|
||||
(modifiers & (control | shift | option)) == 0,
|
||||
event.keyCode == 13 // W
|
||||
{
|
||||
self?.view.superview?.window?.resignKey()
|
||||
} else if (modifiers & command) == command,
|
||||
(modifiers & (control | shift | option)) == 0,
|
||||
event.keyCode == 15 // R
|
||||
{
|
||||
self?.reloadWidget()
|
||||
} else if (modifiers & (command & shift)) == command & shift,
|
||||
(modifiers & (control | option)) == 0,
|
||||
event.keyCode == 15 // R
|
||||
{
|
||||
self?.reloadWidgets()
|
||||
} else if (modifiers & command) == command,
|
||||
(modifiers & (control | shift | option)) == 0,
|
||||
event.keyCode == 8 // C
|
||||
{
|
||||
self?.textLabel.currentEditor()?.copy(nil)
|
||||
} else if event.keyCode == 12 || event.keyCode == 53 { // Q, ESC
|
||||
self?.view.superview?.window?.resignKey()
|
||||
if modsContains(keys: OSCmd, in: modifiers) {
|
||||
if key == kVK_ANSI_Q {
|
||||
self?.terminateApp()
|
||||
} else if key == kVK_ANSI_W {
|
||||
self?.view.superview?.window?.resignKey()
|
||||
} else if key == kVK_ANSI_R {
|
||||
self?.reloadWidget()
|
||||
} else if key == kVK_ANSI_C {
|
||||
self?.textLabel.currentEditor()?.copy(nil)
|
||||
}
|
||||
} else if modsContains(keys: OSCmd | OSShift, in: modifiers) {
|
||||
if key == kVK_ANSI_R {
|
||||
// NOTE: We need to resign the window in order to
|
||||
// prevent the program from intercepting the
|
||||
// events, which result in sounds beign made for
|
||||
// missing performKeyEquivalent.
|
||||
self?.view.window?.resignKey()
|
||||
self?.reloadWidgets()
|
||||
}
|
||||
} else if modsContainsNone(in: modifiers) {
|
||||
if key == kVK_ANSI_Q || key == kVK_Escape {
|
||||
self?.view.superview?.window?.resignKey()
|
||||
}
|
||||
}
|
||||
|
||||
return event
|
||||
|
||||
Reference in New Issue
Block a user