Add menu and keyboard shortcut to Reader
This commit is contained in:
parent
6a7d1df423
commit
76056e4fef
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14865.1" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14868" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14865.1"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14868"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--Application-->
|
||||
|
@ -440,6 +440,11 @@
|
|||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="qgr-Gl-Xhw"/>
|
||||
<menuItem title="Show Reader View" keyEquivalent="R" id="p5x-Xq-1fW">
|
||||
<connections>
|
||||
<action selector="toggleArticleExtractor:" target="Ady-hI-5gd" id="H3B-RR-1tB"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Open in Browser" keyEquivalent="" id="4iQ-1v-dTa">
|
||||
<connections>
|
||||
<action selector="openArticleInBrowser:" target="Ady-hI-5gd" id="KeH-ES-fpo"/>
|
||||
|
@ -595,8 +600,8 @@
|
|||
<connections>
|
||||
<outlet property="checkForUpdatesMenuItem" destination="1nF-7O-aKU" id="JmT-jc-DJ8"/>
|
||||
<outlet property="debugMenuItem" destination="UqE-mp-gtV" id="OnR-lr-Zlt"/>
|
||||
<outlet property="groupArticlesByFeedMenuItem" destination="Zxm-O6-NRE" id="gwn-VT-2YZ"/>
|
||||
<outlet property="enableWebInspectorMenuItem" destination="EwI-z4-ZA3" id="EGp-lP-f91"/>
|
||||
<outlet property="groupArticlesByFeedMenuItem" destination="Zxm-O6-NRE" id="gwn-VT-2YZ"/>
|
||||
<outlet property="sortByNewestArticleOnTopMenuItem" destination="TNS-TV-n0U" id="gix-Nd-9k4"/>
|
||||
<outlet property="sortByOldestArticleOnTopMenuItem" destination="iii-kP-qoF" id="fTe-Tf-EWG"/>
|
||||
</connections>
|
||||
|
|
|
@ -208,7 +208,6 @@
|
|||
</connections>
|
||||
</window>
|
||||
<connections>
|
||||
<outlet property="articleExtractorButton" destination="1b9-Tf-u5V" id="W8P-DA-hmV"/>
|
||||
<segue destination="reS-fe-pD8" kind="relationship" relationship="window.shadowedContentViewController" id="WS2-WB-dc4"/>
|
||||
</connections>
|
||||
</windowController>
|
||||
|
|
|
@ -17,8 +17,7 @@ enum TimelineSourceMode {
|
|||
|
||||
class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
||||
|
||||
@IBOutlet weak var articleExtractorButton: ArticleExtractorButton!
|
||||
|
||||
private var isShowingExtractedArticle = false
|
||||
private var articleExtractor: ArticleExtractor? = nil
|
||||
private var sharingServicePickerDelegate: NSSharingServicePickerDelegate?
|
||||
|
||||
|
@ -304,15 +303,28 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
|||
guard let currentLink = currentLink, let article = oneSelectedArticle else {
|
||||
return
|
||||
}
|
||||
|
||||
defer {
|
||||
makeToolbarValidate()
|
||||
}
|
||||
|
||||
guard articleExtractorButton.state == .on else {
|
||||
let detailState = DetailState.article(article)
|
||||
detailViewController?.setState(detailState, mode: timelineSourceMode)
|
||||
guard articleExtractor?.state != .processing else {
|
||||
articleExtractor?.cancel()
|
||||
articleExtractor = nil
|
||||
isShowingExtractedArticle = false
|
||||
detailViewController?.setState(DetailState.article(article), mode: timelineSourceMode)
|
||||
return
|
||||
}
|
||||
|
||||
guard !isShowingExtractedArticle else {
|
||||
isShowingExtractedArticle = false
|
||||
detailViewController?.setState(DetailState.article(article), mode: timelineSourceMode)
|
||||
return
|
||||
}
|
||||
|
||||
if let articleExtractor = articleExtractor, let extractedArticle = articleExtractor.article {
|
||||
if currentLink == articleExtractor.articleLink {
|
||||
isShowingExtractedArticle = true
|
||||
let detailState = DetailState.extracted(article, extractedArticle)
|
||||
detailViewController?.setState(detailState, mode: timelineSourceMode)
|
||||
}
|
||||
|
@ -322,7 +334,6 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
|||
extractor.process()
|
||||
articleExtractor = extractor
|
||||
}
|
||||
makeToolbarValidate()
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -442,11 +453,13 @@ extension MainWindowController: SidebarDelegate {
|
|||
extension MainWindowController: TimelineContainerViewControllerDelegate {
|
||||
|
||||
func timelineSelectionDidChange(_: TimelineContainerViewController, articles: [Article]?, mode: TimelineSourceMode) {
|
||||
articleExtractorButton.isError = false
|
||||
articleExtractorButton.isInProgress = false
|
||||
articleExtractorButton.state = .off
|
||||
articleExtractor = nil
|
||||
|
||||
articleExtractor?.cancel()
|
||||
articleExtractor = nil
|
||||
isShowingExtractedArticle = false
|
||||
|
||||
makeToolbarValidate()
|
||||
|
||||
let detailState: DetailState
|
||||
if let articles = articles {
|
||||
detailState = articles.count == 1 ? .article(articles.first!) : .multipleSelection
|
||||
|
@ -531,10 +544,11 @@ extension MainWindowController: ArticleExtractorDelegate {
|
|||
}
|
||||
|
||||
func articleExtractionDidComplete(extractedArticle: ExtractedArticle) {
|
||||
makeToolbarValidate()
|
||||
if articleExtractorButton.state == .on, let article = oneSelectedArticle {
|
||||
if let article = oneSelectedArticle, articleExtractor?.state != .cancelled {
|
||||
isShowingExtractedArticle = true
|
||||
let detailState = DetailState.extracted(article, extractedArticle)
|
||||
detailViewController?.setState(detailState, mode: timelineSourceMode)
|
||||
makeToolbarValidate()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -692,32 +706,35 @@ private extension MainWindowController {
|
|||
}
|
||||
|
||||
func validateToggleArticleExtractor(_ item: NSValidatedUserInterfaceItem) -> Bool {
|
||||
guard let articleExtractorState = articleExtractor?.state else {
|
||||
articleExtractorButton.isError = false
|
||||
articleExtractorButton.isInProgress = false
|
||||
articleExtractorButton.state = .off
|
||||
guard let toolbarItem = item as? NSToolbarItem, let toolbarButton = toolbarItem.view as? ArticleExtractorButton else {
|
||||
if let menuItem = item as? NSMenuItem {
|
||||
menuItem.state = isShowingExtractedArticle ? .on : .off
|
||||
}
|
||||
return currentLink != nil
|
||||
}
|
||||
|
||||
switch articleExtractorState {
|
||||
case .ready:
|
||||
articleExtractorButton.isError = false
|
||||
articleExtractorButton.isInProgress = false
|
||||
return currentLink != nil
|
||||
case .processing:
|
||||
articleExtractorButton.isError = false
|
||||
articleExtractorButton.isInProgress = true
|
||||
return true
|
||||
case .failedToParse:
|
||||
articleExtractorButton.isError = true
|
||||
articleExtractorButton.isInProgress = false
|
||||
articleExtractorButton.state = .off
|
||||
return true
|
||||
case .complete:
|
||||
articleExtractorButton.isError = false
|
||||
articleExtractorButton.isInProgress = false
|
||||
toolbarButton.state = isShowingExtractedArticle ? .on : .off
|
||||
|
||||
guard let state = articleExtractor?.state else {
|
||||
toolbarButton.isError = false
|
||||
toolbarButton.isInProgress = false
|
||||
toolbarButton.state = .off
|
||||
return currentLink != nil
|
||||
}
|
||||
|
||||
switch state {
|
||||
case .processing:
|
||||
toolbarButton.isError = false
|
||||
toolbarButton.isInProgress = true
|
||||
case .failedToParse:
|
||||
toolbarButton.isError = true
|
||||
toolbarButton.isInProgress = false
|
||||
case .ready, .cancelled, .complete:
|
||||
toolbarButton.isError = false
|
||||
toolbarButton.isInProgress = false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func canMarkOlderArticlesAsRead() -> Bool {
|
||||
|
|
|
@ -13,6 +13,7 @@ public enum ArticleExtractorState {
|
|||
case processing
|
||||
case failedToParse
|
||||
case complete
|
||||
case cancelled
|
||||
}
|
||||
|
||||
protocol ArticleExtractorDelegate {
|
||||
|
@ -27,6 +28,8 @@ enum ArticleExtractorError: Error {
|
|||
}
|
||||
|
||||
class ArticleExtractor {
|
||||
|
||||
private var dataTask: URLSessionDataTask? = nil
|
||||
|
||||
var state: ArticleExtractorState!
|
||||
var article: ExtractedArticle?
|
||||
|
@ -57,7 +60,7 @@ class ArticleExtractor {
|
|||
|
||||
state = .processing
|
||||
|
||||
let dataTask = URLSession.shared.dataTask(with: url) { [weak self] data, response, error in
|
||||
dataTask = URLSession.shared.dataTask(with: url) { [weak self] data, response, error in
|
||||
|
||||
guard let self = self else { return }
|
||||
|
||||
|
@ -95,8 +98,13 @@ class ArticleExtractor {
|
|||
|
||||
}
|
||||
|
||||
dataTask.resume()
|
||||
|
||||
dataTask!.resume()
|
||||
|
||||
}
|
||||
|
||||
public func cancel() {
|
||||
state = .cancelled
|
||||
dataTask?.cancel()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue