From 9885505a689ff07847a9a8d0557f89b995d2f630 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Thu, 4 Aug 2016 23:34:09 +0200 Subject: [PATCH] GH-226 Enable or disable cut/copy/paste menu items --- SwiftNeoVim/NeoVimView.swift | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/SwiftNeoVim/NeoVimView.swift b/SwiftNeoVim/NeoVimView.swift index d6a547a2..28f33876 100644 --- a/SwiftNeoVim/NeoVimView.swift +++ b/SwiftNeoVim/NeoVimView.swift @@ -17,7 +17,7 @@ private struct RowRun: CustomStringConvertible { } } -public class NeoVimView: NSView { +public class NeoVimView: NSView, NSUserInterfaceValidations { public static let minFontSize = CGFloat(4) public static let maxFontSize = CGFloat(128) @@ -346,23 +346,40 @@ public class NeoVimView: NSView { } } +// MARK: - NSUserInterfaceValidationsProtocol +extension NeoVimView { + + public func validateUserInterfaceItem(item: NSValidatedUserInterfaceItem) -> Bool { + let canCopyOrCut = self.mode != .Insert && self.mode != .Cmdline + + switch item.action() { + case NSSelectorFromString("copy:"), NSSelectorFromString("cut:"): + return canCopyOrCut + default: + return true + } + } +} + // MARK: - Edit Menu Items extension NeoVimView { @IBAction func cut(sender: AnyObject!) { - if self.mode == .Insert { + if self.mode == .Insert || self.mode == .Cmdline { return } self.agent.vimCommand("norm! \"+d") + self.agent.vimInput(self.wrapNamedKeys(KeyUtils.specialKeys[NSRightArrowFunctionKey]!)) } @IBAction func copy(sender: AnyObject!) { - if self.mode == .Insert { + if self.mode == .Insert || self.mode == .Cmdline { return } self.agent.vimCommand("norm! \"+y") + self.agent.vimInput(self.wrapNamedKeys(KeyUtils.specialKeys[NSRightArrowFunctionKey]!)) } @IBAction func paste(sender: AnyObject!) {