1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-26 23:36:08 +03:00

Inform the user if there is a blocked window when quitting

This commit is contained in:
Tae Won Ha 2020-01-19 17:22:31 +01:00
parent 0951b5ce97
commit 25a72ead35
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
3 changed files with 30 additions and 8 deletions

View File

@ -9,6 +9,10 @@ import MessagePack
extension NvimView {
public func isBlocked() -> Single<Bool> {
return self.api.getMode().map { dict in dict["blocking"]?.boolValue ?? false }
}
public func waitTillNvimExits() {
self.nvimExitedCondition.wait(for: 5)
}

View File

@ -167,7 +167,21 @@ extension AppDelegate {
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
self.context.savePrefs()
if self.hasDirtyWindows && self.hasMainWindows {
guard self.hasMainWindows else {
self.uiRoot?.prepareQuit()
return .terminateNow
}
// check first whether there are blocked nvim instances, if so, abort and inform the user
if self.uiRoot?.hasBlockedWindows() == true {
let alert = NSAlert()
alert.messageText = "There are windows waiting for your input."
alert.alertStyle = .informational
alert.runModal()
return .terminateCancel
}
if self.hasDirtyWindows {
let alert = NSAlert()
alert.addButton(withTitle: "Cancel")
let discardAndQuitButton = alert.addButton(withTitle: "Discard and Quit")
@ -185,13 +199,8 @@ extension AppDelegate {
return .terminateCancel
}
if self.hasMainWindows {
self.updateMainWindowTemplateBeforeQuitting()
self.uiRoot?.prepareQuit()
return .terminateNow
}
// There are no open main window, then just quit.
self.updateMainWindowTemplateBeforeQuitting()
self.uiRoot?.prepareQuit()
return .terminateNow
}

View File

@ -67,6 +67,15 @@ class UiRoot: UiComponent {
.disposed(by: self.disposeBag)
}
// The following should only be used when Cmd-Q'ing
func hasBlockedWindows() -> Bool {
for mainWin in self.mainWindows.values {
if mainWin.neoVimView.isBlocked().syncValue() == true { return true }
}
return false
}
// The following should only be used when Cmd-Q'ing
func prepareQuit() {
self.mainWindows.values.forEach { $0.prepareClosing() }