Convert Activity Log to .xib.

This commit is contained in:
Brent Simmons committed 2026-06-04 10:39:30 -07:00
1 parent e133d4f276
commit fbb60717e0
4 files changed
+202 -119

No files matched your search

+34 -115
View File
@@ -9,10 +9,9 @@ import AppKit
import Account
import ActivityLog
@MainActor final class ActivityLogWindowController: NSWindowController, NSWindowDelegate {
final class ActivityLogWindowController: NSWindowController, NSWindowDelegate {
private static let windowIsOpenKey = "ActivityLogWindowIsOpen"
private static let activityLogWindowAutosaveFrameName = "ActivityLogWindow"
static private(set) var shouldOpenAtStartup: Bool {
get {
@@ -23,8 +22,9 @@ import ActivityLog
}
}
private var textView = NSTextView()
private var copyButton: NSButton?
@IBOutlet private var textView: NSTextView?
@IBOutlet private var copyButton: NSButton?
private var hasBeenShown = false
/// Activity IDs for which we've logged the completion entry.
@@ -36,29 +36,24 @@ import ActivityLog
private var needsRebuild = false
private static let defaultWindowSize = NSSize(width: 640, height: 400)
private static let minimumWindowSize = NSSize(width: 640, height: 300)
private static let aboveCenterOffset: CGFloat = 40
init() {
let window = NSWindow(contentRect: NSRect(origin: .zero, size: Self.defaultWindowSize), styleMask: [.titled, .closable, .resizable, .miniaturizable], backing: .buffered, defer: true)
window.title = NSLocalizedString("Activity Log", comment: "Activity Log window title")
window.minSize = Self.minimumWindowSize
window.isReleasedWhenClosed = false
convenience init() {
self.init(windowNibName: "ActivityLogWindow")
}
super.init(window: window)
setupUI()
override func windowDidLoad() {
super.windowDidLoad()
window?.delegate = self
textView?.font = NSFont.monospacedSystemFont(ofSize: Self.fontSize, weight: .regular)
textView?.textContainerInset = NSSize(width: Self.textContainerInset, height: Self.textContainerInset)
updateCopyButtonState()
NotificationCenter.default.addObserver(self, selector: #selector(handleActivityDidChange(_:)), name: .activityDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleWindowDidResignMain(_:)), name: NSWindow.didResignMainNotification, object: window)
NotificationCenter.default.addObserver(self, selector: #selector(handleAppDidResignActive(_:)), name: NSApplication.didResignActiveNotification, object: nil)
window.delegate = self
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) is not supported")
}
override func showWindow(_ sender: Any?) {
@@ -69,7 +64,6 @@ import ActivityLog
frame.origin.y += Self.aboveCenterOffset
window?.setFrame(frame, display: false)
}
window?.setFrameAutosaveName(Self.activityLogWindowAutosaveFrameName)
}
super.showWindow(sender)
reloadEntries()
@@ -82,7 +76,7 @@ import ActivityLog
// MARK: - NSWindowDelegate
func windowDidResize(_ notification: Notification) {
guard let container = textView.textContainer else {
guard let textView, let container = textView.textContainer else {
return
}
container.size = NSSize(width: textView.bounds.width - textView.textContainerInset.width * 2, height: CGFloat.greatestFiniteMagnitude)
@@ -105,6 +99,16 @@ import ActivityLog
@objc func handleAppDidResignActive(_ notification: Notification) {
rebuildIfNeeded()
}
// MARK: - Actions
@IBAction func copyContents(_ sender: Any?) {
guard let text = textView?.string, !text.isEmpty else {
return
}
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(text, forType: .string)
}
}
// MARK: - Private
@@ -119,10 +123,6 @@ private extension ActivityLogWindowController {
static let fontSize: CGFloat = 16.0
static let textContainerInset: CGFloat = 8
static let separatorHeight: CGFloat = 1
static let separatorWhite: CGFloat = 0.75
static let bottomBarHeight: CGFloat = 52
static let bottomBarPadding: CGFloat = 16
static let lineSpacing: CGFloat = 4
static let paragraphSpacing: CGFloat = 7
static let entryParagraphStyle: NSParagraphStyle = {
@@ -132,84 +132,6 @@ private extension ActivityLogWindowController {
return style
}()
func setupUI() {
guard let contentView = window?.contentView else {
return
}
let scrollView = NSTextView.scrollableTextView()
scrollView.translatesAutoresizingMaskIntoConstraints = false
scrollView.hasVerticalScroller = true
scrollView.autohidesScrollers = true
scrollView.drawsBackground = true
let embeddedTextView = scrollView.documentView as! NSTextView
embeddedTextView.isEditable = false
embeddedTextView.isSelectable = true
embeddedTextView.usesFindBar = true
embeddedTextView.isIncrementalSearchingEnabled = true
embeddedTextView.textContainerInset = NSSize(width: Self.textContainerInset, height: Self.textContainerInset)
embeddedTextView.font = NSFont.monospacedSystemFont(ofSize: Self.fontSize, weight: .regular)
self.textView = embeddedTextView
let separator = NSView()
separator.translatesAutoresizingMaskIntoConstraints = false
separator.wantsLayer = true
separator.layer?.backgroundColor = NSColor(white: Self.separatorWhite, alpha: 1.0).cgColor
let bottomBar = NSVisualEffectView()
bottomBar.translatesAutoresizingMaskIntoConstraints = false
bottomBar.blendingMode = .withinWindow
bottomBar.material = .titlebar
let warningLabel = NSTextField(wrappingLabelWithString: NSLocalizedString("This log may contain feed URLs and other information you may not want to share publicly.", comment: "Activity log privacy warning"))
warningLabel.translatesAutoresizingMaskIntoConstraints = false
warningLabel.font = NSFont.systemFont(ofSize: Self.fontSize)
warningLabel.textColor = .secondaryLabelColor
let copyButton = NSButton(title: NSLocalizedString("Copy Contents", comment: "Copy Contents button"), target: self, action: #selector(copyContents(_:)))
copyButton.translatesAutoresizingMaskIntoConstraints = false
copyButton.controlSize = .large
copyButton.font = NSFont.systemFont(ofSize: NSFont.systemFontSize)
copyButton.isEnabled = false
self.copyButton = copyButton
bottomBar.addSubview(warningLabel)
bottomBar.addSubview(copyButton)
warningLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
copyButton.setContentCompressionResistancePriority(.required, for: .horizontal)
copyButton.setContentHuggingPriority(.required, for: .horizontal)
contentView.addSubview(scrollView)
contentView.addSubview(separator)
contentView.addSubview(bottomBar)
NSLayoutConstraint.activate([
scrollView.topAnchor.constraint(equalTo: contentView.topAnchor),
scrollView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
scrollView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
scrollView.bottomAnchor.constraint(equalTo: separator.topAnchor),
separator.heightAnchor.constraint(equalToConstant: Self.separatorHeight),
separator.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
separator.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
separator.bottomAnchor.constraint(equalTo: bottomBar.topAnchor),
warningLabel.leadingAnchor.constraint(equalTo: bottomBar.leadingAnchor, constant: Self.bottomBarPadding),
warningLabel.centerYAnchor.constraint(equalTo: bottomBar.centerYAnchor),
warningLabel.trailingAnchor.constraint(lessThanOrEqualTo: copyButton.leadingAnchor, constant: -Self.bottomBarPadding),
copyButton.trailingAnchor.constraint(equalTo: bottomBar.trailingAnchor, constant: -Self.bottomBarPadding),
copyButton.centerYAnchor.constraint(equalTo: bottomBar.centerYAnchor),
bottomBar.heightAnchor.constraint(equalToConstant: Self.bottomBarHeight),
bottomBar.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
bottomBar.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
bottomBar.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)
])
}
func rebuildIfNeeded() {
guard needsRebuild else {
return
@@ -219,6 +141,9 @@ private extension ActivityLogWindowController {
}
func reloadEntries() {
guard let textView else {
return
}
loggedCompletionIDs.removeAll()
textEntryCount = 0
@@ -240,6 +165,9 @@ private extension ActivityLogWindowController {
}
func appendNewEntries() {
guard let textView else {
return
}
if textEntryCount > Self.maxTextEntries {
needsRebuild = true
}
@@ -269,11 +197,11 @@ private extension ActivityLogWindowController {
}
func updateCopyButtonState() {
copyButton?.isEnabled = !textView.string.isEmpty
copyButton?.isEnabled = !(textView?.string.isEmpty ?? true)
}
var isScrolledToBottom: Bool {
guard let scrollView = textView.enclosingScrollView else {
guard let textView, let scrollView = textView.enclosingScrollView else {
return true
}
let contentView = scrollView.contentView
@@ -509,13 +437,4 @@ private extension ActivityLogWindowController {
return .secondaryLabelColor
}
}
@objc func copyContents(_ sender: Any?) {
let text = textView.string
guard !text.isEmpty else {
return
}
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(text, forType: .string)
}
}
@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="24765" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="24765"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="ActivityLogWindowController" customModule="NetNewsWire" customModuleProvider="target">
<connections>
<outlet property="copyButton" destination="TeH-NA-QRq" id="o8C-q3-FO7"/>
<outlet property="textView" destination="OtL-Sx-OU0" id="bff-Xp-YUM"/>
<outlet property="window" destination="QvC-M9-y7g" id="aLw-Wn-out"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="Activity Log" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" frameAutosaveName="ActivityLogWindow" animationBehavior="default" id="QvC-M9-y7g">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="640" height="400"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1410"/>
<value key="minSize" type="size" width="640" height="300"/>
<view key="contentView" wantsLayer="YES" id="EiT-Mj-1SZ">
<rect key="frame" x="0.0" y="0.0" width="640" height="400"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" translatesAutoresizingMaskIntoConstraints="NO" id="kJF-uq-4TQ">
<rect key="frame" x="0.0" y="65" width="768" height="256"/>
<clipView key="contentView" id="Ypo-Qv-ix4">
<rect key="frame" x="0.0" y="0.0" width="768" height="256"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView wantsLayer="YES" importsGraphics="NO" richText="NO" editable="NO" selectable="YES" usesFindBar="YES" incrementalSearchingEnabled="YES" verticallyResizable="YES" spellingCorrection="YES" smartInsertDelete="YES" id="OtL-Sx-OU0">
<rect key="frame" x="0.0" y="0.0" width="768" height="256"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
<size key="minSize" width="768" height="256"/>
<size key="maxSize" width="768" height="10000000"/>
</textView>
</subviews>
</clipView>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="768" id="i3T-Hz-zYO"/>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="256" id="xYp-MP-yQU"/>
</constraints>
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="6eX-un-x8T">
<rect key="frame" x="-100" y="-100" width="240" height="17"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="pRJ-De-3rI">
<rect key="frame" x="751" y="0.0" width="17" height="256"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
<visualEffectView blendingMode="withinWindow" material="titlebar" state="followsWindowActiveState" translatesAutoresizingMaskIntoConstraints="NO" id="U19-VM-vwr">
<rect key="frame" x="0.0" y="0.0" width="768" height="65"/>
<subviews>
<box verticalHuggingPriority="750" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="Kf8-Md-KPZ">
<rect key="frame" x="0.0" y="62" width="768" height="5"/>
</box>
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="te9-50-gJu">
<rect key="frame" x="18" y="24" width="546" height="16"/>
<textFieldCell key="cell" lineBreakMode="wordWrap" title="This log may contain feed URLs and other information you may not want to share publicly." id="lKl-03-8bv">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="TeH-NA-QRq">
<rect key="frame" x="634" y="20" width="114" height="24"/>
<buttonCell key="cell" type="push" title="Copy Contents" controlSize="large" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="k75-bg-mhK">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="copyContents:" target="-2" id="Zw7-Db-af2"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="Kf8-Md-KPZ" firstAttribute="leading" secondItem="U19-VM-vwr" secondAttribute="leading" id="QyU-Q1-Wp9"/>
<constraint firstItem="te9-50-gJu" firstAttribute="leading" secondItem="U19-VM-vwr" secondAttribute="leading" constant="20" symbolic="YES" id="RFM-aV-AaM"/>
<constraint firstAttribute="trailing" secondItem="Kf8-Md-KPZ" secondAttribute="trailing" id="Szn-da-iY2"/>
<constraint firstAttribute="bottom" secondItem="TeH-NA-QRq" secondAttribute="bottom" constant="20" symbolic="YES" id="Uxn-0p-YPX"/>
<constraint firstItem="Kf8-Md-KPZ" firstAttribute="top" secondItem="U19-VM-vwr" secondAttribute="top" id="dVT-fU-zJI"/>
<constraint firstItem="TeH-NA-QRq" firstAttribute="firstBaseline" secondItem="te9-50-gJu" secondAttribute="firstBaseline" id="i9n-ax-BCp"/>
<constraint firstItem="TeH-NA-QRq" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="te9-50-gJu" secondAttribute="trailing" constant="8" symbolic="YES" id="jCG-W2-tLx"/>
<constraint firstAttribute="trailing" secondItem="TeH-NA-QRq" secondAttribute="trailing" constant="20" symbolic="YES" id="u5X-Bh-ELF"/>
<constraint firstItem="TeH-NA-QRq" firstAttribute="top" secondItem="Kf8-Md-KPZ" secondAttribute="bottom" constant="20" symbolic="YES" id="yPO-y0-lEk"/>
</constraints>
</visualEffectView>
</subviews>
<constraints>
<constraint firstItem="U19-VM-vwr" firstAttribute="top" secondItem="kJF-uq-4TQ" secondAttribute="bottom" id="ES3-Fu-XNe"/>
<constraint firstAttribute="trailing" secondItem="kJF-uq-4TQ" secondAttribute="trailing" id="ZI5-xh-GTb"/>
<constraint firstItem="U19-VM-vwr" firstAttribute="leading" secondItem="EiT-Mj-1SZ" secondAttribute="leading" id="Zfc-tO-Etl"/>
<constraint firstAttribute="trailing" secondItem="U19-VM-vwr" secondAttribute="trailing" id="aVN-xe-Qft"/>
<constraint firstAttribute="bottom" secondItem="U19-VM-vwr" secondAttribute="bottom" id="bEJ-hv-zAD"/>
<constraint firstItem="kJF-uq-4TQ" firstAttribute="top" secondItem="EiT-Mj-1SZ" secondAttribute="top" id="enk-H1-xIp"/>
<constraint firstItem="kJF-uq-4TQ" firstAttribute="leading" secondItem="EiT-Mj-1SZ" secondAttribute="leading" id="uCM-y7-M54"/>
</constraints>
</view>
<point key="canvasLocation" x="276.5" y="-15"/>
</window>
</objects>
</document>
@@ -0,0 +1,60 @@
{
"sourceLanguage" : "en",
"strings" : {
"k75-bg-mhK.title" : {
"comment" : "Class = \"NSButtonCell\"; title = \"Copy Contents\"; ObjectID = \"k75-bg-mhK\";",
"extractionState" : "extracted_with_value",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "Copy Contents"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Copiar contenido"
}
}
}
},
"lKl-03-8bv.title" : {
"comment" : "Class = \"NSTextFieldCell\"; title = \"This log may contain feed URLs and other information you may not want to share publicly.\"; ObjectID = \"lKl-03-8bv\";",
"extractionState" : "extracted_with_value",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "This log may contain feed URLs and other information you may not want to share publicly."
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Este registro puede contener URL de fuentes y otra información que quizás no quieras compartir públicamente."
}
}
}
},
"QvC-M9-y7g.title" : {
"comment" : "Class = \"NSWindow\"; title = \"Activity Log\"; ObjectID = \"QvC-M9-y7g\";",
"extractionState" : "extracted_with_value",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "Activity Log"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Registro de actividad"
}
}
}
}
},
"version" : "1.2"
}
+1 -4
View File
@@ -34,7 +34,7 @@
"comment" : "Activity window Activity column"
},
"Activity Log" : {
"comment" : "Activity Log button\nActivity Log window title"
"comment" : "Activity Log button"
},
"Add Account" : {
@@ -719,9 +719,6 @@
"There is already an account of this type with that username created." : {
"comment" : "Duplicate Error"
},
"This log may contain feed URLs and other information you may not want to share publicly." : {
"comment" : "Activity log privacy warning"
},
"This may take several minutes." : {
"comment" : "Clean up confirmation suffix"
},