Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOShipGroupDebugInspectorModule.m
Go to the documentation of this file.
1/*
2
3OOShipGroupDebugInspectorModule.m
4
5
6Oolite Debug Bundle
7
8Copyright © 2007-2009 Jens Ayton
9
10Permission is hereby granted, free of charge, to any person obtaining a copy
11of this software and associated documentation files (the “Software”), to deal
12in the Software without restriction, including without limitation the rights
13to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14copies of the Software, and to permit persons to whom the Software is
15furnished to do so, subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26SOFTWARE.
27
28*/
29
32#import "OOShipGroup.h"
33
34
35@interface NSObject (OOCompareByPointerValue)
36
37- (NSComparisonResult) ooCompareByPointerValue:(id)other;
38
39@end
40
41
43
44- (void) awakeFromNib
45{
46 [membersList setDoubleAction:[membersList action]];
47 [membersList setAction:NULL];
48}
49
50
51- (void) update
52{
53 OOShipGroup *object = [self object];
54 NSString *placeholder = InspectorUnknownValueString();
55 NSEnumerator *memberEnum = nil;
56 ShipEntity *member = nil;
57 NSMutableArray *members = nil;
58
59 [leaderField setStringValue:[[object leader] inspDescription] ?: placeholder];
60
61 // Make array of weakRefs to group members.
62 members = [NSMutableArray array];
63 for (memberEnum = [object objectEnumerator]; (member = [memberEnum nextObject]); )
64 {
65 id memberRef = [member weakRetain];
66 [members addObject:memberRef];
67 [memberRef release];
68 }
69
70 // Sort array.
71 [members sortUsingSelector:@selector(ooCompareByPointerValue:)];
72 if (![_members isEqualToArray:members])
73 {
74 [_members release];
75 _members = [members copy];
76 [membersList reloadData];
77 }
78}
79
80
81- (IBAction) inspectLeader:(id)sender
82{
83 [[[self object] leader] inspect];
84}
85
86
87- (IBAction) inspectMember:(id)sender
88{
89 NSInteger clickedRow = [sender clickedRow];
90 if (clickedRow < 0) return;
91
92 [[_members objectAtIndex:clickedRow] inspect];
93}
94
95
96- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
97{
98 return [_members count];
99}
100
101
102- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
103{
104 return [[_members objectAtIndex:row] inspDescription];
105}
106
107@end
108
109
110@implementation OOShipGroup (OOInspectorExtensions)
111
112- (NSString *) inspDescription
113{
114 NSString *name = [self name];
115 if (name != nil) name = [NSString stringWithFormat:@"\"%@\"", name];
116 else name = @"anonymous";
117
118 return [NSString stringWithFormat:@"%@, %lu ships", name, [self count]];
119}
120
121
122- (NSString *) inspBasicIdentityLine
123{
124 NSString *name = [self name];
125 if (name != nil) return [NSString stringWithFormat:@"Group \"%@\"", name];
126 else return @"Anonymous group";
127}
128
129
130- (NSArray *) debugInspectorModules
131{
132 return [[super debugInspectorModules] arrayByAddingInspectorModuleOfClass:[OOShipGroupDebugInspectorModule class]
133 forObject:(id)self];
134}
135
136@end
137
138
139@implementation NSObject (OOCompareByPointerValue)
140
141- (NSComparisonResult) ooCompareByPointerValue:(id)other
142{
143 if ((uintptr_t)self < (uintptr_t)other) return NSOrderedAscending;
144 if ((uintptr_t)self > (uintptr_t)other) return NSOrderedDescending;
145 return NSOrderedSame;
146}
147
148@end
NSString * InspectorUnknownValueString(void)
return nil
NSUInteger count()
NSString * name()
ShipEntity * leader()