2003-06-06 06:24:46 +00:00
|
|
|
/** <title>GormClassInspector</title>
|
|
|
|
|
|
|
|
<abstract>allow user to select custom classes</abstract>
|
|
|
|
|
|
|
|
Copyright (C) 2003 Free Software Foundation, Inc.
|
|
|
|
Author: Gregory John Casamento <greg_casamento@yahoo.com>
|
|
|
|
Date: March 2003
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* All Rights reserved */
|
|
|
|
|
|
|
|
#include <AppKit/AppKit.h>
|
|
|
|
#include "GormClassInspector.h"
|
|
|
|
#include "GormPrivate.h"
|
|
|
|
#include "GormClassManager.h"
|
|
|
|
#include "GormDocument.h"
|
2003-06-08 04:38:59 +00:00
|
|
|
#include <InterfaceBuilder/IBApplicationAdditions.h>
|
2003-06-06 06:24:46 +00:00
|
|
|
|
2003-06-07 19:31:48 +00:00
|
|
|
NSNotificationCenter *nc = nil;
|
|
|
|
|
2004-02-13 03:38:01 +00:00
|
|
|
// interfaces
|
|
|
|
@interface GormDocument (GormClassInspectorAdditions)
|
|
|
|
- (void) collapseClass: (NSString *)className;
|
2004-04-26 03:26:23 +00:00
|
|
|
- (void) reloadClasses;
|
2004-02-13 03:38:01 +00:00
|
|
|
@end
|
|
|
|
|
2003-06-06 06:24:46 +00:00
|
|
|
// the data source classes for each of the tables...
|
|
|
|
@interface GormOutletDataSource : NSObject
|
|
|
|
{
|
|
|
|
id inspector;
|
|
|
|
}
|
|
|
|
- (void) setInspector: (id)ins;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface GormActionDataSource : NSObject
|
|
|
|
{
|
|
|
|
id inspector;
|
|
|
|
}
|
|
|
|
- (void) setInspector: (id)ins;
|
|
|
|
@end
|
|
|
|
|
2004-02-12 06:56:56 +00:00
|
|
|
@interface GormClassesDataSource : NSObject
|
|
|
|
{
|
|
|
|
id inspector;
|
|
|
|
}
|
|
|
|
- (void) setInspector: (id)ins;
|
|
|
|
@end
|
|
|
|
|
2004-02-13 03:38:01 +00:00
|
|
|
// implementation
|
|
|
|
@implementation GormDocument (GormClassInspectorAdditions)
|
|
|
|
- (void) collapseClass: (NSString *)className
|
|
|
|
{
|
|
|
|
NSDebugLog(@"%@",className);
|
2004-04-26 05:03:53 +00:00
|
|
|
[classesView reset];
|
2004-04-28 01:48:49 +00:00
|
|
|
[classesView expandItem: className];
|
|
|
|
[classesView collapseItem: className collapseChildren: YES];
|
2004-02-13 03:38:01 +00:00
|
|
|
}
|
2004-04-26 03:26:23 +00:00
|
|
|
|
|
|
|
- (void) reloadClasses
|
|
|
|
{
|
|
|
|
[classesView reloadData];
|
|
|
|
}
|
2004-02-13 03:38:01 +00:00
|
|
|
@end
|
|
|
|
|
2003-06-06 06:24:46 +00:00
|
|
|
@implementation GormOutletDataSource
|
|
|
|
- (int) numberOfRowsInTableView: (NSTableView *)tv
|
|
|
|
{
|
|
|
|
NSArray *list = [[(Gorm *)NSApp classManager] allOutletsForClassNamed: [inspector _currentClass]];
|
|
|
|
return [list count];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) tableView: (NSTableView *)tv
|
|
|
|
objectValueForTableColumn: (NSTableColumn *)tc
|
|
|
|
row: (int)rowIndex
|
|
|
|
{
|
|
|
|
NSArray *list = [[(Gorm *)NSApp classManager] allOutletsForClassNamed: [inspector _currentClass]];
|
2003-08-28 04:32:41 +00:00
|
|
|
id value = nil;
|
|
|
|
if([list count] > 0)
|
|
|
|
{
|
|
|
|
value = [list objectAtIndex: rowIndex];
|
|
|
|
}
|
|
|
|
return value;
|
2003-06-06 06:24:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) tableView: (NSTableView *)tv
|
|
|
|
setObjectValue: (id)anObject
|
|
|
|
forTableColumn: (NSTableColumn *)tc
|
|
|
|
row: (int)rowIndex
|
|
|
|
{
|
2004-08-18 04:19:45 +00:00
|
|
|
id classManager = [(Gorm *)NSApp classManager];
|
|
|
|
NSString *currentClass = [inspector _currentClass];
|
|
|
|
NSArray *list = [classManager allOutletsForClassNamed: currentClass];
|
2003-06-06 06:24:46 +00:00
|
|
|
NSString *name = [list objectAtIndex: rowIndex];
|
2004-01-05 03:36:24 +00:00
|
|
|
NSString *formattedOutlet = [GormDocument formatOutlet: anObject];
|
2004-04-26 05:03:53 +00:00
|
|
|
GormDocument *document = (GormDocument *)[(id <IB>)NSApp activeDocument];
|
2004-08-18 04:19:45 +00:00
|
|
|
|
|
|
|
if(![name isEqual: anObject])
|
|
|
|
{
|
|
|
|
BOOL removed = [document
|
|
|
|
removeConnectionsWithLabel: name
|
|
|
|
forClassNamed: currentClass
|
|
|
|
isAction: NO];
|
|
|
|
if(removed)
|
|
|
|
{
|
|
|
|
[classManager replaceOutlet: name
|
|
|
|
withOutlet: formattedOutlet
|
|
|
|
forClassNamed: currentClass];
|
|
|
|
|
|
|
|
// collapse the class in question if it's being edited and make
|
|
|
|
// certain that names in the list are kept in sync.
|
|
|
|
[document collapseClass: currentClass];
|
|
|
|
[document reloadClasses];
|
|
|
|
[document selectClass: currentClass];
|
|
|
|
}
|
|
|
|
}
|
2003-06-06 06:24:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// set methods
|
|
|
|
- (void) setInspector: (id)ins
|
|
|
|
{
|
|
|
|
ASSIGN(inspector, ins);
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GormActionDataSource
|
|
|
|
- (int) numberOfRowsInTableView: (NSTableView *)tv
|
|
|
|
{
|
|
|
|
NSArray *list = [[(Gorm *)NSApp classManager] allActionsForClassNamed: [inspector _currentClass]];
|
|
|
|
return [list count];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) tableView: (NSTableView *)tv
|
|
|
|
objectValueForTableColumn: (NSTableColumn *)tc
|
|
|
|
row: (int)rowIndex
|
|
|
|
{
|
|
|
|
NSArray *list = [[(Gorm *)NSApp classManager] allActionsForClassNamed: [inspector _currentClass]];
|
|
|
|
return [list objectAtIndex: rowIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) tableView: (NSTableView *)tv
|
|
|
|
setObjectValue: (id)anObject
|
|
|
|
forTableColumn: (NSTableColumn *)tc
|
|
|
|
row: (int)rowIndex
|
|
|
|
{
|
2004-08-18 04:19:45 +00:00
|
|
|
id classManager = [(Gorm *)NSApp classManager];
|
|
|
|
NSString *currentClass = [inspector _currentClass];
|
2004-08-24 02:17:25 +00:00
|
|
|
NSArray *list = [classManager allActionsForClassNamed: currentClass];
|
2003-06-06 06:24:46 +00:00
|
|
|
NSString *name = [list objectAtIndex: rowIndex];
|
2004-01-05 03:36:24 +00:00
|
|
|
NSString *formattedAction = [GormDocument formatAction: anObject];
|
2004-04-26 05:03:53 +00:00
|
|
|
GormDocument *document = (GormDocument *)[(id <IB>)NSApp activeDocument];
|
2003-06-06 06:24:46 +00:00
|
|
|
|
2004-08-18 04:19:45 +00:00
|
|
|
if(![name isEqual: anObject])
|
|
|
|
{
|
|
|
|
BOOL removed = [document
|
|
|
|
removeConnectionsWithLabel: name
|
|
|
|
forClassNamed: currentClass
|
|
|
|
isAction: YES];
|
|
|
|
if(removed)
|
|
|
|
{
|
|
|
|
[classManager replaceAction: name
|
|
|
|
withAction: formattedAction
|
|
|
|
forClassNamed: currentClass];
|
|
|
|
|
|
|
|
// collapse the class in question if it's being edited and make
|
|
|
|
// certain that names in the list are kept in sync.
|
|
|
|
[document collapseClass: currentClass];
|
|
|
|
[document reloadClasses];
|
|
|
|
[document selectClass: currentClass];
|
|
|
|
}
|
|
|
|
}
|
2003-06-06 06:24:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// set method
|
|
|
|
- (void) setInspector: (id)ins
|
|
|
|
{
|
|
|
|
ASSIGN(inspector, ins);
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2004-02-12 06:56:56 +00:00
|
|
|
@implementation GormClassesDataSource
|
|
|
|
- (int) numberOfRowsInTableView: (NSTableView *)tv
|
|
|
|
{
|
|
|
|
NSArray *list = [[(Gorm *)NSApp classManager] allClassNames];
|
|
|
|
return [list count];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) tableView: (NSTableView *)tv
|
|
|
|
objectValueForTableColumn: (NSTableColumn *)tc
|
|
|
|
row: (int)rowIndex
|
|
|
|
{
|
|
|
|
NSArray *list = [[(Gorm *)NSApp classManager] allClassNames];
|
|
|
|
id value = nil;
|
|
|
|
if([list count] > 0)
|
|
|
|
{
|
|
|
|
value = [list objectAtIndex: rowIndex];
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) tableView: (NSTableView *)tv
|
|
|
|
setObjectValue: (id)anObject
|
|
|
|
forTableColumn: (NSTableColumn *)tc
|
|
|
|
row: (int)rowIndex
|
|
|
|
{
|
|
|
|
// cannot replace any values for this data source...
|
|
|
|
}
|
|
|
|
|
|
|
|
// set methods
|
|
|
|
- (void) setInspector: (id)ins
|
|
|
|
{
|
|
|
|
ASSIGN(inspector, ins);
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2003-06-06 06:24:46 +00:00
|
|
|
@implementation GormClassInspector
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (self == [GormClassInspector class])
|
|
|
|
{
|
2003-06-07 19:31:48 +00:00
|
|
|
nc = [NSNotificationCenter defaultCenter];
|
2003-06-06 06:24:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self != nil)
|
|
|
|
{
|
|
|
|
// initialize all member variables...
|
|
|
|
actionTable = nil;
|
2003-06-07 05:21:16 +00:00
|
|
|
addAction = nil;
|
|
|
|
addOutlet = nil;
|
2003-06-06 06:24:46 +00:00
|
|
|
classField = nil;
|
|
|
|
outletTable = nil;
|
2003-06-07 05:21:16 +00:00
|
|
|
removeAction = nil;
|
|
|
|
removeOutlet = nil;
|
2003-06-06 06:24:46 +00:00
|
|
|
tabView = nil;
|
|
|
|
currentClass = nil;
|
|
|
|
actionData = nil;
|
|
|
|
outletData = nil;
|
2004-02-12 06:56:56 +00:00
|
|
|
parentClassData = nil;
|
2003-06-06 06:24:46 +00:00
|
|
|
|
|
|
|
// load the gui...
|
|
|
|
if (![NSBundle loadNibNamed: @"GormClassInspector"
|
|
|
|
owner: self])
|
|
|
|
{
|
|
|
|
NSLog(@"Could not open gorm GormClassInspector");
|
|
|
|
return nil;
|
|
|
|
}
|
2003-06-08 04:38:59 +00:00
|
|
|
|
|
|
|
[nc addObserver: self
|
|
|
|
selector: @selector(handleNotification:)
|
|
|
|
name: GormDidModifyClassNotification
|
|
|
|
object: nil];
|
|
|
|
|
2003-06-06 06:24:46 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
|
|
|
// instantiate..
|
|
|
|
actionData = [[GormActionDataSource alloc] init];
|
|
|
|
outletData = [[GormOutletDataSource alloc] init];
|
2004-02-12 06:56:56 +00:00
|
|
|
parentClassData = [[GormClassesDataSource alloc] init];
|
2003-06-06 06:24:46 +00:00
|
|
|
|
|
|
|
// initialize..
|
|
|
|
[actionData setInspector: self];
|
|
|
|
[outletData setInspector: self];
|
2004-02-12 06:56:56 +00:00
|
|
|
[parentClassData setInspector: self];
|
2003-06-06 06:24:46 +00:00
|
|
|
|
|
|
|
// use..
|
|
|
|
[actionTable setDataSource: actionData];
|
|
|
|
[outletTable setDataSource: outletData];
|
2004-02-12 06:56:56 +00:00
|
|
|
[parentClass setDataSource: parentClassData];
|
|
|
|
[parentClass setDoubleAction: @selector(selectClass:)];
|
2004-12-18 02:29:31 +00:00
|
|
|
[parentClass setTarget: self];
|
2003-06-06 06:24:46 +00:00
|
|
|
|
|
|
|
// delegate...
|
|
|
|
[actionTable setDelegate: self];
|
|
|
|
[outletTable setDelegate: self];
|
2004-02-12 06:56:56 +00:00
|
|
|
[parentClass setDelegate: self];
|
2003-06-06 06:24:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _refreshView
|
|
|
|
{
|
2003-06-07 05:21:16 +00:00
|
|
|
id addActionCell = [addAction cell];
|
|
|
|
id removeActionCell = [removeAction cell];
|
|
|
|
id addOutletCell = [addOutlet cell];
|
|
|
|
id removeOutletCell = [removeOutlet cell];
|
2004-02-12 06:56:56 +00:00
|
|
|
id selectClassCell = [selectClass cell];
|
|
|
|
id searchCell = [search cell];
|
2004-11-07 19:32:57 +00:00
|
|
|
BOOL isEditable = [classManager isCustomClass: [self _currentClass]];
|
2003-06-07 05:21:16 +00:00
|
|
|
BOOL isFirstResponder = [[self _currentClass] isEqualToString: @"FirstResponder"];
|
2004-02-12 06:56:56 +00:00
|
|
|
NSArray *list = [classManager allClassNames];
|
|
|
|
NSString *superClass = [classManager parentOfClass: [self _currentClass]];
|
|
|
|
int index = [list indexOfObject: superClass];
|
2003-06-06 06:24:46 +00:00
|
|
|
|
|
|
|
[classField setStringValue: [self _currentClass]];
|
|
|
|
[outletTable reloadData];
|
|
|
|
[actionTable reloadData];
|
2004-02-12 06:56:56 +00:00
|
|
|
[parentClass reloadData];
|
2003-06-06 06:24:46 +00:00
|
|
|
|
2003-06-07 05:21:16 +00:00
|
|
|
// activate for actions...
|
2004-11-07 19:32:57 +00:00
|
|
|
[addActionCell setEnabled: YES]; //isEditable];
|
|
|
|
[removeActionCell setEnabled: YES]; //isEditable];
|
2003-06-07 05:21:16 +00:00
|
|
|
|
|
|
|
// activate for outlet...
|
2004-11-07 19:32:57 +00:00
|
|
|
[addOutletCell setEnabled: (isEditable && !isFirstResponder)];
|
|
|
|
[removeOutletCell setEnabled: (isEditable && !isFirstResponder)];
|
2004-02-12 06:56:56 +00:00
|
|
|
|
|
|
|
// activate select class...
|
2004-11-07 19:32:57 +00:00
|
|
|
[selectClassCell setEnabled: (isEditable && !isFirstResponder)];
|
|
|
|
[parentClass setEnabled: (isEditable && !isFirstResponder)];
|
|
|
|
[searchCell setEnabled: (isEditable && !isFirstResponder)];
|
|
|
|
[classField setEditable: (isEditable && !isFirstResponder)];
|
2004-12-11 15:25:54 +00:00
|
|
|
[classField setBackgroundColor: ((isEditable && !isFirstResponder)?[NSColor whiteColor]:[NSColor lightGrayColor])];
|
2004-06-26 22:08:42 +00:00
|
|
|
|
2004-02-12 06:56:56 +00:00
|
|
|
// select the parent class
|
2004-02-15 18:04:32 +00:00
|
|
|
if(index != NSNotFound)
|
|
|
|
{
|
|
|
|
[parentClass selectRow: index byExtendingSelection: NO];
|
|
|
|
[parentClass scrollRowToVisible: index];
|
|
|
|
}
|
2003-06-06 06:24:46 +00:00
|
|
|
}
|
|
|
|
|
2003-06-07 05:21:16 +00:00
|
|
|
- (void) addAction: (id)sender
|
2003-06-06 06:24:46 +00:00
|
|
|
{
|
2004-04-26 05:03:53 +00:00
|
|
|
GormDocument *document = (GormDocument *)[(id <IB>)NSApp activeDocument];
|
|
|
|
NSString *className = [self _currentClass];
|
2004-11-07 19:32:57 +00:00
|
|
|
NSString *newAction = [classManager addNewActionToClassNamed: className];
|
|
|
|
NSArray *list = [classManager allActionsForClassNamed: className];
|
|
|
|
int row = [list indexOfObject: newAction];
|
2004-04-26 05:03:53 +00:00
|
|
|
|
|
|
|
[document collapseClass: className];
|
|
|
|
[document reloadClasses];
|
2003-06-07 19:31:48 +00:00
|
|
|
[nc postNotificationName: IBInspectorDidModifyObjectNotification
|
|
|
|
object: classManager];
|
2003-06-07 05:21:16 +00:00
|
|
|
[actionTable reloadData];
|
2004-11-07 19:32:57 +00:00
|
|
|
[actionTable scrollRowToVisible: row];
|
|
|
|
[actionTable selectRow: row byExtendingSelection: NO];
|
2004-04-26 05:03:53 +00:00
|
|
|
[document selectClass: className];
|
2003-06-06 06:24:46 +00:00
|
|
|
}
|
|
|
|
|
2003-06-07 05:21:16 +00:00
|
|
|
- (void) addOutlet: (id)sender
|
2003-06-06 06:24:46 +00:00
|
|
|
{
|
2004-04-26 05:03:53 +00:00
|
|
|
GormDocument *document = (GormDocument *)[(id <IB>)NSApp activeDocument];
|
|
|
|
NSString *className = [self _currentClass];
|
2004-11-07 19:32:57 +00:00
|
|
|
NSString *newOutlet = [classManager addNewOutletToClassNamed: className];
|
|
|
|
NSArray *list = [classManager allOutletsForClassNamed: className];
|
|
|
|
int row = [list indexOfObject: newOutlet];
|
|
|
|
|
2004-04-26 05:03:53 +00:00
|
|
|
[document collapseClass: className];
|
|
|
|
[document reloadClasses];
|
2003-06-07 19:31:48 +00:00
|
|
|
[nc postNotificationName: IBInspectorDidModifyObjectNotification
|
|
|
|
object: classManager];
|
2003-06-07 05:21:16 +00:00
|
|
|
[outletTable reloadData];
|
2004-11-07 19:32:57 +00:00
|
|
|
[outletTable scrollRowToVisible: row];
|
|
|
|
[outletTable selectRow: row byExtendingSelection: NO];
|
2004-04-26 05:03:53 +00:00
|
|
|
[document selectClass: className];
|
2003-06-07 05:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeAction: (id)sender
|
|
|
|
{
|
|
|
|
int i = [actionTable selectedRow];
|
2003-12-24 02:50:34 +00:00
|
|
|
NSString *className = [self _currentClass];
|
2004-02-12 06:56:56 +00:00
|
|
|
NSArray *list = [classManager allActionsForClassNamed: className];
|
2004-01-03 07:04:47 +00:00
|
|
|
BOOL removed = NO;
|
2004-11-08 03:19:39 +00:00
|
|
|
BOOL isCustom = [classManager isCustomClass: className];
|
2004-01-03 07:04:47 +00:00
|
|
|
NSString *name = nil;
|
2004-04-26 05:03:53 +00:00
|
|
|
GormDocument *document = (GormDocument *)[(id <IB>)NSApp activeDocument];
|
2004-01-03 07:04:47 +00:00
|
|
|
|
|
|
|
// check the count...
|
2004-11-08 03:19:39 +00:00
|
|
|
if(isCustom || [classManager isCategoryForClass: className])
|
2004-01-03 07:04:47 +00:00
|
|
|
{
|
2004-11-07 19:32:57 +00:00
|
|
|
if([list count] > 0 && i >= 0 && i < [list count])
|
|
|
|
{
|
|
|
|
[actionTable deselectAll: self];
|
|
|
|
name = [list objectAtIndex: i];
|
2004-11-08 03:19:39 +00:00
|
|
|
if(isCustom || [classManager isAction: name onCategoryForClassNamed: className])
|
2004-11-07 19:32:57 +00:00
|
|
|
{
|
|
|
|
removed = [document
|
|
|
|
removeConnectionsWithLabel: name
|
|
|
|
forClassNamed: currentClass
|
|
|
|
isAction: YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(removed)
|
|
|
|
{
|
|
|
|
[document collapseClass: className];
|
|
|
|
[document reloadClasses];
|
|
|
|
[classManager removeAction: name fromClassNamed: className];
|
|
|
|
[nc postNotificationName: IBInspectorDidModifyObjectNotification
|
|
|
|
object: classManager];
|
|
|
|
[actionTable reloadData];
|
|
|
|
[document selectClass: className];
|
|
|
|
}
|
2003-12-24 02:50:34 +00:00
|
|
|
}
|
2003-06-07 05:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeOutlet: (id)sender
|
|
|
|
{
|
|
|
|
int i = [outletTable selectedRow];
|
2003-12-24 02:50:34 +00:00
|
|
|
NSString *className = [self _currentClass];
|
2004-02-12 06:56:56 +00:00
|
|
|
NSArray *list = [classManager allOutletsForClassNamed: className];
|
2004-01-03 07:04:47 +00:00
|
|
|
BOOL removed = NO;
|
|
|
|
NSString *name = nil;
|
2004-04-26 05:03:53 +00:00
|
|
|
GormDocument *document = (GormDocument *)[(id <IB>)NSApp activeDocument];
|
2004-01-03 07:04:47 +00:00
|
|
|
|
|
|
|
// check the count...
|
2004-04-26 03:26:23 +00:00
|
|
|
if([list count] > 0 && i >= 0 && i < [list count])
|
2004-01-03 07:04:47 +00:00
|
|
|
{
|
2004-04-26 03:26:23 +00:00
|
|
|
[outletTable deselectAll: self];
|
2004-01-03 07:04:47 +00:00
|
|
|
name = [list objectAtIndex: i];
|
2004-04-26 05:03:53 +00:00
|
|
|
removed = [document
|
|
|
|
removeConnectionsWithLabel: name
|
|
|
|
forClassNamed: currentClass
|
|
|
|
isAction: NO];
|
2004-01-03 07:04:47 +00:00
|
|
|
}
|
2003-12-24 02:50:34 +00:00
|
|
|
|
|
|
|
if(removed)
|
|
|
|
{
|
2004-04-26 05:03:53 +00:00
|
|
|
[document collapseClass: className];
|
|
|
|
[document reloadClasses];
|
2004-02-12 06:56:56 +00:00
|
|
|
[classManager removeOutlet: name fromClassNamed: className];
|
2003-12-24 02:50:34 +00:00
|
|
|
[nc postNotificationName: IBInspectorDidModifyObjectNotification
|
|
|
|
object: classManager];
|
|
|
|
[outletTable reloadData];
|
2004-04-26 05:03:53 +00:00
|
|
|
[document selectClass: className];
|
2003-12-24 02:50:34 +00:00
|
|
|
}
|
2003-06-06 06:24:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) select: (id)sender
|
|
|
|
{
|
|
|
|
NSLog(@"select...");
|
|
|
|
}
|
|
|
|
|
2004-02-12 06:56:56 +00:00
|
|
|
- (void) searchForClass: (id)sender
|
|
|
|
{
|
|
|
|
NSArray *list = [classManager allClassNames];
|
|
|
|
NSString *stringValue = [searchText stringValue];
|
|
|
|
int index = [list indexOfObject: stringValue];
|
|
|
|
|
|
|
|
NSLog(@"Search... %@",[searchText stringValue]);
|
|
|
|
if(index != NSNotFound && [stringValue isEqualToString: @"FirstResponder"] == NO)
|
|
|
|
{
|
|
|
|
// select the parent class
|
|
|
|
[parentClass selectRow: index byExtendingSelection: NO];
|
|
|
|
[parentClass scrollRowToVisible: index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) selectClass: (id)sender
|
|
|
|
{
|
|
|
|
NSArray *list = [classManager allClassNames];
|
|
|
|
int row = [parentClass selectedRow];
|
2004-02-12 07:04:07 +00:00
|
|
|
|
2004-12-18 02:29:31 +00:00
|
|
|
if(row >= 0)
|
2004-02-12 07:04:07 +00:00
|
|
|
{
|
2004-12-18 02:29:31 +00:00
|
|
|
NSString *newParent = [list objectAtIndex: row];
|
|
|
|
NSString *name = [self _currentClass];
|
|
|
|
BOOL removed = NO;
|
|
|
|
GormDocument *document = (GormDocument *)[(id <IB>)NSApp activeDocument];
|
2004-02-13 03:38:01 +00:00
|
|
|
|
2004-12-18 02:29:31 +00:00
|
|
|
// if it's a custom class, let it go, if not do nothing.
|
|
|
|
if([classManager isCustomClass: name])
|
|
|
|
{
|
|
|
|
// check to see if the user wants to do this and remove the connections.
|
|
|
|
removed = [document removeConnectionsForClassNamed: name];
|
|
|
|
|
|
|
|
// if removed, move the class and notify...
|
|
|
|
if(removed)
|
|
|
|
{
|
|
|
|
NSString *oldSuper = [classManager superClassNameForClassNamed: name];
|
|
|
|
|
|
|
|
[classManager setSuperClassNamed: newParent forClassNamed: name];
|
|
|
|
[nc postNotificationName: IBInspectorDidModifyObjectNotification
|
|
|
|
object: classManager];
|
|
|
|
[document collapseClass: oldSuper];
|
|
|
|
[document collapseClass: name];
|
|
|
|
[document reloadClasses];
|
|
|
|
[document selectClass: name];
|
|
|
|
}
|
|
|
|
}
|
2004-02-12 07:04:07 +00:00
|
|
|
}
|
2004-02-12 06:56:56 +00:00
|
|
|
}
|
|
|
|
|
2004-06-26 03:36:29 +00:00
|
|
|
- (void) changeClassName: (id)sender
|
|
|
|
{
|
|
|
|
NSString *name = [self _currentClass];
|
|
|
|
NSString *newName = [sender stringValue];
|
|
|
|
GormDocument *document = (GormDocument *)[(id <IB>)NSApp activeDocument];
|
2004-06-26 22:08:42 +00:00
|
|
|
BOOL removed = NO;
|
2004-06-26 03:36:29 +00:00
|
|
|
|
2004-06-26 22:08:42 +00:00
|
|
|
// check to see if the user wants to do this and remove the connections.
|
|
|
|
removed = [document removeConnectionsForClassNamed: name];
|
|
|
|
|
|
|
|
if(removed)
|
|
|
|
{
|
|
|
|
[document collapseClass: name];
|
|
|
|
[classManager renameClassNamed: name
|
|
|
|
newName: newName];
|
|
|
|
[nc postNotificationName: IBInspectorDidModifyObjectNotification
|
|
|
|
object: classManager];
|
|
|
|
[document reloadClasses];
|
|
|
|
[document selectClass: newName];
|
|
|
|
}
|
2004-06-26 03:36:29 +00:00
|
|
|
}
|
|
|
|
|
2004-02-12 06:56:56 +00:00
|
|
|
- (void) clickOnClass: (id)sender
|
|
|
|
{
|
|
|
|
NSLog(@"Click on class %@",sender);
|
|
|
|
}
|
|
|
|
|
2003-06-06 06:24:46 +00:00
|
|
|
- (void) setObject: (id)anObject
|
|
|
|
{
|
2004-12-11 05:53:51 +00:00
|
|
|
int outletsCount = 0;
|
|
|
|
int actionsCount = 0;
|
|
|
|
NSTabViewItem *item = nil;
|
|
|
|
|
2004-04-26 05:03:53 +00:00
|
|
|
[super setObject: anObject];
|
2003-06-06 06:24:46 +00:00
|
|
|
ASSIGN(classManager, [(Gorm *)NSApp classManager]);
|
2004-04-26 05:03:53 +00:00
|
|
|
ASSIGN(currentClass, [object className]);
|
2004-12-11 05:53:51 +00:00
|
|
|
|
|
|
|
outletsCount = [[classManager allOutletsForClassNamed: currentClass] count];
|
|
|
|
actionsCount = [[classManager allActionsForClassNamed: currentClass] count];
|
|
|
|
|
|
|
|
item = [tabView tabViewItemAtIndex: 1]; // actions;
|
|
|
|
[item setLabel: [NSString stringWithFormat: @"Actions (%d)",actionsCount]];
|
|
|
|
item = [tabView tabViewItemAtIndex: 0]; // outlets;
|
|
|
|
[item setLabel: [NSString stringWithFormat: @"Outlets (%d)",outletsCount]];
|
|
|
|
[tabView setNeedsDisplay: YES];
|
|
|
|
|
2003-06-06 06:24:46 +00:00
|
|
|
[self _refreshView];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _currentClass
|
|
|
|
{
|
2004-04-26 05:03:53 +00:00
|
|
|
return [object className];
|
2003-06-06 06:24:46 +00:00
|
|
|
}
|
|
|
|
|
2003-06-08 04:38:59 +00:00
|
|
|
- (void) handleNotification: (NSNotification *)notification
|
|
|
|
{
|
|
|
|
if([notification object] == classManager)
|
|
|
|
{
|
|
|
|
[self _refreshView];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// table delegate/data source methods...
|
2003-06-06 06:24:46 +00:00
|
|
|
- (BOOL) tableView: (NSTableView *)tableView
|
|
|
|
shouldEditTableColumn: (NSTableColumn *)aTableColumn
|
|
|
|
row: (int)rowIndex
|
|
|
|
{
|
|
|
|
BOOL result = NO;
|
|
|
|
|
2004-02-12 06:56:56 +00:00
|
|
|
if(tableView != parentClass)
|
2003-06-06 06:24:46 +00:00
|
|
|
{
|
2004-02-12 06:56:56 +00:00
|
|
|
NSArray *list = nil;
|
|
|
|
NSString *name = nil;
|
|
|
|
NSString *className = [self _currentClass];
|
|
|
|
|
2004-11-09 13:52:27 +00:00
|
|
|
if(tableView == actionTable)
|
2004-02-12 06:56:56 +00:00
|
|
|
{
|
|
|
|
list = [classManager allActionsForClassNamed: className];
|
|
|
|
name = [list objectAtIndex: rowIndex];
|
|
|
|
}
|
2004-11-09 13:52:27 +00:00
|
|
|
else if(tableView == outletTable)
|
2004-02-12 06:56:56 +00:00
|
|
|
{
|
|
|
|
list = [classManager allOutletsForClassNamed: className];
|
|
|
|
name = [list objectAtIndex: rowIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
if([classManager isCustomClass: className])
|
|
|
|
{
|
2004-11-09 13:52:27 +00:00
|
|
|
if(tableView == actionTable)
|
2004-02-12 06:56:56 +00:00
|
|
|
{
|
|
|
|
result = [classManager isAction: name
|
|
|
|
ofClass: className];
|
|
|
|
}
|
2004-11-09 13:52:27 +00:00
|
|
|
else if(tableView == outletTable)
|
2004-02-12 06:56:56 +00:00
|
|
|
{
|
|
|
|
result = [classManager isOutlet: name
|
|
|
|
ofClass: className];
|
|
|
|
}
|
|
|
|
}
|
2004-11-07 19:32:57 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
result = [classManager isAction: name onCategoryForClassNamed: className];
|
|
|
|
}
|
2003-06-06 06:24:46 +00:00
|
|
|
}
|
2004-02-12 06:56:56 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2004-11-09 13:52:27 +00:00
|
|
|
/*
|
|
|
|
- (void) tableView: (NSTableView *)tableView
|
|
|
|
willDisplayCell: (id)aCell
|
|
|
|
forTableColumn: (NSTableColumn *)aTableColumn
|
|
|
|
row: (int)rowIndex
|
|
|
|
{
|
|
|
|
NSString *name = [aCell stringValue];
|
|
|
|
NSString *className = [self _currentClass];
|
|
|
|
|
|
|
|
if(tableView == actionTable)
|
|
|
|
{
|
|
|
|
if(([classManager isCustomClass: className] &&
|
|
|
|
[classManager isAction: name ofClass: className]) ||
|
|
|
|
[classManager isAction: name onCategoryForClassNamed: className])
|
|
|
|
{
|
|
|
|
[aCell setTextColor: [NSColor blackColor]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[aCell setTextColor: [NSColor darkGrayColor]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(tableView == outletTable)
|
|
|
|
{
|
|
|
|
if([classManager isCustomClass: className] &&
|
|
|
|
[classManager isOutlet: name ofClass: className])
|
|
|
|
{
|
|
|
|
[aCell setTextColor: [NSColor blackColor]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[aCell setTextColor: [NSColor darkGrayColor]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2004-02-12 06:56:56 +00:00
|
|
|
- (BOOL) tableView: (NSTableView *)tv
|
|
|
|
shouldSelectRow: (int)rowIndex
|
|
|
|
{
|
|
|
|
BOOL result = YES;
|
|
|
|
if(tv == parentClass)
|
2003-06-06 06:24:46 +00:00
|
|
|
{
|
2004-02-12 06:56:56 +00:00
|
|
|
NSArray *list = [classManager allClassNames];
|
|
|
|
NSString *className = [list objectAtIndex: rowIndex];
|
2004-02-13 03:38:01 +00:00
|
|
|
NSString *name = [self _currentClass];
|
2004-02-12 06:56:56 +00:00
|
|
|
BOOL isFirstResponder = [className isEqualToString: @"FirstResponder"];
|
2004-02-13 03:38:01 +00:00
|
|
|
BOOL isCurrentClass = [className isEqualToString: name];
|
|
|
|
BOOL isSubClass = [classManager isSuperclass: name linkedToClass: className];
|
|
|
|
if(isFirstResponder || isCurrentClass || isSubClass)
|
2003-06-06 06:24:46 +00:00
|
|
|
{
|
2004-02-12 06:56:56 +00:00
|
|
|
NSBeep();
|
|
|
|
result = NO;
|
2003-06-06 06:24:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2004-02-12 06:56:56 +00:00
|
|
|
|
2003-06-06 06:24:46 +00:00
|
|
|
@end
|