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

Merge remote-tracking branch 'origin/pr/745'

Conflicts:
	VimR/VimR/GeneralPref.swift
	VimR/VimR/GeneralPrefReducer.swift
	VimR/VimR/PreviewMiddleware.swift
	VimR/VimR/States.swift
This commit is contained in:
Tae Won Ha 2023-11-05 19:49:33 +01:00
commit 94df77a072
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
5 changed files with 86 additions and 7 deletions

View File

@ -17,11 +17,16 @@ final class GeneralPref: PrefPane, UiComponent, NSTextFieldDelegate {
case setActivateAsciiImInNormalModeAction(Bool)
case setOpenOnReactivation(Bool)
case setDefaultUsesVcsIgnores(Bool)
case setCustomMarkdownProcessor(String)
}
override var displayName: String { "General" }
override var pinToContainer: Bool { true }
override func windowWillClose() {
self.customMarkdownProcessorAction()
}
required init(source: Observable<StateType>, emitter: ActionEmitter, state: StateType) {
self.emit = emitter.typedEmit()
@ -45,6 +50,9 @@ final class GeneralPref: PrefPane, UiComponent, NSTextFieldDelegate {
self.afterLastWindowPopup
.selectItem(at: indexToAfterLastWindowAction.firstIndex(of: state.afterLastWindowAction) ?? 0)
self.customMarkdownProcessor = state.mainWindowTemplate.customMarkdownProcessor
self.customMarkdownProcessorField.stringValue = state.mainWindowTemplate.customMarkdownProcessor
source
.observe(on: MainScheduler.instance)
.subscribe(onNext: { state in
@ -88,6 +96,9 @@ final class GeneralPref: PrefPane, UiComponent, NSTextFieldDelegate {
private let openFilesFromApplicationsPopup = NSPopUpButton(forAutoLayout: ())
private let afterLastWindowPopup = NSPopUpButton(forAutoLayout: ())
private var customMarkdownProcessor = ""
private let customMarkdownProcessorField = NSTextField(forAutoLayout: ())
@available(*, unavailable)
required init?(coder _: NSCoder) { fatalError("init(coder:) has not been implemented") }
@ -161,6 +172,14 @@ final class GeneralPref: PrefPane, UiComponent, NSTextFieldDelegate {
You can change this setting for each VimR window in the Open Quickly window.
"""#)
let customMarkdownProcessorTitle = self.titleTextField(title: "Custom Markdown Processor:")
let customMarkdownProcessorField = self.customMarkdownProcessorField
NotificationCenter.default.addObserver(forName: NSControl.textDidEndEditingNotification,
object: customMarkdownProcessorField,
queue: nil) { [unowned self] _ in
self.customMarkdownProcessorAction()
}
let cliToolTitle = self.titleTextField(title: "CLI Tool:")
let cliToolButton = NSButton(forAutoLayout: ())
cliToolButton.title = "Copy 'vimr' CLI Tool..."
@ -202,6 +221,9 @@ final class GeneralPref: PrefPane, UiComponent, NSTextFieldDelegate {
self.addSubview(cliToolButton)
self.addSubview(cliToolInfo)
self.addSubview(customMarkdownProcessorTitle)
self.addSubview(customMarkdownProcessorField)
paneTitle.autoPinEdge(toSuperviewEdge: .top, withInset: 18)
paneTitle.autoPinEdge(toSuperviewEdge: .left, withInset: 18)
paneTitle.autoPinEdge(toSuperviewEdge: .right, withInset: 18, relation: .greaterThanOrEqual)
@ -308,6 +330,14 @@ final class GeneralPref: PrefPane, UiComponent, NSTextFieldDelegate {
cliToolInfo.autoPinEdge(.top, to: .bottom, of: cliToolButton, withOffset: 5)
cliToolInfo.autoPinEdge(toSuperviewEdge: .right, withInset: 18, relation: .greaterThanOrEqual)
cliToolInfo.autoPinEdge(.left, to: .right, of: cliToolTitle, withOffset: 5)
customMarkdownProcessorTitle.autoAlignAxis(.baseline, toSameAxisOf: customMarkdownProcessorField)
customMarkdownProcessorTitle.autoPinEdge(.right, to: .right, of: openUntitledWindowTitle)
customMarkdownProcessorTitle.autoPinEdge(toSuperviewEdge: .left, withInset: 18, relation: .greaterThanOrEqual)
customMarkdownProcessorField.autoPinEdge(.top, to: .bottom, of: cliToolInfo, withOffset: 18)
customMarkdownProcessorField.autoPinEdge(toSuperviewEdge: .right, withInset: 18)
customMarkdownProcessorField.autoPinEdge(.left, to: .right, of: customMarkdownProcessorTitle, withOffset: 5)
}
}
@ -389,6 +419,14 @@ extension GeneralPref {
)
}
private func customMarkdownProcessorAction() {
let command = self.customMarkdownProcessorField.stringValue
if command == self.customMarkdownProcessor { return }
self.customMarkdownProcessor = command
self.emit(.setCustomMarkdownProcessor(self.customMarkdownProcessor))
}
private func alert(title: String, info: String) {
let alert = NSAlert()
alert.alertStyle = .warning

View File

@ -30,6 +30,10 @@ final class GeneralPrefReducer: ReducerType {
case let .setDefaultUsesVcsIgnores(value):
state.openQuickly.defaultUsesVcsIgnores = value
case let .setCustomMarkdownProcessor(command):
state.mainWindowTemplate.customMarkdownProcessor = command
state.mainWindows.keys.forEach { state.mainWindows[$0]?.customMarkdownProcessor = command }
}
return (state, pair.action, true)

View File

@ -53,7 +53,11 @@ final class MarkdownPreviewMiddleware {
guard let buffer = preview.buffer else { return }
do {
try self.render(buffer, to: htmlUrl)
try self.render(
buffer,
to: htmlUrl,
customMarkdownProcessor: state.customMarkdownProcessor
)
self.previewFiles[uuid] = htmlUrl
} catch let error as NSError {
// FIXME: error handling!
@ -102,10 +106,34 @@ final class MarkdownPreviewMiddleware {
category: Defs.LoggerCategory.middleware
)
private func render(_ bufferUrl: URL, to htmlUrl: URL) throws {
private func render(_ bufferUrl: URL, to htmlUrl: URL, customMarkdownProcessor cmp: String?) throws {
let body: String
if let cmp, cmp != "" {
let content = try Data(contentsOf: bufferUrl)
let sh = Process()
let output = Pipe()
let input = Pipe()
let err = Pipe()
sh.executableURL = URL(fileURLWithPath: "/usr/bin/env")
sh.arguments = ["bash", "-l", "-c", cmp]
sh.standardInput = input
sh.standardOutput = output
sh.standardError = err
input.fileHandleForWriting.write(content)
input.fileHandleForWriting.closeFile()
try sh.run()
body = String(decoding: output.fileHandleForReading.readDataToEndOfFile(), as: UTF8.self)
} else {
let md = try String(contentsOf: bufferUrl)
let down = Down(markdownString: md)
let body = try down.toHTML(DownOptions.sourcePos)
body = try down.toHTML(DownOptions.sourcePos)
}
let html = self.filledTemplate(body: body, title: bufferUrl.lastPathComponent)
let htmlFilePath = htmlUrl.path

View File

@ -305,6 +305,8 @@ extension MainWindow {
var isTemporarySession = false
var customMarkdownProcessor = ""
// neovim
var uuid = UUID()
var currentBuffer: NvimView.Buffer?
@ -349,6 +351,7 @@ extension MainWindow {
case useLiveResize = "use-live-resize"
case drawsParallel = "draws-parallel"
case isShowHidden = "is-show-hidden"
case customMarkdownProcessor = "custom-markdown-processor"
case appearance
case workspaceTools = "workspace-tool"
@ -393,6 +396,11 @@ extension MainWindow {
default: State.default.isToolButtonsVisible
)
self.customMarkdownProcessor = try container.decode(
forKey: .customMarkdownProcessor,
default: State.default.customMarkdownProcessor
)
self.appearance = try container.decode(forKey: .appearance, default: State.default.appearance)
self.orderedTools = try container.decode(
@ -447,6 +455,7 @@ extension MainWindow {
try container.encode(NSStringFromRect(self.frame), forKey: .frame)
try container.encode(self.useLiveResize, forKey: .useLiveResize)
try container.encode(self.drawsParallel, forKey: .drawsParallel)
try container.encode(self.customMarkdownProcessor, forKey: .customMarkdownProcessor)
try container.encode(self.isLeftOptionMeta, forKey: .isLeftOptionMeta)
try container.encode(self.isRightOptionMeta, forKey: .isRightOptionMeta)
try container.encode(self.useInteractiveZsh, forKey: .useInteractiveZsh)

View File

@ -36,13 +36,13 @@ public final class Workspace: NSView, WorkspaceBarDelegate {
public var foreground = NSColor.black
public var background = NSColor.white
public var separator = NSColor.controlShadowColor
public var separator = NSColor.separatorColor
public var barBackground = NSColor.windowBackgroundColor
public var barFocusRing = NSColor.selectedControlColor
public var barButtonBackground = NSColor.clear
public var barButtonHighlight = NSColor.controlShadowColor
public var barButtonHighlight = NSColor.separatorColor
public var toolbarForeground = NSColor.darkGray
public var toolbarBackground = NSColor(red: 0.899, green: 0.934, blue: 0.997, alpha: 1)