Stop using the builtin textField and imageView in the sidebar cell — this fixes the drag image issue. Fix #532.

This commit is contained in:
Brent Simmons 2019-02-09 18:54:16 -08:00
parent 1c2759dd2b
commit df768da253
2 changed files with 46 additions and 58 deletions

View File

@ -309,26 +309,6 @@
<tableCellView identifier="DataCell" id="HJn-Tm-YNO" customClass="SidebarCell" customModule="NetNewsWire" customModuleProvider="target">
<rect key="frame" x="1" y="17" width="164" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ocU-b4-EaY">
<rect key="frame" x="3" y="0.0" width="17" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" imageScaling="proportionallyUpOrDown" id="UzL-Uv-Vhz"/>
</imageView>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="fst-vi-Wue" userLabel="Text field">
<rect key="frame" x="25" y="0.0" width="120" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" allowsUndo="NO" sendsActionOnEndEditing="YES" title="Table View Cell" usesSingleLineMode="YES" id="axz-6y-tjw">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<connections>
<outlet property="imageView" destination="ocU-b4-EaY" id="bop-dt-qh2"/>
<outlet property="textField" destination="fst-vi-Wue" id="Az1-He-siv"/>
</connections>
</tableCellView>
</prototypeCellViews>
</tableColumn>

View File

@ -19,12 +19,12 @@ class SidebarCell : NSTableCellView {
var image: NSImage? {
didSet {
if let image = image {
imageView?.image = shouldShowImage ? image : nil
imageView?.alphaValue = image.isTemplate ? 0.75 : 1.0
faviconImageView.image = shouldShowImage ? image : nil
faviconImageView.alphaValue = image.isTemplate ? 0.75 : 1.0
}
else {
imageView?.image = nil
imageView?.alphaValue = 1.0
faviconImageView.image = nil
faviconImageView.alphaValue = 1.0
}
}
}
@ -34,11 +34,10 @@ class SidebarCell : NSTableCellView {
if shouldShowImage != oldValue {
needsLayout = true
}
imageView?.image = shouldShowImage ? image : nil
faviconImageView.image = shouldShowImage ? image : nil
}
}
private let unreadCountView = UnreadCountView(frame: NSZeroRect)
var cellAppearance: SidebarCellAppearance? {
didSet {
@ -63,14 +62,11 @@ class SidebarCell : NSTableCellView {
var name: String {
get {
if let s = textField?.stringValue {
return s
}
return ""
return titleView.stringValue
}
set {
if textField?.stringValue != newValue {
textField?.stringValue = newValue
if titleView.stringValue != newValue {
titleView.stringValue = newValue
needsDisplay = true
needsLayout = true
}
@ -81,50 +77,52 @@ class SidebarCell : NSTableCellView {
return objectValue as? Node
}
private let titleView: NSTextField = {
let textField = NSTextField(labelWithString: "")
textField.usesSingleLineMode = true
textField.maximumNumberOfLines = 1
textField.isEditable = false
textField.lineBreakMode = .byTruncatingTail
textField.allowsDefaultTighteningForTruncation = false
return textField
}()
private let faviconImageView: NSImageView = {
let image = AppImages.genericFeedImage
let imageView = image != nil ? NSImageView(image: image!) : NSImageView(frame: NSRect.zero)
imageView.animates = false
imageView.imageAlignment = .alignCenter
imageView.imageScaling = .scaleProportionallyDown
imageView.wantsLayer = true
return imageView
}()
private let unreadCountView = UnreadCountView(frame: NSZeroRect)
override var isFlipped: Bool {
return true
}
override var textField: NSTextField? {
didSet {
textField?.translatesAutoresizingMaskIntoConstraints = false
}
}
override var imageView: NSImageView? {
didSet {
imageView?.translatesAutoresizingMaskIntoConstraints = false
}
}
private func commonInit() {
unreadCountView.translatesAutoresizingMaskIntoConstraints = false
addSubview(unreadCountView)
}
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
commonInit()
}
required init?(coder: NSCoder) {
required init?(coder: NSCoder) {
super.init(coder: coder)
commonInit()
}
override func layout() {
resizeSubviews(withOldSize: NSZeroSize)
}
override func resizeSubviews(withOldSize oldSize: NSSize) {
guard let textField = textField, let cellAppearance = cellAppearance else {
guard let cellAppearance = cellAppearance else {
return
}
let layout = SidebarCellLayout(appearance: cellAppearance, cellSize: bounds.size, shouldShowImage: shouldShowImage, textField: textField, unreadCountView: unreadCountView)
let layout = SidebarCellLayout(appearance: cellAppearance, cellSize: bounds.size, shouldShowImage: shouldShowImage, textField: titleView, unreadCountView: unreadCountView)
layoutWith(layout)
}
@ -136,14 +134,24 @@ class SidebarCell : NSTableCellView {
return name
}
}
}
private extension SidebarCell {
func commonInit() {
addSubviewAtInit(unreadCountView)
addSubviewAtInit(faviconImageView)
addSubviewAtInit(titleView)
}
func addSubviewAtInit(_ view: NSView) {
addSubview(view)
view.translatesAutoresizingMaskIntoConstraints = false
}
func layoutWith(_ layout: SidebarCellLayout) {
imageView?.rs_setFrameIfNotEqual(layout.faviconRect)
textField?.rs_setFrameIfNotEqual(layout.titleRect)
faviconImageView.rs_setFrameIfNotEqual(layout.faviconRect)
titleView.rs_setFrameIfNotEqual(layout.titleRect)
unreadCountView.rs_setFrameIfNotEqual(layout.unreadCountRect)
}
}