Skip to content

Commit b8dca33

Browse files
committed
Short name for application and extension.
Now the app/extension works with space inside his path. New debug options to create a colorize.log file on your Desktop with the log of last operations.
1 parent ac84ff2 commit b8dca33

File tree

21 files changed

+791
-186
lines changed

21 files changed

+791
-186
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
## User settings
66
xcuserdata/
7+
*xcworkspace/xcuserdata/*
78

89
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
910
*.xcscmblueprint

Application/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// along with SourceCodeSyntaxHighlight. If not, see <http://www.gnu.org/licenses/>.
2222

2323
import Cocoa
24-
import SourceCodeSyntaxHighlightXPCService
24+
import Syntax_Highlight_XPC_Service
2525

2626
@NSApplicationMain
2727
class AppDelegate: NSObject, NSApplicationDelegate {

Application/Base.lproj/Main.storyboard

Lines changed: 31 additions & 20 deletions
Large diffs are not rendered by default.

Application/Info.plist

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,7 @@
139139
<key>CFBundleInfoDictionaryVersion</key>
140140
<string>6.0</string>
141141
<key>CFBundleName</key>
142-
<string>Syntax Highlight</string>
143-
<key>CFBundleDisplayName</key>
144-
<string>Source Code Syntax Highlight</string>
142+
<string>$(PRODUCT_NAME)</string>
145143
<key>CFBundlePackageType</key>
146144
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
147145
<key>CFBundleShortVersionString</key>
@@ -151,7 +149,7 @@
151149
<string>MacOSX</string>
152150
</array>
153151
<key>CFBundleVersion</key>
154-
<string>1</string>
152+
<string>$(CURRENT_PROJECT_VERSION)</string>
155153
<key>LSApplicationCategoryType</key>
156154
<string>public.app-category.developer-tools</string>
157155
<key>LSMinimumSystemVersion</key>
@@ -446,12 +444,12 @@
446444
</dict>
447445
</dict>
448446
<dict>
449-
<key>UTTypeDescription</key>
450-
<string>Markdown document</string>
451447
<key>UTTypeConformsTo</key>
452448
<array>
453449
<string>public.plain-text</string>
454450
</array>
451+
<key>UTTypeDescription</key>
452+
<string>Markdown document</string>
455453
<key>UTTypeIdentifier</key>
456454
<string>net.daringfireball.markdown</string>
457455
<key>UTTypeTagSpecification</key>

Application/PreferencesViewController.swift

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import Cocoa
2424
import WebKit
25-
import SourceCodeSyntaxHighlightXPCService
25+
import Syntax_Highlight_XPC_Service
2626

2727
typealias SuppressedExtension = (ext: String, uti: String)
2828

@@ -140,6 +140,7 @@ class PreferencesViewController: NSViewController {
140140
@IBOutlet weak var lineNumbersPopup: NSPopUpButton!
141141
@IBOutlet weak var tabSpacesSlider: NSSlider!
142142
@IBOutlet weak var argumentsTextField: NSTextField!
143+
@IBOutlet weak var debugButton: NSButton!
143144

144145
@IBOutlet weak var examplesPopup: NSPopUpButton!
145146

@@ -412,13 +413,28 @@ class PreferencesViewController: NSViewController {
412413

413414
// MARK: - Settings
414415

416+
/// Get the url of the quicklook extension.
417+
func getQLAppexUrl() -> URL? {
418+
guard let base_url = Bundle.main.builtInPlugInsURL else {
419+
return nil
420+
}
421+
do {
422+
for url in try FileManager.default.contentsOfDirectory(at: base_url, includingPropertiesForKeys: nil, options: []) {
423+
// Suppose only one appex on the plugin dir.
424+
if url.pathExtension == "appex" {
425+
return url
426+
}
427+
}
428+
} catch {
429+
return nil
430+
}
431+
return nil
432+
}
433+
415434
/// Get all handled UTIs.
416435
func fetchUtis() -> [UTIDesc] {
417-
let url = Bundle.main.bundleURL.appendingPathComponent("Contents/PlugIns/SourceCodeSyntaxHighlightExtension.appex")
418-
419436
// Get the list of all uti supported by the quicklook extension.
420-
guard let bundle = Bundle(url: url), let extensionInfo = bundle.object(forInfoDictionaryKey: "NSExtension") as? [String: Any], let attributes = extensionInfo["NSExtensionAttributes"] as? [String: Any], let supportedTypes = attributes["QLSupportedContentTypes"] as? [String] else {
421-
self.dismiss(self)
437+
guard let url = getQLAppexUrl(), let bundle = Bundle(url: url), let extensionInfo = bundle.object(forInfoDictionaryKey: "NSExtension") as? [String: Any], let attributes = extensionInfo["NSExtensionAttributes"] as? [String: Any], let supportedTypes = attributes["QLSupportedContentTypes"] as? [String] else {
422438
return []
423439
}
424440

@@ -604,6 +620,9 @@ class PreferencesViewController: NSViewController {
604620

605621
fontChooseButton.isEnabled = settings != nil
606622

623+
debugButton.state = settings?.debug ?? false ? .on : .off
624+
debugButton.isEnabled = settings != nil
625+
607626
previewThemeControl.isEnabled = settings != nil
608627
refreshButton.isEnabled = settings != nil
609628
saveButton.isEnabled = settings != nil
@@ -762,6 +781,8 @@ class PreferencesViewController: NSViewController {
762781
settings.tabSpaces = tabSpacesSlider.integerValue
763782
settings.extra = argumentsTextField.stringValue
764783

784+
settings.debug = debugButton.state == .on
785+
765786
return settings
766787
}
767788

@@ -1230,7 +1251,7 @@ class PreferencesViewController: NSViewController {
12301251
// Show standard theme preview.
12311252
if let theme: SCSHTheme = themes.first(where: { $0.name == custom_settings.theme }) {
12321253
if custom_settings.format == .html {
1233-
webView.loadHTMLString(theme.getHtmlExample(fontName: settings.fontFamily ?? "Menlo", fontSize: settings.fontSize ?? 12), baseURL: nil)
1254+
webView.loadHTMLString(theme.getHtmlExample(fontName: settings.fontFamily ?? "Menlo", fontSize: (settings.fontSize ?? 12) * 1), baseURL: nil)
12341255
} else {
12351256
textView.textStorage?.setAttributedString(theme.getAttributedExample(fontName: custom_settings.fontFamily ?? "Menlo", fontSize: custom_settings.fontSize ?? 12))
12361257

Application/ViewController.swift

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import Cocoa
2424
import WebKit
25-
import SourceCodeSyntaxHighlightXPCService
25+
import Syntax_Highlight_XPC_Service
2626

2727
class ViewController: NSViewController {
2828
var webView: WKWebView?
@@ -40,12 +40,12 @@ class ViewController: NSViewController {
4040
}
4141

4242
func load(url: URL) {
43-
self.webView?.loadHTMLString("", baseURL: nil)
4443
self.webView?.isHidden = true
44+
self.webView?.loadHTMLString("", baseURL: nil)
4545

46-
self.textView?.string = ""
4746
self.textScrollView?.isHidden = true
48-
47+
self.textView?.string = ""
48+
4949
self.representedObject = url
5050
}
5151

@@ -59,8 +59,8 @@ class ViewController: NSViewController {
5959
}
6060
}
6161

62-
func initializeView(forMode mode: String) {
63-
if mode == SCSHFormat.rtf.rawValue {
62+
func initializeView(forMode mode: SCSHFormat) {
63+
if mode == .rtf {
6464
if self.textScrollView == nil {
6565
self.textScrollView = NSScrollView(frame: self.view.bounds)
6666
self.textScrollView!.autoresizingMask = [.height, .width]
@@ -116,9 +116,10 @@ class ViewController: NSViewController {
116116

117117
self.webView = WKWebView(frame: self.view.bounds, configuration: configuration)
118118
self.webView!.autoresizingMask = [.height, .width]
119+
self.webView?.isHidden = true
119120

120121
self.view.addSubview(self.webView!)
121-
self.webView?.addObserver(self, forKeyPath: #keyPath(WKWebView.estimatedProgress), options: .new, context: nil)
122+
self.webView?.navigationDelegate = self
122123
}
123124

124125
if let tsv = textScrollView {
@@ -142,11 +143,11 @@ class ViewController: NSViewController {
142143
textScrollView?.isHidden = true
143144

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

149-
if format == SCSHFormat.rtf.rawValue {
150+
if format == .rtf {
150151
let text: NSAttributedString
151152
if let e = error {
152153
text = NSAttributedString(string: String(data: response, encoding: .utf8) ?? e.localizedDescription)
@@ -170,18 +171,21 @@ class ViewController: NSViewController {
170171
let html: String = response.decodeToString().trimmingCharacters(in: CharacterSet.newlines)
171172

172173
self.webView?.loadHTMLString(html, baseURL: nil)
173-
self.view.window?.makeFirstResponder(self.webView!)
174174
}
175175
}
176176
}
177177
}
178+
}
179+
180+
extension ViewController: WKNavigationDelegate {
181+
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
182+
// Show the quicklook preview only after the complete rendering (preventing a flickering glitch).
183+
webView.isHidden = false
184+
self.view.window?.makeFirstResponder(webView)
185+
}
178186

179-
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
180-
if keyPath == "estimatedProgress", let w = self.webView, w.estimatedProgress == 1 {
181-
// Show the webview only when loading is complete.
182-
self.progressIndicatorView.stopAnimation(self)
183-
self.webView?.isHidden = false
184-
}
187+
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
188+
webView.isHidden = false
185189
}
186190
}
187191

QLExtension/Info.plist

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@
44
<dict>
55
<key>CFBundleDevelopmentRegion</key>
66
<string>$(DEVELOPMENT_LANGUAGE)</string>
7-
<key>CFBundleDisplayName</key>
8-
<string>Source Code Syntax Highlight Quicklook extension</string>
97
<key>CFBundleExecutable</key>
108
<string>$(EXECUTABLE_NAME)</string>
119
<key>CFBundleIdentifier</key>
1210
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
1311
<key>CFBundleInfoDictionaryVersion</key>
1412
<string>6.0</string>
1513
<key>CFBundleName</key>
16-
<string>Source Code Syntax Highlight Quicklook extension</string>
14+
<string>$(PRODUCT_NAME)</string>
1715
<key>CFBundlePackageType</key>
1816
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
1917
<key>CFBundleShortVersionString</key>
@@ -23,7 +21,7 @@
2321
<string>MacOSX</string>
2422
</array>
2523
<key>CFBundleVersion</key>
26-
<string>1</string>
24+
<string>$(CURRENT_PROJECT_VERSION)</string>
2725
<key>LSMinimumSystemVersion</key>
2826
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
2927
<key>NSExtension</key>

QLExtension/PreviewViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import Quartz
2525
import WebKit
2626
import OSLog
2727

28-
import SourceCodeSyntaxHighlightXPCService
28+
import Syntax_Highlight_XPC_Service
2929

3030
class MyDraggingView: NSTextView {
3131
var trackArea: NSTrackingArea? = nil

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ On MacOs every file extension is associated to an [Uniform Type Identifier (UTI)
3434

3535
For this reason, this application supports many UTIs even if they are apparently redundant.
3636

37-
Apparently the operating system does not allow to manage some file formats including (but not limited to) .xml, .plist, .html.
37+
Apparently the operating system does not allow to manage some file formats including (but not limited to) .xml, .plist, .html, .ts, .dart.
3838

3939

4040
## Application preferences

0 commit comments

Comments
 (0)