From f9ff961e9e8fa2d47846568c40e95b56378f8cca Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Wed, 26 Jul 2017 19:28:04 -0400 Subject: [PATCH] Add night mode option --- writeas/AppDelegate.swift | 6 ++++++ writeas/Base.lproj/Main.storyboard | 12 ++++++++++++ writeas/ViewController.swift | 13 +++++++++++++ 3 files changed, 31 insertions(+) diff --git a/writeas/AppDelegate.swift b/writeas/AppDelegate.swift index 7410c55..8e6fc95 100644 --- a/writeas/AppDelegate.swift +++ b/writeas/AppDelegate.swift @@ -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() } diff --git a/writeas/Base.lproj/Main.storyboard b/writeas/Base.lproj/Main.storyboard index fa197e0..ff74376 100644 --- a/writeas/Base.lproj/Main.storyboard +++ b/writeas/Base.lproj/Main.storyboard @@ -226,6 +226,18 @@ + + + + + + + + + + + + diff --git a/writeas/ViewController.swift b/writeas/ViewController.swift index 8ce22a3..7cc9f05 100644 --- a/writeas/ViewController.swift +++ b/writeas/ViewController.swift @@ -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 + } + } }