// // AppDelegate.m // OBJCBrowser // // Created by Langley, Edward on 1/4/19. // Copyright © 2019 Langley, Edward. All rights reserved. // #import "AppDelegate.h" #include #include @interface AppDelegate () @property (weak) IBOutlet NSWindow *window; @property (weak) IBOutlet NSOutlineView *classOutline; @property NSMutableDictionary*> *classesSource; @property NSArray *rootClass; @property unsigned int classesSourceCount; //@property (weak) IBOutlet NSWindow *window; @end @implementation AppDelegate - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item { if (item == nil) { return [self.rootClass count]; } else { return [[self.classesSource valueForKey:item] count]; } } - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item { return item != nil && [item isKindOfClass:[NSString class]] && [self.classesSource valueForKey:item] != nil && [[self.classesSource valueForKey:item] count] != 0; } - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item { if (item == nil) { return [self.rootClass objectAtIndex:index]; } else { return [[self.classesSource objectForKey:(NSString*)item] objectAtIndex:index]; } } - (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item { NSTableCellView *v = [outlineView makeViewWithIdentifier:@"ItemName" owner:self]; [v.textField setStringValue:item]; return v; } - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { // Insert code here to initialize your application self.classesSourceCount = objc_getClassList(NULL, 0); Class *classesSource = (Class*)calloc(self.classesSourceCount, sizeof(Class)); NSMutableArray *classList = [[NSMutableArray alloc] initWithCapacity:self.classesSourceCount]; self.classesSource = [[NSMutableDictionary alloc] initWithCapacity:self.classesSourceCount]; printf("There are %d classes\n", self.classesSourceCount); printf("Got %d classes\n", objc_getClassList(classesSource, self.classesSourceCount)); for (unsigned int cur = 0; cur < self.classesSourceCount; cur++) { unsigned int methodCount = 0; Class cur_class = classesSource[cur]; Method *methods = class_copyMethodList(cur_class, &methodCount); NSString *class_name = [NSString stringWithUTF8String:class_getName(cur_class)]; // if (!([class_name characterAtIndex:0] == '_')) { classList[cur] = class_name; // } else { // self.classesSourceCount -= 1; // } NSMutableArray *method_arr = [[NSMutableArray alloc] initWithCapacity:methodCount]; for (int cur_m = 0; cur_m < methodCount; cur_m++) { Method cur_method = methods[cur_m]; NSString *method_name = [NSString stringWithUTF8String:sel_getName(method_getName(cur_method))]; method_arr[cur_m] = method_name; } self.classesSource[class_name] = [method_arr sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; } self.rootClass = [classList sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; self.classOutline.autoresizesOutlineColumn = YES; [self.classOutline setDelegate:self]; [self.classOutline setDataSource:self]; } - (void)applicationWillTerminate:(NSNotification *)aNotification { // Insert code here to tear down your application } @end