diff --git a/OpenInTerminal/AppDelegate.swift b/OpenInTerminal/AppDelegate.swift index 070c00c..9dcfbe7 100644 --- a/OpenInTerminal/AppDelegate.swift +++ b/OpenInTerminal/AppDelegate.swift @@ -8,6 +8,7 @@ import Cocoa import OpenInTerminalCore +import MASShortcut @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { @@ -32,6 +33,9 @@ class AppDelegate: NSObject, NSApplicationDelegate { setStatusItemIcon() setStatusItemVisible() setStatusToggle() + + // bind global shortcuts + bindShortcuts() } func applicationWillTerminate(_ notification: Notification) { @@ -172,3 +176,23 @@ extension AppDelegate { } } } + +extension AppDelegate { + // global shortcuts + func bindShortcuts() { + MASShortcutBinder.shared()?.bindShortcut(withDefaultsKey: Constants.Key.defaultTerminalShortcut) { + let appDelegate = NSApplication.shared.delegate as! AppDelegate + appDelegate.openDefaultTerminal() + } + + MASShortcutBinder.shared()?.bindShortcut(withDefaultsKey: Constants.Key.defaultEditorShortcut) { + let appDelegate = NSApplication.shared.delegate as! AppDelegate + appDelegate.openDefaultEditor() + } + + MASShortcutBinder.shared()?.bindShortcut(withDefaultsKey: Constants.Key.copyPathShortcut) { + let appDelegate = NSApplication.shared.delegate as! AppDelegate + appDelegate.copyPathToClipboard() + } + } +} diff --git a/OpenInTerminal/PreferencesWindow/AdvancedPreferencesViewController.swift b/OpenInTerminal/PreferencesWindow/AdvancedPreferencesViewController.swift index 3818c92..70d2509 100644 --- a/OpenInTerminal/PreferencesWindow/AdvancedPreferencesViewController.swift +++ b/OpenInTerminal/PreferencesWindow/AdvancedPreferencesViewController.swift @@ -12,7 +12,7 @@ import ServiceManagement import MASShortcut class AdvancedPreferencesViewController: PreferencesViewController { - + @IBOutlet weak var defaultTerminalShortcut: MASShortcutView! @IBOutlet weak var defaultEditorShortcut: MASShortcutView! @IBOutlet weak var copyPathShortcut: MASShortcutView! @@ -26,26 +26,8 @@ class AdvancedPreferencesViewController: PreferencesViewController { defaultTerminalShortcut.associatedUserDefaultsKey = Constants.Key.defaultTerminalShortcut defaultEditorShortcut.associatedUserDefaultsKey = Constants.Key.defaultEditorShortcut copyPathShortcut.associatedUserDefaultsKey = Constants.Key.copyPathShortcut - - bindShortcuts() } - func bindShortcuts() { - MASShortcutBinder.shared()?.bindShortcut(withDefaultsKey: Constants.Key.defaultTerminalShortcut) { - let appDelegate = NSApplication.shared.delegate as! AppDelegate - appDelegate.openDefaultTerminal() - } - - MASShortcutBinder.shared()?.bindShortcut(withDefaultsKey: Constants.Key.defaultEditorShortcut) { - let appDelegate = NSApplication.shared.delegate as! AppDelegate - appDelegate.openDefaultEditor() - } - - MASShortcutBinder.shared()?.bindShortcut(withDefaultsKey: Constants.Key.copyPathShortcut) { - let appDelegate = NSApplication.shared.delegate as! AppDelegate - appDelegate.copyPathToClipboard() - } - } // MARK: Button Actions