1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-25 06:06:21 +03:00

GH-436 Add Theme to mainwindow

This commit is contained in:
Tae Won Ha 2017-06-25 11:46:43 +02:00
parent 0a21c43acd
commit 7164f47ad7
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
6 changed files with 55 additions and 1 deletions

View File

@ -152,6 +152,8 @@ extension NeoVimView {
self.bridgeLogger.debug(ColorUtils.colorIgnoringAlpha(fg)) self.bridgeLogger.debug(ColorUtils.colorIgnoringAlpha(fg))
self.grid.foreground = fg self.grid.foreground = fg
self.delegate?.foregroundChanged(to: ColorUtils.colorIgnoringAlpha(fg))
} }
} }
@ -161,6 +163,8 @@ extension NeoVimView {
self.grid.background = bg self.grid.background = bg
self.layer?.backgroundColor = ColorUtils.colorIgnoringAlpha(self.grid.background).cgColor self.layer?.backgroundColor = ColorUtils.colorIgnoringAlpha(self.grid.background).cgColor
self.delegate?.backgroundChanged(to: ColorUtils.colorIgnoringAlpha(bg))
} }
} }
@ -169,6 +173,8 @@ extension NeoVimView {
self.bridgeLogger.debug(ColorUtils.colorIgnoringAlpha(sp)) self.bridgeLogger.debug(ColorUtils.colorIgnoringAlpha(sp))
self.grid.special = sp self.grid.special = sp
self.delegate?.specialChanged(to: ColorUtils.colorIgnoringAlpha(sp))
} }
} }
@ -198,6 +204,10 @@ extension NeoVimView {
gui.async { gui.async {
// self.bridgeLogger.debug("\(neoVimAutoCommandEventName(event)) -> \(bufferHandle)") // self.bridgeLogger.debug("\(neoVimAutoCommandEventName(event)) -> \(bufferHandle)")
if event == .COLORSCHEME {
NSLog(self.agent.vimCommandOutput("hi")!)
}
if event == .BUFWINENTER || event == .BUFWINLEAVE { if event == .BUFWINENTER || event == .BUFWINLEAVE {
self.bufferListChanged() self.bufferListChanged()
} }
@ -206,6 +216,15 @@ extension NeoVimView {
self.tabChanged() self.tabChanged()
} }
let output = "SpecialComment xxx links to Special\n" +
"Debug xxx links to Special\n" +
"FoldColmun xxx ctermfg=246 ctermbg=235 guifg=#909194 guibg=#44475a\n" +
"Normal xxx guifg=#f8f8f2 guibg=#282a36\n" +
"rubyClass xxx ctermfg=212 guifg=#ff79c6\n" +
"rubyFunction xxx ctermfg=84 guifg=#50fa7b\n" +
"rubyInterpolationDelimiter xxx cleared\n" +
"rubySymbol xxx ctermfg=141 guifg=#bd93f9"
if event == .BUFREADPOST || event == .BUFWRITEPOST { if event == .BUFREADPOST || event == .BUFWRITEPOST {
self.currentBufferChanged(bufferHandle) self.currentBufferChanged(bufferHandle)
} }

View File

@ -136,7 +136,7 @@ public class NeoVimView: NSView,
@IBAction public func debug1(_ sender: Any?) { @IBAction public func debug1(_ sender: Any?) {
self.logger.debug("DEBUG 1 - Start") self.logger.debug("DEBUG 1 - Start")
NSApp.hide(self) NSLog(self.agent.vimCommandOutput("hi")!)
self.logger.debug("DEBUG 1 - End") self.logger.debug("DEBUG 1 - End")
} }

View File

@ -16,6 +16,10 @@ public protocol NeoVimViewDelegate: class {
func tabChanged() func tabChanged()
func currentBufferChanged(_ currentBuffer: NeoVimBuffer) func currentBufferChanged(_ currentBuffer: NeoVimBuffer)
func foregroundChanged(to: NSColor)
func backgroundChanged(to: NSColor)
func specialChanged(to: NSColor)
func ipcBecameInvalid(reason: String) func ipcBecameInvalid(reason: String)
func scroll() func scroll()

View File

@ -39,6 +39,8 @@ class MainWindow: NSObject,
case setState(for: Tools, with: WorkspaceTool) case setState(for: Tools, with: WorkspaceTool)
case setToolsState([(Tools, WorkspaceTool)]) case setToolsState([(Tools, WorkspaceTool)])
case setTheme(Theme)
case close case close
} }
@ -68,6 +70,14 @@ class MainWindow: NSObject,
case verticalSplit case verticalSplit
} }
struct Theme {
static let `default` = Theme()
var foreground = NSColor.black
var background = NSColor.white
}
required init(source: Observable<StateType>, emitter: ActionEmitter, state: StateType) { required init(source: Observable<StateType>, emitter: ActionEmitter, state: StateType) {
self.emit = emitter.typedEmit() self.emit = emitter.typedEmit()
self.uuid = state.uuid self.uuid = state.uuid
@ -270,6 +280,8 @@ class MainWindow: NSObject,
fileprivate var linespacing: CGFloat fileprivate var linespacing: CGFloat
fileprivate var usesLigatures: Bool fileprivate var usesLigatures: Bool
fileprivate var theme = Theme.default
fileprivate let fontManager = NSFontManager.shared() fileprivate let fontManager = NSFontManager.shared()
fileprivate let workspace: Workspace fileprivate let workspace: Workspace
@ -394,6 +406,20 @@ extension MainWindow {
self.currentBufferChanged(currentBuffer) self.currentBufferChanged(currentBuffer)
} }
func foregroundChanged(to color: NSColor) {
self.theme.foreground = color
self.emit(uuidAction(for: .setTheme(self.theme)))
}
func backgroundChanged(to color: NSColor) {
self.theme.background = color
self.emit(uuidAction(for: .setTheme(self.theme)))
}
func specialChanged(to color: NSColor) {
// noop
}
func ipcBecameInvalid(reason: String) { func ipcBecameInvalid(reason: String) {
let alert = NSAlert() let alert = NSAlert()
alert.addButton(withTitle: "Close") alert.addButton(withTitle: "Close")

View File

@ -82,6 +82,9 @@ class MainWindowReducer {
case let .toggleToolButtons(value): case let .toggleToolButtons(value):
state.isToolButtonsVisible = value state.isToolButtonsVisible = value
case let .setTheme(theme):
state.theme = Marked(theme)
default: default:
return pair return pair

View File

@ -208,6 +208,8 @@ extension MainWindow {
Tools.htmlPreview: true, Tools.htmlPreview: true,
] ]
var theme = Marked(Theme.default)
////// transient ////// transient
var lastFileSystemUpdate = Marked(FileUtils.userHomeUrl) var lastFileSystemUpdate = Marked(FileUtils.userHomeUrl)