Skip to content

Commit e8f3a0d

Browse files
committed
Sparkle updated, quicklook window size option, autosave option, .readme support.
1 parent e2ad067 commit e8f3a0d

File tree

227 files changed

+483
-8151
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+483
-8151
lines changed

Application/AppDelegate.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
100100
func validateMenuItem(_ menuItem: NSMenuItem) -> Bool
101101
{
102102
if menuItem.action == #selector(self.checkForUpdates(_:)) {
103-
return self.userDriver?.canCheckForUpdates ?? false
103+
return self.updater?.canCheckForUpdates ?? false
104+
}
105+
if menuItem.identifier?.rawValue == "revert", let settings = SCSHWrapper.shared.settings {
106+
return settings.isDirty
104107
}
105108
return true
106109
}
@@ -258,14 +261,19 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
258261
}
259262
let alert = NSAlert()
260263
let path = "/usr/local/bin/syntax_highlight_cli"
261-
do {
262-
try FileManager.default.createSymbolicLink(at: URL(fileURLWithPath: path), withDestinationURL: app)
263-
alert.messageText = "Command line tool installed on `\(path)`"
264+
if FileManager.default.fileExists(atPath: path) {
265+
alert.messageText = "The Command line tool already exists on the `/usr/local/bin/` folder."
264266
alert.alertStyle = .informational
265-
} catch {
266-
alert.messageText = "Unable to link the command line tool link into `\(path)`!"
267-
alert.informativeText = error.localizedDescription
268-
alert.alertStyle = .critical
267+
} else {
268+
do {
269+
try FileManager.default.createSymbolicLink(at: URL(fileURLWithPath: path), withDestinationURL: app)
270+
alert.messageText = "Command line tool installed on `\(path)`"
271+
alert.alertStyle = .informational
272+
} catch {
273+
alert.messageText = "Unable to link the command line tool link into `\(path)`!"
274+
alert.informativeText = error.localizedDescription
275+
alert.alertStyle = .critical
276+
}
269277
}
270278
alert.runModal()
271279
}

Application/SCSHApp.entitlements

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<dict>
55
<key>com.apple.security.temporary-exception.files.absolute-path.read-write</key>
66
<array>
7+
<string>/usr/local/bin</string>
78
<string>/usr/local/bin/syntax_highlight_cli</string>
89
</array>
910
<key>com.apple.security.temporary-exception.files.home-relative-path.read-write</key>

Application/Settings+App.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extension SettingsBase {
1616

1717
extension SettingsFormat {
1818
@objc override var hasAdvancedSettings: Bool {
19-
return super.hasAdvancedSettings || (isPreprocessorDefined && !preprocessor.isEmpty) || (isSyntaxDefined && !syntax.isEmpty) || (isAppendArgumentsDefined && !appendArguments.isEmpty) || isUsingLSP
19+
return super.hasAdvancedSettings || (isPreprocessorDefined && !preprocessor.trimmingCharacters(in: .whitespaces).isEmpty) || (isSyntaxDefined && !syntax.isEmpty) || (isAppendArgumentsDefined && !appendArguments.isEmpty) || isUsingLSP
2020
}
2121

2222
var isLSPValid: Bool {

Application/SettingsSplitViewController.swift

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,31 @@ class SettingsSplitViewController: NSSplitViewController {
7979
case plain
8080
}
8181

82+
@objc dynamic var isAutoSaving: Bool {
83+
get {
84+
return UserDefaults.standard.value(forKey: "auto-save") as? Bool ?? true
85+
}
86+
set {
87+
guard newValue != isAutoSaving else { return }
88+
89+
self.willChangeValue(forKey: "isAutoSaving")
90+
UserDefaults.standard.setValue(newValue, forKey: "auto-save")
91+
self.didChangeValue(forKey: "isAutoSaving")
92+
93+
if newValue && (SCSHWrapper.shared.settings?.isDirty ?? false) {
94+
saveAction(self)
95+
}
96+
}
97+
}
98+
8299
@IBOutlet weak var listItem: NSSplitViewItem!
83100
@IBOutlet weak var mainItem: NSSplitViewItem!
84101
@IBOutlet weak var previewItem: NSSplitViewItem!
85102

103+
@IBAction func handleAutosaveSwitch(_ sender: NSSwitch) {
104+
self.isAutoSaving = sender.state == .on
105+
}
106+
86107
@IBAction func performClose(_ sender: Any) {
87108
NSApplication.shared.terminate(self)
88109
}
@@ -220,7 +241,7 @@ class SettingsSplitViewController: NSSplitViewController {
220241
alert.runModal()
221242
return
222243
}
223-
if SCSHWrapper.shared.settings?.isDebug ?? false {
244+
if !self.isAutoSaving && SCSHWrapper.shared.settings?.isDebug ?? false {
224245
let alert = NSAlert()
225246
alert.messageText = "Settings saved."
226247
alert.addButton(withTitle: "Close")
@@ -246,6 +267,13 @@ class SettingsSplitViewController: NSSplitViewController {
246267
}
247268
}
248269

270+
override func viewWillAppear() {
271+
super.viewWillAppear()
272+
if let autosaveView = self.view.window?.toolbar?.visibleItems?.first(where: {$0.itemIdentifier.rawValue == "autosave"})?.view as? NSSwitch {
273+
autosaveView.state = isAutoSaving ? .on : .off
274+
}
275+
}
276+
249277
@objc internal func handleSettingsAvailable(_ notification: Notification) {
250278
initSettings()
251279
}
@@ -261,6 +289,9 @@ class SettingsSplitViewController: NSSplitViewController {
261289
return
262290
}
263291
self.view.window?.isDocumentEdited = true
292+
if isAutoSaving && settings.isDirty {
293+
saveAction(self)
294+
}
264295
}
265296

266297
func editTheme(name: String) {

Application/SettingsView.swift

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ class SettingsView: NSView, SettingsSplitViewElement {
6262
@IBOutlet weak var vcsSwitch: NSSwitch!
6363
@IBOutlet weak var vcsButton: NSButton!
6464

65+
@IBOutlet weak var qlSizeSwitch: NSSwitch!
66+
@IBOutlet weak var qlWidthField: NSTextField!
67+
@IBOutlet weak var qlHeightField: NSTextField!
68+
6569
@IBOutlet weak var lspButton: NSButton!
6670

6771
@IBOutlet weak var advancedWarning: NSTextField!
@@ -353,7 +357,7 @@ class SettingsView: NSView, SettingsSplitViewElement {
353357
preprocessorTextField.isEnabled = false
354358
}
355359
preprocessorTextField.stringValue = s.isPreprocessorDefined || s.specialPreprocessor == nil ? s.preprocessor : s.specialPreprocessor ?? ""
356-
preprocessorWarningImageView.isHidden = s.preprocessor.isEmpty || s.preprocessor.range(of: #"(?<=\s|^)\$targetHL(?=\s|$)"#, options: .regularExpression, range: nil, locale: nil) != nil
360+
preprocessorWarningImageView.isHidden = s.preprocessor.trimmingCharacters(in: .whitespaces).isEmpty || s.preprocessor.range(of: #"(?<=\s|^)\$targetHL(?=\s|$)"#, options: .regularExpression, range: nil, locale: nil) != nil
357361
gridView.cell(for: preprocessorTextField)?.row?.isHidden = !self.isAdvancedSettingsVisible
358362

359363
updateCheckbox(syntaxCheckBox, s.isSyntaxDefined, [syntaxPopupButton])
@@ -417,6 +421,12 @@ class SettingsView: NSView, SettingsSplitViewElement {
417421
dataLimitPopupButton.selectItem(at: 0)
418422
}
419423
gridView.cell(for: dataLimitTextField)?.row?.isHidden = false
424+
425+
gridView.cell(for: qlSizeSwitch)?.row?.isHidden = false
426+
qlSizeSwitch.state = settings.qlWindowWidth ?? 0 > 0 && settings.qlWindowHeight ?? 0 > 0 ? .on : .off
427+
qlWidthField.integerValue = settings.qlWindowWidth ?? 1000
428+
qlHeightField.integerValue = settings.qlWindowHeight ?? 800
429+
self.handleQLSizeChanged(self.qlSizeSwitch)
420430
} else {
421431
gridView.cell(for: debugSwitch)?.row?.isHidden = true
422432

@@ -428,6 +438,8 @@ class SettingsView: NSView, SettingsSplitViewElement {
428438

429439
gridView.cell(for: EOLSwitch)?.row?.isHidden = true
430440
gridView.cell(for: dataLimitTextField)?.row?.isHidden = true
441+
442+
gridView.cell(for: qlSizeSwitch)?.row?.isHidden = true
431443
}
432444

433445
gridView.cell(for: advancedWarning)?.row?.isHidden = isAdvancedSettingsVisible || !settings.hasAdvancedSettings
@@ -594,7 +606,7 @@ class SettingsView: NSView, SettingsSplitViewElement {
594606
@IBAction func onPreprocessorChanged(_ sender: Any) {
595607
if let settings = self.settings as? SettingsFormat {
596608
settings.preprocessor = self.preprocessorTextField.stringValue
597-
self.preprocessorWarningImageView.isHidden = settings.preprocessor.isEmpty || settings.preprocessor.range(of: #"(?<=\s|^)\$targetHL(?=\s|$)"#, options: .regularExpression, range: nil, locale: nil) != nil
609+
self.preprocessorWarningImageView.isHidden = settings.preprocessor.trimmingCharacters(in: .whitespaces).isEmpty || settings.preprocessor.range(of: #"(?<=\s|^)\$targetHL(?=\s|$)"#, options: .regularExpression, range: nil, locale: nil) != nil
598610
}
599611
}
600612
@IBAction func onSyntaxChanged(_ sender: Any) {
@@ -672,6 +684,35 @@ class SettingsView: NSView, SettingsSplitViewElement {
672684
}
673685
}
674686

687+
@IBAction func handleQLSizeChanged(_ sender: NSSwitch) {
688+
self.qlWidthField.isEnabled = sender.state == .on
689+
self.qlHeightField.isEnabled = sender.state == .on
690+
691+
guard let settings = self.settings as? Settings else {
692+
return
693+
}
694+
settings.lockDirty += 1
695+
if sender.state == .on {
696+
settings.qlWindowWidth = self.qlWidthField.integerValue
697+
settings.qlWindowHeight = self.qlHeightField.integerValue
698+
} else {
699+
settings.qlWindowWidth = nil
700+
settings.qlWindowHeight = nil
701+
}
702+
settings.lockDirty -= 1
703+
}
704+
705+
@IBAction func onQLSizeChanged(_ sender: NSTextField) {
706+
guard let settings = self.settings as? Settings else {
707+
return
708+
}
709+
if sender.tag == 1 {
710+
settings.qlWindowWidth = sender.integerValue
711+
} else if sender.tag == 2 {
712+
settings.qlWindowHeight = sender.integerValue
713+
}
714+
}
715+
675716
@IBAction func handleVCSCheckbox(_ sender: NSButton) {
676717
guard let _ = self.settings as? SettingsFormat else { return }
677718
settings?.isVCSDefined = sender.state == .on

0 commit comments

Comments
 (0)