Skip to content

Commit d1dda01

Browse files
committedMay 10, 2016
• Refactored SSYArrayController into a superclass which only has the workaround for Apple Bug Apple Bug ID 7827354 which was closed as a duplicate of 3404770.
1 parent 51c98d4 commit d1dda01

4 files changed

+67
-60
lines changed
 

‎SSYArrayController.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
@end
99

10+
#import "SSYMoreObserveableArrayController.h"
11+
1012
/*!
1113
@brief An array controller which supports reordering of objects by the user,
1214
better-behaved -remove:, a new "add" method which behaves better than -add:,
@@ -116,7 +118,7 @@
116118
font size to be set in the table view's cell. It does this by implementing
117119
the delegate method tableView:willDisplayCell:forTableColumn:row:.
118120
*/
119-
@interface SSYArrayController : NSArrayController {
121+
@interface SSYArrayController : SSYMoreObserveableArrayController {
120122
id m_parentObject ;
121123
NSString* m_parentObjectKey ;
122124
NSString* m_contentKey ;
@@ -133,9 +135,6 @@
133135
@property (copy) NSString* contentKey ;
134136
@property (assign) CGFloat tableFontSize ;
135137

136-
/* To work around bug in NSArrayController, Apple Bug ID 7827354 which was
137-
closed as a duplicate of 3404770. */
138-
@property (assign, readonly) BOOL hasSelection ;
139138

140139
/*!
141140
@brief Adds a new item below the current selection, or at the

‎SSYArrayController.m

+1-56
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ @interface SSYArrayController ()
1414
@end
1515

1616

17-
@interface SSYArrayController ()
18-
19-
@property (assign) BOOL hasSelection ;
20-
21-
@end
2217

2318
@implementation SSYArrayController
2419

@@ -28,12 +23,8 @@ @implementation SSYArrayController
2823
@synthesize pendingObjectsIndexSet = m_pendingObjectsIndexSet ;
2924
@synthesize lineHeightMultiplier = m_lineHeightMultiplier ;
3025
@synthesize tableFontSize = m_tableFontSize ;
31-
@synthesize hasSelection = m_hasSelection ;
3226

33-
- (void)dealloc {
34-
[self removeObserver:self
35-
forKeyPath:@"selectedObjects"] ;
36-
27+
- (void)dealloc {
3728
[m_parentObjectKey release] ;
3829
[m_contentKey release] ;
3930
[m_pendingObjectsIndexSet release] ;
@@ -55,52 +46,8 @@ - (void)awakeFromNib {
5546
nil] ;
5647
[tableView registerForDraggedTypes:draggedTypes] ;
5748
[tableView setAllowsMultipleSelection:YES] ;
58-
59-
[self addObserver:self
60-
forKeyPath:@"selectedObjects"
61-
options:0
62-
context:NULL] ;
6349
}
6450

65-
- (void)observeValueForKeyPath:(NSString *)keyPath
66-
ofObject:(id)object
67-
change:(NSDictionary *)change
68-
context:(void *)context {
69-
if ([keyPath isEqualToString:@"selectedObjects"]) {
70-
#if 0
71-
#warning observing changes to selected objects for Mythical Deep Observer
72-
NSLog(@"1681: Some sleazeball changed selection: %@", [change shortDescription]) ;
73-
NSLog(@"continuing") ;
74-
#endif
75-
NSInteger selectionCount = [[self selectedObjects] count] ;
76-
[self setHasSelection:(selectionCount > 0)] ;
77-
}
78-
79-
// NSTimeInterval startTime = [NSDate timeIntervalSinceReferenceDate] ;
80-
81-
[super observeValueForKeyPath:keyPath
82-
ofObject:object
83-
change:change
84-
context:context] ;
85-
86-
/*
87-
NSTimeInterval thisTime = [NSDate timeIntervalSinceReferenceDate] - startTime ;
88-
if ([object isKindOfClass:[Starkoid class]]) {
89-
starkoidTime += thisTime ;
90-
NSLog(@"starkoidTime = %0.3f", starkoidTime) ;
91-
}
92-
else if ([object isKindOfClass:[SSYArrayController class]]) {
93-
arrayControllerTime += thisTime ;
94-
NSLog(@"arrayControllerTime = %0.3f", arrayControllerTime) ;
95-
}
96-
else {
97-
otherTime += thisTime ;
98-
NSLog(@"otherTime = %0.3f", otherTime) ;
99-
}
100-
*/
101-
}
102-
103-
10451
- (BOOL) tableView:(NSTableView *)tv
10552
writeRowsWithIndexes:(NSIndexSet*)indexes
10653
toPasteboard:(NSPasteboard*)pboard {
@@ -114,8 +61,6 @@ - (BOOL) tableView:(NSTableView *)tv
11461
return YES ;
11562
}
11663

117-
118-
11964
- (NSDragOperation)tableView:(NSTableView*)tv
12065
validateDrop:(id <NSDraggingInfo>)info
12166
proposedRow:(NSInteger)targetRow

‎SSYMoreObserveableArrayController.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#import "SSYMoreObserveableArrayController.h"
2+
3+
@interface SSYMoreObserveableArrayController : NSArrayController
4+
5+
/*!
6+
@brief Workaround for Apple Bug ID 7827354, which was closed as a duplicate
7+
of 3404770, in NSArrayController
8+
9+
@details Provides a -hasSelection property which actually works.
10+
*/
11+
12+
@property (assign, readonly) BOOL hasSelection ;
13+
14+
@end

‎SSYMoreObserveableArrayController.m

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#import "SSYMoreObserveableArrayController.h"
2+
3+
@interface SSYMoreObserveableArrayController ()
4+
5+
@property (assign) BOOL hasSelection ;
6+
7+
@end
8+
9+
10+
@implementation SSYMoreObserveableArrayController
11+
12+
- (void)dealloc {
13+
[self removeObserver:self
14+
forKeyPath:@"selectedObjects"] ;
15+
16+
#if !__has_feature(objc_arc)
17+
[super dealloc] ;
18+
#endif
19+
}
20+
21+
- (void)awakeFromNib {
22+
// Per Discussion in documentation of -[NSObject respondsToSelector:].
23+
// the superclass name in the following must be hard-coded.
24+
if ([NSArrayController instancesRespondToSelector:@selector(awakeFromNib)]) {
25+
[super awakeFromNib] ;
26+
}
27+
28+
[self addObserver:self
29+
forKeyPath:@"selectedObjects"
30+
options:0
31+
context:NULL] ;
32+
}
33+
34+
- (void)observeValueForKeyPath:(NSString *)keyPath
35+
ofObject:(id)object
36+
change:(NSDictionary *)change
37+
context:(void *)context {
38+
if ([keyPath isEqualToString:@"selectedObjects"]) {
39+
NSInteger selectionCount = [[self selectedObjects] count] ;
40+
[self setHasSelection:(selectionCount > 0)] ;
41+
}
42+
43+
[super observeValueForKeyPath:keyPath
44+
ofObject:object
45+
change:change
46+
context:context] ;
47+
}
48+
49+
@end

0 commit comments

Comments
 (0)
Please sign in to comment.