Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 48 additions & 53 deletions Clipy/Sources/Managers/MenuManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3004,11 +3004,27 @@ final class BoardManHeaderSegmentedControl: NSSegmentedControl {
setHoveredSegment(-1)
return
}
let segmentWidth = bounds.width / CGFloat(segmentCount)
let index = min(segmentCount - 1, max(0, Int(point.x / segmentWidth)))
let index = (0..<segmentCount).first { segmentFrame(for: $0)?.contains(point) == true } ?? -1
setHoveredSegment(index)
}

func hoverBackgroundRect(forSegment segment: Int) -> NSRect? {
guard let segmentRect = segmentFrame(for: segment) else { return nil }
return NSIntegralRect(segmentRect.insetBy(dx: 2, dy: 3))
}

private func segmentFrame(for segment: Int) -> NSRect? {
guard segment >= 0, segment < segmentCount, bounds.width > 0 else { return nil }
let configuredWidths = (0..<segmentCount).map { max(0, width(forSegment: $0)) }
let configuredTotal = configuredWidths.reduce(0, +)
let widths = configuredTotal > 0
? configuredWidths.map { bounds.width * ($0 / configuredTotal) }
: Array(repeating: bounds.width / CGFloat(segmentCount), count: segmentCount)
let minX = bounds.minX + widths.prefix(segment).reduce(0, +)
let maxX = segment == segmentCount - 1 ? bounds.maxX : minX + widths[segment]
return NSRect(x: minX, y: bounds.minY, width: max(0, maxX - minX), height: bounds.height)
}

private func setHoveredSegment(_ value: Int) {
guard hoveredSegment != value else { return }
hoveredSegment = value
Expand All @@ -3017,28 +3033,14 @@ final class BoardManHeaderSegmentedControl: NSSegmentedControl {

override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
guard hoveredSegment >= 0, hoveredSegment < segmentCount, segmentCount > 0 else { return }

let segmentWidth = bounds.width / CGFloat(segmentCount)
let minX = floor(CGFloat(hoveredSegment) * segmentWidth) + 2
let maxX = min(bounds.maxX - 2, floor(CGFloat(hoveredSegment + 1) * segmentWidth) - 2)
let hoverRect = NSRect(
x: minX,
y: 3,
width: max(0, maxX - minX),
height: max(0, bounds.height - 6)
)
guard let hoverRect = hoverBackgroundRect(forSegment: hoveredSegment) else { return }

let isSelected = hoveredSegment == selectedSegment
let path = NSBezierPath(roundedRect: hoverRect, xRadius: 8, yRadius: 8)
(isSelected
? NSColor.selectedControlTextColor.withAlphaComponent(0.12)
: NSColor.labelColor.withAlphaComponent(0.10)).setFill()
? NSColor.selectedControlTextColor.withAlphaComponent(0.10)
: NSColor.labelColor.withAlphaComponent(0.08)).setFill()
path.fill()
(isSelected
? NSColor.selectedControlTextColor.withAlphaComponent(0.36)
: NSColor.labelColor.withAlphaComponent(0.28)).setStroke()
path.lineWidth = 1
path.stroke()
}
}

Expand Down Expand Up @@ -3118,31 +3120,6 @@ final class BoardManCenteredSearchFieldCell: NSSearchFieldCell {
return verticallyCentered(original, height: original.height)
}

override func edit(withFrame aRect: NSRect,
in controlView: NSView,
editor textObj: NSText,
delegate: Any?,
event: NSEvent?) {
super.edit(withFrame: searchTextRect(forBounds: aRect),
in: controlView,
editor: textObj,
delegate: delegate,
event: event)
}

override func select(withFrame aRect: NSRect,
in controlView: NSView,
editor textObj: NSText,
delegate: Any?,
start selStart: Int,
length selLength: Int) {
super.select(withFrame: searchTextRect(forBounds: aRect),
in: controlView,
editor: textObj,
delegate: delegate,
start: selStart,
length: selLength)
}
}

final class BoardManHistoryCellView: NSTableCellView {
Expand Down Expand Up @@ -5709,6 +5686,7 @@ class BoardManPanel: NSPanel {
snippetAddButton = addSnippet

let editSnippet = NSButton(title: boardManText("Edit Mode"), target: self, action: #selector(editSelectedSnippetFromPanel(_:)))
editSnippet.identifier = NSUserInterfaceItemIdentifier("BoardManSnippetEditButton")
editSnippet.font = NSFont.systemFont(ofSize: 11)
editSnippet.bezelStyle = .rounded
editSnippet.isHidden = true
Expand Down Expand Up @@ -5790,6 +5768,9 @@ class BoardManPanel: NSPanel {
let editorTitle = NSTextField(frame: .zero)
editorTitle.cell = BoardManCenteredTextFieldCell(textCell: "")
editorTitle.font = NSFont.systemFont(ofSize: 12)
editorTitle.textColor = .textColor
editorTitle.backgroundColor = .textBackgroundColor
editorTitle.drawsBackground = true
editorTitle.placeholderString = boardManText("Untitled snippet")
editorTitle.identifier = NSUserInterfaceItemIdentifier("BoardManSnippetEditorTitleField")
editorTitle.target = self
Expand All @@ -5805,11 +5786,20 @@ class BoardManPanel: NSPanel {
snippetEditorContentLabel = editorContentLabel

let editorScroll = NSScrollView(frame: .zero)
editorScroll.identifier = NSUserInterfaceItemIdentifier("BoardManSnippetEditorScrollView")
editorScroll.hasVerticalScroller = true
editorScroll.borderType = .bezelBorder
editorScroll.autohidesScrollers = true
editorScroll.drawsBackground = true
editorScroll.backgroundColor = .textBackgroundColor
let editorText = NSTextView(frame: .zero)
editorText.identifier = NSUserInterfaceItemIdentifier("BoardManSnippetEditorTextView")
editorText.font = NSFont.systemFont(ofSize: 12)
editorText.textColor = .textColor
editorText.backgroundColor = .textBackgroundColor
editorText.insertionPointColor = .textColor
editorText.drawsBackground = true
editorText.textContainerInset = NSSize(width: 8, height: 8)
editorText.isRichText = false
editorText.isAutomaticQuoteSubstitutionEnabled = false
editorText.enabledTextCheckingTypes = 0
Expand Down Expand Up @@ -7225,6 +7215,14 @@ class BoardManPanel: NSPanel {
}

#if DEBUG
func loadItemsForTesting(_ items: [BoardManHistoryItem]) {
reloadHistoryItems(items)
}

func selectItemForTesting(at index: Int) {
setSelectedIndex(index)
}

fileprivate func prepareReadmeScreenshot(scene: String, width: CGFloat?, height: CGFloat?) {
var targetFrame = frame
if let width {
Expand Down Expand Up @@ -7886,11 +7884,11 @@ class BoardManPanel: NSPanel {
snippetEnableButton?.state = snippet.enable ? .on : .off
snippetFolderEnableButton?.state = (folder?.enable ?? false) ? .on : .off
}
let canEditTitleDirectly = !isSnippetReorderMode
snippetEditorTitleField?.isEnabled = canEditTitleDirectly
snippetEditorTitleField?.isEditable = canEditTitleDirectly
snippetEditorTitleField?.isSelectable = canEditTitleDirectly
snippetEditorTextView?.isEditable = isEditingSelection
let canEditSelection = isEditingSelection && !isSnippetReorderMode
snippetEditorTitleField?.isEnabled = !isSnippetReorderMode
snippetEditorTitleField?.isEditable = canEditSelection
snippetEditorTitleField?.isSelectable = canEditSelection
snippetEditorTextView?.isEditable = canEditSelection
snippetEditorTextView?.isSelectable = true

if isEditingSelection {
Expand Down Expand Up @@ -8128,8 +8126,6 @@ class BoardManPanel: NSPanel {
editingSnippetIdentifier = item.dataHash
NSHapticFeedbackManager.defaultPerformer.perform(.alignment, performanceTime: .now)
updateSnippetActionButtons()
makeFirstResponder(snippetEditorTitleField)
snippetEditorTitleField?.selectText(nil)
}

@objc private func cancelSnippetEditing(_ sender: Any?) {
Expand Down Expand Up @@ -8915,7 +8911,6 @@ class BoardManPanel: NSPanel {
self.applyCurrentFilter()
}
DispatchQueue.main.async {
alert.window.level = .floating
alert.window.makeFirstResponder(includedField)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="date" id="nG5-PB-zcE">
<dateFormatter key="formatter" dateStyle="full" timeStyle="medium" id="uhI-da-0iN"/>
<font key="font" metaFont="smallSystem"/>
<color key="textColor" red="0.26666666666666666" green="0.26666666666666666" blue="0.26666666666666666" alpha="1" colorSpace="calibratedRGB"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
Expand Down Expand Up @@ -75,7 +75,7 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="v1.0.0" id="hhl-AS-dQ0">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" red="0.26666666666666666" green="0.26666666666666666" blue="0.26666666666666666" alpha="0.84999999999999998" colorSpace="calibratedRGB"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
Expand Down
Loading
Loading