mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Add right-click action to the Article Extractor Button. Fixes #3695
This commit is contained in:
@@ -17,6 +17,8 @@ enum ArticleExtractorButtonState {
|
||||
|
||||
class ArticleExtractorButton: NSButton {
|
||||
|
||||
public var rightClickAction: Selector?
|
||||
|
||||
private var animatedLayer: CALayer?
|
||||
|
||||
var buttonState: ArticleExtractorButtonState = .off {
|
||||
@@ -69,6 +71,7 @@ class ArticleExtractorButton: NSButton {
|
||||
image = AppAssets.articleExtractorOff
|
||||
imageScaling = .scaleProportionallyDown
|
||||
widthAnchor.constraint(equalTo: heightAnchor).isActive = true
|
||||
sendAction(on: [.leftMouseDown, .rightMouseDown])
|
||||
}
|
||||
|
||||
override func layout() {
|
||||
@@ -80,6 +83,10 @@ class ArticleExtractorButton: NSButton {
|
||||
addAnimatedSublayer(to: layer!)
|
||||
}
|
||||
|
||||
override func rightMouseDown(with event: NSEvent) {
|
||||
_ = target?.perform(rightClickAction, with: self)
|
||||
}
|
||||
|
||||
private func stripAnimatedSublayer() {
|
||||
animatedLayer?.removeFromSuperlayer()
|
||||
}
|
||||
|
||||
36
Mac/MainWindow/MainWindow.swift
Normal file
36
Mac/MainWindow/MainWindow.swift
Normal file
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// MainWindow.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Maurice Parker on 9/26/22.
|
||||
// Copyright © 2022 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class MainWindow: NSWindow {
|
||||
|
||||
override func sendEvent(_ event: NSEvent) {
|
||||
|
||||
// Since the Toolbar intercepts right clicks we need to stop it from doing that here
|
||||
// so that the ArticleExtractorButton can receive right click events.
|
||||
if event.isRightClick,
|
||||
let frameView = contentView?.superview,
|
||||
let view = frameView.hitTest(frameView.convert(event.locationInWindow, from: nil)),
|
||||
type(of: view).description() == "NSToolbarView" {
|
||||
|
||||
for subview in view.subviews {
|
||||
for subsubview in subview.subviews {
|
||||
let candidateView = subsubview.hitTest(subsubview.convert(event.locationInWindow, from: nil))
|
||||
if candidateView is ArticleExtractorButton {
|
||||
candidateView?.rightMouseDown(with: event)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
super.sendEvent(event)
|
||||
}
|
||||
}
|
||||
@@ -560,6 +560,40 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
||||
self.detailViewController?.performFindPanelAction(sender)
|
||||
}
|
||||
|
||||
@objc func showArticleExtractorMenu(_ button: NSButton) {
|
||||
guard oneSelectedArticle?.webFeed != nil else {
|
||||
return
|
||||
}
|
||||
|
||||
let menu = NSMenu()
|
||||
|
||||
let alwaysUseReaderViewItem = NSMenuItem()
|
||||
alwaysUseReaderViewItem.title = NSLocalizedString("Always Use Reader View", comment: "Always Use Reader View")
|
||||
alwaysUseReaderViewItem.target = self
|
||||
alwaysUseReaderViewItem.action = #selector(alwaysUseReaderView)
|
||||
alwaysUseReaderViewItem.state = {
|
||||
if oneSelectedArticle?.webFeed?.isArticleExtractorAlwaysOn ?? false {
|
||||
return NSControl.StateValue.on
|
||||
} else {
|
||||
return NSControl.StateValue.off
|
||||
}
|
||||
}()
|
||||
|
||||
menu.addItem(alwaysUseReaderViewItem)
|
||||
|
||||
menu.popUp(positioning: alwaysUseReaderViewItem, at: button.frame.origin, in: button)
|
||||
}
|
||||
|
||||
@objc func alwaysUseReaderView() {
|
||||
guard let feed = oneSelectedArticle?.webFeed else {
|
||||
return
|
||||
}
|
||||
|
||||
if feed.isArticleExtractorAlwaysOn == nil { feed.isArticleExtractorAlwaysOn = false }
|
||||
feed.isArticleExtractorAlwaysOn?.toggle()
|
||||
NotificationCenter.default.post(Notification(name: .DidUpdateFeedPreferencesFromContextMenu))
|
||||
}
|
||||
|
||||
@objc func selectArticleTheme(_ menuItem: NSMenuItem) {
|
||||
ArticleThemesManager.shared.currentThemeName = menuItem.title
|
||||
}
|
||||
@@ -852,7 +886,9 @@ extension MainWindowController: NSToolbarDelegate {
|
||||
toolbarItem.toolTip = description
|
||||
toolbarItem.label = description
|
||||
let button = ArticleExtractorButton()
|
||||
button.target = self
|
||||
button.action = #selector(toggleArticleExtractor(_:))
|
||||
button.rightClickAction = #selector(showArticleExtractorMenu(_:))
|
||||
toolbarItem.view = button
|
||||
return toolbarItem
|
||||
|
||||
|
||||
Reference in New Issue
Block a user