From baaf92008982a1429d01f3c39f4195e5a8e0625c Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Wed, 9 Dec 2020 22:14:51 +0100 Subject: [PATCH] Forward warning to main window --- NvimView/Sources/NvimView/NvimView+Types.swift | 7 +++++++ NvimView/Sources/NvimView/NvimView.swift | 8 ++++++-- VimR/VimR/MainWindow.swift | 18 ++++++++++++------ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/NvimView/Sources/NvimView/NvimView+Types.swift b/NvimView/Sources/NvimView/NvimView+Types.swift index c82a41d7..228b62e8 100644 --- a/NvimView/Sources/NvimView/NvimView+Types.swift +++ b/NvimView/Sources/NvimView/NvimView+Types.swift @@ -46,6 +46,11 @@ extension NvimView { } } + public enum Warning { + case cannotCloseLastTab + case noWriteSinceLastChange + } + public enum Event { case neoVimStopped @@ -68,6 +73,8 @@ extension NvimView { case rpcEvent([MessagePack.MessagePackValue]) case rpcEventSubscribed + case warning(Warning) + case initVimError // FIXME: maybe do onError()? diff --git a/NvimView/Sources/NvimView/NvimView.swift b/NvimView/Sources/NvimView/NvimView.swift index 2b0f3e4a..47fb162b 100644 --- a/NvimView/Sources/NvimView/NvimView.swift +++ b/NvimView/Sources/NvimView/NvimView.swift @@ -183,8 +183,12 @@ public class NvimView: NSView, array[0].uint64Value == RxNeovimApi.Error.exceptionRawValue, let errorMsg = array[1].stringValue else { return } - if errorMsg.contains("Vim(tabclose):E784") { Swift.print("cannot close last tab page!") } - if errorMsg.starts(with: "Vim(tabclose):E37") { Swift.print("no write!") } + if errorMsg.contains("Vim(tabclose):E784") { + self?.eventsSubject.onNext(.warning(.cannotCloseLastTab)) + } + if errorMsg.starts(with: "Vim(tabclose):E37") { + self?.eventsSubject.onNext(.warning(.noWriteSinceLastChange)) + } default: self?.log.debug("???: This should not happen") diff --git a/VimR/VimR/MainWindow.swift b/VimR/VimR/MainWindow.swift index 9fc29acd..a59907f4 100644 --- a/VimR/VimR/MainWindow.swift +++ b/VimR/VimR/MainWindow.swift @@ -310,6 +310,8 @@ class MainWindow: NSObject, case let .rpcEvent(params): self?.rpcEventAction(params: params) + case let .warning(warning): self?.show(warning: warning) + case .rpcEventSubscribed: break } }, onError: { error in @@ -476,15 +478,15 @@ class MainWindow: NSObject, private func set(tabsThemeWith _: Theme) { var tabsTheme = Tabs.Theme.default - tabsTheme.foregroundColor = theme.foreground - tabsTheme.backgroundColor = theme.background + tabsTheme.foregroundColor = self.theme.foreground + tabsTheme.backgroundColor = self.theme.background - tabsTheme.separatorColor = theme.background.brightening(by: 0.75) + tabsTheme.separatorColor = self.theme.background.brightening(by: 0.75) - tabsTheme.selectedForegroundColor = theme.highlightForeground - tabsTheme.selectedBackgroundColor = theme.highlightBackground + tabsTheme.selectedForegroundColor = self.theme.highlightForeground + tabsTheme.selectedBackgroundColor = self.theme.highlightBackground - tabsTheme.tabSelectedIndicatorColor = theme.highlightForeground + tabsTheme.tabSelectedIndicatorColor = self.theme.highlightForeground self.neoVimView.tabBar?.update(theme: tabsTheme) } @@ -581,4 +583,8 @@ class MainWindow: NSObject, NSUserNotificationCenter.default.deliver(notification) } + + private func show(warning: NvimView.Warning) { + Swift.print(warning) + } }