Make shift key invert the "open in background" preference

- Also add an appropriate menu item.
This commit is contained in:
Nate Weaver 2020-05-20 19:41:23 -05:00
parent 314df88e12
commit e79cafc82e
4 changed files with 28 additions and 2 deletions

View File

@ -496,6 +496,12 @@
<action selector="openArticleInBrowser:" target="Ady-hI-5gd" id="KeH-ES-fpo"/>
</connections>
</menuItem>
<menuItem title="Open in Browser Inverted" alternate="YES" keyEquivalent="" id="EjD-X9-Pjf">
<modifierMask key="keyEquivalentModifierMask" shift="YES" command="YES"/>
<connections>
<action selector="openArticleInBrowser:" target="Ady-hI-5gd" id="Frq-Uo-DQs"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>

View File

@ -6,14 +6,16 @@
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
//
import Foundation
import AppKit
import RSWeb
struct Browser {
static func open(_ urlString: String) {
let shouldInvertPreference = NSApp.currentEvent?.modifierFlags.contains(.shift) ?? false
// Opens according to prefs.
open(urlString, inBackground: AppDefaults.openInBrowserInBackground)
open(urlString, inBackground: shouldInvertPreference ? !AppDefaults.openInBrowserInBackground : AppDefaults.openInBrowserInBackground)
}
static func open(_ urlString: String, inBackground: Bool) {
@ -23,3 +25,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")
}
}

View File

@ -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
}

View File

@ -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
}