The Write.as desktop (GUI) app for macOS.
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

95 satır
2.7 KiB

  1. //
  2. // AppDelegate.swift
  3. // writeas
  4. //
  5. // Created by Matt Baer on 12/29/15.
  6. // Copyright © 2015 A Bunch Tell. All rights reserved.
  7. //
  8. import Cocoa
  9. @NSApplicationMain
  10. class AppDelegate: NSObject, NSApplicationDelegate {
  11. var vc: ViewController?
  12. @IBOutlet weak var nightModeItem: NSMenuItem!
  13. @IBOutlet weak var formatFontSerifItem: NSMenuItem!
  14. @IBOutlet weak var formatFontSansItem: NSMenuItem!
  15. @IBOutlet weak var formatFontMonoItem: NSMenuItem!
  16. func applicationDidFinishLaunching(_ aNotification: Notification) {
  17. // Set night mode state
  18. nightModeItem.state = Int(UserDefaults.standard.string(forKey: "night_mode_state") ?? String(NSOffState))!
  19. if nightModeItem.state == NSOnState {
  20. vc?.toggle(isNight: true)
  21. }
  22. // Set font
  23. let font = Preferences.getFont()
  24. if font == Preferences.PostFont.serif {
  25. formatFontSerifItem.state = NSOnState
  26. vc?.setFont(.serif)
  27. } else if font == Preferences.PostFont.sans {
  28. formatFontSansItem.state = NSOnState
  29. vc?.setFont(.sans)
  30. } else if font == Preferences.PostFont.mono {
  31. formatFontMonoItem.state = NSOnState
  32. vc?.setFont(.mono)
  33. }
  34. }
  35. func applicationWillTerminate(_ aNotification: Notification) {
  36. vc?.saveDocument()
  37. }
  38. func applicationDidBecomeActive(_ notification: Notification) {
  39. if vc == nil {
  40. vc = NSApplication.shared().mainWindow?.contentViewController as! ViewController
  41. }
  42. }
  43. @IBAction func toggleNightMode(_ sender: NSMenuItem) {
  44. let isOff = sender.state == NSOffState
  45. vc?.toggle(isNight: isOff)
  46. sender.state = isOff ? NSOnState : NSOffState
  47. UserDefaults.standard.set(String(sender.state), forKey: "night_mode_state")
  48. }
  49. @IBAction func setFontSerif(_ sender: NSMenuItem) {
  50. deselectAllFonts()
  51. sender.state = NSOnState
  52. vc?.setFont(.serif)
  53. Preferences.setFont(.serif)
  54. }
  55. @IBAction func setFontSans(_ sender: NSMenuItem) {
  56. deselectAllFonts()
  57. sender.state = NSOnState
  58. vc?.setFont(.sans)
  59. Preferences.setFont(.sans)
  60. }
  61. @IBAction func setFontMono(_ sender: NSMenuItem) {
  62. deselectAllFonts()
  63. sender.state = NSOnState
  64. vc?.setFont(.mono)
  65. Preferences.setFont(.mono)
  66. }
  67. func deselectAllFonts() {
  68. formatFontSerifItem.state = NSOffState
  69. formatFontSansItem.state = NSOffState
  70. formatFontMonoItem.state = NSOffState
  71. }
  72. @IBAction func saveDocument(_ sender: AnyObject) {
  73. vc?.saveDocument()
  74. }
  75. @IBAction func publishDoc(_ sender: Any) {
  76. vc?.publish()
  77. }
  78. }