Enable previous/next search in debug log

This commit is contained in:
Davide De Rosa 2021-04-10 09:43:35 +02:00
parent 762e0d2c05
commit 6e0a46a24c
2 changed files with 30 additions and 23 deletions

View File

@ -119,7 +119,7 @@
<rect key="frame" x="0.0" y="0.0" width="550" height="20"/>
<subviews>
<button horizontalHuggingPriority="249" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="UTb-MT-GBZ">
<rect key="frame" x="-2" y="1" width="472" height="18"/>
<rect key="frame" x="-2" y="1" width="63" height="18"/>
<buttonCell key="cell" type="check" title="MASK" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="fr1-Ae-OKs">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
@ -128,8 +128,8 @@
<action selector="toggleMasking:" target="ATy-TE-Vs0" id="Z26-Ah-yif"/>
</connections>
</button>
<button hidden="YES" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="m2Y-4s-bVk">
<rect key="frame" x="-7" y="-7" width="102" height="32"/>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="m2Y-4s-bVk">
<rect key="frame" x="277" y="-7" width="102" height="32"/>
<buttonCell key="cell" type="push" title="&lt;previous&gt;" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="R4S-an-c68">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
@ -138,8 +138,8 @@
<action selector="previousSession:" target="ATy-TE-Vs0" id="m7K-Cl-xrh"/>
</connections>
</button>
<button hidden="YES" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="rDF-K8-yFT">
<rect key="frame" x="91" y="-7" width="102" height="32"/>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="rDF-K8-yFT">
<rect key="frame" x="375" y="-7" width="102" height="32"/>
<buttonCell key="cell" type="push" title="&lt;next&gt;" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="8jk-bu-DVf">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
@ -160,15 +160,14 @@
</button>
</subviews>
<constraints>
<constraint firstItem="b8r-ZS-86k" firstAttribute="leading" secondItem="UTb-MT-GBZ" secondAttribute="trailing" constant="10" id="4Mc-du-HXN"/>
<constraint firstItem="b8r-ZS-86k" firstAttribute="top" secondItem="Ftb-C7-gDH" secondAttribute="top" id="9Nt-ab-quI"/>
<constraint firstAttribute="trailing" secondItem="b8r-ZS-86k" secondAttribute="trailing" id="FSb-cu-30n"/>
<constraint firstItem="b8r-ZS-86k" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="rDF-K8-yFT" secondAttribute="trailing" constant="10" id="VzN-CR-tTV"/>
<constraint firstItem="b8r-ZS-86k" firstAttribute="leading" secondItem="rDF-K8-yFT" secondAttribute="trailing" constant="10" id="VzN-CR-tTV"/>
<constraint firstItem="rDF-K8-yFT" firstAttribute="leading" secondItem="m2Y-4s-bVk" secondAttribute="trailing" constant="10" id="bZt-Ge-Quw"/>
<constraint firstItem="UTb-MT-GBZ" firstAttribute="centerY" secondItem="b8r-ZS-86k" secondAttribute="centerY" id="d10-KF-xsL"/>
<constraint firstItem="rDF-K8-yFT" firstAttribute="centerY" secondItem="m2Y-4s-bVk" secondAttribute="centerY" id="d7N-tX-8q2"/>
<constraint firstItem="m2Y-4s-bVk" firstAttribute="leading" secondItem="Ftb-C7-gDH" secondAttribute="leading" id="dJ0-CQ-DFG"/>
<constraint firstItem="m2Y-4s-bVk" firstAttribute="width" secondItem="rDF-K8-yFT" secondAttribute="width" id="e9W-zM-AiX"/>
<constraint firstItem="m2Y-4s-bVk" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="UTb-MT-GBZ" secondAttribute="trailing" constant="10" id="iqR-lF-x76"/>
<constraint firstItem="UTb-MT-GBZ" firstAttribute="leading" secondItem="Ftb-C7-gDH" secondAttribute="leading" id="ruL-eN-A7E"/>
<constraint firstAttribute="bottom" secondItem="b8r-ZS-86k" secondAttribute="bottom" id="svr-ck-SJm"/>
<constraint firstItem="m2Y-4s-bVk" firstAttribute="centerY" secondItem="b8r-ZS-86k" secondAttribute="centerY" id="ycP-XO-sOy"/>

View File

@ -66,15 +66,8 @@ class DebugLogViewController: NSViewController {
labelExchangedCaption.stringValue = L10n.Core.Service.Cells.DataCount.caption.asCaption
labelLog.stringValue = L10n.Core.Service.Cells.DebugLog.caption.asCaption
// scrollTextLog.scrollerStyle = .overlay
// scrollTextLog.autohidesScrollers = false
if #available(macOS 10.12.2, *) {
buttonPrevious.image = NSImage(named: NSImage.touchBarRewindTemplateName)
buttonNext.image = NSImage(named: NSImage.touchBarFastForwardTemplateName)
} else {
buttonPrevious.title = L10n.Core.DebugLog.Buttons.previous
buttonNext.title = L10n.Core.DebugLog.Buttons.next
}
buttonPrevious.image = NSImage(named: NSImage.touchBarRewindTemplateName)
buttonNext.image = NSImage(named: NSImage.touchBarFastForwardTemplateName)
buttonShare.image = NSImage(named: NSImage.shareTemplateName)
let nc = NotificationCenter.default
@ -136,15 +129,30 @@ class DebugLogViewController: NSViewController {
}
@IBAction private func previousSession(_ sender: Any?) {
// FIXME
// textFinderLog.performAction(.previousMatch)
// textLog.findPrevious(string: GroupConstants.Log.sessionMarker)
let visibleRow = firstVisibleRow()
let viewport = logLines[0..<visibleRow]
let row = viewport.lastIndex(of: Substring(GroupConstants.VPN.sessionMarker)) ?? 0
tableTextLog.scrollRowToVisible(row)
}
@IBAction private func nextSession(_ sender: Any?) {
// FIXME
// textFinderLog.performAction(.previousMatch)
// textLog.findNext(string: GroupConstants.Log.sessionMarker)
let visibleRow = lastVisibleRow()
guard visibleRow < logLines.count else {
return
}
let viewport = logLines[(visibleRow + 1)..<logLines.count]
let row = viewport.firstIndex(of: Substring(GroupConstants.VPN.sessionMarker)) ?? (logLines.count - 1)
tableTextLog.scrollRowToVisible(row)
}
private func firstVisibleRow() -> Int {
let range = tableTextLog.rows(in: tableTextLog.visibleRect)
return range.location
}
private func lastVisibleRow() -> Int {
let range = tableTextLog.rows(in: tableTextLog.visibleRect)
return range.location + range.length
}
private func startRefreshingLog() {