.../Source/App/Preferences/PreferencesPastePipelineView.swift
Line | Count | Source (jump to first uncovered line) |
1 | | // |
2 | | // PreferencesJavascriptTransformView.swift |
3 | | // CutBox |
4 | | // |
5 | | // Created by Jason Milkins on 13/5/18. |
6 | | // Copyright © 2018-2023 ocodo. All rights reserved. |
7 | | // |
8 | | |
9 | | import Cocoa |
10 | | import RxSwift |
11 | | |
12 | | class PreferencesPastePipelineView: CutBoxBaseView { |
13 | | |
14 | | var prefs: CutBoxPreferencesService! |
15 | 51 | var js = JSFuncService() |
16 | 51 | let disposeBag = DisposeBag() |
17 | | |
18 | | @IBOutlet weak var javascriptTransformSectionTitle: CutBoxBaseTextField! |
19 | | @IBOutlet weak var javascriptReplCommandLine: CutBoxBaseTextField! |
20 | | @IBOutlet weak var javascriptTransformInfo: CutBoxBaseTextField! |
21 | | @IBOutlet weak var javascriptTransformREPLOutput: CutBoxBaseTextView! |
22 | | @IBOutlet weak var javascriptTransformReloadButton: CutBoxBaseButton! |
23 | | @IBOutlet weak var javascriptClearReplButton: CutBoxBaseButton! |
24 | | |
25 | 49 | override func awakeFromNib() { |
26 | 49 | self.prefs = CutBoxPreferencesService.shared |
27 | 49 | |
28 | 49 | applyJavascriptREPLTheme() |
29 | 49 | setupJavascriptTransformSection() |
30 | 49 | } |
31 | | |
32 | 1 | func focusReplCommandLine() { |
33 | 1 | if let replTextField = javascriptReplCommandLine { |
34 | 1 | self.window?.makeFirstResponder(replTextField) |
35 | 1 | if let editor = replTextField.currentEditor() as? CutBoxBaseTextView { |
36 | 1 | let size = editor.string.count |
37 | 1 | editor.setSelectedRange(NSRange(location: size, length: 0)) |
38 | 1 | } |
39 | 1 | } |
40 | 1 | } |
41 | | |
42 | 49 | func applyJavascriptREPLTheme() { |
43 | 49 | let textColor = NSColor.white |
44 | 49 | let backgroundColor = NSColor.black |
45 | 49 | let commandLineBackground = #colorLiteral(red: 0.03556041353, green: 0.08317251856, blue: 0.1092823802, alpha: 1) |
46 | 49 | |
47 | 49 | self.javascriptTransformREPLOutput.font = NSFont.userFixedPitchFont(ofSize: 13) |
48 | 49 | self.javascriptTransformREPLOutput.textColor = textColor |
49 | 49 | self.javascriptTransformREPLOutput.backgroundColor = backgroundColor |
50 | 49 | |
51 | 49 | self.javascriptReplCommandLine.font = NSFont.userFixedPitchFont(ofSize: 13) |
52 | 49 | self.javascriptReplCommandLine.textColor = textColor |
53 | 49 | self.javascriptReplCommandLine.backgroundColor = commandLineBackground |
54 | 49 | } |
55 | | |
56 | 49 | func setupJavascriptTransformSection() { |
57 | 49 | self.javascriptTransformSectionTitle |
58 | 49 | .stringValue = "preferences_javascript_transform_section_title".l7n |
59 | 49 | |
60 | 49 | self.javascriptTransformInfo |
61 | 49 | .stringValue = "preferences_javascript_transform_section_note".l7n |
62 | 49 | |
63 | 49 | self.javascriptTransformREPLOutput |
64 | 49 | .string = "preferences_javascript_repl_help".l7n |
65 | 49 | |
66 | 49 | self.javascriptTransformReloadButton |
67 | 49 | .title = "preferences_javascript_transform_reload".l7n |
68 | 49 | |
69 | 49 | self.javascriptClearReplButton |
70 | 49 | .title = "preferences_javascript_clear_button".l7n |
71 | 49 | |
72 | 49 | self.javascriptClearReplButton.rx.tap |
73 | 49 | .bind(onNext: { self.javascriptTransformREPLOutput.string = "" }) |
74 | 49 | .disposed(by: disposeBag) |
75 | 49 | |
76 | 49 | self.javascriptTransformReloadButton.rx.tap |
77 | 49 | .bind(onNext: self.prefs.loadJavascript) $s15CutBoxUnitTests28PreferencesPastePipelineViewC31setupJavascriptTransformSectionyyFyycAA0abE7ServiceCcfu_ Line | Count | Source | 77 | 49 | .bind(onNext: self.prefs.loadJavascript) |
Unexecuted instantiation: $s15CutBoxUnitTests28PreferencesPastePipelineViewC31setupJavascriptTransformSectionyyFyycAA0abE7ServiceCcfu_yycfu0_ |
78 | 49 | .disposed(by: disposeBag) |
79 | 49 | } |
80 | | |
81 | 1 | @IBAction func exec(_ sender: AnyObject) { |
82 | 1 | let cmd = javascriptReplCommandLine.stringValue |
83 | 1 | javascriptReplCommandLine.stringValue = "" |
84 | 1 | |
85 | 1 | if !cmd.isEmpty { |
86 | 1 | let value = js.repl(cmd) |
87 | 1 | |
88 | 1 | append("> " + cmd) |
89 | 1 | append(value) |
90 | 1 | |
91 | 1 | if let textStorage = javascriptTransformREPLOutput.textStorage { |
92 | 1 | let textCount = textStorage.string.count |
93 | 1 | let location = max(textCount - 1, 0) |
94 | 1 | let range = NSRange(location: location, length: 1) |
95 | 1 | javascriptTransformREPLOutput.scrollRangeToVisible(range) |
96 | 1 | } |
97 | 1 | } |
98 | 1 | } |
99 | | |
100 | 2 | private func append(_ string: String) { |
101 | 2 | javascriptTransformREPLOutput.string += "\n" + string |
102 | 2 | } |
103 | | } |