Stop using the builtin textField and imageView in the sidebar cell — this fixes the drag image issue. Fix #532.
This commit is contained in:
parent
1c2759dd2b
commit
df768da253
|
@ -309,26 +309,6 @@
|
||||||
<tableCellView identifier="DataCell" id="HJn-Tm-YNO" customClass="SidebarCell" customModule="NetNewsWire" customModuleProvider="target">
|
<tableCellView identifier="DataCell" id="HJn-Tm-YNO" customClass="SidebarCell" customModule="NetNewsWire" customModuleProvider="target">
|
||||||
<rect key="frame" x="1" y="17" width="164" height="17"/>
|
<rect key="frame" x="1" y="17" width="164" height="17"/>
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<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>
|
</tableCellView>
|
||||||
</prototypeCellViews>
|
</prototypeCellViews>
|
||||||
</tableColumn>
|
</tableColumn>
|
||||||
|
|
|
@ -19,12 +19,12 @@ class SidebarCell : NSTableCellView {
|
||||||
var image: NSImage? {
|
var image: NSImage? {
|
||||||
didSet {
|
didSet {
|
||||||
if let image = image {
|
if let image = image {
|
||||||
imageView?.image = shouldShowImage ? image : nil
|
faviconImageView.image = shouldShowImage ? image : nil
|
||||||
imageView?.alphaValue = image.isTemplate ? 0.75 : 1.0
|
faviconImageView.alphaValue = image.isTemplate ? 0.75 : 1.0
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
imageView?.image = nil
|
faviconImageView.image = nil
|
||||||
imageView?.alphaValue = 1.0
|
faviconImageView.alphaValue = 1.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,11 +34,10 @@ class SidebarCell : NSTableCellView {
|
||||||
if shouldShowImage != oldValue {
|
if shouldShowImage != oldValue {
|
||||||
needsLayout = true
|
needsLayout = true
|
||||||
}
|
}
|
||||||
imageView?.image = shouldShowImage ? image : nil
|
faviconImageView.image = shouldShowImage ? image : nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private let unreadCountView = UnreadCountView(frame: NSZeroRect)
|
|
||||||
|
|
||||||
var cellAppearance: SidebarCellAppearance? {
|
var cellAppearance: SidebarCellAppearance? {
|
||||||
didSet {
|
didSet {
|
||||||
|
@ -63,14 +62,11 @@ class SidebarCell : NSTableCellView {
|
||||||
|
|
||||||
var name: String {
|
var name: String {
|
||||||
get {
|
get {
|
||||||
if let s = textField?.stringValue {
|
return titleView.stringValue
|
||||||
return s
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
if textField?.stringValue != newValue {
|
if titleView.stringValue != newValue {
|
||||||
textField?.stringValue = newValue
|
titleView.stringValue = newValue
|
||||||
needsDisplay = true
|
needsDisplay = true
|
||||||
needsLayout = true
|
needsLayout = true
|
||||||
}
|
}
|
||||||
|
@ -81,50 +77,52 @@ class SidebarCell : NSTableCellView {
|
||||||
return objectValue as? Node
|
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 {
|
override var isFlipped: Bool {
|
||||||
return true
|
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) {
|
override init(frame frameRect: NSRect) {
|
||||||
|
|
||||||
super.init(frame: frameRect)
|
super.init(frame: frameRect)
|
||||||
commonInit()
|
commonInit()
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder: NSCoder) {
|
||||||
|
|
||||||
super.init(coder: coder)
|
super.init(coder: coder)
|
||||||
commonInit()
|
commonInit()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func layout() {
|
override func layout() {
|
||||||
|
|
||||||
resizeSubviews(withOldSize: NSZeroSize)
|
resizeSubviews(withOldSize: NSZeroSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func resizeSubviews(withOldSize oldSize: NSSize) {
|
override func resizeSubviews(withOldSize oldSize: NSSize) {
|
||||||
|
|
||||||
guard let textField = textField, let cellAppearance = cellAppearance else {
|
guard let cellAppearance = cellAppearance else {
|
||||||
return
|
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)
|
layoutWith(layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,14 +134,24 @@ class SidebarCell : NSTableCellView {
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension SidebarCell {
|
private extension SidebarCell {
|
||||||
|
|
||||||
|
func commonInit() {
|
||||||
|
addSubviewAtInit(unreadCountView)
|
||||||
|
addSubviewAtInit(faviconImageView)
|
||||||
|
addSubviewAtInit(titleView)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addSubviewAtInit(_ view: NSView) {
|
||||||
|
addSubview(view)
|
||||||
|
view.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
}
|
||||||
|
|
||||||
func layoutWith(_ layout: SidebarCellLayout) {
|
func layoutWith(_ layout: SidebarCellLayout) {
|
||||||
imageView?.rs_setFrameIfNotEqual(layout.faviconRect)
|
faviconImageView.rs_setFrameIfNotEqual(layout.faviconRect)
|
||||||
textField?.rs_setFrameIfNotEqual(layout.titleRect)
|
titleView.rs_setFrameIfNotEqual(layout.titleRect)
|
||||||
unreadCountView.rs_setFrameIfNotEqual(layout.unreadCountRect)
|
unreadCountView.rs_setFrameIfNotEqual(layout.unreadCountRect)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue