Disable inline editing in the sidebar. Fix #156.

This commit is contained in:
Brent Simmons 2018-12-14 19:10:03 -08:00
parent 379126b701
commit b891341ea6
2 changed files with 1 additions and 30 deletions

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS"> <document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies> <dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
@ -319,14 +318,11 @@
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="fst-vi-Wue" userLabel="Text field"> <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"/> <rect key="frame" x="25" y="0.0" width="120" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" title="Table View Cell" usesSingleLineMode="YES" id="axz-6y-tjw"> <textFieldCell key="cell" lineBreakMode="truncatingTail" allowsUndo="NO" sendsActionOnEndEditing="YES" title="Table View Cell" usesSingleLineMode="YES" id="axz-6y-tjw">
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/> <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell> </textFieldCell>
<connections>
<action selector="editingEnded:" target="HJn-Tm-YNO" id="dGd-n1-zvp"/>
</connections>
</textField> </textField>
</subviews> </subviews>
<connections> <connections>

View File

@ -16,12 +16,6 @@ private var textSizeCache = [String: NSSize]()
class SidebarCell : NSTableCellView { class SidebarCell : NSTableCellView {
override var objectValue: Any? {
didSet {
didSetObjectValue()
}
}
var image: NSImage? { var image: NSImage? {
didSet { didSet {
if let image = image { if let image = image {
@ -94,7 +88,6 @@ class SidebarCell : NSTableCellView {
override var textField: NSTextField? { override var textField: NSTextField? {
didSet { didSet {
textField?.translatesAutoresizingMaskIntoConstraints = false textField?.translatesAutoresizingMaskIntoConstraints = false
updateTextFieldIsEditable()
} }
} }
@ -134,12 +127,6 @@ class SidebarCell : NSTableCellView {
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: textField, unreadCountView: unreadCountView)
layoutWith(layout) layoutWith(layout)
} }
@IBAction func editingEnded(_ sender: NSTextField) {
if let renamableItem = node?.representedObject as? Renamable {
renamableItem.rename(to: sender.stringValue)
}
}
} }
private extension SidebarCell { private extension SidebarCell {
@ -149,17 +136,5 @@ private extension SidebarCell {
textField?.rs_setFrameIfNotEqual(layout.titleRect) textField?.rs_setFrameIfNotEqual(layout.titleRect)
unreadCountView.rs_setFrameIfNotEqual(layout.unreadCountRect) unreadCountView.rs_setFrameIfNotEqual(layout.unreadCountRect)
} }
func didSetObjectValue() {
updateTextFieldIsEditable()
}
func updateTextFieldIsEditable() {
var canRename = false
if let _ = node?.representedObject as? Renamable {
canRename = true
}
textField?.isEditable = canRename
}
} }