Skip to content

Commit 4893dbd

Browse files
committed
Some optimisations and bugfix.
1 parent d94fc99 commit 4893dbd

25 files changed

+457
-186
lines changed

Application/Base.lproj/Main.storyboard

Lines changed: 168 additions & 124 deletions
Large diffs are not rendered by default.

Application/NSColor+ext.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ extension NSColor {
3535
// Ensure it only contains valid hex characters 0
3636
let validHexPattern = "[a-fA-F0-9]+"
3737
if cleanedString.range(of: validHexPattern, options: String.CompareOptions.regularExpression) != nil {
38-
var theInt: UInt32 = 0
38+
var theInt: UInt64 = 0
3939
let scanner = Scanner(string: cleanedString)
40-
scanner.scanHexInt32(&theInt)
40+
scanner.scanHexInt64(&theInt)
4141
let red = CGFloat((theInt & 0xFF0000) >> 16) / 255.0
4242
let green = CGFloat((theInt & 0xFF00) >> 8) / 255.0
4343
let blue = CGFloat((theInt & 0xFF)) / 255.0

Application/PreferencesViewController.swift

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ class PreferencesViewController: NSViewController {
120120
@IBOutlet weak var lineNumbersPopup: NSPopUpButton!
121121
@IBOutlet weak var tabSpacesSlider: NSSlider!
122122
@IBOutlet weak var argumentsTextField: NSTextField!
123-
@IBOutlet weak var debugButton: NSButton!
123+
@IBOutlet weak var interactiveButton: NSSwitch!
124+
@IBOutlet weak var debugButton: NSSwitch!
124125

125126
@IBOutlet weak var examplesPopup: NSPopUpButton!
126127

@@ -166,6 +167,9 @@ class PreferencesViewController: NSViewController {
166167
@IBOutlet weak var utiArgumentsCheckbox: NSButton!
167168
@IBOutlet weak var utiArgumentsTextField: NSTextField!
168169

170+
@IBOutlet weak var utiInteractiveCheckbox: NSButton!
171+
@IBOutlet weak var utiInteractiveButton: NSSwitch!
172+
169173
@IBOutlet weak var utiPreprocessorCheckbox: NSButton!
170174
@IBOutlet weak var utiPreprocessorTextField: NSTextField!
171175

@@ -366,6 +370,10 @@ class PreferencesViewController: NSViewController {
366370
utiArgumentsTextField.isEnabled = utiArgumentsCheckbox.state == .on
367371
utiArgumentsTextField.stringValue = currentUTISettings.extra ?? settings?.extra ?? ""
368372

373+
utiInteractiveCheckbox.state = currentUTISettings.allowInteractiveActions != nil ? .on : .off
374+
utiInteractiveButton.isEnabled = utiInteractiveCheckbox.state == .on
375+
utiInteractiveButton.state = currentUTISettings.allowInteractiveActions ?? false ? .on : .off
376+
369377
utiPreprocessorCheckbox.state = currentUTISettings.preprocessor != nil ? .on : .off
370378
utiPreprocessorTextField.isEnabled = utiPreprocessorCheckbox.state == .on
371379
utiPreprocessorTextField.stringValue = currentUTISettings.preprocessor ?? ""
@@ -441,6 +449,7 @@ class PreferencesViewController: NSViewController {
441449
}
442450

443451
utiDetailView.isHidden = true
452+
utiInteractiveButton.toolTip = interactiveButton.toolTip
444453

445454
fetchSettings()
446455

@@ -480,7 +489,6 @@ class PreferencesViewController: NSViewController {
480489
}
481490
}
482491
} else if segue.identifier == "ThemeSegue", let vc = segue.destinationController as? ThemeSelectorViewController {
483-
vc.allThemes = self.themes.map({ SCSHThemePreview(theme: $0) })
484492
if let btn = sender as? NSButton {
485493
vc.style = btn == themeLightIcon || btn == utiThemeLightIcon ? .light : .dark
486494

@@ -502,6 +510,7 @@ class PreferencesViewController: NSViewController {
502510
}
503511
}
504512
}
513+
vc.allThemes = self.themes.map({ SCSHThemePreview(theme: $0) })
505514
}
506515
}
507516

@@ -683,6 +692,9 @@ class PreferencesViewController: NSViewController {
683692
fontChooseButton.isEnabled = settings != nil
684693
refreshFontPanel(withFontFamily: settings?.fontFamily ?? "Menlo", size: settings?.fontSize ?? 12, isGlobal: true)
685694

695+
interactiveButton.state = settings?.allowInteractiveActions ?? false ? .on : .off
696+
interactiveButton.isEnabled = settings != nil
697+
686698
debugButton.state = settings?.debug ?? false ? .on : .off
687699
debugButton.isEnabled = settings != nil
688700

@@ -800,6 +812,8 @@ class PreferencesViewController: NSViewController {
800812
settings.tabSpaces = tabSpacesSlider.integerValue
801813
settings.extra = argumentsTextField.stringValue
802814

815+
settings.allowInteractiveActions = interactiveButton.state == .on
816+
803817
settings.debug = debugButton.state == .on
804818

805819
return settings
@@ -873,6 +887,10 @@ class PreferencesViewController: NSViewController {
873887
if utiArgumentsCheckbox.state == .on {
874888
settings.extra = argumentsTextField.stringValue
875889
}
890+
if utiInteractiveCheckbox.state == .on {
891+
settings.allowInteractiveActions = utiInteractiveButton.state == .on
892+
}
893+
876894
if utiPreprocessorCheckbox.state == .on {
877895
let v = utiPreprocessorTextField.stringValue.trimmingCharacters(in: CharacterSet.whitespaces)
878896
settings.preprocessor = v.isEmpty ? nil : v
@@ -983,6 +1001,12 @@ class PreferencesViewController: NSViewController {
9831001
utiSettings.extra = nil
9841002
}
9851003

1004+
if utiInteractiveCheckbox.state == .on {
1005+
utiSettings.allowInteractiveActions = utiInteractiveButton.state == .on
1006+
} else {
1007+
utiSettings.allowInteractiveActions = nil
1008+
}
1009+
9861010
if utiPreprocessorCheckbox.state == .on {
9871011
let v = utiPreprocessorTextField.stringValue.trimmingCharacters(in: CharacterSet.whitespaces)
9881012
utiSettings.preprocessor = v.isEmpty ? nil : v
@@ -1244,6 +1268,10 @@ class PreferencesViewController: NSViewController {
12441268
refreshUtiPreview(sender)
12451269
}
12461270

1271+
@IBAction func handleUtiInteractiveCheckbox(_ sender: NSButton) {
1272+
utiInteractiveButton.isEnabled = sender.state == .on
1273+
}
1274+
12471275
@IBAction func handleUtiPreprocessorCheckbox(_ sender: NSButton) {
12481276
utiPreprocessorTextField.isEnabled = sender.state == .on
12491277
refreshUtiPreview(sender)

Application/SyntaxHighlight.help/Contents/Resources/English.lproj/preferences.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ <h1>Global Preferences</h1>
2525
<td>Highlight</td>
2626
<td>Path of the highlight utils. You can choose the embedded version or select a different version (compiled by hand or installed with homebrew for example).</td></tr>
2727
<tr>
28-
<td>Mode</td>
28+
<td>Output mode</td>
2929
<td>Output mode in html or rtf. Html output is rendered inside a WKWebView. Rtf output is rendered inside a NSTextView.<br />
3030
<small>(corresponds to --out-format highlight argument)</small>
3131
</td>
@@ -68,6 +68,13 @@ <h1>Global Preferences</h1>
6868
<small>(see man highlight to a list of valid arguments and plugins)</small></td>
6969
</tr>
7070

71+
<tr>
72+
<td>Interactive preview</td>
73+
<td>If enabled allow the execution of javascript code inside the quicklook preview. Enable only when in extra arguments you use a custom plugins that embed js code inside the <code>highlight</code> output.<br />
74+
When enabled you cannot drag the quicklook panel with click and drag on the window but only dragging the title bar. Also doubleclick action to open the file is disabled.<br />
75+
Is valid only html output mode.</td>
76+
</tr>
77+
7178
<tr>
7279
<td>Debug</td>
7380
<td>If on, create on your desktop two file with the result of last rendering:
Binary file not shown.
Binary file not shown.

Application/ThemeCollectionViewItem.xib

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
1111
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
1212
<view id="lQb-Wa-IJH">
13-
<rect key="frame" x="0.0" y="0.0" width="90" height="120"/>
13+
<rect key="frame" x="0.0" y="0.0" width="90" height="116"/>
1414
<autoresizingMask key="autoresizingMask"/>
1515
<subviews>
1616
<imageView translatesAutoresizingMaskIntoConstraints="NO" id="mZv-j4-rQ5">
17-
<rect key="frame" x="0.0" y="30" width="90" height="90"/>
17+
<rect key="frame" x="0.0" y="26" width="90" height="90"/>
1818
<constraints>
1919
<constraint firstAttribute="height" constant="90" id="lXQ-2b-36D"/>
2020
<constraint firstAttribute="width" constant="90" id="trl-dU-azC"/>
2121
</constraints>
2222
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" id="EdP-Qy-28B"/>
2323
</imageView>
2424
<textField allowsExpansionToolTips="YES" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tkO-ff-Wmy">
25-
<rect key="frame" x="-2" y="0.0" width="94" height="26"/>
25+
<rect key="frame" x="-2" y="0.0" width="94" height="24"/>
2626
<constraints>
27-
<constraint firstAttribute="height" constant="26" id="xlj-ps-iGe"/>
27+
<constraint firstAttribute="height" constant="24" id="xlj-ps-iGe"/>
2828
</constraints>
2929
<textFieldCell key="cell" controlSize="mini" allowsUndo="NO" alignment="center" id="an3-3N-5ct">
3030
<font key="font" metaFont="label" size="9"/>

Application/ThemeSelectorViewController.swift

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,25 @@ class ThemeSelectorViewController: NSViewController {
7070

7171
var filter: String = "" {
7272
didSet {
73+
guard oldValue != filter else {
74+
return
75+
}
7376
refreshThemes()
7477
}
7578
}
7679
var style: ThemeStyleFilterEnum = .all {
7780
didSet {
81+
guard style != style else {
82+
return
83+
}
7884
refreshThemes()
7985
}
8086
}
8187
var origin: ThemeOriginFilterEnum = .all {
8288
didSet {
89+
guard origin != origin else {
90+
return
91+
}
8392
refreshThemes()
8493
}
8594
}
@@ -140,11 +149,7 @@ class ThemeSelectorViewController: NSViewController {
140149
override func viewDidLoad() {
141150
searchField.stringValue = filter
142151
themeSegmentedControl.setSelected(true, forSegment: style.rawValue)
143-
144-
refreshThemes()
145152
}
146-
147-
148153
}
149154

150155
// MARK: - NSControlTextEditingDelegate
@@ -200,20 +205,32 @@ class ThemeCollectionViewItem: NSCollectionViewItem {
200205
didSet {
201206
if let theme = self.theme {
202207
self.textField?.stringValue = theme.theme.desc
208+
self.textField?.toolTip = theme.theme.desc
203209

204210
if theme.image == nil {
205211
theme.image = theme.theme.getImage(size: CGSize(width: 90, height: 90), font: NSFont(name: "Menlo", size: 4) ?? NSFont.systemFont(ofSize: 4))
206212
}
207213

208214
self.imageView?.image = theme.image
209-
self.textField?.toolTip = theme.theme.desc
215+
self.imageView?.toolTip = theme.theme.desc
210216
} else {
211217
self.textField?.stringValue = ""
212218
self.textField?.toolTip = nil
213219
self.imageView?.image = nil
220+
self.imageView?.toolTip = nil
214221
}
215222

216223
}
217224
}
218225

226+
override func prepareForReuse() {
227+
super.prepareForReuse()
228+
229+
self.imageView?.image = nil
230+
self.imageView?.toolTip = nil
231+
232+
self.textField?.stringValue = ""
233+
self.textField?.toolTip = nil
234+
}
235+
219236
}

Application/ThemesViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class ThemesViewController: NSViewController {
201201
var settings: [String: Any] = [
202202
SCSHSettings.Key.theme: theme.name,
203203
SCSHSettings.Key.inline_theme: theme.toDictionary(),
204-
SCSHSettings.Key.embedCustomStyle: false,
204+
SCSHSettings.Key.renderForExtension: false,
205205
SCSHSettings.Key.lineNumbers: true,
206206
SCSHSettings.Key.customCSS: "* { box-sizing: border-box; } html, body { height: 100%; margin: 0; } body { padding: 0; }"
207207
]

Application/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class ViewController: NSViewController {
142142
webView?.isHidden = true
143143
textScrollView?.isHidden = true
144144

145-
service?.colorize(url: documentUrl, overrideSettings: [SCSHSettings.Key.embedCustomStyle: false]) { (response, settings, error) in
145+
service?.colorize(url: documentUrl, overrideSettings: [SCSHSettings.Key.renderForExtension: false]) { (response, settings, error) in
146146
let format = SCSHFormat(rawValue: settings[SCSHSettings.Key.format] as? String ?? "html") ?? .html
147147
DispatchQueue.main.async {
148148
self.initializeView(forMode: format)

0 commit comments

Comments
 (0)