Prevent nodes from collapsing when refreshing

This commit is contained in:
Shadowfacts 2020-04-01 21:42:32 -04:00
parent 3e46c06ba8
commit 3a8088033a
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 19 additions and 3 deletions

View File

@ -224,7 +224,7 @@
isa = PBXProject; isa = PBXProject;
attributes = { attributes = {
LastSwiftUpdateCheck = 1130; LastSwiftUpdateCheck = 1130;
LastUpgradeCheck = 1130; LastUpgradeCheck = 1140;
ORGANIZATIONNAME = Shadowfacts; ORGANIZATIONNAME = Shadowfacts;
TargetAttributes = { TargetAttributes = {
D63CDEB923C837DC0012D658 = { D63CDEB923C837DC0012D658 = {
@ -418,6 +418,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = MongoView/MongoView.entitlements; CODE_SIGN_ENTITLEMENTS = MongoView/MongoView.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3; CURRENT_PROJECT_VERSION = 3;
@ -439,6 +440,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = MongoView/MongoView.entitlements; CODE_SIGN_ENTITLEMENTS = MongoView/MongoView.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3; CURRENT_PROJECT_VERSION = 3;

View File

@ -9,7 +9,9 @@
import Foundation import Foundation
import MongoSwift import MongoSwift
class Node { // Node needs to be an NSObject, since NSOutlineView uses NSObject.isEqual(_:) and NSObject.hash to determine item equality
// which is necessary to prevent items from collapsing when refreshing the view
class Node: NSObject {
let key: Key? let key: Key?
let value: BSON let value: BSON
weak var parent: Node? weak var parent: Node?
@ -57,10 +59,22 @@ class Node {
self.init(key: nil, value: .document(document)) self.init(key: nil, value: .document(document))
} }
} }
override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? Node else { return false }
return self.parent == object.parent && self.key == object.key
}
override var hash: Int {
var hasher = Hasher()
hasher.combine(parent)
hasher.combine(key)
return hasher.finalize()
}
} }
extension Node { extension Node {
enum Key { enum Key: Equatable, Hashable {
case index(Int) case index(Int)
case name(String) case name(String)
case objectId(ObjectId) case objectId(ObjectId)