Add night mode option

This commit is contained in:
Matt Baer 2017-07-26 19:28:04 -04:00
parent 681b0358ad
commit f9ff961e9e
3 changed files with 31 additions and 0 deletions

View File

@ -27,6 +27,12 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}
@IBAction func toggleNightMode(_ sender: NSMenuItem) {
let isOff = sender.state == NSOffState
vc?.toggle(isNight: isOff)
sender.state = isOff ? NSOnState : NSOffState
}
@IBAction func saveDocument(_ sender: AnyObject) {
vc?.saveDocument()
}

View File

@ -226,6 +226,18 @@
</items>
</menu>
</menuItem>
<menuItem title="View" id="H8h-7b-M4v">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="View" id="HyV-fh-RgO">
<items>
<menuItem title="Night Mode" keyEquivalent="u" id="jYO-0u-qN9">
<connections>
<action selector="toggleNightMode:" target="Voe-Tx-rLC" id="Nmq-eG-y3w"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem title="Window" id="aUF-d1-5bR">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Window" systemMenu="window" id="Td7-aD-5lo">

View File

@ -86,5 +86,18 @@ class ViewController: NSViewController, NSTextViewDelegate {
print("ERROR loading: \(err)")
}
}
func toggle(isNight: Bool) {
let darkBG = NSColor(red:0.13, green:0.13, blue:0.13, alpha:1.0)
if isNight {
self.view.window!.backgroundColor = darkBG
self.writerText.backgroundColor = darkBG
self.writerText.textColor = NSColor.white
} else {
self.view.window!.backgroundColor = NSColor.white
self.writerText.backgroundColor = NSColor.white
self.writerText.textColor = NSColor.black
}
}
}