Add Copy Value command

This commit is contained in:
Shadowfacts 2020-08-12 18:49:56 -04:00
parent 5ae526934c
commit e40e8d662f
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 38 additions and 4 deletions

View File

@ -230,4 +230,13 @@ extension Node {
return "MaxKey"
}
}
var isValueCopyable: Bool {
switch value {
case .document(_), .array(_), .binary(_), .minKey, .maxKey:
return false
default:
return true
}
}
}

View File

@ -138,6 +138,14 @@ class QueryViewController: NSViewController {
}
}
private func nodeForCopying() -> Node? {
if outlineView.clickedRow >= 0 {
return outlineView.item(atRow: outlineView.clickedRow) as? Node
} else {
return outlineView.item(atRow: outlineView.selectedRow) as? Node
}
}
@objc func outlineCellDoubleClicked() {
if let item = outlineView.item(atRow: outlineView.clickedRow) {
if outlineView.isItemExpanded(item) {
@ -171,6 +179,13 @@ class QueryViewController: NSViewController {
}
wc.showWindow(nil)
}
@IBAction func copy(_ sender: Any) {
guard let node = nodeForCopying() else { return }
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(node.valueString, forType: .string)
// todo: support copying more specific types?
}
}
extension QueryViewController: NSMenuItemValidation {
@ -181,6 +196,9 @@ extension QueryViewController: NSMenuItemValidation {
} else {
return false
}
} else if menuItem.action == #selector(copy(_:)) {
let node = nodeForCopying()
return node != nil && node!.isValueCopyable
}
return true
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="16096" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="16097" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16096"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16097"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
@ -1139,18 +1139,25 @@
</customView>
<menu id="nL5-kg-dty">
<items>
<menuItem title="Edit Document" id="0gS-XH-YDt">
<menuItem title="Edit Document" id="0gS-XH-YDt">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="editDocument:" target="-2" id="DP4-Tq-o5M"/>
</connections>
</menuItem>
<menuItem title="Delete" id="nn0-ZF-eDZ">
<menuItem isSeparatorItem="YES" id="xG5-Uo-1aO"/>
<menuItem title="Delete…" id="nn0-ZF-eDZ">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="deleteNode:" target="-2" id="dgm-SC-hn5"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="giL-0Q-HTl"/>
<menuItem title="Copy Value" keyEquivalent="c" id="UuQ-79-VL3">
<connections>
<action selector="copy:" target="-2" id="HsR-MZ-ayB"/>
</connections>
</menuItem>
</items>
<point key="canvasLocation" x="887" y="210"/>
</menu>