From 58956e049c9de008d8633a6a15def430dcc2972c Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Mon, 25 Mar 2002 01:44:01 +0000 Subject: [PATCH] Changed classesView from an NSTableView to an NSOutlineView so that viewing is more intuitive. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@13222 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 9 ++++ GormClassManager.h | 1 + GormClassManager.m | 19 +++++++ GormDocument.m | 128 ++++++++++++++++++++++++++++++--------------- 4 files changed, 114 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index 55a8ed59..4bfcdb97 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2002-03-24 Gregory John Casamento + + * GormDocument.m: Made necessary modifications to change the + classesView from an NSTableView to an NSOutlineView. + * GormClassManager.m: Added method to return all subclasses for + a given superclass. + * GormClassManager.h: Added declaration for the method described + above. + 2002-03-08 Richard Frith-Macdonald * IBInspector.m: Don't release window on dealloc ... assume it diff --git a/GormClassManager.h b/GormClassManager.h index 7f0c1c20..1d309a0b 100644 --- a/GormClassManager.h +++ b/GormClassManager.h @@ -14,6 +14,7 @@ - (NSArray*) allOutletsForObject: (NSObject*)anObject; - (NSArray*) extraActionsForObject: (NSObject*)anObject; - (NSArray*) extraOutletsForObject: (NSObject*)anObject; +- (NSArray*) subClassesOf: (NSString *)superclass; - (void) removeAction: (NSString*)anAction forObject: (NSObject*)anObject; - (void) removeOutlet: (NSString*)anOutlet forObject: (NSObject*)anObject; diff --git a/GormClassManager.m b/GormClassManager.m index 57a8b348..df70a842 100644 --- a/GormClassManager.m +++ b/GormClassManager.m @@ -490,6 +490,25 @@ NSString *IBClassNameChangedNotification = @"IBClassNameChangedNotification"; return self; } +- (NSArray *) subClassesOf: (NSString *)superclass +{ + NSArray *allClasses = [classInformation allKeys]; + NSEnumerator *cen = [allClasses objectEnumerator]; + id object = nil; + NSMutableArray *subclasses = [NSMutableArray array]; + + while((object = [cen nextObject])) + { + NSDictionary *dictForClass = [classInformation objectForKey: object]; + if([[dictForClass objectForKey: @"Super"] isEqual: superclass]) + { + [subclasses addObject: object]; + } + } + + return subclasses; +} + - (void) removeAction: (NSString*)anAction forObject: (id)anObject { NSMutableDictionary *info = [self classInfoForObject: anObject]; diff --git a/GormDocument.m b/GormDocument.m index 4473b842..b20bdbae 100644 --- a/GormDocument.m +++ b/GormDocument.m @@ -31,8 +31,6 @@ NSString *IBWillSaveDocumentNotification = @"IBWillSaveDocumentNotification"; NSString *IBDidSaveDocumentNotification = @"IBDidSaveDocumentNotification"; NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification"; - - @implementation GormFirstResponder - (NSImage*) imageForViewer { @@ -292,12 +290,11 @@ static NSImage *classesImage = nil; NSLog(@"Double Action"); - if (row >= 0 && row < [classes count]) + if(row >= 0) { - [classEditor setSelectedClassName: [classes objectAtIndex: row]]; + [classEditor setSelectedClassName: [classesView itemAtRow: row]]; [self setSelectionFromEditor: (id)classEditor]; } - } - (void) changeView: (id)sender @@ -446,20 +443,21 @@ static NSImage *classesImage = nil; - (id) createSubclass: (id)sender { int i = [classesView selectedRow]; - NSArray *classNames = [classManager allClassNames]; - if (i >= 0 && i < [classNames count]) + if(i >= 0) { - NSString *newClassName; - + NSString *newClassName; + id itemSelected = [classesView itemAtRow: i]; + newClassName = [classManager addClassWithSuperClassName: - [classNames objectAtIndex: i]]; + itemSelected]; [classesView reloadData]; - classNames = [classManager allClassNames]; - i = [classNames indexOfObject: newClassName]; + [classesView expandItem: itemSelected]; + i = [classesView rowForItem: newClassName]; [classesView selectRow: i byExtendingSelection: NO]; [self editClass: self]; } + return self; } @@ -745,12 +743,12 @@ static NSImage *classesImage = nil; headerName = [sp filename]; NSLog(@"createClassFiles"); - if (row >= 0 && row < [classes count]) + if (row >= 0) { - NSLog([classes objectAtIndex: row]); + NSLog([classesView itemAtRow: row]); if (![classManager makeSourceAndHeaderFilesForClass: - [classes objectAtIndex: row] + [classesView itemAtRow: row] withName: sourceName and: headerName]) { @@ -1166,11 +1164,15 @@ static NSImage *classesImage = nil; NSViewHeightSizable|NSViewWidthSizable]; mainRect.origin = NSMakePoint(0,0); - classesView = [[NSTableView alloc] initWithFrame: mainRect]; + classesView = [[NSOutlineView alloc] initWithFrame: mainRect]; [classesView setMenu: [(Gorm*)NSApp classMenu]]; [classesView setDataSource: self]; [classesView setAutoresizesAllColumnsToFit: YES]; [classesView setAllowsColumnResizing: NO]; + [classesView setDrawsGrid: NO]; + [classesView setIndentationMarkerFollowsCell: YES]; + [classesView setAutoresizesOutlineColumn: YES]; + [classesView setIndentationPerLevel: 10]; [classesScrollView setDocumentView: classesView]; RELEASE(classesView); @@ -1179,7 +1181,8 @@ static NSImage *classesImage = nil; [tableColumn setMinWidth: 250]; [tableColumn setResizable: YES]; [tableColumn setEditable: YES]; - [classesView addTableColumn: tableColumn]; + [classesView addTableColumn: tableColumn]; + [classesView setOutlineTableColumn: tableColumn]; RELEASE(tableColumn); tableColumn = [[NSTableColumn alloc] initWithIdentifier: @"outlets"]; @@ -1196,7 +1199,8 @@ static NSImage *classesImage = nil; [classesView addTableColumn: tableColumn]; RELEASE(tableColumn); - [classesView setFrame: mainRect]; + // expand all of the items in the classesView... + [classesView expandItem: @"NSObject"]; [selectionBox setContentView: scrollView]; @@ -1242,9 +1246,9 @@ static NSImage *classesImage = nil; int i = [classesView selectedRow]; id classNames = [classManager allClassNames]; - if (i >= 0 && i < [classNames count]) + if (i >= 0) { - id className = [classNames objectAtIndex: i]; + id className = [classesView itemAtRow: i]; GSNibItem *item = [[GormObjectProxy alloc] initWithClassName: className frame: NSMakeRect(0,0,0,0)]; @@ -2030,31 +2034,18 @@ static NSImage *classesImage = nil; return YES; } -//--- NSTableView dataSource --- -- (int) numberOfRowsInTableView: (NSTableView *)aTableView -{ - if (aTableView == classesView) - { - return [[classManager allClassNames] count]; - } - return 0; -} - -- (id) tableView: (NSTableView *)aTableView +// --- NSOutlineView dataSource --- +- (id) outlineView: (NSOutlineView *)anOutlineView objectValueForTableColumn: (NSTableColumn *)aTableColumn - row: (int)rowIndex + byItem: item { - if (aTableView == classesView) + NSLog(@"outlineView:objectValue... item = %@", item); + if (anOutlineView == classesView) { id identifier = [aTableColumn identifier]; - id className = @""; + id className = item; id classNames = [classManager allClassNames]; - if (rowIndex >= 0 && rowIndex < [classNames count]) - { - className = [classNames objectAtIndex: rowIndex]; - } - if ([identifier isEqualToString: @"classes"]) { return className; @@ -2073,12 +2064,63 @@ objectValueForTableColumn: (NSTableColumn *)aTableColumn return @""; } -- (void) tableView: (NSTableView *)aTableView - setObjectValue: (id)anObject - forTableColumn: (NSTableColumn *)aTableColumn - row: (int)rowIndex +- (void) outlineView: (NSOutlineView *)anOutlineView + setObjectValue: (id)anObject + forTableColumn: (NSTableColumn *)aTableColumn + row: (int)rowIndex { +} +- (int) outlineView: (NSOutlineView *)anOutlineView +numberOfChildrenOfItem: (id)item +{ + NSLog(@"numchild"); + if(item == nil) + { + return 1; + } + else + { + NSArray *subclasses = [classManager subClassesOf: item]; + return [subclasses count]; + } + + return 0; +} + +- (BOOL) outlineView: (NSOutlineView *)anOutlineView + isItemExpandable: (id)item +{ + NSArray *subclasses = nil; + NSLog(@"isExpandable"); + if(item == nil) + return YES; + + subclasses = [classManager subClassesOf: item]; + if([subclasses count] > 0) + return YES; + + return NO; +} + +- (id) outlineView: (NSOutlineView *)anOutlineView + child: (int)index + ofItem: (id)item +{ + NSLog(@"child:ofItem"); + if(item == nil && index == 0) + { + NSLog(@"return default"); + return @"NSObject"; + } + else + { + NSArray *subclasses = [classManager subClassesOf: item]; + NSLog(@"child:ofItem = %@",[subclasses objectAtIndex: index]); + return [subclasses objectAtIndex: index]; + } + + return nil; } @end