2002-10-13 06:04:05 +00:00
|
|
|
/** <title>GormCustomClassInspector</title>
|
|
|
|
|
|
|
|
<abstract>allow user to select custom classes</abstract>
|
|
|
|
|
|
|
|
Copyright (C) 2002 Free Software Foundation, Inc.
|
|
|
|
Author: Gregory John Casamento <greg_casamento@yahoo.com>
|
|
|
|
Date: September 2002
|
|
|
|
|
|
|
|
This file is part of GNUstep.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
If not, write to the Free Software Foundation,
|
|
|
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2002-07-23 06:00:15 +00:00
|
|
|
/* All Rights reserved */
|
|
|
|
|
|
|
|
#include <AppKit/AppKit.h>
|
|
|
|
#include "GormCustomClassInspector.h"
|
|
|
|
#include "GormPrivate.h"
|
|
|
|
#include "GormClassManager.h"
|
2002-10-13 06:04:05 +00:00
|
|
|
#include "GormDocument.h"
|
|
|
|
#include "GormPrivate.h"
|
2002-07-23 06:00:15 +00:00
|
|
|
|
|
|
|
@implementation GormCustomClassInspector
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (self == [GormCustomClassInspector class])
|
|
|
|
{
|
|
|
|
// TBD
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self != nil)
|
|
|
|
{
|
2002-10-13 06:04:05 +00:00
|
|
|
// initialize all member variables...
|
2002-07-23 06:00:15 +00:00
|
|
|
_classManager = nil;
|
|
|
|
_currentSelection = nil;
|
|
|
|
_currentSelectionClassName = nil;
|
2002-10-13 06:04:05 +00:00
|
|
|
_rowToSelect = 0;
|
|
|
|
|
|
|
|
// load the gui...
|
2002-07-23 06:00:15 +00:00
|
|
|
if (![NSBundle loadNibNamed: @"GormCustomClassInspector"
|
2003-02-13 13:32:59 +00:00
|
|
|
owner: self])
|
2002-07-23 06:00:15 +00:00
|
|
|
{
|
|
|
|
NSLog(@"Could not open gorm GormCustomClassInspector");
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2002-10-13 06:04:05 +00:00
|
|
|
- (void) _setCurrentSelectionClassName: (id)anobject
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
NSString *className;
|
2003-01-09 03:39:27 +00:00
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
className = [_classManager customClassForObject: anobject]; // nameForObject];
|
|
|
|
if ([className isEqualToString: @""]
|
|
|
|
|| className == nil)
|
2002-10-13 06:04:05 +00:00
|
|
|
{
|
|
|
|
className = NSStringFromClass([anobject class]);
|
|
|
|
}
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
ASSIGN(_currentSelectionClassName,
|
|
|
|
[GormClassManager correctClassName: className]);
|
|
|
|
ASSIGN(_parentClassName,
|
|
|
|
[GormClassManager correctClassName: NSStringFromClass([anobject class])]);
|
2002-07-23 06:00:15 +00:00
|
|
|
}
|
|
|
|
|
2002-11-18 20:54:26 +00:00
|
|
|
- (void) setObject: (id)anObject
|
2002-07-23 06:00:15 +00:00
|
|
|
{
|
2002-11-18 20:54:26 +00:00
|
|
|
[super setObject: anObject];
|
|
|
|
_document = [(Gorm *)NSApp activeDocument];
|
|
|
|
_classManager = [(Gorm *)NSApp classManager];
|
|
|
|
_currentSelection = anObject;
|
|
|
|
|
|
|
|
NSDebugLog(@"Current selection %@", _currentSelection);
|
|
|
|
[self _setCurrentSelectionClassName: _currentSelection];
|
|
|
|
[browser reloadColumn: 0];
|
|
|
|
|
|
|
|
// select the class...
|
|
|
|
[browser selectRow: _rowToSelect inColumn: 0];
|
|
|
|
[browser setNeedsDisplay: YES];
|
2002-07-23 06:00:15 +00:00
|
|
|
}
|
|
|
|
|
2002-11-18 20:54:26 +00:00
|
|
|
|
2002-07-23 06:00:15 +00:00
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
|
|
|
[browser setTarget: self];
|
|
|
|
[browser setAction: @selector(select:)];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) select: (id)sender
|
|
|
|
{
|
2002-10-13 06:04:05 +00:00
|
|
|
NSCell *cell = [browser selectedCellInColumn: 0];
|
2002-11-18 06:15:06 +00:00
|
|
|
NSString *stringValue = [NSString stringWithString: [cell stringValue]];
|
2002-10-13 06:04:05 +00:00
|
|
|
NSString *nameForObject = [_document nameForObject: _currentSelection];
|
2002-11-18 06:15:06 +00:00
|
|
|
NSString *classForObject = NSStringFromClass([_currentSelection class]);
|
|
|
|
|
|
|
|
NSDebugLog(@"selected = %@, class = %@",stringValue,nameForObject);
|
|
|
|
|
|
|
|
/* add or remove the mapping as necessary. */
|
2003-02-13 13:32:59 +00:00
|
|
|
if (![stringValue isEqualToString: classForObject])
|
2002-11-18 06:15:06 +00:00
|
|
|
{
|
|
|
|
[_classManager setCustomClass: stringValue
|
|
|
|
forObject: nameForObject];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[_classManager removeCustomClassForObject: nameForObject];
|
|
|
|
}
|
2002-07-23 06:00:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Browser delegate
|
|
|
|
- (void) browser: (NSBrowser *)sender
|
|
|
|
createRowsForColumn: (int)column
|
|
|
|
inMatrix: (NSMatrix *)matrix
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
if (_parentClassName != nil)
|
2002-07-23 06:00:15 +00:00
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
NSMutableArray *classes;
|
|
|
|
NSEnumerator *e = nil;
|
|
|
|
NSString *class = nil;
|
|
|
|
NSBrowserCell *cell = nil;
|
|
|
|
int i = 0;
|
2002-10-13 06:04:05 +00:00
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
classes = [NSMutableArray arrayWithObject: _parentClassName];
|
2002-10-13 06:04:05 +00:00
|
|
|
// get a list of all of the classes allowed and the class to be shown.
|
2003-02-13 13:32:59 +00:00
|
|
|
[classes addObjectsFromArray:
|
|
|
|
[_classManager allCustomSubclassesOf: _parentClassName]];
|
2002-10-13 06:04:05 +00:00
|
|
|
|
|
|
|
// enumerate through the classes...
|
|
|
|
e = [classes objectEnumerator];
|
2003-02-13 13:32:59 +00:00
|
|
|
while ((class = [e nextObject]) != nil)
|
2002-10-13 06:04:05 +00:00
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
if ([class isEqualToString: _currentSelectionClassName])
|
2002-10-13 06:04:05 +00:00
|
|
|
{
|
|
|
|
_rowToSelect = i;
|
|
|
|
}
|
|
|
|
[matrix insertRow: i withCells: nil];
|
|
|
|
cell = [matrix cellAtRow: i column: 0];
|
|
|
|
[cell setLeaf: YES];
|
|
|
|
i++;
|
|
|
|
[cell setStringValue: class];
|
|
|
|
}
|
2002-07-23 06:00:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) browser: (NSBrowser*)sender
|
|
|
|
titleOfColumn: (int)column
|
|
|
|
{
|
2002-10-13 06:04:05 +00:00
|
|
|
NSDebugLog(@"Delegate called");
|
2002-07-23 06:00:15 +00:00
|
|
|
return @"Class";
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) browser: (NSBrowser *)sender
|
|
|
|
willDisplayCell: (id)cell
|
|
|
|
atRow: (int)row
|
|
|
|
column: (int)column
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) browser: (NSBrowser *)sender
|
|
|
|
isColumnValid: (int)column
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|