From c062c85e9d41fa1cfab52f5171bd14b72c9c3fb9 Mon Sep 17 00:00:00 2001 From: Jordan Becker Date: Wed, 3 Oct 2018 10:22:56 +0200 Subject: [PATCH 1/3] Add static systemTheme using 10.14 semantic s --- XiEditor/Theme.swift | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/XiEditor/Theme.swift b/XiEditor/Theme.swift index 4a1ce7ad..7309dbb1 100644 --- a/XiEditor/Theme.swift +++ b/XiEditor/Theme.swift @@ -75,6 +75,29 @@ extension Theme { shadow: nil ) } + + static func systemTheme() -> Theme { + if #available(OSX 10.13, *) { + return Theme(foreground: NSColor.textColor, + background: NSColor.textBackgroundColor, + caret: NSColor.red, // Seems to be ignored + lineHighlight: NSColor.green, // Seems to be ignored + findHighlight: NSColor.blue, // Seems to be ignored + findHighlightForeground: NSColor.purple, // Seems to be ignored + gutter: NSColor.textBackgroundColor, + gutterForeground: NSColor.secondaryLabelColor, + selection: NSColor.selectedTextBackgroundColor, + selectionForeground: NSColor.systemPink, // Seems to be ignored + selectionBorder: NSColor.yellow, // Seems to be ignored + inactiveSelection: NSColor.brown, // Seems to be ignored + inactiveSelectionForeground: NSColor.cyan, // Seems to be ignored + shadow: NSColor.magenta // Seems to be ignored + ) + } else { + // Fallback on earlier versions + return defaultTheme() + } + } init(jsonObject dict: [String: AnyObject]) { let foreground = NSColor(jsonRgbaColor: dict["foreground"] as? [String: AnyObject] ?? [:]) From b18a89f282ec380a80b4ef5dc87e1a9974fb2934 Mon Sep 17 00:00:00 2001 From: Jordan Becker Date: Wed, 3 Oct 2018 10:29:14 +0200 Subject: [PATCH 2/3] Disable theme-based override on OSX >= 10.14 --- XiEditor/EditViewController.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/XiEditor/EditViewController.swift b/XiEditor/EditViewController.swift index fff7d2b5..d05a548b 100644 --- a/XiEditor/EditViewController.swift +++ b/XiEditor/EditViewController.swift @@ -148,11 +148,15 @@ class EditViewController: NSViewController, EditViewDataSource, FindDelegate, Sc statusBar.updateStatusBarColor(newBackgroundColor: self.theme.background, newTextColor: self.theme.foreground, newUnifiedTitlebar: unifiedTitlebar) findViewController.updateColor(newBackgroundColor: self.theme.background, unifiedTitlebar: unifiedTitlebar) - - if color.isDark && unifiedTitlebar { - window.appearance = NSAppearance(named: NSAppearance.Name.vibrantDark) + + if #available(OSX 10.14, *) { + // Let system decide, disregarding active theme color } else { - window.appearance = NSAppearance(named: NSAppearance.Name.aqua) + if color.isDark && unifiedTitlebar { + window.appearance = NSAppearance(named: NSAppearance.Name.vibrantDark) + } else { + window.appearance = NSAppearance(named: NSAppearance.Name.aqua) + } } } } From c42512ef3c347084a286a9b6faf230aa8dc3eb88 Mon Sep 17 00:00:00 2001 From: Jordan Becker Date: Wed, 3 Oct 2018 10:32:58 +0200 Subject: [PATCH 3/3] Add macOS Debug -> Theme menu item and handle specific case --- XiEditor/EditViewController.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/XiEditor/EditViewController.swift b/XiEditor/EditViewController.swift index d05a548b..086065c3 100644 --- a/XiEditor/EditViewController.swift +++ b/XiEditor/EditViewController.swift @@ -50,6 +50,8 @@ class EditViewController: NSViewController, EditViewDataSource, FindDelegate, Sc @IBOutlet weak var editViewHeight: NSLayoutConstraint! @IBOutlet weak var editViewWidth: NSLayoutConstraint! + + let appDelegate = NSApp.delegate as! AppDelegate lazy var findViewController: FindViewController! = { let storyboard = NSStoryboard(name: NSStoryboard.Name(rawValue: "Main"), bundle: nil) @@ -618,6 +620,11 @@ class EditViewController: NSViewController, EditViewDataSource, FindDelegate, Sc // MARK: - Debug Methods @IBAction func debugSetTheme(_ sender: NSMenuItem) { guard sender.state != NSControl.StateValue.on else { print("theme already active"); return } + if sender.title == "macOS" { + let theme = Theme.systemTheme() + appDelegate.themeChanged(name: sender.title, theme: theme) + return + } let req = Events.SetTheme(themeName: sender.title) document.dispatcher.coreConnection.sendRpcAsync(req.method, params: req.params!) } @@ -759,6 +766,12 @@ class EditViewController: NSViewController, EditViewDataSource, FindDelegate, Sc .first?.title pluginsMenu.removeAllItems() + + let systemThemeMenuItem = NSMenuItem(title: "macOS", action: #selector(EditViewController.debugSetTheme(_:)), keyEquivalent: "") + systemThemeMenuItem.state = NSControl.StateValue(rawValue: ("macOS" == currentlyActive) ? 1 : 0) + + pluginsMenu.addItem(systemThemeMenuItem) + pluginsMenu.addItem(NSMenuItem.separator()) for theme in themes { let item = NSMenuItem(title: theme, action: #selector(EditViewController.debugSetTheme(_:)), keyEquivalent: "") item.state = NSControl.StateValue(rawValue: (theme == currentlyActive) ? 1 : 0)