Browse Source

Prevent nodes from collapsing when refreshing

master
Shadowfacts 3 months ago
parent
commit
3a8088033a
Signed by: Shadowfacts <me@shadowfacts.net> GPG Key ID: 94A5AB95422746E5
2 changed files with 19 additions and 3 deletions
  1. 3
    1
      MongoView.xcodeproj/project.pbxproj
  2. 16
    2
      MongoView/Node.swift

+ 3
- 1
MongoView.xcodeproj/project.pbxproj View File

@@ -224,7 +224,7 @@
224 224
 			isa = PBXProject;
225 225
 			attributes = {
226 226
 				LastSwiftUpdateCheck = 1130;
227
-				LastUpgradeCheck = 1130;
227
+				LastUpgradeCheck = 1140;
228 228
 				ORGANIZATIONNAME = Shadowfacts;
229 229
 				TargetAttributes = {
230 230
 					D63CDEB923C837DC0012D658 = {
@@ -418,6 +418,7 @@
418 418
 			buildSettings = {
419 419
 				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
420 420
 				CODE_SIGN_ENTITLEMENTS = MongoView/MongoView.entitlements;
421
+				CODE_SIGN_IDENTITY = "Apple Development";
421 422
 				CODE_SIGN_STYLE = Automatic;
422 423
 				COMBINE_HIDPI_IMAGES = YES;
423 424
 				CURRENT_PROJECT_VERSION = 3;
@@ -439,6 +440,7 @@
439 440
 			buildSettings = {
440 441
 				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
441 442
 				CODE_SIGN_ENTITLEMENTS = MongoView/MongoView.entitlements;
443
+				CODE_SIGN_IDENTITY = "Apple Development";
442 444
 				CODE_SIGN_STYLE = Automatic;
443 445
 				COMBINE_HIDPI_IMAGES = YES;
444 446
 				CURRENT_PROJECT_VERSION = 3;

+ 16
- 2
MongoView/Node.swift View File

@@ -9,7 +9,9 @@
9 9
 import Foundation
10 10
 import MongoSwift
11 11
 
12
-class Node {
12
+// Node needs to be an NSObject, since NSOutlineView uses NSObject.isEqual(_:) and NSObject.hash to determine item equality
13
+// which is necessary to prevent items from collapsing when refreshing the view
14
+class Node: NSObject {
13 15
     let key: Key?
14 16
     let value: BSON
15 17
     weak var parent: Node?
@@ -57,10 +59,22 @@ class Node {
57 59
             self.init(key: nil, value: .document(document))
58 60
         }
59 61
     }
62
+    
63
+    override func isEqual(_ object: Any?) -> Bool {
64
+        guard let object = object as? Node else { return false }
65
+        return self.parent == object.parent && self.key == object.key
66
+    }
67
+    
68
+    override var hash: Int {
69
+        var hasher = Hasher()
70
+        hasher.combine(parent)
71
+        hasher.combine(key)
72
+        return hasher.finalize()
73
+    }
60 74
 }
61 75
 
62 76
 extension Node {
63
-    enum Key {
77
+    enum Key: Equatable, Hashable {
64 78
         case index(Int)
65 79
         case name(String)
66 80
         case objectId(ObjectId)

Loading…
Cancel
Save