1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-27 15:53:31 +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,16 +199,11 @@ extension AppDelegate {
return .terminateCancel
}
if self.hasMainWindows {
self.updateMainWindowTemplateBeforeQuitting()
self.uiRoot?.prepareQuit()
return .terminateNow
}
// There are no open main window, then just quit.
return .terminateNow
}
// For drag & dropping files on the App icon.
func application(_ sender: NSApplication, openFiles filenames: [String]) {
let urls = filenames.map { URL(fileURLWithPath: $0) }

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() }