Refactoring and some minor corrections.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@20422 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2004-12-05 23:30:56 +00:00
parent 0778f595b4
commit 730f3612c4
5 changed files with 246 additions and 243 deletions

View file

@ -1,3 +1,13 @@
2004-12-05 18:21 Gregory John Casamento <greg_casamento@yahoo.com>
* GormClassEditor.m: Added new methods moved from GormDocument.
* GormDocument.m: Moved remove: to deleteSelection on
GormClassEditor, also moved createSubclass to GormClassEditor.
* GormPrivate.h: Added methods moved from GormDocument to
GormClassEditor.
* GormLib/IBEditors.h: Added deleteSelection back into the
protocol.
2004-12-05 15:40 Gregory John Casamento <greg_casamento@yahoo.com>
* GNUmakefile: Added new classes to the makefile.

View file

@ -114,42 +114,6 @@
return className;
}
//--- IBSelectionOwners protocol ---
- (unsigned) selectionCount
{
return ([self selectedRow] == -1)?0:1;
}
- (NSArray*) selection
{
NSString *selectedClassName = [self selectedClassName];
// when asked for a selection, it returns a class proxy
if (selectedClassName != nil)
{
NSArray *array;
GormClassProxy *classProxy;
classProxy = [[GormClassProxy alloc] initWithClassName:
selectedClassName];
array = [NSArray arrayWithObject: classProxy];
RELEASE(classProxy);
return array;
}
else
{
return [NSArray array];
}
}
- (void) drawSelection
{
}
- (void) makeSelectionVisible: (BOOL)flag
{
}
// class selection...
- (void) selectClass: (NSString *)className
{
@ -207,12 +171,6 @@
}
}
- (void) selectObjects: (NSArray*)objects
{
id obj = [objects objectAtIndex: 0];
[self selectClassWithObject: obj];
}
- (BOOL) currentSelectionIsClass
{
int i = [self selectedRow];
@ -229,7 +187,7 @@
return result;
}
- (void) editClass: (id)sender
- (void) editClass
{
int row = [self selectedRow];
if (row >= 0)
@ -237,6 +195,170 @@
[document setSelectionFromEditor: (id)self];
}
}
- (void) createSubclass
{
if (![self isEditing])
{
NSString *newClassName;
NSString *itemSelected = [self selectedClassName];
if(![itemSelected isEqualToString: @"FirstResponder"])
{
int i = 0;
newClassName = [classManager addClassWithSuperClassName:
itemSelected];
[self reloadData];
[self expandItem: itemSelected];
i = [self rowForItem: newClassName];
[self selectRow: i byExtendingSelection: NO];
[self scrollRowToVisible: i];
}
else
{
// beep to inform the user of this error.
NSBeep();
}
}
}
//--- IBSelectionOwners protocol ---
- (unsigned) selectionCount
{
return ([self selectedRow] == -1)?0:1;
}
- (NSArray*) selection
{
NSString *selectedClassName = [self selectedClassName];
// when asked for a selection, it returns a class proxy
if (selectedClassName != nil)
{
NSArray *array;
GormClassProxy *classProxy;
classProxy = [[GormClassProxy alloc] initWithClassName:
selectedClassName];
array = [NSArray arrayWithObject: classProxy];
RELEASE(classProxy);
return array;
}
else
{
return [NSArray array];
}
}
- (void) drawSelection
{
}
- (void) makeSelectionVisible: (BOOL)flag
{
}
- (void) selectObjects: (NSArray*)objects
{
id obj = [objects objectAtIndex: 0];
[self selectClassWithObject: obj];
}
- (void) deleteSelection
{
id anitem;
int i = [self selectedRow];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
// if no selection, then return.
if (i == -1)
{
return;
}
anitem = [self itemAtRow: i];
if ([anitem isKindOfClass: [GormOutletActionHolder class]])
{
id itemBeingEdited = [self itemBeingEdited];
NSString *name = [anitem getName];
// if the class being edited is a custom class or a category,
// then allow the deletion...
if ([classManager isCustomClass: itemBeingEdited] ||
[classManager isAction: name onCategoryForClassNamed: itemBeingEdited])
{
if ([self editType] == Actions)
{
// if this action is an action on the class, not it's superclass
// allow the deletion...
if ([classManager isAction: name
ofClass: itemBeingEdited])
{
BOOL removed = [document removeConnectionsWithLabel: name
forClassNamed: itemBeingEdited
isAction: YES];
if (removed)
{
[classManager removeAction: name
fromClassNamed: itemBeingEdited];
[self removeItemAtRow: i];
[nc postNotificationName: GormDidModifyClassNotification
object: classManager];
}
}
}
else if ([self editType] == Outlets)
{
// if this outlet is an outlet on the class, not it's superclass
// allow the deletion...
if ([classManager isOutlet: name
ofClass: itemBeingEdited])
{
BOOL removed = [document removeConnectionsWithLabel: name
forClassNamed: itemBeingEdited
isAction: NO];
if (removed)
{
[classManager removeOutlet: name
fromClassNamed: itemBeingEdited];
[self removeItemAtRow: i];
[nc postNotificationName: GormDidModifyClassNotification
object: classManager];
}
}
}
}
}
else
{
NSArray *subclasses = [classManager subClassesOf: anitem];
// if the class has no subclasses, then delete.
if ([subclasses count] == 0)
{
// if the class being edited is a custom class, then allow the deletion...
if ([classManager isCustomClass: anitem])
{
BOOL removed = [document removeConnectionsForClassNamed: anitem];
if (removed)
{
[classManager removeClassNamed: anitem];
[self reloadData];
[nc postNotificationName: GormDidModifyClassNotification
object: classManager];
}
}
}
else
{
NSString *message = [NSString stringWithFormat:
_(@"The class %@ has subclasses which must be removed"), anitem];
NSRunAlertPanel(_(@"Problem removing class"),
message,
nil, nil, nil);
}
}
}
@end
@implementation GormClassEditor (NSOutlineViewDataSource)
@ -478,7 +600,7 @@ shouldEditTableColumn: (NSTableColumn *)tableColumn
if (![item isKindOfClass: [GormOutletActionHolder class]])
{
result = [classManager isCustomClass: item];
[self editClass: item];
[self editClass];
}
else
{
@ -520,7 +642,7 @@ shouldEditTableColumn: (NSTableColumn *)tableColumn
id item = [object itemAtRow: [object selectedRow]];
if (![item isKindOfClass: [GormOutletActionHolder class]])
{
[self editClass: item];
[self editClass];
}
}
}

View file

@ -878,34 +878,7 @@ static NSImage *fileImage = nil;
- (id) createSubclass: (id)sender
{
int i = [classesView selectedRow];
if (i >= 0 && ![classesView isEditing])
{
NSString *newClassName;
id itemSelected = [classesView itemAtRow: i];
if([itemSelected isKindOfClass: [NSString class]])
{
if(![itemSelected isEqualToString: @"FirstResponder"])
{
newClassName = [classManager addClassWithSuperClassName:
itemSelected];
[classesView reloadData];
[classesView expandItem: itemSelected];
i = [classesView rowForItem: newClassName];
[classesView selectRow: i byExtendingSelection: NO];
[classesView scrollRowToVisible: i];
// [self editClass: self];
}
else
{
// beep to inform the user of this error.
NSBeep();
}
}
}
[classesView createSubclass];
return self;
}
@ -1074,97 +1047,7 @@ static NSImage *fileImage = nil;
- (id) remove: (id)sender
{
id anitem;
int i = [classesView selectedRow];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
// if no selection, then return.
if (i == -1)
{
return self;
}
anitem = [classesView itemAtRow: i];
if ([anitem isKindOfClass: [GormOutletActionHolder class]])
{
id itemBeingEdited = [classesView itemBeingEdited];
NSString *name = [anitem getName];
// if the class being edited is a custom class or a category,
// then allow the deletion...
if ([classManager isCustomClass: itemBeingEdited] ||
[classManager isAction: name onCategoryForClassNamed: itemBeingEdited])
{
if ([classesView editType] == Actions)
{
// if this action is an action on the class, not it's superclass
// allow the deletion...
if ([classManager isAction: name
ofClass: itemBeingEdited])
{
BOOL removed = [self removeConnectionsWithLabel: name
forClassNamed: itemBeingEdited
isAction: YES];
if (removed)
{
[classManager removeAction: name
fromClassNamed: itemBeingEdited];
[classesView removeItemAtRow: i];
[nc postNotificationName: GormDidModifyClassNotification
object: classManager];
}
}
}
else if ([classesView editType] == Outlets)
{
// if this outlet is an outlet on the class, not it's superclass
// allow the deletion...
if ([classManager isOutlet: name
ofClass: itemBeingEdited])
{
BOOL removed = [self removeConnectionsWithLabel: name
forClassNamed: itemBeingEdited
isAction: NO];
if (removed)
{
[classManager removeOutlet: name
fromClassNamed: itemBeingEdited];
[classesView removeItemAtRow: i];
[nc postNotificationName: GormDidModifyClassNotification
object: classManager];
}
}
}
}
}
else
{
NSArray *subclasses = [classManager subClassesOf: anitem];
// if the class has no subclasses, then delete.
if ([subclasses count] == 0)
{
// if the class being edited is a custom class, then allow the deletion...
if ([classManager isCustomClass: anitem])
{
BOOL removed = [self removeConnectionsForClassNamed: anitem];
if (removed)
{
[classManager removeClassNamed: anitem];
[classesView reloadData];
[nc postNotificationName: GormDidModifyClassNotification
object: classManager];
}
}
}
else
{
NSString *message = [NSString stringWithFormat:
_(@"The class %@ has subclasses which must be removed"), anitem];
NSRunAlertPanel(_(@"Problem removing class"),
message,
nil, nil, nil);
}
}
[classesView deleteSelection];
return self;
}
@ -1216,14 +1099,8 @@ static NSImage *fileImage = nil;
- (id) createClassFiles: (id)sender
{
NSSavePanel *sp;
int row = [classesView selectedRow];
id className = [classesView itemAtRow: row];
NSString *className = [classesView selectedClassName];
int result;
if ([className isKindOfClass: [GormOutletActionHolder class]])
{
className = [classesView itemBeingEdited];
}
sp = [NSSavePanel savePanel];
[sp setRequiredFileType: @"m"];
@ -1620,82 +1497,74 @@ static NSImage *fileImage = nil;
- (id) instantiateClass: (id)sender
{
int i = [classesView selectedRow];
NSString *object = [classesView selectedClassName];
GSNibItem *item = nil;
if (i >= 0)
if([object isEqualToString: @"FirstResponder"])
return nil;
if([classManager isSuperclass: @"NSView" linkedToClass: object] ||
[object isEqual: @"NSView"])
{
id object = [classesView itemAtRow: i];
GSNibItem *item = nil;
Class cls;
NSString *className = object;
BOOL isCustom = [classManager isCustomClass: object];
id instance;
if([object isKindOfClass: [NSString class]])
if(isCustom)
{
if([object isEqualToString: @"FirstResponder"])
return nil;
if([classManager isSuperclass: @"NSView" linkedToClass: object] ||
[object isEqual: @"NSView"])
{
Class cls;
NSString *className = object;
BOOL isCustom = [classManager isCustomClass: object];
id instance;
if(isCustom)
{
className = [classManager nonCustomSuperClassOf: object];
}
// instantiate the object or it's substitute...
cls = NSClassFromString(className);
if([cls respondsToSelector: @selector(allocSubstitute)])
{
instance = [cls allocSubstitute];
}
else
{
instance = [cls alloc];
}
// give it some initial dimensions...
if([instance respondsToSelector: @selector(initWithFrame:)])
{
instance = [instance initWithFrame: NSMakeRect(10,10,380,280)];
}
else
{
instance = [instance init];
}
// add it to the top level objects...
[self setName: nil forObject: instance];
[self attachObject: instance toParent: nil];
[topLevelObjects addObject: instance];
[objectsView addObject: instance];
// we want to record if it's custom or not and act appropriately...
if(isCustom)
{
NSString *name = [self nameForObject: instance];
[classManager setCustomClass: object
forName: name];
}
[selectionBox setContentView: scrollView];
NSLog(@"Instantiate NSView subclass %@",object);
}
else
{
item = [[GormObjectProxy alloc] initWithClassName: object
frame: NSMakeRect(0,0,0,0)];
[self setName: nil forObject: item];
[self attachObject: item toParent: nil];
[selectionBox setContentView: scrollView];
}
className = [classManager nonCustomSuperClassOf: object];
}
// instantiate the object or it's substitute...
cls = NSClassFromString(className);
if([cls respondsToSelector: @selector(allocSubstitute)])
{
instance = [cls allocSubstitute];
}
else
{
instance = [cls alloc];
}
// give it some initial dimensions...
if([instance respondsToSelector: @selector(initWithFrame:)])
{
instance = [instance initWithFrame: NSMakeRect(10,10,380,280)];
}
else
{
instance = [instance init];
}
// add it to the top level objects...
[self setName: nil forObject: instance];
[self attachObject: instance toParent: nil];
[topLevelObjects addObject: instance];
[objectsView addObject: instance];
// we want to record if it's custom or not and act appropriately...
if(isCustom)
{
NSString *name = [self nameForObject: instance];
[classManager setCustomClass: object
forName: name];
}
[selectionBox setContentView: scrollView];
NSLog(@"Instantiate NSView subclass %@",object);
}
else
{
item = [[GormObjectProxy alloc] initWithClassName: object
frame: NSMakeRect(0,0,0,0)];
[self setName: nil forObject: item];
[self attachObject: item toParent: nil];
[selectionBox setContentView: scrollView];
}
return self;
}

View file

@ -108,7 +108,7 @@ extern NSString *IBClassNameChangedNotification;
// /*
// * This method deletes all the objects in the current selection in the editor.
// */
// - (void) deleteSelection;
- (void) deleteSelection;
/**
* This method returns the document that owns the object that the editor edits.

View file

@ -178,7 +178,9 @@ extern NSString *GormResizeCellNotification;
- (void) selectClassWithObject: (id)obj;
- (void) selectClass: (NSString *)className;
- (BOOL) currentSelectionIsClass;
- (void) editClass: (id)sender;
- (void) editClass;
- (void) createSubclass;
- (void) deleteSelection;
@end
@interface GormGenericEditor : NSMatrix <IBEditors, IBSelectionOwners>