Add Copy Value as JSON
This commit is contained in:
parent
c96e093c72
commit
8e71077070
|
@ -195,6 +195,16 @@ class QueryViewController: NSViewController {
|
|||
NSPasteboard.general.setString(node.valueString, forType: .string)
|
||||
// todo: support copying more specific types?
|
||||
}
|
||||
|
||||
@IBAction func copyAsJSON(_ sender: Any) {
|
||||
guard let node = nodeForCopying() else { return }
|
||||
let doc: BSONDocument = ["value": node.value]
|
||||
let ext = doc.toExtendedJSONString()
|
||||
// toExtendedJSON returns `{ "value": <whatever> }`, drop the object wrapper
|
||||
let str = String(ext.dropFirst(12).dropLast(2))
|
||||
NSPasteboard.general.clearContents()
|
||||
NSPasteboard.general.setString(str, forType: .string)
|
||||
}
|
||||
}
|
||||
|
||||
extension QueryViewController: NSMenuItemValidation {
|
||||
|
@ -205,7 +215,7 @@ extension QueryViewController: NSMenuItemValidation {
|
|||
} else {
|
||||
return false
|
||||
}
|
||||
} else if menuItem.action == #selector(copy(_:)) {
|
||||
} else if menuItem.action == #selector(copy(_:)) || menuItem.action == #selector(copyAsJSON(_:)) {
|
||||
let node = nodeForCopying()
|
||||
return node != nil && node!.isValueCopyable
|
||||
}
|
||||
|
|
|
@ -1158,6 +1158,12 @@
|
|||
<action selector="copy:" target="-2" id="HsR-MZ-ayB"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Copy Value as JSON" id="5lo-Mc-kwv">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="copyAsJSON:" target="-2" id="rb1-6U-LO5"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
<point key="canvasLocation" x="887" y="210"/>
|
||||
</menu>
|
||||
|
|
Loading…
Reference in New Issue