mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-26 23:36:08 +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:
parent
95a14d2564
commit
ba9b8576bc
@ -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")
|
||||
}
|
||||
}
|
||||
@ -186,8 +185,11 @@ extension NeoVimView {
|
||||
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() {
|
||||
|
@ -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
|
||||
|
||||
case #selector(openDocument(_:)):
|
||||
return canOpen
|
||||
|
||||
case #selector(openQuickly(_:)):
|
||||
return canOpenQuickly
|
||||
|
||||
case #selector(saveDocument(_:)):
|
||||
return canSave
|
||||
|
||||
case #selector(saveDocumentAs(_:)):
|
||||
return canSaveAs
|
||||
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user