1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/*
import Foundation
class LiquidGlassBezelObjectCell: QSObjectCell {
override func preferredImagePosition() -> NSControl.ImagePosition {
return .imageAbove
}
override func draw(withFrame cellFrame: NSRect, in controlView: NSView?) {
if let controlView {
let isFirstResponder = controlView.window?.firstResponder == controlView && !(controlView is NSTableView)
let dropTarget = isHighlighted && ((highlightsBy.rawValue & NSCell.StyleMask.changeBackgroundCellMask.rawValue) != 0) && !isBezeled
var fillColor: NSColor?
let strokeColor = NSColor.clear
if isFirstResponder {
fillColor = self.highlightColor()
} else {
fillColor = self.backgroundColor
}
if dropTarget {
fillColor = NSColor(red: 0.77, green: 0.91, blue: 0.96, alpha: 1)
}
fillColor?.setFill()
strokeColor.setStroke()
let roundRect = NSBezierPath()
roundRect.append(withRoundedRectangle: cellFrame, withRadius: cellRadiusFactor())
roundRect.fill()
drawInterior(withFrame: drawingRect(forBounds: cellFrame), in: controlView)
}
}
override func titleRect(forBounds _rect: NSRect) -> NSRect {
var rect = _rect
rect = NSOffsetRect(rect, 0, -4)
return super.titleRect(forBounds: rect)
}
override func drawText(for drawObject: QSObject!, withFrame cellFrame: NSRect, in controlView: NSView!) {
if imagePosition == .imageOnly {
return
}
var abbrString: String? = nil
if controlView.responds(to: #selector(QSSearchObjectView.matchedString)) {
abbrString = (controlView as! QSSearchObjectView).matchedString()
}
var nameString: String? = nil
var hitMask: NSIndexSet? = nil
let ranker = drawObject.ranker()
if ranker != nil && abbrString != nil {
nameString = ranker?.matchedString(forAbbreviation: abbrString, hitmask: &hitMask, inContext: nil)
}
if (nameString == nil) {
nameString = drawObject.displayName()
}
let rankedStringIsName = nameString == drawObject.displayName() || nameString == nil
if nameString == nil {
nameString = drawObject.identifier() ?? "Unknown"
}
let useAlternateColor = controlView is NSTableView && (controlView as! NSTableView).isRowSelected((controlView as! NSTableView).row(at: cellFrame.origin))
let mainColor = textColor() ?? (useAlternateColor ? .alternateSelectedControlTextColor : .controlTextColor)
let fadedColor = mainColor.withAlphaComponent(0.50)
let textDrawRect = titleRect(forBounds: cellFrame)
let titleString = NSMutableAttributedString(string: nameString!)
let nameAttributes = (value(forKey: "nameAttributes") as? [NSAttributedString.Key : Any])
let detailsAttributes = (value(forKey: "detailsAttributes") as? [NSAttributedString.Key : Any])
titleString.setAttributes(rankedStringIsName ? nameAttributes : detailsAttributes, range: NSMakeRange(0, titleString.length))
if abbrString != nil && abbrString!.hasPrefix("QSActionMnemonic") {
titleString.addAttribute(.foregroundColor, value: rankedStringIsName ? fadedColor : fadedColor.withAlphaComponent(0.8), range: NSMakeRange(0, titleString.length))
var hits: Int = 0
let count = hitMask?.getIndexes(&hits, maxCount: titleString.length, inIndexRange: nil)
for i in 0..<(count ?? 0) {
for j in 1.. {
}
}
}
}
NSUInteger i = 0;
NSUInteger j = 0;
NSUInteger hits[[titleString length]];
NSUInteger count = [hitMask getIndexes:(NSUInteger *)&hits maxCount:[titleString length] inIndexRange:nil];
NSDictionary *attributes = @{
NSForegroundColorAttributeName: rankedStringIsName ? mainColor : fadedColor
};
for(i = 0; i<count; i += j) {
for (j = 1; i+j<count && hits[i+j-1] +1 == hits[i+j]; j++);
[titleString addAttributes:attributes range:NSMakeRange(hits[i], j)];
}
} else {
[titleString addAttribute:NSBaselineOffsetAttributeName value:[NSNumber numberWithDouble:-1.0] range:NSMakeRange(0, [titleString length])];
}
if (showDetails) {
NSString *detailsString = [drawObject details];
NSRange returnRange = [detailsString rangeOfString:@"\n"];
if (returnRange.location != NSNotFound) {
detailsString = [detailsString substringToIndex:returnRange.location];
}
detailsAttributes = [detailsAttributes mutableCopy];
[detailsAttributes setValue:[NSColor grayColor] forKey:NSForegroundColorAttributeName];
if (detailsString && detailsString.length && ![detailsString isEqualToString:nameString]) {
[titleString appendAttributedString:[[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"\n%@",detailsString] attributes:detailsAttributes] autorelease]];
}
}
NSRect centerRect = rectFromSize([titleString size]);
centerRect.size.width = NSWidth(textDrawRect);
centerRect.size.height = MIN(NSHeight(textDrawRect), centerRect.size.height);
[titleString drawInRect:centerRectInRect(centerRect, textDrawRect)];
}
- (void)drawSearchPlaceholderWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
NSString *defaultText = NSLocalizedStringWithDefaultValue(@"Type to search", nil, [NSBundle mainBundle], @"Type to search", @"Hint that appears in the first pane of the QS interface when it's empty.");
NSSize textSize = [defaultText sizeWithAttributes:nameAttributes];
NSRect textRect = centerRectInRect(rectFromSize(textSize), cellFrame);
BOOL isFirstResponder = [[controlView window] firstResponder] == controlView && ![controlView isKindOfClass:[NSTableView class]];
if (isFirstResponder && [controlView isKindOfClass:[QSSearchObjectView class]]) {
NSImage *find = [NSImage imageWithSystemSymbolName:@"magnifyingglass.circle.fill" accessibilityDescription:nil];
[find setSize:QSSize16];
NSRect findImageRect = expelRectFromRectOnEdge(centerRectInRect(rectFromSize([find size]), cellFrame), textRect, NSRectEdgeMinX, -2);
NSGraphicsContext *graphicsContext = [NSGraphicsContext currentContext];
[graphicsContext saveGraphicsState];
CGContextRef context = [graphicsContext CGContext];
CGContextBeginTransparencyLayerWithRect(context, findImageRect, nil);
CGContextSetBlendMode(context, kCGBlendModeNormal);
[find drawInRect:findImageRect fromRect:rectFromSize([find size]) operation:NSCompositingOperationSourceOver fraction:1];
CGContextSetBlendMode(context, kCGBlendModeSourceIn);
CGContextSetFillColorWithColor(context, [[NSColor textColor] CGColor]);
CGContextFillRect(context, findImageRect);
CGContextEndTransparencyLayer(context);
[defaultText drawInRect:textRect withAttributes:nameAttributes];
}
}
@end
*/
|