From fe597a7c3b31d07c4aa7438e68e885ed73e160c0 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Tue, 23 Jul 2002 06:00:15 +0000 Subject: [PATCH] Forgot to add these... git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@14193 72102866-910b-0410-8b05-ffd578937521 --- GormCustomClassInspector.h | 16 ++++ GormCustomClassInspector.m | 168 +++++++++++++++++++++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 GormCustomClassInspector.h create mode 100644 GormCustomClassInspector.m diff --git a/GormCustomClassInspector.h b/GormCustomClassInspector.h new file mode 100644 index 00000000..84f07468 --- /dev/null +++ b/GormCustomClassInspector.h @@ -0,0 +1,16 @@ +/* All Rights reserved */ + +#import +#import "Gorm.h" + +@class GormClassManager; + +@interface GormCustomClassInspector : IBInspector +{ + id browser; + GormClassManager *_classManager; + id _currentSelection; + NSString *_currentSelectionClassName; +} +- (void) select: (id)sender; +@end diff --git a/GormCustomClassInspector.m b/GormCustomClassInspector.m new file mode 100644 index 00000000..3682f108 --- /dev/null +++ b/GormCustomClassInspector.m @@ -0,0 +1,168 @@ +/* All Rights reserved */ + +#include +#include "GormCustomClassInspector.h" +#include "GormPrivate.h" +#include "GormClassManager.h" + +@implementation GormCustomClassInspector ++ (void) initialize +{ + if (self == [GormCustomClassInspector class]) + { + // TBD + } +} + +- (id) init +{ + self = [super init]; + if (self != nil) + { + NSDictionary *table = nil; + NSBundle *bundle = nil; + _classManager = nil; + _currentSelection = nil; + _currentSelectionClassName = nil; + + if (![NSBundle loadNibNamed: @"GormCustomClassInspector" + owner: self]) + { + NSLog(@"Could not open gorm GormCustomClassInspector"); + NSLog(@"self %@", self); + return nil; + } + else + { + [[NSNotificationCenter defaultCenter] + addObserver: self + selector: @selector(handleNotification:) + name: IBSelectionChangedNotification + object: nil]; + } + } + return self; +} + +- (void) dealloc +{ + [[NSNotificationCenter defaultCenter] removeObserver: self]; +} + +- (void) _setCurrentSelectionClassName: (id)anobject +{ + NSString *prefix = nil, *substring = nil; + + ASSIGN(_currentSelectionClassName, NSStringFromClass([anobject class])); + prefix = [_currentSelectionClassName substringToIndex: 4]; + if([prefix isEqualToString: @"Gorm"]) + { + substring = [_currentSelectionClassName substringFromIndex: 4]; + ASSIGN(_currentSelectionClassName, substring); + } + NSLog(@"%@",_currentSelectionClassName); +} + +- (void) handleNotification: (NSNotification*)aNotification +{ + id editor = [aNotification object]; + + if([editor respondsToSelector: @selector(document)]) + { + id doc = [editor document]; + NSArray *selections = [editor selection]; + + if([selections count] == 1) + { + _classManager = [doc classManager]; + _currentSelection = [selections objectAtIndex: 0]; + [self _setCurrentSelectionClassName: _currentSelection]; + [browser reloadColumn: 0]; + } + else + { + _currentSelection = nil; + NSLog(@"Invalid selection"); + } + } +} + +- (void) awakeFromNib +{ + [browser setTarget: self]; + [browser setAction: @selector(select:)]; +} + +- (void) select: (id)sender +{ + /* insert your code here */ + NSLog(@"Selected"); +} + +- (NSArray *)_additionalSubclasses +{ + NSArray *result = nil; + if([_currentSelectionClassName isEqualToString: @"NSTextField"]) + { + result = [NSArray arrayWithObject: @"NSSecureTextField"]; + } + else if([_currentSelectionClassName isEqualToString: @"NSWindow"]) + { + result = [NSArray arrayWithObject: @"NSPanel"]; + } + return result; +} + +// Browser delegate + +- (BOOL) browser: (NSBrowser*)sender + selectRow: (int)row + inColumn: (int)column +{ + return YES; +} + +- (void) browser: (NSBrowser *)sender +createRowsForColumn: (int)column + inMatrix: (NSMatrix *)matrix +{ + NSMutableArray *classes = [NSMutableArray arrayWithObject: _currentSelectionClassName]; + NSEnumerator *e = nil; + NSString *class = nil; + NSBrowserCell *cell = nil; + int i = 0; + + [classes addObjectsFromArray: [_classManager allCustomSubclassesOf: _currentSelectionClassName]]; + [classes addObjectsFromArray: [self _additionalSubclasses]]; + e = [classes objectEnumerator]; + while((class = [e nextObject]) != nil) + { + [matrix insertRow: i withCells: nil]; + cell = [matrix cellAtRow: i column: 0]; + [cell setLeaf: YES]; + i++; + [cell setStringValue: class]; + } +} + +- (NSString*) browser: (NSBrowser*)sender + titleOfColumn: (int)column +{ + NSLog(@"Delegate called"); + 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 +