Cut/copy/paste now work

Signed-off-by: Eric Kuck <eric@bluelinelabs.com>
This commit is contained in:
Eric Kuck
2019-01-14 14:52:36 +05:30
committed by Roopesh Chander
parent ba731e0099
commit 321b88864c
3 changed files with 40 additions and 8 deletions
+36 -6
View File
@@ -3,15 +3,45 @@
import Cocoa import Cocoa
var appDelegate: AppDelegate?
class Application: NSApplication { class Application: NSApplication {
private let editorCommands = [
"x": #selector(NSText.cut(_:)),
"c": #selector(NSText.copy(_:)),
"v": #selector(NSText.paste(_:)),
"z": #selector(UndoActionRespondable.undo(_:)),
"a": #selector(NSResponder.selectAll(_:)),
"Z": #selector(UndoActionRespondable.redo(_:))
]
private var appDelegate: AppDelegate? //swiftlint:disable:this weak_delegate
// We use a custom Application class to be able to set the app delegate // We use a custom Application class to be able to set the app delegate
// before app.run() gets called in NSApplicationMain(). // before app.run() gets called in NSApplicationMain().
override class var shared: NSApplication { override init() {
let app = NSApplication.shared super.init()
appDelegate = AppDelegate() // Keep a strong reference to the app delegate appDelegate = AppDelegate() // Keep a strong reference to the app delegate
app.delegate = appDelegate delegate = appDelegate
return app }
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func sendEvent(_ event: NSEvent) {
let modifierFlags = event.modifierFlags.rawValue & NSEvent.ModifierFlags.deviceIndependentFlagsMask.rawValue
if event.type == .keyDown,
(modifierFlags == NSEvent.ModifierFlags.command.rawValue || modifierFlags == NSEvent.ModifierFlags.command.rawValue | NSEvent.ModifierFlags.shift.rawValue),
let selector = editorCommands[event.charactersIgnoringModifiers ?? ""] {
sendAction(selector, to: nil, from: self)
} else {
super.sendEvent(event)
} }
} }
}
@objc protocol UndoActionRespondable {
func undo(_ sender: AnyObject)
func redo(_ sender: AnyObject)
}
@@ -10,8 +10,8 @@ class StatusMenu: NSMenu {
var statusMenuItem: NSMenuItem? var statusMenuItem: NSMenuItem?
var networksMenuItem: NSMenuItem? var networksMenuItem: NSMenuItem?
var firstTunnelMenuItemIndex: Int = 0 var firstTunnelMenuItemIndex = 0
var numberOfTunnelMenuItems: Int = 0 var numberOfTunnelMenuItems = 0
var manageTunnelsRootVC: ManageTunnelsRootViewController? var manageTunnelsRootVC: ManageTunnelsRootViewController?
lazy var manageTunnelsWindow: NSWindow = { lazy var manageTunnelsWindow: NSWindow = {
@@ -62,6 +62,7 @@ class StatusMenu: NSMenu {
} }
@discardableResult @discardableResult
//swiftlint:disable:next cyclomatic_complexity
func updateStatusMenuItems(with tunnel: TunnelContainer, ignoreInactive: Bool) -> Bool { func updateStatusMenuItems(with tunnel: TunnelContainer, ignoreInactive: Bool) -> Bool {
guard let statusMenuItem = statusMenuItem, let networksMenuItem = networksMenuItem else { return false } guard let statusMenuItem = statusMenuItem, let networksMenuItem = networksMenuItem else { return false }
var statusText: String var statusText: String
@@ -43,6 +43,7 @@ class ConfTextStorage: NSTextStorage {
fatalError("init(pasteboardPropertyList:ofType:) has not been implemented") fatalError("init(pasteboardPropertyList:ofType:) has not been implemented")
} }
//swiftlint:disable:next function_body_length
func updateAttributes(for theme: TextColorTheme) { func updateAttributes(for theme: TextColorTheme) {
self.defaultAttributes = [ self.defaultAttributes = [
.foregroundColor: theme.plainText, .foregroundColor: theme.plainText,