Implement open in browser timeline context menu item.
This commit is contained in:
parent
a102b9f63d
commit
644e9da1c0
|
@ -6,11 +6,7 @@
|
|||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
#if os(macOS)
|
||||
import AppKit
|
||||
#else
|
||||
import UIKit
|
||||
#endif
|
||||
import Foundation
|
||||
import Combine
|
||||
import Account
|
||||
import Articles
|
||||
|
@ -58,28 +54,22 @@ final class SceneModel: ObservableObject {
|
|||
}
|
||||
}
|
||||
|
||||
// MARK Navigation API
|
||||
|
||||
func openInBrowser() {
|
||||
guard let link = selectedArticles.first?.preferredLink else { return }
|
||||
|
||||
#if os(macOS)
|
||||
Browser.open(link, invertPreference: NSApp.currentEvent?.modifierFlags.contains(.shift) ?? false)
|
||||
#else
|
||||
guard let url = URL(string: link) else { return }
|
||||
UIApplication.shared.open(url, options: [:])
|
||||
#endif
|
||||
}
|
||||
|
||||
// MARK: Article Management API
|
||||
|
||||
/// Toggles the read status for the selected articles
|
||||
func toggleReadStatusForSelectedArticles() {
|
||||
timelineModel.toggleReadStatusForSelectedArticles()
|
||||
}
|
||||
|
||||
/// Toggles the star status for the selected articles
|
||||
func toggleStarredStatusForSelectedArticles() {
|
||||
timelineModel.toggleStarredStatusForSelectedArticles()
|
||||
}
|
||||
|
||||
/// Opens the selected article in an external browser
|
||||
func openSelectedArticleInBrowser() {
|
||||
timelineModel.openSelectedArticleInBrowser()
|
||||
}
|
||||
|
||||
/// Retrieves the article before the given article in the Timeline
|
||||
func findPrevArticle(_ article: Article) -> Article? {
|
||||
|
|
|
@ -158,7 +158,7 @@ struct SceneNavigationView: View {
|
|||
}
|
||||
ToolbarItem {
|
||||
Button {
|
||||
sceneModel.openInBrowser()
|
||||
sceneModel.openSelectedArticleInBrowser()
|
||||
} label: {
|
||||
AppAssets.openInBrowserImage
|
||||
}
|
||||
|
|
|
@ -81,5 +81,17 @@ struct TimelineContextMenu: View {
|
|||
}
|
||||
}
|
||||
|
||||
if timelineModel.canOpenIndicatedArticleInBrowser(timelineItem.article) {
|
||||
Divider()
|
||||
Button {
|
||||
timelineModel.openIndicatedArticleInBrowser(timelineItem.article)
|
||||
} label: {
|
||||
Text("Open in Browser")
|
||||
#if os(iOS)
|
||||
AppAssets.openInBrowserImage
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,11 @@
|
|||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if os(macOS)
|
||||
import AppKit
|
||||
#else
|
||||
import UIKit
|
||||
#endif
|
||||
import Combine
|
||||
import RSCore
|
||||
import Account
|
||||
|
@ -223,6 +227,27 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
|
|||
func markSelectedArticlesAsUnstarred() {
|
||||
markArticlesWithUndo(selectedArticles, statusKey: .starred, flag: false)
|
||||
}
|
||||
|
||||
func canOpenIndicatedArticleInBrowser(_ article: Article) -> Bool {
|
||||
guard indicatedArticles(article).count == 1 else { return false }
|
||||
return article.preferredLink != nil
|
||||
}
|
||||
|
||||
func openIndicatedArticleInBrowser(_ article: Article) {
|
||||
guard let link = article.preferredLink else { return }
|
||||
|
||||
#if os(macOS)
|
||||
Browser.open(link, invertPreference: NSApp.currentEvent?.modifierFlags.contains(.shift) ?? false)
|
||||
#else
|
||||
guard let url = URL(string: link) else { return }
|
||||
UIApplication.shared.open(url, options: [:])
|
||||
#endif
|
||||
}
|
||||
|
||||
func openSelectedArticleInBrowser() {
|
||||
guard let article = selectedArticles.first else { return }
|
||||
openIndicatedArticleInBrowser(article)
|
||||
}
|
||||
|
||||
func articleFor(_ articleID: String) -> Article? {
|
||||
return idToArticleDictionary[articleID]
|
||||
|
|
Loading…
Reference in New Issue