Refactored code in GormClassEditor.m to re-use functionality, corrected a palette problem, and made GormClassManager deal with root classes more generically.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@21463 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2005-07-13 06:19:16 +00:00
parent 1976bc7dba
commit 9b1d69cbc7
5 changed files with 63 additions and 66 deletions

View file

@ -1,3 +1,17 @@
2005-07-13 02:17 Gregory John Casamento <greg_casamento@yahoo.com>
* GormCore/GormClassEditor.m: Changed code in selectClass:editClass:
to use the methods from the GormClassManager as appropriate. Removed
do.. while construct since it did the same thing as
allSuperClassesOf in GormClassManager.
* GormCore/GormClassManager.[hm]: Added new method isRootClass: which
returns true if the argument is a root class. Also replaced
references to @"NSObject" in a number of places with calls to this
method. This makes the code more generic.
* GormCore/GormPalettesManager.m: Added check in
importClasses:withDictionary: which should allow loading palettes
which define root level classes.
2005-07-12 fabien <fabien@sonappart.net> 2005-07-12 fabien <fabien@sonappart.net>
* GormCore/GormClassEditor.m: Fix OutlineView / BrowserView switch * GormCore/GormClassEditor.m: Fix OutlineView / BrowserView switch

View file

@ -257,13 +257,15 @@ NSString *GormSwitchViewPreferencesNotification = @"GormSwitchViewPreferencesNot
// class selection... // class selection...
- (void) selectClass: (NSString *)className editClass: (BOOL)flag - (void) selectClass: (NSString *)className editClass: (BOOL)flag
{ {
NSString *currentClass = nil; NSString *currentClass = nil;
NSArray *classes, *subclasses; NSArray *classes, *subclasses;
NSEnumerator *en; NSMutableArray *subClassesArray = [NSMutableArray array];
int row = 0; NSEnumerator *en;
int col = 0; NSString *superClass;
int row = 0;
int col = 0;
if ( ( ! className ) if ( ( className == nil )
|| ( [className isEqual: @"CustomView"] ) || ( [className isEqual: @"CustomView"] )
|| ( [className isEqual: @"GormSound"] ) || ( [className isEqual: @"GormSound"] )
|| ( [className isEqual: @"GormImage"] ) || ( [className isEqual: @"GormImage"] )
@ -282,7 +284,6 @@ NSString *GormSwitchViewPreferencesNotification = @"GormSwitchViewPreferencesNot
// select the item in the outline view... // select the item in the outline view...
row = [outlineView rowForItem: className]; row = [outlineView rowForItem: className];
if (row != -1) if (row != -1)
{ {
[outlineView selectRow: row byExtendingSelection: NO]; [outlineView selectRow: row byExtendingSelection: NO];
@ -290,51 +291,36 @@ NSString *GormSwitchViewPreferencesNotification = @"GormSwitchViewPreferencesNot
} }
// select class in browser... // select class in browser...
subClassesArray = [classManager allSuperClassesOf: className];
NSMutableArray *subClassesArray = [[NSMutableArray alloc] init]; if ((subClassesArray == nil) || ([subClassesArray count] == 0))
int i;
NSString *superClass;
NSString *className2 = className;
[subClassesArray addObject:className2];
do
{ {
superClass = [classManager superClassNameForClassNamed: className2]; return;
if ( ! superClass )
break;
className2 = superClass;
[subClassesArray addObject:className2];
if ( [superClass isEqualToString:@"NSObject"] )
break;
} }
while ( YES ); [subClassesArray addObject: className]; // include in the list.
if (( ! subClassesArray ) || ( [subClassesArray count] == 0 ) )
return;
// Get the super class position in the browser. Passing "nil" to subClassesOf causes it
// to get all of the root classes.
col = 0; col = 0;
row = [[classManager subClassesOf: nil] indexOfObject: [subClassesArray objectAtIndex: 0]];
if ( [[subClassesArray objectAtIndex:([subClassesArray count] -1)] // reset the enumerator...
isEqualToString:@"NSObject"] ) { currentClass = nil;
row = 0;
}
else
row = 1;
[browserView reloadColumn:col]; [browserView reloadColumn:col];
[browserView selectRow:row inColumn:col];
for (i=([subClassesArray count] - 2);i>=0;i--) // if row is not NSNotFound, then we found something.
if(row != NSNotFound)
{ {
subclasses = [classManager subClassesOf:[[browserView selectedCellInColumn:col] stringValue]]; [browserView selectRow: row inColumn: col];
row = [subclasses indexOfObject: [subClassesArray objectAtIndex:i]]; en = [subClassesArray objectEnumerator];
col++; [en nextObject]; // skip the first one.
[browserView selectRow:row inColumn:col]; while((currentClass = [en nextObject]) != nil)
// [browserView reloadColumn:col]; {
NSString *prevClass = [[browserView selectedCellInColumn: col] stringValue];
subclasses = [classManager subClassesOf: prevClass];
row = [subclasses indexOfObject: currentClass];
col++;
[browserView selectRow:row inColumn:col];
}
} }
if(flag) if(flag)

View file

@ -93,6 +93,7 @@
linkedToClass: (NSString *)subclass; linkedToClass: (NSString *)subclass;
- (NSDictionary *) dictionaryForClassNamed: (NSString *)className; - (NSDictionary *) dictionaryForClassNamed: (NSString *)className;
- (NSString *) uniqueClassNameFrom: (NSString *)name; - (NSString *) uniqueClassNameFrom: (NSString *)name;
- (BOOL) isRootClass: (NSString *)className;
/* Managing custom classes */ /* Managing custom classes */
- (BOOL) isCustomClass: (NSString *)className; - (BOOL) isCustomClass: (NSString *)className;

View file

@ -185,8 +185,7 @@
- (NSString *) addClassWithSuperClassName: (NSString*)name - (NSString *) addClassWithSuperClassName: (NSString*)name
{ {
if (([name isEqualToString: @"NSObject"] if (([self isRootClass: name] || [classInformation objectForKey: name] != nil)
|| [classInformation objectForKey: name] != nil)
&& [name isEqual: @"FirstResponder"] == NO) && [name isEqual: @"FirstResponder"] == NO)
{ {
NSMutableDictionary *classInfo; NSMutableDictionary *classInfo;
@ -278,7 +277,7 @@
// We make an autoreleased copy of all of the inputs. This prevents changes // We make an autoreleased copy of all of the inputs. This prevents changes
// to the original objects from reflecting here. GJC // to the original objects from reflecting here. GJC
if ([superClassNameCopy isEqualToString: @"NSObject"] || if ([self isRootClass: superClassNameCopy] ||
([classInformation objectForKey: superClassNameCopy] != nil && ([classInformation objectForKey: superClassNameCopy] != nil &&
[superClassNameCopy isEqualToString: @"FirstResponder"] == NO)) [superClassNameCopy isEqualToString: @"FirstResponder"] == NO))
{ {
@ -1462,8 +1461,7 @@
if (superclass != nil if (superclass != nil
&& subclass != nil && subclass != nil
&& [cn containsObject: subclass] && [cn containsObject: subclass]
&& ([cn containsObject: superclass] && ([cn containsObject: superclass] || [self isRootClass: superclass])
|| [superclass isEqualToString: @"NSObject"])
&& [self isSuperclass: subclass linkedToClass: superclass] == NO) && [self isSuperclass: subclass linkedToClass: superclass] == NO)
{ {
NSMutableDictionary *info; NSMutableDictionary *info;
@ -1503,10 +1501,6 @@
{ {
superName = [info objectForKey: @"Super"]; superName = [info objectForKey: @"Super"];
} }
if (superName == nil)
{
superName = @"NSObject";
}
return superName; return superName;
} }
@ -1519,14 +1513,6 @@
{ {
return NO; return NO;
} }
if ([superclass isEqualToString: @"NSObject"])
{
return YES;
}
if ([subclass isEqualToString: @"NSObject"])
{
return NO;
}
ssclass = [self superClassNameForClassNamed: subclass]; ssclass = [self superClassNameForClassNamed: subclass];
if ([superclass isEqualToString: ssclass]) if ([superclass isEqualToString: ssclass])
@ -1814,11 +1800,16 @@
return ([customClassMap count] == 0); return ([customClassMap count] == 0);
} }
- (BOOL) isRootClass: (NSString *)className
{
return ([self superClassNameForClassNamed: className] == nil);
}
- (NSString *) nonCustomSuperClassOf: (NSString *)className - (NSString *) nonCustomSuperClassOf: (NSString *)className
{ {
NSString *result = className; NSString *result = className;
if(![self isCustomClass: className] && ![className isEqual: @"NSObject"]) if(![self isCustomClass: className] && ![self isRootClass: className])
{ {
result = [self superClassNameForClassNamed: result]; result = [self superClassNameForClassNamed: result];
} }
@ -1838,7 +1829,7 @@
- (NSArray *) allSuperClassesOf: (NSString *)className - (NSArray *) allSuperClassesOf: (NSString *)className
{ {
NSMutableArray *classes = [NSMutableArray array]; NSMutableArray *classes = [NSMutableArray array];
while (![className isEqualToString: @"NSObject"] && className != nil) while (![self isRootClass: className] && className != nil)
{ {
NSDictionary *dict = [self classInfoForClassName: className]; NSDictionary *dict = [self classInfoForClassName: className];
if(dict != nil) if(dict != nil)

View file

@ -703,7 +703,12 @@ static NSImage *dragImage = nil;
NSMutableArray *actions = [self actionsForClass: cls]; NSMutableArray *actions = [self actionsForClass: cls];
NSMutableArray *outlets = [self outletsForClass: cls]; NSMutableArray *outlets = [self outletsForClass: cls];
[classDict setObject: superClassName forKey: @"Super"]; // if the superclass is defined, set it. if not, don't since
// this might be a palette which adds a root class.
if(superClassName != nil)
{
[classDict setObject: superClassName forKey: @"Super"];
}
// set the action/outlet keys // set the action/outlet keys
if(actions != nil) if(actions != nil)