138 lines
5.7 KiB
Swift
138 lines
5.7 KiB
Swift
import ShortcutRecorder
|
|
|
|
enum SearchKeyResult {
|
|
case handled
|
|
case passToField
|
|
case passToShortcuts
|
|
}
|
|
|
|
class TilesViewMock {
|
|
var isSearchEditing = false
|
|
func handleSearchEditingKeyDown(_ event: NSEvent) -> SearchKeyResult { return .passToField }
|
|
}
|
|
|
|
class TilesPanelMock {
|
|
var tilesView = TilesViewMock()
|
|
var isKeyWindow = false
|
|
}
|
|
|
|
class App {
|
|
class AppMock {
|
|
var appIsBeingUsed = false
|
|
var shortcutIndex = 0
|
|
var forceDoNothingOnRelease = false
|
|
var tilesPanel = TilesPanelMock()
|
|
}
|
|
static let app = AppMock()
|
|
static var appIsBeingUsed: Bool {
|
|
get { app.appIsBeingUsed }
|
|
set { app.appIsBeingUsed = newValue }
|
|
}
|
|
static var shortcutIndex: Int {
|
|
get { app.shortcutIndex }
|
|
set { app.shortcutIndex = newValue }
|
|
}
|
|
static var forceDoNothingOnRelease: Bool {
|
|
get { app.forceDoNothingOnRelease }
|
|
set { app.forceDoNothingOnRelease = newValue }
|
|
}
|
|
}
|
|
|
|
class TilesPanel {
|
|
static let shared = TilesPanel()
|
|
var isKeyWindow: Bool {
|
|
get { App.app.tilesPanel.isKeyWindow }
|
|
set { App.app.tilesPanel.isKeyWindow = newValue }
|
|
}
|
|
}
|
|
|
|
class TilesView {
|
|
static var isSearchEditing: Bool {
|
|
get { App.app.tilesPanel.tilesView.isSearchEditing }
|
|
set { App.app.tilesPanel.tilesView.isSearchEditing = newValue }
|
|
}
|
|
|
|
static func handleSearchEditingKeyDown(_ event: NSEvent) -> SearchKeyResult {
|
|
return App.app.tilesPanel.tilesView.handleSearchEditingKeyDown(event)
|
|
}
|
|
}
|
|
|
|
class ControlsTab {
|
|
static let defaultShortcuts = [
|
|
"holdShortcut": ATShortcut(Shortcut(keyEquivalent: "⌥")!, "holdShortcut", .global, .up, 0),
|
|
"holdShortcut2": ATShortcut(Shortcut(keyEquivalent: "⌥")!, "holdShortcut2", .global, .up, 1),
|
|
"holdShortcut3": ATShortcut(Shortcut(keyEquivalent: "⌥")!, "holdShortcut3", .global, .up, 2),
|
|
"nextWindowShortcut": ATShortcut(Shortcut(keyEquivalent: "⇥")!, "nextWindowShortcut", .global, .down),
|
|
"nextWindowShortcut2": ATShortcut(Shortcut(keyEquivalent: "`")!, "nextWindowShortcut2", .global, .down),
|
|
"→": ATShortcut(Shortcut(keyEquivalent: "→")!, "→", .local, .down),
|
|
"←": ATShortcut(Shortcut(keyEquivalent: "←")!, "←", .local, .down),
|
|
"↑": ATShortcut(Shortcut(keyEquivalent: "↑")!, "↑", .local, .down),
|
|
"↓": ATShortcut(Shortcut(keyEquivalent: "↓")!, "↓", .local, .down),
|
|
// "vimCycleRight": ATShortcut(Shortcut(keyEquivalent: "l")!, "vimCycleRight", .local, .down),
|
|
// "vimCycleLeft": ATShortcut(Shortcut(keyEquivalent: "h")!, "vimCycleLeft", .local, .down),
|
|
// "vimCycleUp": ATShortcut(Shortcut(keyEquivalent: "k")!, "vimCycleUp", .local, .down),
|
|
// "vimCycleDown": ATShortcut(Shortcut(keyEquivalent: "j")!, "vimCycleDown", .local, .down),
|
|
"focusWindowShortcut": ATShortcut(Shortcut(keyEquivalent: " ")!, "focusWindowShortcut", .local, .down),
|
|
"previousWindowShortcut": ATShortcut(Shortcut(keyEquivalent: "⇧")!, "previousWindowShortcut", .local, .down),
|
|
"cancelShortcut": ATShortcut(Shortcut(keyEquivalent: "⎋")!, "cancelShortcut", .local, .down),
|
|
"searchShortcut": ATShortcut(Shortcut(keyEquivalent: "s")!, "searchShortcut", .local, .down),
|
|
"closeWindowShortcut": ATShortcut(Shortcut(keyEquivalent: "w")!, "closeWindowShortcut", .local, .down),
|
|
"minDeminWindowShortcut": ATShortcut(Shortcut(keyEquivalent: "m")!, "minDeminWindowShortcut", .local, .down),
|
|
"toggleFullscreenWindowShortcut": ATShortcut(Shortcut(keyEquivalent: "f")!, "toggleFullscreenWindowShortcut", .local, .down),
|
|
"quitAppShortcut": ATShortcut(Shortcut(keyEquivalent: "q")!, "quitAppShortcut", .local, .down),
|
|
"hideShowAppShortcut": ATShortcut(Shortcut(keyEquivalent: "h")!, "hideShowAppShortcut", .local, .down),
|
|
]
|
|
static var shortcuts = defaultShortcuts
|
|
|
|
static func executeAction(_ action: String) {
|
|
shortcutsActionsTriggered.append(action)
|
|
if action.starts(with: "holdShortcut") {
|
|
App.app.appIsBeingUsed = false
|
|
}
|
|
if action.starts(with: "nextWindowShortcut") {
|
|
App.app.appIsBeingUsed = true
|
|
App.app.shortcutIndex = Preferences.nameToIndex(action)
|
|
}
|
|
}
|
|
|
|
static var shortcutsActionsTriggered: [String] = []
|
|
}
|
|
|
|
class KeyRepeatTimer {
|
|
static func stopTimerForRepeatingKey(_ shortcutName: String) {
|
|
}
|
|
}
|
|
|
|
class Logger {
|
|
static func debug(_ message: @escaping () -> Any?, file: String = #file, function: String = #function, line: Int = #line, context: Any? = nil) {}
|
|
static func info(_ message: @escaping () -> Any?, file: String = #file, function: String = #function, line: Int = #line, context: Any? = nil) {}
|
|
static func warning(_ message: @escaping () -> Any?, file: String = #file, function: String = #function, line: Int = #line, context: Any? = nil) {}
|
|
static func error(_ message: @escaping () -> Any?, file: String = #file, function: String = #function, line: Int = #line, context: Any? = nil) {}
|
|
}
|
|
|
|
class Preferences {
|
|
static var shortcutStyle: ShortcutStylePreference = .focusOnRelease
|
|
static var holdShortcut = ["⌥", "⌥", "⌥"]
|
|
static let minShortcutCount = 1
|
|
static let maxShortcutCount = 9
|
|
|
|
static func indexToName(_ baseName: String, _ index: Int) -> String {
|
|
return baseName + (index == 0 ? "" : String(index + 1))
|
|
}
|
|
|
|
static func nameToIndex(_ name: String) -> Int {
|
|
guard let number = name.last?.wholeNumberValue else { return 0 }
|
|
return number - 1
|
|
}
|
|
}
|
|
|
|
enum ShortcutStylePreference: CaseIterable {
|
|
case focusOnRelease
|
|
case doNothingOnRelease
|
|
case searchOnRelease
|
|
}
|
|
|
|
class ModifierFlags {
|
|
static var current: NSEvent.ModifierFlags = []
|
|
}
|