|
5 | 5 |
|
6 | 6 | NSString* const constKeyChildren = @"children" ;
|
7 | 7 | NSString* const constKeyParent = @"parent" ;
|
| 8 | + |
| 9 | +NSString* const SSYManagedTreeObjectKey = @"SSYManagedTreeObjectKey" ; |
| 10 | +NSString* const SSYManagedTreeChildrenChangedNotification = @"SSYManagedTreeChildrenChangedNotification" ; |
| 11 | + |
8 | 12 | /*
|
9 | 13 | See note on DropboxFalseStart below
|
10 | 14 | // NodeId was going to be needed because, when adding a new bookmark
|
@@ -113,7 +117,7 @@ - (void)handleWillSetNewChildren:(NSSet*)newValue {
|
113 | 117 | /* Testing indicates that this method can be invoked, and children can by
|
114 | 118 | mutated, without invoking -setChildren: or any other setter. In other words,
|
115 | 119 | this method seems to be an independent value-changer. Therefore, the following
|
116 |
| - override is necessary. It was added in BookMacster 1.12.7. */ |
| 120 | + override *is* necessary. It was added in BookMacster 1.12.7. */ |
117 | 121 | - (NSMutableSet*)mutableSetValueForKey:(NSString *)key {
|
118 | 122 | if ([key isEqualToString:constKeyChildren]) {
|
119 | 123 | [self forgetCachedChildrenOrdered];
|
@@ -184,16 +188,25 @@ - (void)setIndex:(NSNumber*)newValue {
|
184 | 188 | // In order to avoid registering undo and unnecessarily dirtying the dot,
|
185 | 189 | // we only do the overwrite if there was a substantive change.
|
186 | 190 | // (Note that current or new value can be nil.)
|
187 |
| - if ([NSObject isEqualHandlesNilObject1:[self index] |
| 191 | + if (![NSObject isEqualHandlesNilObject1:[self index] |
188 | 192 | object2:newValue]) {
|
189 |
| - return ; |
190 |
| - } |
| 193 | + [self postWillSetNewValue:newValue |
| 194 | + forKey:constKeyIndex] ; |
| 195 | + [self willChangeValueForKey:constKeyIndex] ; |
| 196 | + [self setPrimitiveIndex:newValue] ; |
| 197 | + [self didChangeValueForKey:constKeyIndex] ; |
| 198 | + |
| 199 | + SSYManagedTreeObject* parent = [self parent] ; |
| 200 | + if (parent) { |
| 201 | + // The order of the following two statements must be as is: |
| 202 | + [[self parent] forgetCachedChildrenOrdered] ; |
| 203 | + [[NSNotificationCenter defaultCenter] postNotificationName:SSYManagedTreeChildrenChangedNotification |
| 204 | + object:[self owner] |
| 205 | + userInfo:[NSDictionary dictionaryWithObject:[self parent] |
| 206 | + forKey:SSYManagedTreeObjectKey]] ; |
| 207 | + } |
| 208 | + } |
191 | 209 |
|
192 |
| - [self postWillSetNewValue:newValue |
193 |
| - forKey:constKeyIndex] ; |
194 |
| - [self willChangeValueForKey:constKeyIndex] ; |
195 |
| - [self setPrimitiveIndex:newValue] ; |
196 |
| - [self didChangeValueForKey:constKeyIndex] ; |
197 | 210 | }
|
198 | 211 |
|
199 | 212 | - (NSInteger)indexValue {
|
@@ -221,7 +234,7 @@ - (NSArray*)childrenOrdered {
|
221 | 234 | if (!m_cachedChildrenOrdered) {
|
222 | 235 | m_cachedChildrenOrdered = [[[self children] arraySortedByKeyPath:constKeyIndex] retain] ;
|
223 | 236 | }
|
224 |
| - |
| 237 | + |
225 | 238 | // arrayWithArray was added in BookMacster 1.12.8 to fix crashes which
|
226 | 239 | // were occuring in various methods when m_cachedChildrenOrdered was
|
227 | 240 | // changed. I also removed -arrayWithArray in several methods where the
|
@@ -313,13 +326,25 @@ - (NSInteger)numberOfChildren {
|
313 | 326 | }
|
314 | 327 |
|
315 | 328 | // This is required to trigger -[BkmxDoc objectWillChangeNote:]
|
316 |
| -- (void)setParent:(SSYManagedTreeObject*)newValue { |
317 |
| - [self postWillSetNewValue:newValue |
318 |
| - forKey:constKeyParent] ; |
319 |
| - [self willChangeValueForKey:constKeyParent] ; |
320 |
| - [self setPrimitiveParent:newValue] ; |
321 |
| - [self didChangeValueForKey:constKeyParent] ; |
322 |
| - |
| 329 | +- (void)setParent:(SSYManagedTreeObject*)newParent { |
| 330 | + if (![NSObject isEqualHandlesNilObject1:[self index] |
| 331 | + object2:newParent]) { |
| 332 | + [self postWillSetNewValue:newParent |
| 333 | + forKey:constKeyParent] ; |
| 334 | + |
| 335 | + [self willChangeValueForKey:constKeyParent] ; |
| 336 | + [self setPrimitiveParent:newParent] ; |
| 337 | + [self didChangeValueForKey:constKeyParent] ; |
| 338 | + |
| 339 | + if (newParent) { |
| 340 | + // The order of the following two statements must be as is: |
| 341 | + [newParent forgetCachedChildrenOrdered] ; |
| 342 | + [[NSNotificationCenter defaultCenter] postNotificationName:SSYManagedTreeChildrenChangedNotification |
| 343 | + object:[self owner] |
| 344 | + userInfo:[NSDictionary dictionaryWithObject:newParent |
| 345 | + forKey:SSYManagedTreeObjectKey]] ; |
| 346 | + } |
| 347 | + } |
323 | 348 | }
|
324 | 349 |
|
325 | 350 | /*
|
|
0 commit comments