Improvements to class loading and cleanup of some NSLogs.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@15356 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2002-12-27 22:16:12 +00:00
parent e2166db8d3
commit c29826202c
3 changed files with 95 additions and 46 deletions

View file

@ -1,3 +1,11 @@
2002-12-27 Gregory John Casamento <greg_casamento@yahoo.com>
* GormDocument.m: -[GormDocument parseHeader:] added code to select
the class when it is loaded in the classes view. Also modified the
-[GormDocument _selectClass:] method and added a new private method
-[GormDocument _selectClassWithObject:] which will select using an
object which is passed in.
2002-12-27 Gregory John Casamento <greg_casamento@yahoo.com> 2002-12-27 Gregory John Casamento <greg_casamento@yahoo.com>
* GormDocument.m: -[GormDocument parseHeader:] corrected problem * GormDocument.m: -[GormDocument parseHeader:] corrected problem

View file

@ -160,7 +160,7 @@ NSString *IBClassNameChangedNotification = @"IBClassNameChangedNotification";
} }
else else
{ {
NSLog(@"Class already exists"); NSDebugLog(@"Class already exists");
result = NO; result = NO;
} }
} }

View file

@ -428,20 +428,11 @@ static NSImage *classesImage = nil;
} }
} }
- (void) _selectClass // class selection...
- (void) _selectClass: (NSString *)className
{ {
NSArray *selection = [objectsView selection]; NSString *newClassName = [GormClassManager correctClassName: className], *currentClass = nil;
NSArray *classes = [[self classManager] allSuperClassesOf: newClassName];
if([selection count] > 0)
{
id obj = nil;
GormClassManager *cm = [self classManager];
obj = [[objectsView selection] objectAtIndex: 0];
if([obj respondsToSelector: @selector(className)])
{
NSString *className = [GormClassManager correctClassName: [obj className]], *currentClass = nil;
NSArray *classes = [[self classManager] allSuperClassesOf: className];
NSEnumerator *en = [classes objectEnumerator]; NSEnumerator *en = [classes objectEnumerator];
int row = 0; int row = 0;
@ -452,16 +443,25 @@ static NSImage *classesImage = nil;
} }
// select the item... // select the item...
row = [classesView rowForItem: className]; row = [classesView rowForItem: newClassName];
if(row != NSNotFound) if(row != NSNotFound)
{ {
[classesView selectRow: row byExtendingSelection: NO]; [classesView selectRow: row byExtendingSelection: NO];
[classesView scrollRowToVisible: row]; [classesView scrollRowToVisible: row];
} }
} }
- (void) _selectClassWithObject: (id)obj
{
GormClassManager *cm = [self classManager];
if([obj respondsToSelector: @selector(className)])
{
[self _selectClass: [obj className]];
} }
} }
// change the views...
- (void) changeView: (id)sender - (void) changeView: (id)sender
{ {
int tag = [[sender selectedCell] tag]; int tag = [[sender selectedCell] tag];
@ -485,8 +485,16 @@ static NSImage *classesImage = nil;
break; break;
case 3: // classes case 3: // classes
{ {
NSArray *selection = [objectsView selection];
[selectionBox setContentView: classesScrollView]; [selectionBox setContentView: classesScrollView];
[self _selectClass];
// if something is selected, in the object view.
// show the equivalent class in the classes view.
if([selection count] > 0)
{
id obj = [[objectsView selection] objectAtIndex: 0];
[self _selectClassWithObject: obj];
}
} }
break; break;
} }
@ -721,8 +729,9 @@ static NSImage *classesImage = nil;
NSString *headerFile = [NSString stringWithContentsOfFile: headerPath]; NSString *headerFile = [NSString stringWithContentsOfFile: headerPath];
NSScanner *headerScanner = [NSScanner scannerWithString: headerFile]; NSScanner *headerScanner = [NSScanner scannerWithString: headerFile];
GormClassManager *cm = [self classManager]; GormClassManager *cm = [self classManager];
NSCharacterSet *terminatorSet = [NSCharacterSet characterSetWithCharactersInString: @" \n"]; NSCharacterSet *superClassStopSet = [NSCharacterSet characterSetWithCharactersInString: @" \n"];
NSCharacterSet *stopSet = [NSCharacterSet characterSetWithCharactersInString: @" :"]; NSCharacterSet *classStopSet = [NSCharacterSet characterSetWithCharactersInString: @" :"];
NSCharacterSet *actionStopSet = [NSCharacterSet characterSetWithCharactersInString: @";:"];
NSArray *outletTokens = [NSArray arrayWithObjects: @"id", @"IBOutlet id", nil]; NSArray *outletTokens = [NSArray arrayWithObjects: @"id", @"IBOutlet id", nil];
NSArray *actionTokens = [NSArray arrayWithObjects: @"(void)", @"(IBAction)", nil]; NSArray *actionTokens = [NSArray arrayWithObjects: @"(void)", @"(IBAction)", nil];
@ -758,11 +767,11 @@ static NSImage *classesImage = nil;
[classScanner scanString: @"@interface" [classScanner scanString: @"@interface"
intoString: NULL]; intoString: NULL];
[classScanner scanUpToCharactersFromSet: stopSet [classScanner scanUpToCharactersFromSet: classStopSet
intoString: &className]; intoString: &className];
[classScanner scanString: @":" [classScanner scanString: @":"
intoString: NULL]; intoString: NULL];
[classScanner scanUpToCharactersFromSet: terminatorSet [classScanner scanUpToCharactersFromSet: superClassStopSet
intoString: &superClassName]; intoString: &superClassName];
[classScanner scanUpToString: @"{" [classScanner scanUpToString: @"{"
intoString: NULL]; intoString: NULL];
@ -807,14 +816,13 @@ static NSImage *classesImage = nil;
{ {
NSString *action = nil; NSString *action = nil;
BOOL hasArguments = NO; BOOL hasArguments = NO;
NSCharacterSet *stopSet = [NSCharacterSet characterSetWithCharactersInString: @";:"];
// Scan the method name // Scan the method name
[methodScanner scanUpToString: actionToken [methodScanner scanUpToString: actionToken
intoString: NULL]; intoString: NULL];
[methodScanner scanString: actionToken [methodScanner scanString: actionToken
intoString: NULL]; intoString: NULL];
[methodScanner scanUpToCharactersFromSet: stopSet [methodScanner scanUpToCharactersFromSet: actionStopSet
intoString: &action]; intoString: &action];
// This will return true if the method has args. // This will return true if the method has args.
@ -855,13 +863,31 @@ static NSImage *classesImage = nil;
withOutlets: outlets]; withOutlets: outlets];
if(result) if(result)
{ {
NSLog(@"Class %@ added", className); NSDebugLog(@"Class %@ added", className);
[classesView reloadData]; [classesView reloadData];
} }
else else
{ {
NSString *message = [NSString stringWithFormat: NSString *message = [NSString stringWithFormat:
@"The class %@ could not be added", @"The class %@ already exists. Replace it?",
className];
int alert = NSRunAlertPanel(@"Problem adding class from header",
message,
@"Yes",
@"No",
nil);
if (alert == NSAlertDefaultReturn)
{
[cm removeClassNamed: className];
result = [cm addClassNamed: className
withSuperClassNamed: superClassName
withActions: actions
withOutlets: outlets];
if(!result)
{
NSString *message = [NSString stringWithFormat:
@"Could not replace class %@.",
className]; className];
NSRunAlertPanel(@"Problem adding class from header", NSRunAlertPanel(@"Problem adding class from header",
message, message,
@ -870,6 +896,21 @@ static NSImage *classesImage = nil;
nil); nil);
NSDebugLog(@"Class %@ failed to add", className); NSDebugLog(@"Class %@ failed to add", className);
} }
else
{
NSDebugLog(@"Class %@ replaced.", className);
[classesView reloadData];
}
}
}
if(result)
{
// go to the class which was just loaded in the classes view...
[selectionBox setContentView: classesScrollView];
[self _selectClass: className];
}
} // if we found a class } // if we found a class
} }
return self; return self;