Skip to content

Commit

Permalink
Merge pull request #52 from gee1k/master
Browse files Browse the repository at this point in the history
fix(Main): bind global shortcut
  • Loading branch information
Ji4n1ng authored Aug 19, 2019
2 parents 3b6ea8d + 688664c commit 87eb55a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
24 changes: 24 additions & 0 deletions OpenInTerminal/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Cocoa
import OpenInTerminalCore
import MASShortcut

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
Expand All @@ -32,6 +33,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
setStatusItemIcon()
setStatusItemVisible()
setStatusToggle()

// bind global shortcuts
bindShortcuts()
}

func applicationWillTerminate(_ notification: Notification) {
Expand Down Expand Up @@ -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()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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

Expand Down

0 comments on commit 87eb55a

Please sign in to comment.