mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-24 22:33:52 +03:00
GH-436 Add an option in appearance pref pane
- Added a theme struct to VimR module for the case when the option is turned off
This commit is contained in:
parent
313fe5e61c
commit
7a4c5f955e
@ -19,6 +19,7 @@
|
||||
1929B1837C750CADB3A5BCB9 /* OpenQuicklyFileViewRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B1558455B3A74D93EF2A /* OpenQuicklyFileViewRow.swift */; };
|
||||
1929B18A0D7C7407C51DB642 /* DataWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 1929BB6CFF4CC0B5E8B00C62 /* DataWrapper.m */; };
|
||||
1929B1E05C116514C1D3A384 /* CocoaCategories.m in Sources */ = {isa = PBXBuildFile; fileRef = 1929B5C3F2F1CA4113DABFFD /* CocoaCategories.m */; };
|
||||
1929B20CE35B43BB1CE023BA /* Theme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BC2F05E9A5C0DB039739 /* Theme.swift */; };
|
||||
1929B29B95AD176D57942E08 /* UiRootReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B457B9D0FA4D21F3751E /* UiRootReducer.swift */; };
|
||||
1929B3217A7A3D79E28C80DB /* PrefWindowReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B49E6924847AD085C8C9 /* PrefWindowReducer.swift */; };
|
||||
1929B333855A5406C400DA92 /* OpenQuicklyFilterOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BEDE7F92BC7B49E802AF /* OpenQuicklyFilterOperation.swift */; };
|
||||
@ -66,6 +67,7 @@
|
||||
1929BB0A840D93D1A13C25FD /* NeoVimView+MenuItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B4F65149D3C3E326DA65 /* NeoVimView+MenuItems.swift */; };
|
||||
1929BB38525ECCEE8E39288A /* NeoVimView+Key.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BDF3167E15E7F3349798 /* NeoVimView+Key.swift */; };
|
||||
1929BB4A9B2FA42A64CCCC76 /* MainWindowReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BD83A13BF133741766CC /* MainWindowReducer.swift */; };
|
||||
1929BBE28654E4307AF1E2FD /* Theme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BC2F05E9A5C0DB039739 /* Theme.swift */; };
|
||||
1929BC9EF45463113EBF3BCB /* NeoVimView+UiBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B2AD3F9375F57F21AD58 /* NeoVimView+UiBridge.swift */; };
|
||||
1929BCA03A420A83174FD7E7 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B96384F1ED979BD001C556F /* Logger.swift */; };
|
||||
1929BCC7908DD899999B70BE /* AppearancePrefReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BED01F5D94BFCA4CF80F /* AppearancePrefReducer.swift */; };
|
||||
@ -437,6 +439,7 @@
|
||||
1929BB6CFF4CC0B5E8B00C62 /* DataWrapper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DataWrapper.m; sourceTree = "<group>"; };
|
||||
1929BBC84557C8351EC6183E /* FileItemIgnorePatternTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileItemIgnorePatternTest.swift; sourceTree = "<group>"; };
|
||||
1929BBE0A534F2F6009D31BE /* AdvencedPref.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdvencedPref.swift; sourceTree = "<group>"; };
|
||||
1929BC2F05E9A5C0DB039739 /* Theme.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Theme.swift; sourceTree = "<group>"; };
|
||||
1929BCE3E156C06EDF1F2806 /* FileOutlineView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileOutlineView.swift; sourceTree = "<group>"; };
|
||||
1929BD05CA498FC3C229455E /* NeoVimView+Resize.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NeoVimView+Resize.swift"; sourceTree = "<group>"; };
|
||||
1929BD2CA8DD198A6BCDBCB7 /* ThemedTableSubviews.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ThemedTableSubviews.swift; sourceTree = "<group>"; };
|
||||
@ -697,6 +700,7 @@
|
||||
1929B1645977E0AEFE53193D /* File Browser */,
|
||||
1929BD9EEC30C0A498877E5B /* Open Quickly */,
|
||||
1929B85023B042C485409CE1 /* HtmlPreviewTool.swift */,
|
||||
1929BC2F05E9A5C0DB039739 /* Theme.swift */,
|
||||
);
|
||||
name = Components;
|
||||
sourceTree = "<group>";
|
||||
@ -1644,6 +1648,7 @@
|
||||
1929BE407A667356E29386EF /* Logger.swift in Sources */,
|
||||
1929BE2F3E0182CC51F2763A /* ThemedTableSubviews.swift in Sources */,
|
||||
1929B6460862447A31B5B082 /* ImageAndTextTableCell.swift in Sources */,
|
||||
1929BBE28654E4307AF1E2FD /* Theme.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -1670,6 +1675,7 @@
|
||||
1929BAAD7336FDFF1F78E749 /* ScorerTest.swift in Sources */,
|
||||
1929B8E90A1378E494D481E7 /* PrefUtilsTest.swift in Sources */,
|
||||
1929BCA03A420A83174FD7E7 /* Logger.swift in Sources */,
|
||||
1929B20CE35B43BB1CE023BA /* Theme.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -8,11 +8,28 @@ import CocoaMarkdown
|
||||
|
||||
extension NSColor {
|
||||
|
||||
var hex: String {
|
||||
if let color = self.usingColorSpace(.sRGB) {
|
||||
return "#" +
|
||||
String(format: "%X", Int(color.redComponent * 255)) +
|
||||
String(format: "%X", Int(color.greenComponent * 255)) +
|
||||
String(format: "%X", Int(color.blueComponent * 255)) +
|
||||
String(format: "%X", Int(color.alphaComponent * 255))
|
||||
} else {
|
||||
return self.description
|
||||
}
|
||||
}
|
||||
|
||||
func darkening(by factor: CGFloat) -> NSColor {
|
||||
let h = self.hueComponent
|
||||
let s = self.saturationComponent
|
||||
let b = self.brightnessComponent
|
||||
let a = self.alphaComponent
|
||||
guard let color = self.usingColorSpace(.sRGB) else {
|
||||
// TODO: what to do?
|
||||
return self
|
||||
}
|
||||
|
||||
let h = color.hueComponent
|
||||
let s = color.saturationComponent
|
||||
let b = color.brightnessComponent
|
||||
let a = color.alphaComponent
|
||||
|
||||
return NSColor(hue: h, saturation: s, brightness: b * factor, alpha: a)
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ class AppearancePref: PrefPane, NSComboBoxDelegate, NSControlTextEditingDelegate
|
||||
enum Action {
|
||||
|
||||
case setUsesLigatures(Bool)
|
||||
case setUsesColorscheme(Bool)
|
||||
case setFont(NSFont)
|
||||
case setLinespacing(CGFloat)
|
||||
}
|
||||
@ -36,6 +37,7 @@ class AppearancePref: PrefPane, NSComboBoxDelegate, NSControlTextEditingDelegate
|
||||
self.font = state.mainWindowTemplate.appearance.font
|
||||
self.linespacing = state.mainWindowTemplate.appearance.linespacing
|
||||
self.usesLigatures = state.mainWindowTemplate.appearance.usesLigatures
|
||||
self.usesColorscheme = state.mainWindowTemplate.appearance.usesTheme
|
||||
|
||||
super.init(frame: .zero)
|
||||
|
||||
@ -53,6 +55,7 @@ class AppearancePref: PrefPane, NSComboBoxDelegate, NSControlTextEditingDelegate
|
||||
self.font = appearance.font
|
||||
self.linespacing = appearance.linespacing
|
||||
self.usesLigatures = appearance.usesLigatures
|
||||
self.usesColorscheme = appearance.usesTheme
|
||||
|
||||
self.updateViews()
|
||||
}
|
||||
@ -68,6 +71,9 @@ class AppearancePref: PrefPane, NSComboBoxDelegate, NSControlTextEditingDelegate
|
||||
fileprivate var font: NSFont
|
||||
fileprivate var linespacing: CGFloat
|
||||
fileprivate var usesLigatures: Bool
|
||||
fileprivate var usesColorscheme: Bool
|
||||
|
||||
fileprivate let colorschemeCheckbox = NSButton(forAutoLayout: ())
|
||||
|
||||
fileprivate let sizes = [9, 10, 11, 12, 13, 14, 16, 18, 24, 36, 48, 64]
|
||||
fileprivate let sizeCombo = NSComboBox(forAutoLayout: ())
|
||||
@ -91,6 +97,16 @@ class AppearancePref: PrefPane, NSComboBoxDelegate, NSControlTextEditingDelegate
|
||||
fileprivate func addViews() {
|
||||
let paneTitle = self.paneTitleTextField(title: "Appearance")
|
||||
|
||||
let useColorscheme = self.colorschemeCheckbox
|
||||
self.configureCheckbox(button: useColorscheme,
|
||||
title: "Use Neovim's color scheme for tools.",
|
||||
action: #selector(AppearancePref.usesColorschemeAction(_:)))
|
||||
|
||||
let useColorschemeInfo = self.infoTextField(
|
||||
markdown: "If checked, the colors of the selected `colorscheme` will be \n" +
|
||||
"used to render tools, e.g. the file browser."
|
||||
)
|
||||
|
||||
let fontTitle = self.titleTextField(title: "Default Font:")
|
||||
|
||||
let fontPopup = self.fontPopup
|
||||
@ -141,6 +157,8 @@ class AppearancePref: PrefPane, NSComboBoxDelegate, NSControlTextEditingDelegate
|
||||
|
||||
self.addSubview(paneTitle)
|
||||
|
||||
self.addSubview(useColorscheme)
|
||||
self.addSubview(useColorschemeInfo)
|
||||
self.addSubview(fontTitle)
|
||||
self.addSubview(fontPopup)
|
||||
self.addSubview(sizeCombo)
|
||||
@ -152,10 +170,16 @@ class AppearancePref: PrefPane, NSComboBoxDelegate, NSControlTextEditingDelegate
|
||||
paneTitle.autoPinEdge(toSuperviewEdge: .top, withInset: 18)
|
||||
paneTitle.autoPinEdge(toSuperviewEdge: .left, withInset: 18)
|
||||
|
||||
useColorscheme.autoPinEdge(.left, to: .right, of: fontTitle, withOffset: 5)
|
||||
useColorscheme.autoPinEdge(.top, to: .bottom, of: paneTitle, withOffset: 18)
|
||||
|
||||
useColorschemeInfo.autoPinEdge(.top, to: .bottom, of: useColorscheme, withOffset: 5)
|
||||
useColorschemeInfo.autoPinEdge(.left, to: .left, of: useColorscheme)
|
||||
|
||||
fontTitle.autoPinEdge(toSuperviewEdge: .left, withInset: 18, relation: .greaterThanOrEqual)
|
||||
fontTitle.autoAlignAxis(.baseline, toSameAxisOf: fontPopup)
|
||||
|
||||
fontPopup.autoPinEdge(.top, to: .bottom, of: paneTitle, withOffset: 18)
|
||||
fontPopup.autoPinEdge(.top, to: .bottom, of: useColorschemeInfo, withOffset: 18)
|
||||
fontPopup.autoPinEdge(.left, to: .right, of: fontTitle, withOffset: 5)
|
||||
fontPopup.autoSetDimension(.width, toSize: 240)
|
||||
|
||||
@ -193,6 +217,7 @@ class AppearancePref: PrefPane, NSComboBoxDelegate, NSControlTextEditingDelegate
|
||||
self.linespacingField.stringValue = String(format: "%.2f", self.linespacing)
|
||||
self.ligatureCheckbox.boolState = self.usesLigatures
|
||||
self.previewArea.font = self.font
|
||||
self.colorschemeCheckbox.boolState = self.usesColorscheme
|
||||
|
||||
if self.usesLigatures {
|
||||
self.previewArea.useAllLigatures(self)
|
||||
@ -205,6 +230,10 @@ class AppearancePref: PrefPane, NSComboBoxDelegate, NSControlTextEditingDelegate
|
||||
// MARK: - Actions
|
||||
extension AppearancePref {
|
||||
|
||||
func usesColorschemeAction(_ sender: NSButton) {
|
||||
self.emit(.setUsesColorscheme(sender.boolState))
|
||||
}
|
||||
|
||||
func usesLigaturesAction(_ sender: NSButton) {
|
||||
self.emit(.setUsesLigatures(sender.boolState))
|
||||
}
|
||||
|
@ -18,6 +18,9 @@ class AppearancePrefReducer {
|
||||
case let .setUsesLigatures(value):
|
||||
appearance.usesLigatures = value
|
||||
|
||||
case let .setUsesColorscheme(value):
|
||||
appearance.usesTheme = value
|
||||
|
||||
case let .setFont(font):
|
||||
appearance.font = font
|
||||
|
||||
|
@ -16,7 +16,7 @@ class FileOutlineView: NSOutlineView,
|
||||
|
||||
typealias StateType = MainWindow.State
|
||||
|
||||
fileprivate(set) var theme = NeoVimView.Theme.default
|
||||
fileprivate(set) var theme = Theme.default
|
||||
|
||||
required init(source: Observable<StateType>, emitter: ActionEmitter, state: StateType) {
|
||||
self.emit = emitter.typedEmit()
|
||||
@ -25,6 +25,8 @@ class FileOutlineView: NSOutlineView,
|
||||
self.root = FileBrowserItem(state.cwd)
|
||||
self.isShowHidden = state.fileBrowserShowHidden
|
||||
|
||||
self.usesTheme = state.appearance.usesTheme
|
||||
|
||||
super.init(frame: .zero)
|
||||
NSOutlineView.configure(toStandard: self)
|
||||
|
||||
@ -64,14 +66,29 @@ class FileOutlineView: NSOutlineView,
|
||||
self.beFirstResponder()
|
||||
}
|
||||
|
||||
guard self.shouldReloadData(for: state) else {
|
||||
let themeChanged = changeTheme(
|
||||
themePrefChanged: state.appearance.usesTheme != self.usesTheme,
|
||||
themeChanged: state.appearance.theme.mark != self.lastThemeMark,
|
||||
usesTheme: state.appearance.usesTheme,
|
||||
forTheme: {
|
||||
self.theme = state.appearance.theme.payload
|
||||
self.enclosingScrollView?.backgroundColor = self.theme.background
|
||||
self.backgroundColor = self.theme.background
|
||||
self.lastThemeMark = state.appearance.theme.mark
|
||||
},
|
||||
forDefaultTheme: {
|
||||
self.theme = Theme.default
|
||||
self.enclosingScrollView?.backgroundColor = self.theme.background
|
||||
self.backgroundColor = self.theme.background
|
||||
self.lastThemeMark = state.appearance.theme.mark
|
||||
})
|
||||
|
||||
self.usesTheme = state.appearance.usesTheme
|
||||
|
||||
guard self.shouldReloadData(for: state, themeChanged: themeChanged) else {
|
||||
return
|
||||
}
|
||||
|
||||
self.lastThemeMark = state.appearance.theme.mark
|
||||
self.theme = state.appearance.theme.payload
|
||||
self.enclosingScrollView?.backgroundColor = self.theme.background
|
||||
self.backgroundColor = self.theme.background
|
||||
self.isShowHidden = state.fileBrowserShowHidden
|
||||
self.lastFileSystemUpdateMark = state.lastFileSystemUpdate.mark
|
||||
self.root = FileBrowserItem(state.cwd)
|
||||
@ -105,8 +122,10 @@ class FileOutlineView: NSOutlineView,
|
||||
|
||||
fileprivate let uuid: String
|
||||
fileprivate var lastFileSystemUpdateMark = Token()
|
||||
fileprivate var usesTheme: Bool
|
||||
fileprivate var lastThemeMark = Token()
|
||||
|
||||
|
||||
fileprivate var cwd: URL {
|
||||
return self.root.url
|
||||
}
|
||||
@ -118,12 +137,12 @@ class FileOutlineView: NSOutlineView,
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
fileprivate func shouldReloadData(for state: StateType) -> Bool {
|
||||
fileprivate func shouldReloadData(for state: StateType, themeChanged: Bool = false) -> Bool {
|
||||
if self.isShowHidden != state.fileBrowserShowHidden {
|
||||
return true
|
||||
}
|
||||
|
||||
if state.appearance.theme.mark != self.lastThemeMark {
|
||||
if themeChanged {
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,27 @@ import RxSwift
|
||||
import SwiftNeoVim
|
||||
import PureLayout
|
||||
|
||||
func changeTheme(themePrefChanged: Bool, themeChanged: Bool, usesTheme: Bool,
|
||||
forTheme: () -> Void, forDefaultTheme: () -> Void) -> Bool {
|
||||
|
||||
if themePrefChanged && usesTheme {
|
||||
forTheme()
|
||||
return true
|
||||
}
|
||||
|
||||
if themePrefChanged && !usesTheme {
|
||||
forDefaultTheme()
|
||||
return true
|
||||
}
|
||||
|
||||
if !themePrefChanged && themeChanged && usesTheme {
|
||||
forTheme()
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
class MainWindow: NSObject,
|
||||
UiComponent,
|
||||
NeoVimViewDelegate,
|
||||
@ -39,7 +60,7 @@ class MainWindow: NSObject,
|
||||
case setState(for: Tools, with: WorkspaceTool)
|
||||
case setToolsState([(Tools, WorkspaceTool)])
|
||||
|
||||
case setTheme(NeoVimView.Theme)
|
||||
case setTheme(Theme)
|
||||
|
||||
case close
|
||||
}
|
||||
@ -147,6 +168,8 @@ class MainWindow: NSObject,
|
||||
workspace.append(tool: tool, location: state.tools[toolId]?.location ?? .left)
|
||||
}
|
||||
|
||||
self.usesTheme = state.appearance.usesTheme
|
||||
|
||||
super.init()
|
||||
|
||||
self.tools.forEach { (toolId, toolContainer) in
|
||||
@ -207,6 +230,22 @@ class MainWindow: NSObject,
|
||||
self.neoVimView.select(buffer: currentBuffer)
|
||||
}
|
||||
|
||||
let usesTheme = state.appearance.usesTheme
|
||||
let themePrefChanged = state.appearance.usesTheme != self.usesTheme
|
||||
let themeChanged = state.appearance.theme.mark != self.lastThemeMark
|
||||
|
||||
_ = changeTheme(
|
||||
themePrefChanged: themePrefChanged, themeChanged: themeChanged, usesTheme: usesTheme,
|
||||
forTheme: {
|
||||
self.setWorkspaceTheme(with: state.appearance.theme.payload)
|
||||
self.lastThemeMark = state.appearance.theme.mark
|
||||
},
|
||||
forDefaultTheme: {
|
||||
self.workspace.theme = Workspace.Theme.default
|
||||
})
|
||||
|
||||
self.usesTheme = state.appearance.usesTheme
|
||||
|
||||
if self.defaultFont != state.appearance.font
|
||||
|| self.linespacing != state.appearance.linespacing
|
||||
|| self.usesLigatures != state.appearance.usesLigatures {
|
||||
@ -238,28 +277,11 @@ class MainWindow: NSObject,
|
||||
}
|
||||
|
||||
@IBAction func debug2(_: Any?) {
|
||||
// var theme = Workspace.Theme()
|
||||
// theme.foreground = .red
|
||||
// theme.background = .yellow
|
||||
//
|
||||
// theme.separator = .blue
|
||||
//
|
||||
// theme.barBackground = .cyan
|
||||
// theme.barFocusRing = .black
|
||||
//
|
||||
// theme.barButtonBackground = .brown
|
||||
// theme.barButtonHighlight = .magenta
|
||||
//
|
||||
// theme.toolbarForeground = .green
|
||||
// theme.toolbarBackground = .orange
|
||||
//
|
||||
// self.workspace.theme = theme
|
||||
|
||||
var theme = NeoVimView.Theme.default
|
||||
var theme = Theme.default
|
||||
theme.foreground = .blue
|
||||
theme.background = .yellow
|
||||
theme.visualForeground = .orange
|
||||
theme.visualBackground = .red
|
||||
theme.highlightForeground = .orange
|
||||
theme.highlightBackground = .red
|
||||
self.emit(uuidAction(for: .setTheme(theme)))
|
||||
}
|
||||
|
||||
@ -299,6 +321,9 @@ class MainWindow: NSObject,
|
||||
|
||||
fileprivate let tools: [Tools: WorkspaceTool]
|
||||
|
||||
fileprivate var usesTheme: Bool
|
||||
fileprivate var lastThemeMark = Token()
|
||||
|
||||
fileprivate let scrollDebouncer = Debouncer<Action>(interval: 0.75)
|
||||
fileprivate let cursorDebouncer = Debouncer<Action>(interval: 0.75)
|
||||
|
||||
@ -315,6 +340,24 @@ class MainWindow: NSObject,
|
||||
return UuidAction(uuid: self.uuid, action: action)
|
||||
}
|
||||
|
||||
fileprivate func setWorkspaceTheme(with theme: Theme) {
|
||||
var workspaceTheme = Workspace.Theme()
|
||||
workspaceTheme.foreground = theme.foreground
|
||||
workspaceTheme.background = theme.background
|
||||
|
||||
workspaceTheme.separator = theme.background.darkening(by: 0.75)
|
||||
|
||||
workspaceTheme.barBackground = theme.background
|
||||
workspaceTheme.barFocusRing = theme.foreground
|
||||
|
||||
workspaceTheme.barButtonHighlight = theme.background.darkening(by: 0.75)
|
||||
|
||||
workspaceTheme.toolbarForeground = theme.foreground
|
||||
workspaceTheme.toolbarBackground = theme.background.darkening(by: 0.75)
|
||||
|
||||
self.workspace.theme = workspaceTheme
|
||||
}
|
||||
|
||||
fileprivate func open(urls: [URL: OpenMode]) {
|
||||
// If we don't call the following in the next tick, only half of the existing swap file warning is displayed.
|
||||
// Dunno why...
|
||||
@ -403,26 +446,8 @@ extension MainWindow {
|
||||
self.currentBufferChanged(currentBuffer)
|
||||
}
|
||||
|
||||
func colorschemeChanged(to theme: NeoVimView.Theme) {
|
||||
self.emit(uuidAction(for: .setTheme(theme)))
|
||||
|
||||
DispatchQueue.main.async {
|
||||
var workspaceTheme = Workspace.Theme()
|
||||
workspaceTheme.foreground = theme.foreground
|
||||
workspaceTheme.background = theme.background
|
||||
|
||||
workspaceTheme.separator = theme.background.darkening(by: 0.75)
|
||||
|
||||
workspaceTheme.barBackground = theme.background
|
||||
workspaceTheme.barFocusRing = theme.foreground
|
||||
|
||||
workspaceTheme.barButtonHighlight = theme.background.darkening(by: 0.75)
|
||||
|
||||
workspaceTheme.toolbarForeground = theme.foreground
|
||||
workspaceTheme.toolbarBackground = theme.background.darkening(by: 0.75)
|
||||
|
||||
self.workspace.theme = workspaceTheme
|
||||
}
|
||||
func colorschemeChanged(to neoVimTheme: NeoVimView.Theme) {
|
||||
self.emit(uuidAction(for: .setTheme(Theme(neoVimTheme))))
|
||||
}
|
||||
|
||||
func ipcBecameInvalid(reason: String) {
|
||||
|
@ -83,9 +83,7 @@ class MainWindowReducer {
|
||||
state.isToolButtonsVisible = value
|
||||
|
||||
case let .setTheme(theme):
|
||||
if state.appearance.usesNeoVimTheme {
|
||||
state.appearance.theme = Marked(theme)
|
||||
}
|
||||
state.appearance.theme = Marked(theme)
|
||||
|
||||
default:
|
||||
return pair
|
||||
|
@ -21,7 +21,7 @@ class OpenedFileList: NSView,
|
||||
case open(NeoVimBuffer)
|
||||
}
|
||||
|
||||
fileprivate(set) var theme = NeoVimView.Theme.default
|
||||
fileprivate(set) var theme = Theme.default
|
||||
|
||||
required init(source: Observable<StateType>, emitter: ActionEmitter, state: StateType) {
|
||||
self.emit = emitter.typedEmit()
|
||||
@ -29,6 +29,8 @@ class OpenedFileList: NSView,
|
||||
|
||||
self.genericIcon = FileUtils.icon(forType: "public.data")
|
||||
|
||||
self.usesTheme = state.appearance.usesTheme
|
||||
|
||||
super.init(frame: .zero)
|
||||
|
||||
self.bufferList.dataSource = self
|
||||
@ -42,13 +44,30 @@ class OpenedFileList: NSView,
|
||||
source
|
||||
.observeOn(MainScheduler.instance)
|
||||
.subscribe(onNext: { state in
|
||||
let themeChanged = changeTheme(
|
||||
themePrefChanged: state.appearance.usesTheme != self.usesTheme,
|
||||
themeChanged: state.appearance.theme.mark != self.lastThemeMark,
|
||||
usesTheme: state.appearance.usesTheme,
|
||||
forTheme: {
|
||||
self.theme = state.appearance.theme.payload
|
||||
self.bufferList.enclosingScrollView?.backgroundColor = self.theme.background
|
||||
self.bufferList.backgroundColor = self.theme.background
|
||||
self.lastThemeMark = state.appearance.theme.mark
|
||||
},
|
||||
forDefaultTheme: {
|
||||
self.theme = Theme.default
|
||||
self.bufferList.enclosingScrollView?.backgroundColor = self.theme.background
|
||||
self.bufferList.backgroundColor = self.theme.background
|
||||
self.lastThemeMark = state.appearance.theme.mark
|
||||
})
|
||||
|
||||
self.usesTheme = state.appearance.usesTheme
|
||||
|
||||
let buffers = state.buffers.removingDuplicatesPreservingFromBeginning()
|
||||
if self.buffers == buffers && self.lastThemeMark == state.appearance.theme.mark {
|
||||
if self.buffers == buffers && !themeChanged {
|
||||
return
|
||||
}
|
||||
|
||||
self.lastThemeMark = state.appearance.theme.mark
|
||||
self.theme = state.appearance.theme.payload
|
||||
self.buffers = buffers
|
||||
self.bufferList.reloadData()
|
||||
self.adjustFileViewWidth()
|
||||
@ -60,6 +79,7 @@ class OpenedFileList: NSView,
|
||||
fileprivate let disposeBag = DisposeBag()
|
||||
|
||||
fileprivate let uuid: String
|
||||
fileprivate var usesTheme: Bool
|
||||
fileprivate var lastThemeMark = Token()
|
||||
|
||||
fileprivate let bufferList = NSTableView.standardTableView()
|
||||
|
@ -166,8 +166,8 @@ struct AppearanceState: SerializableState {
|
||||
var usesLigatures = false
|
||||
|
||||
// FIXME GH-436: set to false and make it an option
|
||||
var usesNeoVimTheme = true
|
||||
var theme = Marked(NeoVimView.Theme.default)
|
||||
var usesTheme = true
|
||||
var theme = Marked(Theme.default)
|
||||
|
||||
init() {
|
||||
|
||||
|
37
VimR/Theme.swift
Normal file
37
VimR/Theme.swift
Normal file
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Tae Won Ha - http://taewon.de - @hataewon
|
||||
* See LICENSE
|
||||
*/
|
||||
|
||||
import Cocoa
|
||||
import SwiftNeoVim
|
||||
|
||||
struct Theme: CustomStringConvertible {
|
||||
|
||||
static let `default` = Theme()
|
||||
|
||||
var foreground = NSColor.textColor
|
||||
var background = NSColor.textBackgroundColor
|
||||
|
||||
var highlightForeground = NSColor.selectedMenuItemTextColor
|
||||
var highlightBackground = NSColor.selectedMenuItemColor
|
||||
|
||||
public var description: String {
|
||||
return "Theme<" +
|
||||
"fg: \(self.foreground.hex), bg: \(self.background.hex), " +
|
||||
"hl-fg: \(self.highlightForeground.hex), hl-bg: \(self.highlightBackground.hex)" +
|
||||
">"
|
||||
}
|
||||
|
||||
init() {
|
||||
|
||||
}
|
||||
|
||||
init(_ neoVimTheme: NeoVimView.Theme) {
|
||||
self.foreground = neoVimTheme.foreground
|
||||
self.background = neoVimTheme.background
|
||||
|
||||
self.highlightForeground = neoVimTheme.visualForeground
|
||||
self.highlightBackground = neoVimTheme.visualBackground
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ import PureLayout
|
||||
|
||||
protocol ThemedView: class {
|
||||
|
||||
var theme: NeoVimView.Theme { get }
|
||||
var theme: Theme { get }
|
||||
}
|
||||
|
||||
class ThemedTableRow: NSTableRowView {
|
||||
@ -24,7 +24,7 @@ class ThemedTableRow: NSTableRowView {
|
||||
|
||||
open override func drawBackground(in dirtyRect: NSRect) {
|
||||
if let cell = self.view(atColumn: 0) as? ThemedTableCell {
|
||||
cell.textField?.textColor = self.themedView?.theme.foreground ?? NeoVimView.Theme.default.foreground
|
||||
cell.textField?.textColor = self.themedView?.theme.foreground ?? Theme.default.foreground
|
||||
}
|
||||
|
||||
self.themedView?.theme.background.set()
|
||||
@ -33,10 +33,10 @@ class ThemedTableRow: NSTableRowView {
|
||||
|
||||
override func drawSelection(in dirtyRect: NSRect) {
|
||||
if let cell = self.view(atColumn: 0) as? ThemedTableCell {
|
||||
cell.textField?.textColor = self.themedView?.theme.visualForeground ?? NeoVimView.Theme.default.visualForeground
|
||||
cell.textField?.textColor = self.themedView?.theme.highlightForeground ?? Theme.default.highlightForeground
|
||||
}
|
||||
|
||||
self.themedView?.theme.visualBackground.set()
|
||||
self.themedView?.theme.highlightBackground.set()
|
||||
NSRectFill(dirtyRect)
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,9 @@ class UiRootReducer {
|
||||
|
||||
appState.mainWindows.removeValue(forKey: uuid)
|
||||
|
||||
case let .setTheme(theme):
|
||||
appState.mainWindowTemplate.appearance.theme = Marked(theme)
|
||||
|
||||
default:
|
||||
return pair
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user