From 954b0bc8a6c569494c073027895082198d70b932 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 12 Jan 2020 11:05:01 -0500 Subject: [PATCH] Add type column to query results outline view --- MongoView/Node.swift | 64 +++++++++++++++++++ .../QueryViewController.swift | 7 ++ .../View Controllers/QueryViewController.xib | 47 ++++++++++++-- 3 files changed, 111 insertions(+), 7 deletions(-) diff --git a/MongoView/Node.swift b/MongoView/Node.swift index c42c487..875267c 100644 --- a/MongoView/Node.swift +++ b/MongoView/Node.swift @@ -143,4 +143,68 @@ extension Node { return "(max key)" } } + + var typeString: String { + switch value { + case .double(_): + return "Double" + case .string(_): + return "String" + case .document(_): + return "Document" + case .array(_): + return "Array" + case let .binary(value): + switch Binary.Subtype(rawValue: value.subtype) { + case nil: + return "Unknown binary data" + case .generic: + return "Generic binary data" + case .function: + return "Function binary data" + case .binaryDeprecated: + return "Binary data" + case .uuidDeprecated: + fallthrough + case .uuid: + return "UUID" + case .md5: + return "MD5 hash" + case .userDefined: + return "User defined binary data" + } + case .undefined: + return "Undefined" + case .objectId(_): + return "ObjectId" + case .bool(_): + return "Bool" + case .datetime(_): + return "DateTime" + case .null: + return "Null" + case .regex(_): + return "RegEx" + case .dbPointer(_): + return "DBRef" + case .symbol(_): + return "Symbol" + case .code(_): + return "Code" + case .codeWithScope(_): + return "Code with scope" + case .int32(_): + return "Int32" + case .timestamp(_): + return "Timestamp" + case .int64(_): + return "Int64" + case .decimal128(_): + return "Decimal128" + case .minKey: + return "MinKey" + case .maxKey: + return "MaxKey" + } + } } diff --git a/MongoView/View Controllers/QueryViewController.swift b/MongoView/View Controllers/QueryViewController.swift index 7517169..1201673 100644 --- a/MongoView/View Controllers/QueryViewController.swift +++ b/MongoView/View Controllers/QueryViewController.swift @@ -154,6 +154,11 @@ extension QueryViewController: NSOutlineViewDelegate { cell.textField!.stringValue = node.valueString cell.textField!.isEditable = false return cell + } else if tableColumn.identifier == .valueTypeColumn { + let cell = outlineView.makeView(withIdentifier: .valueTypeCell, owner: nil) as! NSTableCellView + cell.textField!.stringValue = node.typeString + cell.textField!.isEditable = false + return cell } else { return nil } @@ -166,4 +171,6 @@ extension NSUserInterfaceItemIdentifier { static let fieldValueColumn = NSUserInterfaceItemIdentifier(rawValue: "FieldValueCol") static let fieldNameCell = NSUserInterfaceItemIdentifier(rawValue: "FieldNameCell") static let fieldValueCell = NSUserInterfaceItemIdentifier(rawValue: "FieldValueCell") + static let valueTypeColumn = NSUserInterfaceItemIdentifier(rawValue: "ValueTypeCol") + static let valueTypeCell = NSUserInterfaceItemIdentifier(rawValue: "ValueTypeCell") } diff --git a/MongoView/View Controllers/QueryViewController.xib b/MongoView/View Controllers/QueryViewController.xib index a26f4ba..ce3985f 100644 --- a/MongoView/View Controllers/QueryViewController.xib +++ b/MongoView/View Controllers/QueryViewController.xib @@ -44,7 +44,7 @@ - + eu @@ -1004,7 +1004,7 @@ - + @@ -1018,11 +1018,11 @@ - + - + @@ -1037,7 +1037,7 @@ - + @@ -1051,11 +1051,11 @@ - + - + @@ -1070,6 +1070,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +