Skip to content

Commit 8591e20

Browse files
committed
Fixed bugs on the color scheme code.
1 parent 51cccb7 commit 8591e20

14 files changed

+167
-61
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "checkmark.circle.pdf",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
},
12+
"properties" : {
13+
"preserves-vector-representation" : true,
14+
"template-rendering-intent" : "template"
15+
}
16+
}
Binary file not shown.

Application/Info.plist

+2-2
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,12 @@
369369
</dict>
370370
</dict>
371371
<dict>
372-
<key>UTTypeDescription</key>
373-
<string>Property List</string>
374372
<key>UTTypeConformsTo</key>
375373
<array>
376374
<string>dyn.ah62d4rv4ge81s3xqr75u</string>
377375
</array>
376+
<key>UTTypeDescription</key>
377+
<string>Property List</string>
378378
<key>UTTypeIdentifier</key>
379379
<string>is.workflow.my.workflow</string>
380380
<key>UTTypeTagSpecification</key>

Application/SCSHWrapper.swift

+23-4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public class SCSHWrapper: NSObject {
9191

9292
NotificationCenter.default.addObserver(self, selector: #selector(afterThemeDeleted(_:)), name: .CustomThemeRemoved, object: nil)
9393
NotificationCenter.default.addObserver(self, selector: #selector(afterThemeChanged(_:)), name: .ThemeNeedRefresh, object: nil)
94+
NotificationCenter.default.addObserver(self, selector: #selector(afterThemeSaved(_:)), name: .CustomThemeSaved, object: nil)
9495
}
9596

9697
deinit {
@@ -220,12 +221,14 @@ public class SCSHWrapper: NSObject {
220221
})
221222
}
222223

223-
@objc internal func afterThemeChanged(_ notification: Notification) {
224+
@objc internal func afterThemeSaved(_ notification: Notification) {
224225
guard let theme = notification.object as? SCSHTheme else { return }
225-
SCSHWrapper.service?.updateSettingsAfterThemeBGChanged(name: theme.name, background: theme.backgroundColor) { changed in
226-
226+
SCSHWrapper.service?.updateBGSettingsAfterThemeSaved(name: theme.nameForSettings, background: theme.backgroundColor) { changed in
227227
}
228-
228+
}
229+
230+
@objc internal func afterThemeChanged(_ notification: Notification) {
231+
guard let theme = notification.object as? SCSHTheme else { return }
229232
let name = theme.nameForSettings
230233
if self.settings?.lightThemeName == name {
231234
self.settings?.lightBackgroundColor = theme.backgroundColor
@@ -272,4 +275,20 @@ public class SCSHWrapper: NSObject {
272275
return .terminateCancel
273276
}
274277
}
278+
279+
func getFormatsUsedBy(theme theme_name: String) -> [SettingsBase] {
280+
guard let settings = self.settings else {
281+
return []
282+
}
283+
var result: [SettingsBase] = []
284+
if settings.lightThemeName == theme_name || settings.darkThemeName == theme_name {
285+
result.append(settings)
286+
}
287+
for (_, s) in settings.utiSettings {
288+
if (s.isLightThemeNameDefined && s.lightThemeName == theme_name) || (s.isDarkThemeNameDefined && s.darkThemeName == theme_name) {
289+
result.append(s)
290+
}
291+
}
292+
return result
293+
}
275294
}

Application/SettingsView.xib

+13-13
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@
5656
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
5757
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
5858
<customView id="c22-O7-iKe">
59-
<rect key="frame" x="0.0" y="0.0" width="3939" height="850"/>
59+
<rect key="frame" x="0.0" y="0.0" width="3969" height="850"/>
6060
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
6161
<subviews>
6262
<gridView horizontalHuggingPriority="249" xPlacement="leading" yPlacement="center" rowAlignment="none" translatesAutoresizingMaskIntoConstraints="NO" id="0T1-eh-T9u">
63-
<rect key="frame" x="0.0" y="184" width="3939" height="666"/>
63+
<rect key="frame" x="0.0" y="184" width="3969" height="666"/>
6464
<constraints>
6565
<constraint firstItem="9lC-ZQ-SGD" firstAttribute="width" secondItem="g84-Vh-moe" secondAttribute="width" id="Fqy-kk-Dwn"/>
6666
<constraint firstItem="82g-3c-DCS" firstAttribute="width" secondItem="Bul-2i-RVw" secondAttribute="width" id="GrS-Pu-23I"/>
@@ -307,13 +307,13 @@
307307
</gridCell>
308308
<gridCell row="7Fa-ya-moY" column="Gck-5r-ihD" id="ZDk-j6-PgP">
309309
<box key="contentView" horizontalHuggingPriority="247" borderType="line" title="Box" titlePosition="noTitle" translatesAutoresizingMaskIntoConstraints="NO" id="UX1-Xe-OEz">
310-
<rect key="frame" x="205" y="464" width="3737" height="29"/>
310+
<rect key="frame" x="205" y="464" width="3767" height="29"/>
311311
<view key="contentView" id="kwH-Hg-vPS">
312-
<rect key="frame" x="3" y="3" width="3731" height="23"/>
312+
<rect key="frame" x="3" y="3" width="3761" height="23"/>
313313
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
314314
<subviews>
315315
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="SCg-7c-w8J">
316-
<rect key="frame" x="3708" y="4" width="15" height="15"/>
316+
<rect key="frame" x="3738" y="4" width="15" height="15"/>
317317
<buttonCell key="cell" type="inline" bezelStyle="inline" image="font_panel" imagePosition="overlaps" alignment="center" imageScaling="proportionallyDown" inset="2" id="idR-RX-9HI">
318318
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
319319
<font key="font" metaFont="smallSystemBold"/>
@@ -323,7 +323,7 @@
323323
</connections>
324324
</button>
325325
<textField horizontalHuggingPriority="248" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="hvR-2L-HaF">
326-
<rect key="frame" x="6" y="4" width="3696" height="16"/>
326+
<rect key="frame" x="6" y="4" width="3726" height="16"/>
327327
<textFieldCell key="cell" lineBreakMode="clipping" id="qZf-V6-K5M">
328328
<font key="font" metaFont="system"/>
329329
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
@@ -503,7 +503,7 @@
503503
</gridCell>
504504
<gridCell row="e7O-7U-xRn" column="Gck-5r-ihD" id="woA-gs-gjM">
505505
<textField key="contentView" toolTip="Extra highlight parameters. Any arguments with space must be protect inside quotes." horizontalHuggingPriority="249" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="3Pp-20-3aF">
506-
<rect key="frame" x="208" y="338" width="3731" height="21"/>
506+
<rect key="frame" x="208" y="338" width="3761" height="21"/>
507507
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" id="7Jr-6I-PJB">
508508
<font key="font" usesAppearanceFont="YES"/>
509509
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -528,7 +528,7 @@
528528
</gridCell>
529529
<gridCell row="Gx3-JB-Vav" column="Gck-5r-ihD" id="jFx-kA-loO">
530530
<textField key="contentView" toolTip="Highlight parameters added to the global arguments. Any arguments with space must be protect inside quote." horizontalHuggingPriority="249" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="wny-WT-rgn">
531-
<rect key="frame" x="208" y="311" width="3731" height="21"/>
531+
<rect key="frame" x="208" y="311" width="3761" height="21"/>
532532
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" id="SBF-ib-xex">
533533
<font key="font" usesAppearanceFont="YES"/>
534534
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -553,10 +553,10 @@
553553
</gridCell>
554554
<gridCell row="jUh-vB-Wi1" column="Gck-5r-ihD" id="jdS-Ur-03u">
555555
<stackView key="contentView" distribution="fill" orientation="horizontal" alignment="centerY" spacing="4" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" horizontalHuggingPriority="249" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="E8R-g7-R4x">
556-
<rect key="frame" x="208" y="284" width="3731" height="21"/>
556+
<rect key="frame" x="208" y="284" width="3761" height="21"/>
557557
<subviews>
558558
<textField horizontalHuggingPriority="249" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ncm-z0-FS0">
559-
<rect key="frame" x="0.0" y="0.0" width="3711" height="21"/>
559+
<rect key="frame" x="0.0" y="0.0" width="3741" height="21"/>
560560
<string key="toolTip">Preprocessor is any command line program or shell script that returns to the stdout the data to be formatted. Use the placeholder $targetHL for the target file name. </string>
561561
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" placeholderString="cat $targetHL" drawsBackground="YES" id="ySl-JY-XvU">
562562
<font key="font" usesAppearanceFont="YES"/>
@@ -568,7 +568,7 @@
568568
</connections>
569569
</textField>
570570
<imageView toolTip="Warning: the preprocessor do not contain the $targetHL placeholder." horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="f5n-uP-zlA">
571-
<rect key="frame" x="3715" y="3" width="16" height="16"/>
571+
<rect key="frame" x="3745" y="3" width="16" height="16"/>
572572
<constraints>
573573
<constraint firstAttribute="width" constant="16" id="EXD-Jh-He6"/>
574574
<constraint firstAttribute="height" constant="16" id="itg-u5-YGI"/>
@@ -819,7 +819,7 @@
819819
<numberFormatter formatterBehavior="custom10_4" numberStyle="decimal" usesGroupingSeparator="NO" formatWidth="-1" minimumIntegerDigits="1" maximumIntegerDigits="2000000000" id="5Za-IZ-J9y"/>
820820
<menu id="Qmk-mN-gmi">
821821
<items>
822-
<menuItem title="Show in schema editor" tag="1" id="EyN-nB-vAf">
822+
<menuItem title="Show in scheme editor" tag="1" id="EyN-nB-vAf">
823823
<modifierMask key="keyEquivalentModifierMask"/>
824824
<connections>
825825
<action selector="handleThemeEditor:" target="-2" id="gMJ-JY-4Zp"/>
@@ -830,7 +830,7 @@
830830
</menu>
831831
<menu id="3xe-3U-U9p">
832832
<items>
833-
<menuItem title="Show in schema editor" tag="2" id="ag9-zh-vcF">
833+
<menuItem title="Show in scheme editor" tag="2" id="ag9-zh-vcF">
834834
<modifierMask key="keyEquivalentModifierMask"/>
835835
<connections>
836836
<action selector="handleThemeEditor:" target="-2" id="P5M-RL-YoQ"/>

Application/ThemesListView.swift

+35
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class ThemesListView: NSView, SettingsSplitViewElement {
2323

2424
@IBOutlet weak var exportMenuItem: NSMenuItem!
2525
@IBOutlet weak var exportMenuItem2: NSMenuItem!
26+
@IBOutlet weak var settingsMenuItem: NSMenu!
2627
@IBOutlet weak var deleteMenuItem: NSMenuItem!
2728
@IBOutlet weak var deleteMenuItem2: NSMenuItem!
2829
@IBOutlet weak var duplicateMenuItem: NSMenuItem!
@@ -544,19 +545,52 @@ extension ThemesListView: NSOutlineViewDelegate {
544545
}
545546

546547
extension ThemesListView: NSMenuDelegate {
548+
var settingsController: SettingsSplitViewController? {
549+
return self.window?.windowController?.contentViewController as? SettingsSplitViewController
550+
}
551+
547552
func menuNeedsUpdate(_ menu: NSMenu) {
548553
let theme = outlineView.item(atRow: outlineView.clickedRow) as? SCSHThemePreview
549554
exportMenuItem2.isEnabled = theme != nil
550555
revealMenuItem2.isEnabled = theme != nil && theme!.exists
551556
duplicateMenuItem2.isEnabled = theme != nil
552557
deleteMenuItem2.isEnabled = theme != nil && !theme!.isStandalone
558+
let settings = theme != nil ? SCSHWrapper.shared.getFormatsUsedBy(theme: theme!.nameForSettings) : []
559+
settingsMenuItem.removeAllItems()
560+
561+
let UTIs = (NSApplication.shared.delegate as? AppDelegate)?.handledUTIs ?? []
562+
for s in settings {
563+
if s is Settings {
564+
settingsMenuItem.addItem(withTitle: "General settings", action: #selector(self.handleSettingsMenu(_:)), keyEquivalent: "")
565+
} else if let s = s as? SettingsFormat {
566+
for u in UTIs {
567+
if u.UTI == s.uti {
568+
settingsMenuItem.addItem(withTitle: u.description, action: #selector(self.handleSettingsMenu(_:)), keyEquivalent: "").representedObject = u
569+
break
570+
}
571+
}
572+
}
573+
}
574+
575+
if settingsMenuItem.items.isEmpty {
576+
settingsMenuItem.addItem(withTitle: "None", action: nil, keyEquivalent: "")
577+
}
578+
}
579+
580+
@objc func handleSettingsMenu(_ sender: NSMenuItem) {
581+
if let u = sender.representedObject as? UTI {
582+
settingsController?.selectUTI(u)
583+
} else {
584+
settingsController?.mode = .global
585+
}
553586
}
554587
}
555588

556589
// Theme cell with icon and description for the outline view.
557590
class ThemeTableCellView: NSTableCellView {
558591
@IBOutlet weak var changedLabel: NSView!
559592
@IBOutlet weak var htmlLabel: NSView!
593+
@IBOutlet weak var usedLabel: NSView!
560594

561595
override var objectValue: Any? {
562596
didSet {
@@ -565,6 +599,7 @@ class ThemeTableCellView: NSTableCellView {
565599
textField?.stringValue = theme.desc
566600
changedLabel.isHidden = !theme.isDirty
567601
htmlLabel.isHidden = !theme.isRequireHTMLEngine(ignoringLSTokens: !((NSApplication.shared.delegate as? AppDelegate)?.isAdvancedSettingsVisible ?? false))
602+
usedLabel.isHidden = SCSHWrapper.shared.getFormatsUsedBy(theme: theme.nameForSettings).isEmpty
568603
} else {
569604
imageView?.image = nil
570605
textField?.stringValue = ""

0 commit comments

Comments
 (0)