Browse Source

Add night mode option

master
Matt Baer 4 years ago
parent
commit
f9ff961e9e
3 changed files with 31 additions and 0 deletions
  1. +6
    -0
      writeas/AppDelegate.swift
  2. +12
    -0
      writeas/Base.lproj/Main.storyboard
  3. +13
    -0
      writeas/ViewController.swift

+ 6
- 0
writeas/AppDelegate.swift 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()
}


+ 12
- 0
writeas/Base.lproj/Main.storyboard 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">


+ 13
- 0
writeas/ViewController.swift 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
}
}
}


Loading…
Cancel
Save