2017-12-16 10:18:02 -08:00
|
|
|
//
|
|
|
|
// DetailStatusBarView.swift
|
2018-08-28 22:18:24 -07:00
|
|
|
// NetNewsWire
|
2017-12-16 10:18:02 -08:00
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 12/16/17.
|
|
|
|
// Copyright © 2017 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2018-02-02 22:51:32 -08:00
|
|
|
import AppKit
|
2018-07-23 18:29:08 -07:00
|
|
|
import Articles
|
2017-12-16 10:18:02 -08:00
|
|
|
|
|
|
|
final class DetailStatusBarView: NSView {
|
|
|
|
|
|
|
|
@IBOutlet var urlLabel: NSTextField!
|
|
|
|
|
2019-02-10 21:39:11 -08:00
|
|
|
var mouseoverLink: String? {
|
2017-12-16 10:18:02 -08:00
|
|
|
didSet {
|
2017-12-28 18:41:01 -08:00
|
|
|
updateLinkForDisplay()
|
2017-12-16 10:18:02 -08:00
|
|
|
}
|
|
|
|
}
|
2017-12-28 18:41:01 -08:00
|
|
|
|
|
|
|
private var linkForDisplay: String? {
|
2017-12-16 10:18:02 -08:00
|
|
|
didSet {
|
2017-12-28 18:41:01 -08:00
|
|
|
needsLayout = true
|
|
|
|
if let link = linkForDisplay {
|
|
|
|
urlLabel.stringValue = link
|
|
|
|
self.isHidden = false
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
urlLabel.stringValue = ""
|
|
|
|
self.isHidden = true
|
|
|
|
}
|
2017-12-16 10:18:02 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-10 21:39:11 -08:00
|
|
|
private var didConfigureLayerRadius = false
|
|
|
|
|
2017-12-28 18:41:01 -08:00
|
|
|
override var isOpaque: Bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-12-16 10:18:02 -08:00
|
|
|
override var isFlipped: Bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2017-12-28 18:41:01 -08:00
|
|
|
override var wantsUpdateLayer: Bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
override func updateLayer() {
|
2018-09-10 23:03:24 -07:00
|
|
|
guard let layer = layer else {
|
2017-12-28 18:41:01 -08:00
|
|
|
return
|
|
|
|
}
|
2018-09-10 23:03:24 -07:00
|
|
|
if !didConfigureLayerRadius {
|
2017-12-28 18:41:01 -08:00
|
|
|
layer.cornerRadius = 4.0
|
2018-09-10 23:03:24 -07:00
|
|
|
didConfigureLayerRadius = true
|
2017-12-28 18:41:01 -08:00
|
|
|
}
|
2018-09-10 23:03:24 -07:00
|
|
|
|
2019-04-13 12:18:55 -07:00
|
|
|
let color = self.effectiveAppearance.isDarkMode ? NSColor.textBackgroundColor : NSColor(named: "DetailStatusBarBackground")!
|
2018-09-10 23:03:24 -07:00
|
|
|
layer.backgroundColor = color.cgColor
|
2017-12-28 18:41:01 -08:00
|
|
|
}
|
2017-12-16 10:18:02 -08:00
|
|
|
}
|
|
|
|
|
2019-02-10 21:39:11 -08:00
|
|
|
// MARK: - Private
|
2017-12-16 10:18:02 -08:00
|
|
|
|
2019-02-10 21:39:11 -08:00
|
|
|
private extension DetailStatusBarView {
|
2017-12-16 10:18:02 -08:00
|
|
|
|
2017-12-28 18:41:01 -08:00
|
|
|
func updateLinkForDisplay() {
|
2017-12-16 10:18:02 -08:00
|
|
|
if let mouseoverLink = mouseoverLink, !mouseoverLink.isEmpty {
|
2017-12-28 18:41:01 -08:00
|
|
|
linkForDisplay = (mouseoverLink as NSString).rs_stringByStrippingHTTPOrHTTPSScheme()
|
2017-12-16 10:18:02 -08:00
|
|
|
}
|
|
|
|
else {
|
2017-12-28 18:41:01 -08:00
|
|
|
linkForDisplay = nil
|
2017-12-16 10:18:02 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|