diff --git a/Mac/Base.lproj/Main.storyboard b/Mac/Base.lproj/Main.storyboard index 64ecd1357..dcccfcf9c 100644 --- a/Mac/Base.lproj/Main.storyboard +++ b/Mac/Base.lproj/Main.storyboard @@ -496,6 +496,12 @@ + + + + + + diff --git a/Mac/Base.lproj/Preferences.storyboard b/Mac/Base.lproj/Preferences.storyboard index 1e3394f8a..a1e976819 100644 --- a/Mac/Base.lproj/Preferences.storyboard +++ b/Mac/Base.lproj/Preferences.storyboard @@ -30,15 +30,15 @@ - - + + - + - + @@ -46,7 +46,7 @@ - + @@ -81,7 +81,7 @@ - + @@ -89,7 +89,7 @@ - + @@ -104,7 +104,7 @@ - + @@ -112,7 +112,7 @@ + + + + + + + + @@ -168,13 +176,15 @@ + - + + @@ -184,6 +194,7 @@ + @@ -205,7 +216,7 @@ - + @@ -385,16 +396,16 @@ - + - + - + - + @@ -501,7 +512,7 @@ - + @@ -556,16 +567,16 @@ - + - + - + - + @@ -668,7 +679,7 @@ - + diff --git a/Mac/Browser.swift b/Mac/Browser.swift index 335a1a560..b36a27ea0 100644 --- a/Mac/Browser.swift +++ b/Mac/Browser.swift @@ -11,9 +11,9 @@ import RSWeb struct Browser { - static func open(_ urlString: String) { + static func open(_ urlString: String, invertPreference invert: Bool = false) { // Opens according to prefs. - open(urlString, inBackground: AppDefaults.openInBrowserInBackground) + open(urlString, inBackground: invert ? !AppDefaults.openInBrowserInBackground : AppDefaults.openInBrowserInBackground) } static func open(_ urlString: String, inBackground: Bool) { @@ -23,3 +23,13 @@ struct Browser { } } +extension Browser { + + static var titleForOpenInBrowserInverted: String { + let openInBackgroundPref = AppDefaults.openInBrowserInBackground + + return openInBackgroundPref ? + NSLocalizedString("Open in Browser in Foreground", comment: "Open in Browser in Foreground menu item title") : + NSLocalizedString("Open in Browser in Background", comment: "Open in Browser in Background menu item title") + } +} diff --git a/Mac/MainWindow/Detail/DetailWebViewController.swift b/Mac/MainWindow/Detail/DetailWebViewController.swift index 8b4cdfc08..e77101f9d 100644 --- a/Mac/MainWindow/Detail/DetailWebViewController.swift +++ b/Mac/MainWindow/Detail/DetailWebViewController.swift @@ -193,7 +193,9 @@ extension DetailWebViewController: WKNavigationDelegate { public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { if navigationAction.navigationType == .linkActivated { if let url = navigationAction.request.url { - Browser.open(url.absoluteString) + let flags = navigationAction.modifierFlags + let invert = flags.contains(.shift) || flags.contains(.command) + Browser.open(url.absoluteString, invertPreference: invert) } decisionHandler(.cancel) return diff --git a/Mac/MainWindow/MainWindowController.swift b/Mac/MainWindow/MainWindowController.swift index f7de9c485..4e2a74f88 100644 --- a/Mac/MainWindow/MainWindowController.swift +++ b/Mac/MainWindow/MainWindowController.swift @@ -179,6 +179,10 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations { public func validateUserInterfaceItem(_ item: NSValidatedUserInterfaceItem) -> Bool { if item.action == #selector(openArticleInBrowser(_:)) { + if let item = item as? NSMenuItem, item.keyEquivalentModifierMask.contains(.shift) { + item.title = Browser.titleForOpenInBrowserInverted + } + return currentLink != nil } @@ -261,7 +265,7 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations { @IBAction func openArticleInBrowser(_ sender: Any?) { if let link = currentLink { - Browser.open(link) + Browser.open(link, invertPreference: NSApp.currentEvent?.modifierFlags.contains(.shift) ?? false) } } diff --git a/Mac/MainWindow/Sidebar/SidebarViewController.swift b/Mac/MainWindow/Sidebar/SidebarViewController.swift index b268be44f..7cb181d39 100644 --- a/Mac/MainWindow/Sidebar/SidebarViewController.swift +++ b/Mac/MainWindow/Sidebar/SidebarViewController.swift @@ -237,7 +237,7 @@ protocol SidebarDelegate: class { guard let feed = singleSelectedWebFeed, let homePageURL = feed.homePageURL else { return } - Browser.open(homePageURL) + Browser.open(homePageURL, invertPreference: NSApp.currentEvent?.modifierFlags.contains(.shift) ?? false) } @IBAction func gotoToday(_ sender: Any?) { diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index ab1e9642d..a283ebd41 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -297,7 +297,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr @objc func openArticleInBrowser(_ sender: Any?) { if let link = oneSelectedArticle?.preferredLink { - Browser.open(link) + Browser.open(link, invertPreference: NSApp.currentEvent?.modifierFlags.contains(.shift) ?? false) } } @@ -725,6 +725,10 @@ extension TimelineViewController: NSUserInterfaceValidations { func validateUserInterfaceItem(_ item: NSValidatedUserInterfaceItem) -> Bool { if item.action == #selector(openArticleInBrowser(_:)) { + if let item = item as? NSMenuItem, item.keyEquivalentModifierMask.contains(.shift) { + item.title = Browser.titleForOpenInBrowserInverted + } + let currentLink = oneSelectedArticle?.preferredLink return currentLink != nil }