Skip to content

Commit b6059e4

Browse files
committed
Added an option to limit the amount of data to format.
1 parent 4005f22 commit b6059e4

File tree

13 files changed

+255
-309
lines changed

13 files changed

+255
-309
lines changed

Application/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
7272
}
7373

7474
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
75-
return true
75+
return !documentsOpenedAtStart
7676
}
7777

7878
/// Get the url of the quicklook extension.

Application/Base.lproj/Main.storyboard

Lines changed: 86 additions & 38 deletions
Large diffs are not rendered by default.

Application/PreferencesViewController.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ class PreferencesViewController: NSViewController {
120120
@IBOutlet weak var lineNumbersPopup: NSPopUpButton!
121121
@IBOutlet weak var tabSpacesSlider: NSSlider!
122122
@IBOutlet weak var argumentsTextField: NSTextField!
123+
124+
@IBOutlet weak var dataSize: NSTextField!
125+
@IBOutlet weak var dataSizeUM: NSPopUpButton!
126+
123127
@IBOutlet weak var interactiveButton: NSSwitch!
124128
@IBOutlet weak var debugButton: NSSwitch!
125129

@@ -703,6 +707,20 @@ class PreferencesViewController: NSViewController {
703707
fontChooseButton.isEnabled = settings != nil
704708
refreshFontPanel(withFontFamily: settings?.fontFamily ?? "Menlo", size: settings?.fontSize ?? 12, isGlobal: true)
705709

710+
if var size = settings?.maxData {
711+
size /= 1024 // Convert Bytes to KB.
712+
if size % 1024 == 0 {
713+
dataSize.intValue = Int32(size / 1024)
714+
dataSizeUM.selectItem(at: 1)
715+
} else {
716+
dataSize.intValue = Int32(size)
717+
dataSizeUM.selectItem(at: 0)
718+
}
719+
} else {
720+
dataSize.intValue = 0
721+
dataSizeUM.selectItem(at: 0)
722+
}
723+
706724
interactiveButton.state = settings?.allowInteractiveActions ?? false ? .on : .off
707725
interactiveButton.isEnabled = settings != nil
708726

@@ -828,6 +846,16 @@ class PreferencesViewController: NSViewController {
828846
settings.tabSpaces = tabSpacesSlider.integerValue
829847
settings.extra = argumentsTextField.stringValue
830848

849+
if (dataSize.floatValue > 0) {
850+
var dataSize = self.dataSize.floatValue
851+
if (self.dataSizeUM.indexOfSelectedItem == 1) {
852+
dataSize *= 1024 // Convert MB to KB.
853+
}
854+
dataSize *= 1024 // Convert KB to Bytes.
855+
856+
settings.maxData = UInt64(dataSize)
857+
}
858+
831859
settings.allowInteractiveActions = interactiveButton.state == .on
832860

833861
settings.debug = debugButton.state == .on

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ <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>Data limit</td>
73+
<td>Maximum amount of data to format, data beyond the limit is omitted. Specify 0 to not limit. Note that if is set a preprocessor, the filter is applied to the preprocessor's and not to the source file.</td>
74+
</tr>
75+
7176
<tr>
7277
<td>Interactive preview</td>
7378
<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 />
Binary file not shown.
Binary file not shown.

CHANGELOG.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
1.0.b17
2+
New features:
3+
- added an option to limit the amount of data to format.
4+
15
1.0.b16
26

37
New features:

SourceCodeSyntaxHighlight.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@
548548
8359233D235599F6001506B6 /* Project object */ = {
549549
isa = PBXProject;
550550
attributes = {
551-
LastSwiftUpdateCheck = 1100;
551+
LastSwiftUpdateCheck = 1130;
552552
LastUpgradeCheck = 1100;
553553
ORGANIZATIONNAME = sbarex;
554554
TargetAttributes = {
@@ -940,7 +940,7 @@
940940
CODE_SIGN_IDENTITY = "-";
941941
CODE_SIGN_STYLE = Manual;
942942
COMBINE_HIDPI_IMAGES = YES;
943-
CURRENT_PROJECT_VERSION = 16;
943+
CURRENT_PROJECT_VERSION = 17;
944944
DEVELOPMENT_TEAM = "";
945945
ENABLE_HARDENED_RUNTIME = YES;
946946
INFOPLIST_FILE = Application/Info.plist;
@@ -965,7 +965,7 @@
965965
CODE_SIGN_IDENTITY = "-";
966966
CODE_SIGN_STYLE = Manual;
967967
COMBINE_HIDPI_IMAGES = YES;
968-
CURRENT_PROJECT_VERSION = 16;
968+
CURRENT_PROJECT_VERSION = 17;
969969
DEVELOPMENT_TEAM = "";
970970
ENABLE_HARDENED_RUNTIME = YES;
971971
INFOPLIST_FILE = Application/Info.plist;

XPCService/SCSHBaseSettings.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class SCSHBaseSettings {
8282
static let preprocessor = "preprocessor"
8383

8484
static let interactive = "interactive"
85+
static let maxData = "max-data"
8586
static let version = "version"
8687

8788
}
@@ -353,6 +354,8 @@ class SCSHGlobalBaseSettings: SCSHBaseSettings {
353354
/// Customized settings for UTIs.
354355
var customizedSettings: [String: SCSHUTIBaseSettings] = [:]
355356

357+
var maxData: UInt64?
358+
356359
/// Return if exists customized settings.
357360
override var isCustomized: Bool {
358361
// Global settings are always customized.
@@ -422,6 +425,8 @@ class SCSHGlobalBaseSettings: SCSHBaseSettings {
422425
if allowInteractiveActions == nil {
423426
allowInteractiveActions = false
424427
}
428+
429+
maxData = settings[Key.maxData] as? UInt64;
425430
}
426431

427432
/// Initialize the setting based on the preferences provided.
@@ -473,6 +478,10 @@ class SCSHGlobalBaseSettings: SCSHBaseSettings {
473478
r[Key.backgroundColor] = color
474479
}
475480

481+
if let maxData = self.maxData {
482+
r[Key.maxData] = maxData
483+
}
484+
476485
r[Key.debug] = self.debug
477486
r[Key.version] = SCSHBaseSettings.version
478487

@@ -520,6 +529,10 @@ class SCSHGlobalBaseSettings: SCSHBaseSettings {
520529
self.renderForExtension = v
521530
}
522531

532+
if let v = data[Key.maxData] as? UInt64 {
533+
self.maxData = v;
534+
}
535+
523536
super.override(fromDictionary: dict)
524537
}
525538

XPCService/SCSHBaseXPCService.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,15 @@ class SCSHBaseXPCService: NSObject {
152152
}
153153
}
154154

155+
let maxData: String
156+
if let v = custom_settings.maxData {
157+
maxData = "\(v)"
158+
} else {
159+
maxData = ""
160+
}
161+
155162
env.merge([
156-
"maxFileSize": "",
163+
"maxFileSize": maxData,
157164
"textEncoding": "UTF-8",
158165
"webkitTextEncoding": "UTF-8",
159166

0 commit comments

Comments
 (0)