1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-26 07:13:24 +03:00

GH-303 Disable some menu items, e.g. open/save, when NeoVim reports that there is no current buffer

- This can happen when the CtrlP panel is open.
This commit is contained in:
Tae Won Ha 2016-10-12 19:41:18 +02:00
parent 95a14d2564
commit ba9b8576bc
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
2 changed files with 41 additions and 12 deletions

View File

@ -166,8 +166,7 @@ public class NeoVimView: NSView, NSUserInterfaceValidations {
@IBAction public func debug1(_ sender: AnyObject!) {
NSLog("DEBUG 1 - Start")
NSLog("\(self.agent.vimCommandOutput("silent echo $PATH"))")
NSLog("\(self.agent.vimCommandOutput("silent pwd"))")
NSLog("\(self.agent.buffers())")
NSLog("DEBUG 1 - End")
}
}
@ -185,9 +184,12 @@ extension NeoVimView {
self.needsDisplay = true
self.resizeNeoVimUiTo(size: self.bounds.size)
}
public func currentBuffer() -> NeoVimBuffer {
return self.agent.buffers().filter { $0.current }.first!
/**
- returns: nil when for exampls a quickfix panel is open.
*/
public func currentBuffer() -> NeoVimBuffer? {
return self.agent.buffers().filter { $0.current }.first
}
public func hasDirtyDocs() -> Bool {
@ -195,7 +197,8 @@ extension NeoVimView {
}
public func isCurrentBufferDirty() -> Bool {
return self.agent.buffers().filter { $0.current }.first?.dirty ?? true
let curBuf = self.currentBuffer()
return curBuf?.dirty ?? true
}
public func newTab() {

View File

@ -222,7 +222,9 @@ extension MainWindowComponent {
}
@IBAction func saveDocument(_ sender: Any?) {
let curBuf = self.neoVimView.currentBuffer()
guard let curBuf = self.neoVimView.currentBuffer() else {
return
}
if curBuf.fileName == nil {
self.savePanelSheet { self.neoVimView.saveCurrentTab(url: $0) }
@ -233,6 +235,10 @@ extension MainWindowComponent {
}
@IBAction func saveDocumentAs(_ sender: Any?) {
if self.neoVimView.currentBuffer() == nil {
return
}
self.savePanelSheet { url in
self.neoVimView.saveCurrentTab(url: url)
@ -396,14 +402,34 @@ extension MainWindowComponent {
extension MainWindowComponent {
public func validateUserInterfaceItem(_ item: NSValidatedUserInterfaceItem) -> Bool {
guard item.action == #selector(focusNeoVimView(_:)) else {
let canSave = self.neoVimView.currentBuffer() != nil
let canSaveAs = canSave
let canOpen = canSave
let canOpenQuickly = canSave
let canFocusNeoVimView = self.window.firstResponder != self.neoVimView
guard let action = item.action else {
return true
}
if self.window.firstResponder == self.neoVimView {
return false
}
switch action {
case #selector(focusNeoVimView(_:)):
return canFocusNeoVimView
return true
case #selector(openDocument(_:)):
return canOpen
case #selector(openQuickly(_:)):
return canOpenQuickly
case #selector(saveDocument(_:)):
return canSave
case #selector(saveDocumentAs(_:)):
return canSaveAs
default:
return true
}
}
}