1999-12-08 15:04:57 +00:00
|
|
|
|
/* GormDocument.m
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 1999 Free Software Foundation, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Author: Richard Frith-Macdonald <richard@brainstrom.co.uk>
|
|
|
|
|
* Date: 1999
|
2002-11-23 22:52:27 +00:00
|
|
|
|
* Author: Gregory John Casamento <greg_casamento@yahoo.com>
|
|
|
|
|
* Date: 2002
|
|
|
|
|
*
|
1999-12-08 15:04:57 +00:00
|
|
|
|
* This file is part of GNUstep.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "GormPrivate.h"
|
2001-10-05 15:02:55 +00:00
|
|
|
|
#include "GormClassManager.h"
|
|
|
|
|
#include "GormCustomView.h"
|
2002-07-08 04:45:23 +00:00
|
|
|
|
#include "GormOutlineView.h"
|
2002-11-18 20:54:26 +00:00
|
|
|
|
#include <AppKit/NSImage.h>
|
2002-11-04 13:52:31 +00:00
|
|
|
|
#include <AppKit/NSSound.h>
|
2003-01-02 06:17:15 +00:00
|
|
|
|
#include <Foundation/NSUserDefaults.h>
|
2003-05-23 02:25:34 +00:00
|
|
|
|
#include <AppKit/NSNibConnector.h>
|
2003-10-08 05:00:21 +00:00
|
|
|
|
#include <GNUstepGUI/GSNibTemplates.h>
|
1999-12-08 15:04:57 +00:00
|
|
|
|
|
2003-04-18 05:40:25 +00:00
|
|
|
|
@interface GormDisplayCell : NSButtonCell
|
|
|
|
|
@end
|
2003-10-08 05:00:21 +00:00
|
|
|
|
|
2003-04-18 05:40:25 +00:00
|
|
|
|
@implementation GormDisplayCell
|
|
|
|
|
- (void) setShowsFirstResponder: (BOOL)flag
|
|
|
|
|
{
|
|
|
|
|
[super setShowsFirstResponder: NO]; // Never show ugly frame round button
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
2004-01-06 06:11:24 +00:00
|
|
|
|
@interface NSNibControlConnector (GormExtension)
|
|
|
|
|
- (BOOL) isEqual: (id)object;
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation NSNibControlConnector (GormExtension)
|
|
|
|
|
- (BOOL) isEqual: (id)object
|
|
|
|
|
{
|
|
|
|
|
BOOL result = NO;
|
|
|
|
|
if([[self source] isEqual: [object source]] &&
|
|
|
|
|
[[self destination] isEqual: [object destination]] &&
|
|
|
|
|
[[self label] isEqual: [object label]])
|
|
|
|
|
{
|
|
|
|
|
result = YES;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
2002-12-22 00:33:44 +00:00
|
|
|
|
// Internal only
|
|
|
|
|
NSString *GSCustomClassMap = @"GSCustomClassMap";
|
|
|
|
|
|
2002-11-13 16:10:22 +00:00
|
|
|
|
@interface GormDocument (GModel)
|
|
|
|
|
- (id) openGModel: (NSString *)path;
|
2002-11-05 05:42:45 +00:00
|
|
|
|
@end
|
|
|
|
|
|
1999-12-13 17:01:35 +00:00
|
|
|
|
@implementation GormFirstResponder
|
|
|
|
|
- (NSImage*) imageForViewer
|
|
|
|
|
{
|
|
|
|
|
static NSImage *image = nil;
|
|
|
|
|
|
|
|
|
|
if (image == nil)
|
|
|
|
|
{
|
|
|
|
|
NSBundle *bundle = [NSBundle mainBundle];
|
|
|
|
|
NSString *path = [bundle pathForImageResource: @"GormFirstResponder"];
|
|
|
|
|
|
|
|
|
|
image = [[NSImage alloc] initWithContentsOfFile: path];
|
|
|
|
|
}
|
|
|
|
|
return image;
|
|
|
|
|
}
|
1999-12-21 11:38:49 +00:00
|
|
|
|
- (NSString*) inspectorClassName
|
|
|
|
|
{
|
1999-12-21 16:48:32 +00:00
|
|
|
|
return @"GormNotApplicableInspector";
|
|
|
|
|
}
|
|
|
|
|
- (NSString*) connectInspectorClassName
|
|
|
|
|
{
|
2002-01-29 22:41:02 +00:00
|
|
|
|
return @"GormConnectionInspector";
|
1999-12-21 16:48:32 +00:00
|
|
|
|
}
|
|
|
|
|
- (NSString*) sizeInspectorClassName
|
|
|
|
|
{
|
|
|
|
|
return @"GormNotApplicableInspector";
|
1999-12-21 11:38:49 +00:00
|
|
|
|
}
|
2002-11-24 05:52:50 +00:00
|
|
|
|
- (NSString*) classInspectorClassName
|
|
|
|
|
{
|
|
|
|
|
return @"GormNotApplicableInspector";
|
|
|
|
|
}
|
2004-03-04 04:01:09 +00:00
|
|
|
|
- (NSString*) className
|
|
|
|
|
{
|
|
|
|
|
return @"FirstResponder";
|
|
|
|
|
}
|
1999-12-13 17:01:35 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation GormFontManager
|
|
|
|
|
- (NSImage*) imageForViewer
|
|
|
|
|
{
|
|
|
|
|
static NSImage *image = nil;
|
|
|
|
|
|
|
|
|
|
if (image == nil)
|
|
|
|
|
{
|
|
|
|
|
NSBundle *bundle = [NSBundle mainBundle];
|
|
|
|
|
NSString *path = [bundle pathForImageResource: @"GormFontManager"];
|
|
|
|
|
|
|
|
|
|
image = [[NSImage alloc] initWithContentsOfFile: path];
|
|
|
|
|
}
|
|
|
|
|
return image;
|
|
|
|
|
}
|
2003-01-09 05:52:19 +00:00
|
|
|
|
- (NSString*) inspectorClassName
|
|
|
|
|
{
|
|
|
|
|
return @"GormNotApplicableInspector";
|
|
|
|
|
}
|
|
|
|
|
- (NSString*) connectInspectorClassName
|
|
|
|
|
{
|
|
|
|
|
return @"GormConnectionInspector";
|
|
|
|
|
}
|
|
|
|
|
- (NSString*) sizeInspectorClassName
|
|
|
|
|
{
|
|
|
|
|
return @"GormNotApplicableInspector";
|
|
|
|
|
}
|
|
|
|
|
- (NSString*) classInspectorClassName
|
|
|
|
|
{
|
|
|
|
|
return @"GormNotApplicableInspector";
|
|
|
|
|
}
|
1999-12-08 15:04:57 +00:00
|
|
|
|
@end
|
|
|
|
|
|
1999-12-13 17:01:35 +00:00
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
|
1999-12-14 17:38:17 +00:00
|
|
|
|
/*
|
|
|
|
|
* Trivial classes for connections from objects to their editors, and from
|
|
|
|
|
* child editors to their parents. This does nothing special, but we can
|
|
|
|
|
* use the fact that it's a different class to search for it in the connections
|
|
|
|
|
* array.
|
|
|
|
|
*/
|
|
|
|
|
@interface GormObjectToEditor : NSNibConnector
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation GormObjectToEditor
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@interface GormEditorToParent : NSNibConnector
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation GormEditorToParent
|
|
|
|
|
@end
|
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
@implementation GormDocument
|
|
|
|
|
|
1999-12-14 19:55:18 +00:00
|
|
|
|
static NSImage *objectsImage = nil;
|
|
|
|
|
static NSImage *imagesImage = nil;
|
|
|
|
|
static NSImage *soundsImage = nil;
|
|
|
|
|
static NSImage *classesImage = nil;
|
|
|
|
|
|
1999-12-14 17:38:17 +00:00
|
|
|
|
+ (void) initialize
|
|
|
|
|
{
|
|
|
|
|
if (self == [GormDocument class])
|
|
|
|
|
{
|
1999-12-14 19:55:18 +00:00
|
|
|
|
NSBundle *bundle;
|
|
|
|
|
NSString *path;
|
|
|
|
|
|
|
|
|
|
bundle = [NSBundle mainBundle];
|
|
|
|
|
path = [bundle pathForImageResource: @"GormObject"];
|
|
|
|
|
if (path != nil)
|
|
|
|
|
{
|
|
|
|
|
objectsImage = [[NSImage alloc] initWithContentsOfFile: path];
|
|
|
|
|
}
|
|
|
|
|
path = [bundle pathForImageResource: @"GormImage"];
|
|
|
|
|
if (path != nil)
|
|
|
|
|
{
|
|
|
|
|
imagesImage = [[NSImage alloc] initWithContentsOfFile: path];
|
|
|
|
|
}
|
|
|
|
|
path = [bundle pathForImageResource: @"GormSound"];
|
|
|
|
|
if (path != nil)
|
|
|
|
|
{
|
|
|
|
|
soundsImage = [[NSImage alloc] initWithContentsOfFile: path];
|
|
|
|
|
}
|
|
|
|
|
path = [bundle pathForImageResource: @"GormClass"];
|
|
|
|
|
if (path != nil)
|
|
|
|
|
{
|
|
|
|
|
classesImage = [[NSImage alloc] initWithContentsOfFile: path];
|
|
|
|
|
}
|
2002-11-18 06:15:06 +00:00
|
|
|
|
|
|
|
|
|
[self setVersion: GNUSTEP_NIB_VERSION];
|
1999-12-14 17:38:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-30 05:39:20 +00:00
|
|
|
|
/*
|
2003-08-31 03:46:46 +00:00
|
|
|
|
- (void) awakeWithContext: (NSDictionary *)context
|
|
|
|
|
{
|
|
|
|
|
// do nothing.. This is defined to override the one in GSNibContainer.
|
2003-12-24 02:50:34 +00:00
|
|
|
|
NSLog(@"In awakeWithContext");
|
2003-08-31 03:46:46 +00:00
|
|
|
|
}
|
2003-12-30 05:39:20 +00:00
|
|
|
|
*/
|
2003-08-31 03:46:46 +00:00
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
- (void) addConnector: (id<IBConnectors>)aConnector
|
|
|
|
|
{
|
|
|
|
|
if ([connections indexOfObjectIdenticalTo: aConnector] == NSNotFound)
|
|
|
|
|
{
|
2003-05-23 02:25:34 +00:00
|
|
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
|
|
|
|
[nc postNotificationName: IBWillAddConnectorNotification
|
|
|
|
|
object: aConnector];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
[connections addObject: aConnector];
|
2003-05-23 02:25:34 +00:00
|
|
|
|
[nc postNotificationName: IBDidAddConnectorNotification
|
|
|
|
|
object: aConnector];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSArray*) allConnectors
|
|
|
|
|
{
|
1999-12-14 17:38:17 +00:00
|
|
|
|
return [NSArray arrayWithArray: connections];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-08-14 00:01:42 +00:00
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
- (void) attachObject: (id)anObject toParent: (id)aParent
|
|
|
|
|
{
|
|
|
|
|
NSArray *old;
|
2004-02-01 23:18:16 +00:00
|
|
|
|
BOOL newObject = NO;
|
|
|
|
|
|
|
|
|
|
// if the object is already attached, don't bother attaching it again.
|
|
|
|
|
/*
|
|
|
|
|
if([self nameForObject: anObject] != nil)
|
|
|
|
|
{
|
|
|
|
|
// object already attached.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
*/
|
1999-12-08 15:04:57 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Create a connector that links this object to its parent.
|
|
|
|
|
* A nil parent is the root of the hierarchy so we use a dummy object for it.
|
|
|
|
|
*/
|
|
|
|
|
if (aParent == nil)
|
|
|
|
|
{
|
1999-12-13 17:01:35 +00:00
|
|
|
|
aParent = filesOwner;
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
1999-12-13 17:01:35 +00:00
|
|
|
|
old = [self connectorsForSource: anObject ofClass: [NSNibConnector class]];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
if ([old count] > 0)
|
|
|
|
|
{
|
|
|
|
|
[[old objectAtIndex: 0] setDestination: aParent];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1999-12-13 17:01:35 +00:00
|
|
|
|
NSNibConnector *con = [NSNibConnector new];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
|
|
|
|
|
[con setSource: anObject];
|
|
|
|
|
[con setDestination: aParent];
|
|
|
|
|
[self addConnector: (id<IBConnectors>)con];
|
|
|
|
|
RELEASE(con);
|
|
|
|
|
}
|
2000-01-07 06:47:08 +00:00
|
|
|
|
/*
|
|
|
|
|
* Make sure that there is a name for this object.
|
|
|
|
|
*/
|
|
|
|
|
if ([self nameForObject: anObject] == nil)
|
|
|
|
|
{
|
2004-02-01 23:18:16 +00:00
|
|
|
|
newObject = YES;
|
2000-01-07 06:47:08 +00:00
|
|
|
|
[self setName: nil forObject: anObject];
|
|
|
|
|
}
|
2002-02-18 12:48:31 +00:00
|
|
|
|
|
2000-01-07 06:47:08 +00:00
|
|
|
|
/*
|
|
|
|
|
* Add top-level objects to objectsView and open their editors.
|
|
|
|
|
*/
|
1999-12-13 17:01:35 +00:00
|
|
|
|
if ([anObject isKindOfClass: [NSWindow class]] == YES
|
2003-02-13 13:32:59 +00:00
|
|
|
|
|| [anObject isKindOfClass: [GSNibItem class]] == YES)
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[objectsView addObject: anObject];
|
1999-12-14 17:38:17 +00:00
|
|
|
|
[[self openEditorForObject: anObject] activate];
|
2000-02-25 17:26:57 +00:00
|
|
|
|
if ([anObject isKindOfClass: [NSWindow class]] == YES)
|
|
|
|
|
{
|
2003-10-28 05:25:14 +00:00
|
|
|
|
RETAIN(anObject);
|
2000-02-25 17:26:57 +00:00
|
|
|
|
[anObject setReleasedWhenClosed: NO];
|
|
|
|
|
}
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
2002-02-18 12:37:26 +00:00
|
|
|
|
|
2002-04-07 22:02:41 +00:00
|
|
|
|
if ([anObject isKindOfClass: [NSMenu class]] == YES)
|
|
|
|
|
{
|
|
|
|
|
[[self openEditorForObject: anObject] activate];
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-18 12:37:26 +00:00
|
|
|
|
/*
|
|
|
|
|
* if this a scrollview, it is interesting to add its contentview
|
|
|
|
|
* if it is a tableview or a textview
|
|
|
|
|
*/
|
|
|
|
|
if (([anObject isKindOfClass: [NSScrollView class]] == YES)
|
2003-02-13 13:32:59 +00:00
|
|
|
|
&& ([(NSScrollView *)anObject documentView] != nil))
|
2002-02-18 12:37:26 +00:00
|
|
|
|
{
|
|
|
|
|
if ([[anObject documentView] isKindOfClass:
|
|
|
|
|
[NSTableView class]] == YES)
|
|
|
|
|
{
|
2002-03-29 16:30:01 +00:00
|
|
|
|
int i;
|
|
|
|
|
int count;
|
|
|
|
|
NSArray *tc;
|
|
|
|
|
id tv = [anObject documentView];
|
|
|
|
|
tc = [tv tableColumns];
|
|
|
|
|
count = [tc count];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
[self attachObject: tv toParent: aParent];
|
2002-03-29 16:30:01 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
|
{
|
|
|
|
|
[self attachObject: [tc objectAtIndex: i]
|
2003-02-13 13:32:59 +00:00
|
|
|
|
toParent: aParent];
|
2002-03-29 16:30:01 +00:00
|
|
|
|
}
|
2002-02-18 12:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
else if ([[anObject documentView] isKindOfClass:
|
|
|
|
|
[NSTextView class]] == YES)
|
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
[self attachObject: [anObject documentView] toParent: aParent];
|
2002-02-18 12:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2004-01-06 06:11:24 +00:00
|
|
|
|
|
|
|
|
|
// Detect and add any connection the object might have.
|
|
|
|
|
// This is done so that any palette items which have predefined connections will be
|
|
|
|
|
// shown in the connections list.
|
|
|
|
|
if([anObject respondsToSelector: @selector(action)] == YES &&
|
2004-02-01 23:18:16 +00:00
|
|
|
|
[anObject respondsToSelector: @selector(target)] == YES &&
|
|
|
|
|
newObject == YES)
|
2004-01-06 06:11:24 +00:00
|
|
|
|
{
|
|
|
|
|
SEL sel = [anObject action];
|
|
|
|
|
|
|
|
|
|
if(sel != NULL)
|
|
|
|
|
{
|
|
|
|
|
NSString *label = NSStringFromSelector(sel);
|
|
|
|
|
id source = anObject;
|
|
|
|
|
NSNibControlConnector *con = [NSNibControlConnector new];
|
|
|
|
|
id destination = [anObject target];
|
|
|
|
|
NSArray *sourceConnections = [self connectorsForSource: source];
|
|
|
|
|
|
|
|
|
|
if(destination == nil)
|
|
|
|
|
{
|
2004-01-14 06:37:54 +00:00
|
|
|
|
if(aParent == nil)
|
|
|
|
|
destination = firstResponder;
|
|
|
|
|
else
|
|
|
|
|
destination = aParent;
|
2004-01-06 06:11:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// build the connection
|
|
|
|
|
[con setSource: source];
|
|
|
|
|
[con setDestination: destination];
|
|
|
|
|
[con setLabel: label];
|
|
|
|
|
|
|
|
|
|
// don't duplicate the connection if it already exists.
|
|
|
|
|
// if([sourceConnections indexOfObjectIdenticalTo: con] == NSNotFound)
|
|
|
|
|
if([sourceConnections containsObject: con] == NO)
|
|
|
|
|
{
|
|
|
|
|
// add it to our connections set.
|
|
|
|
|
[self addConnector: (id<IBConnectors>)con];
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-05 04:20:43 +00:00
|
|
|
|
// destroy the connection in the object to
|
|
|
|
|
// prevent any conflict. The connections are restored when the
|
|
|
|
|
// .gorm is loaded, so there's no need for it anymore.
|
|
|
|
|
[anObject setTarget: nil];
|
|
|
|
|
[anObject setAction: NULL];
|
|
|
|
|
|
|
|
|
|
// release the connection.
|
2004-01-06 06:11:24 +00:00
|
|
|
|
RELEASE(con);
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) attachObjects: (NSArray*)anArray toParent: (id)aParent
|
|
|
|
|
{
|
|
|
|
|
NSEnumerator *enumerator = [anArray objectEnumerator];
|
|
|
|
|
NSObject *obj;
|
|
|
|
|
|
|
|
|
|
while ((obj = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
[self attachObject: obj toParent: aParent];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-04 13:52:31 +00:00
|
|
|
|
// sound support
|
|
|
|
|
- (GormSound *)_createSoundPlaceHolder: (NSString *)path
|
|
|
|
|
{
|
|
|
|
|
NSString *name = [[path lastPathComponent] stringByDeletingPathExtension];
|
2003-11-19 05:59:55 +00:00
|
|
|
|
return [[GormSound alloc] initWithName: name path: path];
|
2002-11-04 13:52:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-11-18 20:54:26 +00:00
|
|
|
|
// image support
|
|
|
|
|
- (GormImage *)_createImagePlaceHolder: (NSString *)path
|
|
|
|
|
{
|
|
|
|
|
NSString *name = [[path lastPathComponent] stringByDeletingPathExtension];
|
2003-11-19 05:59:55 +00:00
|
|
|
|
return [[GormImage alloc] initWithName: name path: path];
|
2002-11-18 20:54:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-03 11:00:14 +00:00
|
|
|
|
- (void) beginArchiving
|
|
|
|
|
{
|
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
|
id<IBConnectors> con;
|
|
|
|
|
id obj;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Map all connector sources and destinations to their name strings.
|
|
|
|
|
* Deactivate editors so they won't be archived.
|
|
|
|
|
*/
|
2002-10-13 06:04:05 +00:00
|
|
|
|
|
2000-01-03 11:00:14 +00:00
|
|
|
|
enumerator = [connections objectEnumerator];
|
|
|
|
|
while ((con = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
if ([con isKindOfClass: [GormObjectToEditor class]] == YES)
|
|
|
|
|
{
|
|
|
|
|
[savedEditors addObject: con];
|
|
|
|
|
[[con destination] deactivate];
|
|
|
|
|
}
|
|
|
|
|
else if ([con isKindOfClass: [GormEditorToParent class]] == YES)
|
|
|
|
|
{
|
|
|
|
|
[savedEditors addObject: con];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NSString *name;
|
|
|
|
|
obj = [con source];
|
|
|
|
|
name = [self nameForObject: obj];
|
|
|
|
|
[con setSource: name];
|
|
|
|
|
obj = [con destination];
|
|
|
|
|
name = [self nameForObject: obj];
|
|
|
|
|
[con setDestination: name];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[connections removeObjectsInArray: savedEditors];
|
|
|
|
|
|
2002-12-15 18:17:53 +00:00
|
|
|
|
NSDebugLog(@"*** customClassMap = %@",[classManager customClassMap]);
|
2002-12-22 00:33:44 +00:00
|
|
|
|
[nameTable setObject: [classManager customClassMap] forKey: GSCustomClassMap];
|
2002-10-13 06:04:05 +00:00
|
|
|
|
|
2000-01-03 11:00:14 +00:00
|
|
|
|
/*
|
|
|
|
|
* Remove objects and connections that shouldn't be archived.
|
|
|
|
|
*/
|
2000-12-27 09:00:32 +00:00
|
|
|
|
NSMapRemove(objToName, (void*)[nameTable objectForKey: @"NSOwner"]);
|
2000-01-03 11:00:14 +00:00
|
|
|
|
[nameTable removeObjectForKey: @"NSOwner"];
|
2000-12-27 09:00:32 +00:00
|
|
|
|
NSMapRemove(objToName, (void*)[nameTable objectForKey: @"NSFirst"]);
|
2000-01-03 11:00:14 +00:00
|
|
|
|
[nameTable removeObjectForKey: @"NSFirst"];
|
|
|
|
|
if (fontManager != nil)
|
|
|
|
|
{
|
2000-12-27 09:00:32 +00:00
|
|
|
|
NSMapRemove(objToName, (void*)[nameTable objectForKey: @"NSFont"]);
|
2000-01-03 11:00:14 +00:00
|
|
|
|
[nameTable removeObjectForKey: @"NSFont"];
|
|
|
|
|
}
|
2001-06-20 16:00:19 +00:00
|
|
|
|
|
|
|
|
|
/* Add information about the NSOwner to the archive */
|
|
|
|
|
NSMapInsert(objToName, (void*)[filesOwner className], (void*)@"NSOwner");
|
2002-04-07 22:02:41 +00:00
|
|
|
|
[nameTable setObject: [filesOwner className] forKey: @"NSOwner"];
|
2000-01-03 11:00:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-05-08 09:43:11 +00:00
|
|
|
|
- (void) changeCurrentClass: (id)sender
|
|
|
|
|
{
|
|
|
|
|
int row = [classesView selectedRow];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (row >= 0)
|
2001-05-08 09:43:11 +00:00
|
|
|
|
{
|
2002-03-25 01:44:01 +00:00
|
|
|
|
[classEditor setSelectedClassName: [classesView itemAtRow: row]];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
[self setSelectionFromEditor: (id)classEditor];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-27 22:16:12 +00:00
|
|
|
|
// class selection...
|
|
|
|
|
- (void) _selectClass: (NSString *)className
|
2002-12-15 07:30:35 +00:00
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
NSString *currentClass = nil;
|
|
|
|
|
NSArray *classes;
|
|
|
|
|
NSEnumerator *en;
|
|
|
|
|
int row = 0;
|
2002-12-27 22:16:12 +00:00
|
|
|
|
|
2003-08-23 12:54:13 +00:00
|
|
|
|
if(className != nil)
|
|
|
|
|
{
|
|
|
|
|
if([className isEqualToString: @"CustomView"])
|
|
|
|
|
return; // return only if it is a special class name...
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return; // return if it is nil
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-04 04:01:09 +00:00
|
|
|
|
classes = [[self classManager] allSuperClassesOf: className];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
en = [classes objectEnumerator];
|
|
|
|
|
|
2002-12-27 22:16:12 +00:00
|
|
|
|
// open the items...
|
2003-02-13 13:32:59 +00:00
|
|
|
|
while ((currentClass = [en nextObject]) != nil)
|
2002-12-15 07:30:35 +00:00
|
|
|
|
{
|
2002-12-27 22:16:12 +00:00
|
|
|
|
[classesView expandItem: currentClass];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// select the item...
|
2004-03-04 04:01:09 +00:00
|
|
|
|
row = [classesView rowForItem: className];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (row != NSNotFound)
|
2002-12-27 22:16:12 +00:00
|
|
|
|
{
|
|
|
|
|
[classesView selectRow: row byExtendingSelection: NO];
|
|
|
|
|
[classesView scrollRowToVisible: row];
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-12-15 07:30:35 +00:00
|
|
|
|
|
2003-08-23 06:31:53 +00:00
|
|
|
|
- (void) selectClassWithObject: (id)obj
|
2002-12-27 22:16:12 +00:00
|
|
|
|
{
|
2003-08-23 06:31:53 +00:00
|
|
|
|
NSString *customClass = [classManager customClassForObject: obj];
|
|
|
|
|
|
|
|
|
|
if(customClass != nil)
|
2002-12-27 22:16:12 +00:00
|
|
|
|
{
|
2003-08-23 06:31:53 +00:00
|
|
|
|
[self _selectClass: customClass];
|
|
|
|
|
}
|
|
|
|
|
else if ([obj respondsToSelector: @selector(className)])
|
|
|
|
|
{
|
2002-12-27 22:16:12 +00:00
|
|
|
|
[self _selectClass: [obj className]];
|
2002-12-15 07:30:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-27 22:16:12 +00:00
|
|
|
|
// change the views...
|
2001-05-08 09:43:11 +00:00
|
|
|
|
- (void) changeView: (id)sender
|
|
|
|
|
{
|
|
|
|
|
int tag = [[sender selectedCell] tag];
|
|
|
|
|
|
|
|
|
|
switch (tag)
|
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
case 0: // objects
|
|
|
|
|
{
|
|
|
|
|
[selectionBox setContentView: scrollView];
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 1: // images
|
|
|
|
|
{
|
|
|
|
|
[selectionBox setContentView: imagesScrollView];
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2: // sounds
|
|
|
|
|
{
|
|
|
|
|
[selectionBox setContentView: soundsScrollView];
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 3: // classes
|
|
|
|
|
{
|
2003-08-24 01:29:35 +00:00
|
|
|
|
NSArray *selection = [[(id<IB>)NSApp selectionOwner] selection];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
[selectionBox setContentView: classesScrollView];
|
|
|
|
|
|
|
|
|
|
// if something is selected, in the object view.
|
|
|
|
|
// show the equivalent class in the classes view.
|
|
|
|
|
if ([selection count] > 0)
|
|
|
|
|
{
|
2003-08-24 01:29:35 +00:00
|
|
|
|
id obj = [selection objectAtIndex: 0];
|
2003-08-25 04:53:45 +00:00
|
|
|
|
// if it's a scrollview focus on it's contents.
|
|
|
|
|
if([obj isKindOfClass: [NSScrollView class]])
|
|
|
|
|
{
|
|
|
|
|
id newobj = nil;
|
|
|
|
|
newobj = [obj documentView];
|
|
|
|
|
if(newobj != nil)
|
|
|
|
|
{
|
|
|
|
|
obj = newobj;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-08-23 06:31:53 +00:00
|
|
|
|
[self selectClassWithObject: obj];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2001-05-08 09:43:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (GormClassManager*) classManager
|
|
|
|
|
{
|
|
|
|
|
return classManager;
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-13 17:01:35 +00:00
|
|
|
|
/*
|
|
|
|
|
* A Gorm document is encoded in the archive as a GSNibContainer ...
|
|
|
|
|
* A class that the gnustep gui library knbows about and can unarchive.
|
|
|
|
|
*/
|
|
|
|
|
- (Class) classForCoder
|
|
|
|
|
{
|
|
|
|
|
return [GSNibContainer class];
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
- (NSArray*) connectorsForDestination: (id)destination
|
|
|
|
|
{
|
|
|
|
|
return [self connectorsForDestination: destination ofClass: 0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSArray*) connectorsForDestination: (id)destination
|
|
|
|
|
ofClass: (Class)aConnectorClass
|
|
|
|
|
{
|
|
|
|
|
NSMutableArray *array = [NSMutableArray arrayWithCapacity: 16];
|
|
|
|
|
NSEnumerator *enumerator = [connections objectEnumerator];
|
|
|
|
|
id<IBConnectors> c;
|
|
|
|
|
|
|
|
|
|
while ((c = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
if ([c destination] == destination
|
|
|
|
|
&& (aConnectorClass == 0 || aConnectorClass == [c class]))
|
|
|
|
|
{
|
|
|
|
|
[array addObject: c];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return array;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSArray*) connectorsForSource: (id)source
|
|
|
|
|
{
|
|
|
|
|
return [self connectorsForSource: source ofClass: 0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSArray*) connectorsForSource: (id)source
|
|
|
|
|
ofClass: (Class)aConnectorClass
|
|
|
|
|
{
|
|
|
|
|
NSMutableArray *array = [NSMutableArray arrayWithCapacity: 16];
|
|
|
|
|
NSEnumerator *enumerator = [connections objectEnumerator];
|
|
|
|
|
id<IBConnectors> c;
|
|
|
|
|
|
|
|
|
|
while ((c = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
if ([c source] == source
|
|
|
|
|
&& (aConnectorClass == 0 || aConnectorClass == [c class]))
|
|
|
|
|
{
|
|
|
|
|
[array addObject: c];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return array;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) containsObject: (id)anObject
|
|
|
|
|
{
|
|
|
|
|
if ([self nameForObject: anObject] == nil)
|
|
|
|
|
{
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) containsObjectWithName: (NSString*)aName forParent: (id)parent
|
|
|
|
|
{
|
|
|
|
|
id obj = [nameTable objectForKey: aName];
|
|
|
|
|
|
|
|
|
|
if (obj == nil)
|
|
|
|
|
{
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) copyObject: (id)anObject
|
|
|
|
|
type: (NSString*)aType
|
|
|
|
|
toPasteboard: (NSPasteboard*)aPasteboard
|
|
|
|
|
{
|
|
|
|
|
return [self copyObjects: [NSArray arrayWithObject: anObject]
|
|
|
|
|
type: aType
|
|
|
|
|
toPasteboard: aPasteboard];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) copyObjects: (NSArray*)anArray
|
|
|
|
|
type: (NSString*)aType
|
|
|
|
|
toPasteboard: (NSPasteboard*)aPasteboard
|
|
|
|
|
{
|
2000-01-14 17:07:44 +00:00
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
|
NSMutableSet *editors;
|
|
|
|
|
id obj;
|
2003-10-12 05:45:44 +00:00
|
|
|
|
NSMutableData *data;
|
|
|
|
|
NSArchiver *archiver;
|
2000-01-14 17:07:44 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Remove all editors from the selected objects before archiving
|
|
|
|
|
* and restore them afterwards.
|
|
|
|
|
*/
|
|
|
|
|
editors = [NSMutableSet new];
|
|
|
|
|
enumerator = [anArray objectEnumerator];
|
|
|
|
|
while ((obj = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
id editor = [self editorForObject: obj create: NO];
|
|
|
|
|
|
|
|
|
|
if (editor != nil)
|
|
|
|
|
{
|
|
|
|
|
[editors addObject: editor];
|
|
|
|
|
[editor deactivate];
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-10-12 05:45:44 +00:00
|
|
|
|
|
|
|
|
|
// encode the data
|
|
|
|
|
data = [NSMutableData dataWithCapacity: 0];
|
|
|
|
|
archiver = [[NSArchiver alloc] initForWritingWithMutableData: data];
|
|
|
|
|
[archiver encodeClassName: @"GormCustomView"
|
|
|
|
|
intoClassName: @"GSCustomView"];
|
|
|
|
|
[archiver encodeRootObject: anArray];
|
|
|
|
|
|
|
|
|
|
// reactivate
|
2000-01-14 17:07:44 +00:00
|
|
|
|
enumerator = [editors objectEnumerator];
|
|
|
|
|
while ((obj = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
[obj activate];
|
|
|
|
|
}
|
|
|
|
|
RELEASE(editors);
|
1999-12-08 15:04:57 +00:00
|
|
|
|
|
|
|
|
|
[aPasteboard declareTypes: [NSArray arrayWithObject: aType]
|
|
|
|
|
owner: self];
|
2000-01-14 17:07:44 +00:00
|
|
|
|
return [aPasteboard setData: data forType: aType];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-05-08 09:43:11 +00:00
|
|
|
|
- (id) createSubclass: (id)sender
|
|
|
|
|
{
|
|
|
|
|
int i = [classesView selectedRow];
|
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (i >= 0 && ![classesView isEditing])
|
2001-05-08 09:43:11 +00:00
|
|
|
|
{
|
2002-03-25 01:44:01 +00:00
|
|
|
|
NSString *newClassName;
|
|
|
|
|
id itemSelected = [classesView itemAtRow: i];
|
|
|
|
|
|
2003-05-26 00:40:57 +00:00
|
|
|
|
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();
|
|
|
|
|
}
|
2001-05-08 09:43:11 +00:00
|
|
|
|
}
|
2002-03-25 01:44:01 +00:00
|
|
|
|
|
2001-06-20 16:00:19 +00:00
|
|
|
|
return self;
|
2001-05-08 09:43:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-14 13:34:15 +00:00
|
|
|
|
- (void) pasteboardChangedOwner: (NSPasteboard*)sender
|
|
|
|
|
{
|
2000-01-16 09:56:48 +00:00
|
|
|
|
NSDebugLog(@"Owner changed for %@", sender);
|
2000-01-14 13:34:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
1999-12-15 15:29:27 +00:00
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[window setDelegate: nil];
|
|
|
|
|
[window performClose: self];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
RELEASE(classManager);
|
|
|
|
|
RELEASE(classEditor);
|
2000-02-03 17:04:37 +00:00
|
|
|
|
RELEASE(hidden);
|
1999-12-13 17:01:35 +00:00
|
|
|
|
RELEASE(filesOwner);
|
|
|
|
|
RELEASE(firstResponder);
|
|
|
|
|
RELEASE(fontManager);
|
2003-03-03 09:15:48 +00:00
|
|
|
|
if (objToName != 0)
|
|
|
|
|
{
|
|
|
|
|
NSFreeMapTable(objToName);
|
|
|
|
|
}
|
1999-12-08 15:04:57 +00:00
|
|
|
|
RELEASE(documentPath);
|
2000-01-03 11:00:14 +00:00
|
|
|
|
RELEASE(savedEditors);
|
2001-05-08 09:43:11 +00:00
|
|
|
|
RELEASE(scrollView);
|
|
|
|
|
RELEASE(classesScrollView);
|
1999-12-08 15:04:57 +00:00
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) detachObject: (id)anObject
|
|
|
|
|
{
|
2001-07-10 05:40:15 +00:00
|
|
|
|
NSString *name = RETAIN([self nameForObject: anObject]);
|
2003-08-23 01:04:36 +00:00
|
|
|
|
GormClassManager *cm = [self classManager];
|
2000-01-03 11:00:14 +00:00
|
|
|
|
unsigned count;
|
2003-08-23 05:49:26 +00:00
|
|
|
|
|
1999-12-14 17:38:17 +00:00
|
|
|
|
[[self editorForObject: anObject create: NO] close];
|
|
|
|
|
|
2000-01-03 11:00:14 +00:00
|
|
|
|
count = [connections count];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
while (count-- > 0)
|
|
|
|
|
{
|
|
|
|
|
id<IBConnectors> con = [connections objectAtIndex: count];
|
|
|
|
|
|
|
|
|
|
if ([con destination] == anObject || [con source] == anObject)
|
|
|
|
|
{
|
|
|
|
|
[connections removeObjectAtIndex: count];
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-10-18 06:20:45 +00:00
|
|
|
|
|
1999-12-13 17:01:35 +00:00
|
|
|
|
if ([anObject isKindOfClass: [NSWindow class]] == YES
|
|
|
|
|
|| [anObject isKindOfClass: [NSMenu class]] == YES)
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[objectsView removeObject: anObject];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
2000-01-03 11:00:14 +00:00
|
|
|
|
/*
|
|
|
|
|
* Make sure this object isn't in the list of objects to be made visible
|
|
|
|
|
* on nib loading.
|
|
|
|
|
*/
|
|
|
|
|
[self setObject: anObject isVisibleAtLaunch: NO];
|
|
|
|
|
|
2003-10-18 06:20:45 +00:00
|
|
|
|
// some objects are given a name, some are not. The only ones we need
|
|
|
|
|
// to worry about are those that have names.
|
|
|
|
|
if(name != nil)
|
2003-08-23 05:49:26 +00:00
|
|
|
|
{
|
2003-10-18 06:20:45 +00:00
|
|
|
|
// remove from custom class map...
|
|
|
|
|
NSDebugLog(@"Delete from custom class map -> %@",name);
|
|
|
|
|
[cm removeCustomClassForObject: name];
|
|
|
|
|
if([anObject isKindOfClass: [NSScrollView class]] == YES)
|
|
|
|
|
{
|
|
|
|
|
NSView *subview = [anObject documentView];
|
|
|
|
|
NSString *objName = [self nameForObject: subview];
|
|
|
|
|
NSDebugLog(@"Delete from custom class map -> %@",objName);
|
|
|
|
|
[cm removeCustomClassForObject: objName];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// remove from name table...
|
|
|
|
|
[nameTable removeObjectForKey: name];
|
|
|
|
|
|
|
|
|
|
// free...
|
|
|
|
|
NSMapRemove(objToName, (void*)anObject);
|
|
|
|
|
RELEASE(name);
|
2003-08-23 05:49:26 +00:00
|
|
|
|
}
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) detachObjects: (NSArray*)anArray
|
|
|
|
|
{
|
|
|
|
|
NSEnumerator *enumerator = [anArray objectEnumerator];
|
|
|
|
|
NSObject *obj;
|
|
|
|
|
|
|
|
|
|
while ((obj = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
[self detachObject: obj];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSString*) documentPath
|
|
|
|
|
{
|
|
|
|
|
return documentPath;
|
|
|
|
|
}
|
|
|
|
|
|
2001-12-19 07:13:54 +00:00
|
|
|
|
- (id) parseHeader: (NSString *)headerPath
|
|
|
|
|
{
|
|
|
|
|
NSString *headerFile = [NSString stringWithContentsOfFile: headerPath];
|
|
|
|
|
NSScanner *headerScanner = [NSScanner scannerWithString: headerFile];
|
|
|
|
|
GormClassManager *cm = [self classManager];
|
2002-12-27 22:16:12 +00:00
|
|
|
|
NSCharacterSet *superClassStopSet = [NSCharacterSet characterSetWithCharactersInString: @" \n"];
|
2003-07-15 04:57:37 +00:00
|
|
|
|
NSCharacterSet *classStopSet = [NSCharacterSet characterSetWithCharactersInString: @" :"];
|
|
|
|
|
NSCharacterSet *categoryStopSet = [NSCharacterSet characterSetWithCharactersInString: @" ("];
|
2003-05-29 05:40:28 +00:00
|
|
|
|
NSCharacterSet *typeStopSet = [NSCharacterSet characterSetWithCharactersInString: @" "];
|
2002-12-27 22:16:12 +00:00
|
|
|
|
NSCharacterSet *actionStopSet = [NSCharacterSet characterSetWithCharactersInString: @";:"];
|
2003-01-12 06:29:19 +00:00
|
|
|
|
NSCharacterSet *outletStopSet = [NSCharacterSet characterSetWithCharactersInString: @";,"];
|
2003-06-22 06:08:16 +00:00
|
|
|
|
NSCharacterSet *illegalOutletSet = [NSCharacterSet characterSetWithCharactersInString: @"~`@#$%^&*()+={}|[]\\:;'<>?,./"];
|
|
|
|
|
NSCharacterSet *illegalActionSet = [NSCharacterSet characterSetWithCharactersInString: @"~`@#$%^&*()+={}|[]\\;'<>?,./"];
|
2003-05-29 05:40:28 +00:00
|
|
|
|
NSArray *outletTokens = [NSArray arrayWithObjects: @"id", @"IBOutlet", nil];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
NSArray *actionTokens = [NSArray arrayWithObjects: @"(void)", @"(IBAction)", @"(id)", nil];
|
2003-06-22 05:13:11 +00:00
|
|
|
|
NSRange notFoundRange = NSMakeRange(NSNotFound,0);
|
2003-07-20 20:26:20 +00:00
|
|
|
|
// NSCharacterSet *commentStopSet = [NSCharacterSet characterSetWithCharactersInString: @"\n"];
|
2001-12-19 07:13:54 +00:00
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
while (![headerScanner isAtEnd])
|
2001-12-19 07:13:54 +00:00
|
|
|
|
{
|
|
|
|
|
NSString *classString = nil;
|
2003-07-15 04:20:09 +00:00
|
|
|
|
BOOL classfound = NO, result = NO, category = NO;
|
2001-12-19 07:13:54 +00:00
|
|
|
|
NSEnumerator *outletEnum = [outletTokens objectEnumerator];
|
|
|
|
|
NSEnumerator *actionEnum = [actionTokens objectEnumerator];
|
|
|
|
|
NSString *outletToken = nil;
|
|
|
|
|
NSString *actionToken = nil;
|
2003-07-15 04:20:09 +00:00
|
|
|
|
int alert;
|
2001-12-19 07:13:54 +00:00
|
|
|
|
|
|
|
|
|
classfound = [headerScanner scanUpToString: @"@interface"
|
2002-08-14 00:01:42 +00:00
|
|
|
|
intoString: NULL];
|
2001-12-19 07:13:54 +00:00
|
|
|
|
|
|
|
|
|
[headerScanner scanUpToString: @"@end"
|
|
|
|
|
intoString: &classString];
|
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (classfound && ![headerScanner isAtEnd])
|
2001-12-19 07:13:54 +00:00
|
|
|
|
{
|
|
|
|
|
NSString
|
|
|
|
|
*className = nil,
|
|
|
|
|
*superClassName = nil,
|
|
|
|
|
*ivarString = nil,
|
|
|
|
|
*methodString = nil;
|
|
|
|
|
NSScanner
|
|
|
|
|
*classScanner = [NSScanner scannerWithString: classString],
|
|
|
|
|
*ivarScanner = nil,
|
|
|
|
|
*methodScanner = nil;
|
|
|
|
|
NSMutableArray
|
|
|
|
|
*actions = [NSMutableArray array],
|
|
|
|
|
*outlets = [NSMutableArray array];
|
|
|
|
|
|
|
|
|
|
[classScanner scanString: @"@interface"
|
2002-08-14 00:01:42 +00:00
|
|
|
|
intoString: NULL];
|
2002-12-27 22:16:12 +00:00
|
|
|
|
[classScanner scanUpToCharactersFromSet: classStopSet
|
2001-12-19 07:13:54 +00:00
|
|
|
|
intoString: &className];
|
|
|
|
|
[classScanner scanString: @":"
|
2002-08-14 00:01:42 +00:00
|
|
|
|
intoString: NULL];
|
2002-12-27 22:16:12 +00:00
|
|
|
|
[classScanner scanUpToCharactersFromSet: superClassStopSet
|
2001-12-19 07:13:54 +00:00
|
|
|
|
intoString: &superClassName];
|
|
|
|
|
[classScanner scanUpToString: @"{"
|
2002-08-14 00:01:42 +00:00
|
|
|
|
intoString: NULL];
|
2001-12-19 07:13:54 +00:00
|
|
|
|
[classScanner scanUpToString: @"}"
|
|
|
|
|
intoString: &ivarString];
|
|
|
|
|
|
2003-07-15 04:20:09 +00:00
|
|
|
|
category = (ivarString == nil);
|
2003-07-15 04:57:37 +00:00
|
|
|
|
if(!category)
|
|
|
|
|
{
|
|
|
|
|
[classScanner scanUpToString: @"@end"
|
|
|
|
|
intoString: &methodString];
|
|
|
|
|
NSDebugLog(@"Found a class \"%@\" with super class \"%@\"", className,
|
|
|
|
|
superClassName);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NSDebugLog(@"A CATEGORY");
|
|
|
|
|
classScanner = [NSScanner scannerWithString: classString];
|
|
|
|
|
[classScanner scanString: @"@interface"
|
|
|
|
|
intoString: NULL];
|
|
|
|
|
[classScanner scanUpToCharactersFromSet: categoryStopSet
|
|
|
|
|
intoString: &className];
|
|
|
|
|
[classScanner scanString: @"("
|
|
|
|
|
intoString: NULL];
|
|
|
|
|
[classScanner scanUpToCharactersFromSet: superClassStopSet
|
|
|
|
|
intoString: &superClassName];
|
|
|
|
|
[classScanner scanString: @")"
|
|
|
|
|
intoString: NULL];
|
|
|
|
|
[classScanner scanUpToString: @"@end"
|
|
|
|
|
intoString: &methodString];
|
|
|
|
|
NSDebugLog(@"method String %@",methodString);
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-15 04:20:09 +00:00
|
|
|
|
|
|
|
|
|
// if its' not a category and it's known, ask before proceeding...
|
|
|
|
|
if([cm isKnownClass: className] && !category)
|
|
|
|
|
{
|
|
|
|
|
NSString *message = [NSString stringWithFormat:
|
|
|
|
|
_(@"The class %@ already exists. Replace it?"),
|
|
|
|
|
className];
|
|
|
|
|
alert = NSRunAlertPanel(_(@"Problem adding class from header"),
|
|
|
|
|
message,
|
|
|
|
|
_(@"Yes"),
|
|
|
|
|
_(@"No"),
|
|
|
|
|
nil);
|
|
|
|
|
if (alert != NSAlertDefaultReturn)
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if it's not a category go through the ivars...
|
|
|
|
|
if(!category)
|
2001-12-19 07:13:54 +00:00
|
|
|
|
{
|
2003-07-15 04:20:09 +00:00
|
|
|
|
NSDebugLog(@"Ivar string is not nil");
|
|
|
|
|
// Interate over the possible tokens which can make an
|
|
|
|
|
// ivar an outlet.
|
|
|
|
|
while ((outletToken = [outletEnum nextObject]) != nil)
|
2001-12-19 07:13:54 +00:00
|
|
|
|
{
|
2003-07-15 04:20:09 +00:00
|
|
|
|
NSString *delimiter = nil;
|
|
|
|
|
NSDebugLog(@"outlet Token = %@", outletToken);
|
|
|
|
|
// Scan the variables of the class...
|
|
|
|
|
ivarScanner = [NSScanner scannerWithString: ivarString];
|
|
|
|
|
while (![ivarScanner isAtEnd])
|
2003-01-12 06:29:19 +00:00
|
|
|
|
{
|
2003-07-15 04:20:09 +00:00
|
|
|
|
NSString *outlet = nil;
|
|
|
|
|
NSString *type = nil;
|
|
|
|
|
|
|
|
|
|
if (delimiter == nil || [delimiter isEqualToString: @";"])
|
|
|
|
|
{
|
|
|
|
|
[ivarScanner scanUpToString: outletToken
|
|
|
|
|
intoString: NULL];
|
|
|
|
|
[ivarScanner scanString: outletToken
|
|
|
|
|
intoString: NULL];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if using the IBOutlet token in the header, scan in the outlet type
|
|
|
|
|
// as well.
|
|
|
|
|
if([outletToken isEqualToString: @"IBOutlet"])
|
|
|
|
|
{
|
|
|
|
|
[ivarScanner scanUpToCharactersFromSet: typeStopSet
|
|
|
|
|
intoString: NULL];
|
|
|
|
|
[ivarScanner scanCharactersFromSet: typeStopSet
|
|
|
|
|
intoString: NULL];
|
|
|
|
|
[ivarScanner scanUpToCharactersFromSet: typeStopSet
|
|
|
|
|
intoString: &type];
|
|
|
|
|
NSDebugLog(@"outlet type = %@",type);
|
|
|
|
|
}
|
2003-05-29 05:40:28 +00:00
|
|
|
|
|
2003-07-15 04:20:09 +00:00
|
|
|
|
[ivarScanner scanUpToCharactersFromSet: outletStopSet
|
|
|
|
|
intoString: &outlet];
|
|
|
|
|
[ivarScanner scanCharactersFromSet: outletStopSet
|
|
|
|
|
intoString: &delimiter];
|
|
|
|
|
if ([ivarScanner isAtEnd] == NO
|
|
|
|
|
&& [outlets indexOfObject: outlet] == NSNotFound)
|
2003-06-22 05:13:11 +00:00
|
|
|
|
{
|
2003-07-15 04:20:09 +00:00
|
|
|
|
NSDebugLog(@"outlet = %@", outlet);
|
|
|
|
|
if(NSEqualRanges([outlet rangeOfCharacterFromSet: illegalOutletSet],notFoundRange))
|
|
|
|
|
{
|
|
|
|
|
[outlets addObject: outlet];
|
|
|
|
|
}
|
2003-06-22 05:13:11 +00:00
|
|
|
|
}
|
2001-12-19 07:13:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
while ((actionToken = [actionEnum nextObject]) != nil)
|
2001-12-19 07:13:54 +00:00
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
NSDebugLog(@"Action token %@", actionToken);
|
2001-12-19 07:13:54 +00:00
|
|
|
|
methodScanner = [NSScanner scannerWithString: methodString];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
while (![methodScanner isAtEnd])
|
2001-12-19 07:13:54 +00:00
|
|
|
|
{
|
|
|
|
|
NSString *action = nil;
|
|
|
|
|
BOOL hasArguments = NO;
|
|
|
|
|
|
|
|
|
|
// Scan the method name
|
|
|
|
|
[methodScanner scanUpToString: actionToken
|
2002-08-14 00:01:42 +00:00
|
|
|
|
intoString: NULL];
|
2001-12-19 07:13:54 +00:00
|
|
|
|
[methodScanner scanString: actionToken
|
2002-08-14 00:01:42 +00:00
|
|
|
|
intoString: NULL];
|
2002-12-27 22:16:12 +00:00
|
|
|
|
[methodScanner scanUpToCharactersFromSet: actionStopSet
|
2001-12-19 07:13:54 +00:00
|
|
|
|
intoString: &action];
|
|
|
|
|
|
|
|
|
|
// This will return true if the method has args.
|
|
|
|
|
hasArguments = [methodScanner scanString: @":"
|
2002-08-14 00:01:42 +00:00
|
|
|
|
intoString: NULL];
|
2001-12-19 07:13:54 +00:00
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (hasArguments)
|
2001-12-19 07:13:54 +00:00
|
|
|
|
{
|
|
|
|
|
BOOL isAction = NO;
|
|
|
|
|
NSString *argType = nil;
|
|
|
|
|
|
|
|
|
|
// If the argument is (id) then the method can
|
|
|
|
|
// be considered an action and we add it to the list.
|
|
|
|
|
isAction = [methodScanner scanString: @"(id)"
|
|
|
|
|
intoString: &argType];
|
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (![methodScanner isAtEnd])
|
2001-12-19 07:13:54 +00:00
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (isAction)
|
2001-12-19 07:13:54 +00:00
|
|
|
|
{
|
2002-11-12 21:44:48 +00:00
|
|
|
|
/* Add the ':' back */
|
|
|
|
|
action = [action stringByAppendingString: @":"];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
NSDebugLog(@"action = %@", action);
|
2003-06-22 06:08:16 +00:00
|
|
|
|
if(NSEqualRanges([action rangeOfCharacterFromSet: illegalActionSet],notFoundRange))
|
2003-06-22 05:13:11 +00:00
|
|
|
|
{
|
|
|
|
|
[actions addObject: action];
|
|
|
|
|
}
|
2001-12-19 07:13:54 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NSDebugLog(@"Not an action");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} // end while
|
|
|
|
|
} // end while
|
|
|
|
|
|
2003-07-15 04:20:09 +00:00
|
|
|
|
if([cm isKnownClass: className] &&
|
|
|
|
|
[cm isCustomClass: className] && category)
|
|
|
|
|
{
|
|
|
|
|
[cm addActions: actions forClassNamed: className];
|
2003-07-15 04:57:37 +00:00
|
|
|
|
[cm addOutlets: outlets forClassNamed: className];
|
2003-07-15 04:20:09 +00:00
|
|
|
|
result = YES;
|
|
|
|
|
}
|
2003-07-16 05:06:10 +00:00
|
|
|
|
else if(!category)
|
2003-07-15 04:20:09 +00:00
|
|
|
|
{
|
|
|
|
|
result = [cm addClassNamed: className
|
|
|
|
|
withSuperClassNamed: superClassName
|
|
|
|
|
withActions: actions
|
|
|
|
|
withOutlets: outlets];
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (result)
|
2001-12-19 07:13:54 +00:00
|
|
|
|
{
|
2002-12-27 22:16:12 +00:00
|
|
|
|
NSDebugLog(@"Class %@ added", className);
|
2002-11-15 04:02:00 +00:00
|
|
|
|
[classesView reloadData];
|
2001-12-19 07:13:54 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2003-07-15 04:20:09 +00:00
|
|
|
|
if (alert == NSAlertDefaultReturn)
|
|
|
|
|
{
|
|
|
|
|
[cm removeClassNamed: className];
|
|
|
|
|
result = [cm addClassNamed: className
|
|
|
|
|
withSuperClassNamed: superClassName
|
|
|
|
|
withActions: actions
|
|
|
|
|
withOutlets: outlets];
|
|
|
|
|
if (!result)
|
|
|
|
|
{
|
|
|
|
|
NSString *message = [NSString stringWithFormat:
|
|
|
|
|
_(@"Could not replace class %@."), className];
|
|
|
|
|
NSRunAlertPanel(_(@"Problem adding class from header"),
|
2002-12-27 22:16:12 +00:00
|
|
|
|
message,
|
2003-07-15 04:20:09 +00:00
|
|
|
|
nil,
|
|
|
|
|
nil,
|
|
|
|
|
nil);
|
|
|
|
|
NSDebugLog(@"Class %@ failed to add", className);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NSDebugLog(@"Class %@ replaced.", className);
|
|
|
|
|
[classesView reloadData];
|
2002-12-27 22:16:12 +00:00
|
|
|
|
}
|
2003-07-15 04:20:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (result)
|
2002-12-27 22:16:12 +00:00
|
|
|
|
{
|
|
|
|
|
// go to the class which was just loaded in the classes view...
|
|
|
|
|
[selectionBox setContentView: classesScrollView];
|
|
|
|
|
[self _selectClass: className];
|
2001-12-19 07:13:54 +00:00
|
|
|
|
}
|
|
|
|
|
} // if we found a class
|
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-09 13:30:59 +00:00
|
|
|
|
- (id) addAttributeToClass: (id)sender
|
|
|
|
|
{
|
|
|
|
|
[classesView addAttributeToClass];
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-15 05:58:01 +00:00
|
|
|
|
- (id) remove: (id)sender
|
2002-07-12 05:46:29 +00:00
|
|
|
|
{
|
2002-11-12 21:44:48 +00:00
|
|
|
|
id anitem;
|
2002-07-22 15:24:37 +00:00
|
|
|
|
int i = [classesView selectedRow];
|
2002-11-07 02:43:26 +00:00
|
|
|
|
|
|
|
|
|
// if no selection, then return.
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (i == -1)
|
2002-11-07 02:43:26 +00:00
|
|
|
|
{
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-12 21:44:48 +00:00
|
|
|
|
anitem = [classesView itemAtRow: i];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([anitem isKindOfClass: [GormOutletActionHolder class]])
|
2002-07-22 15:24:37 +00:00
|
|
|
|
{
|
|
|
|
|
id itemBeingEdited = [classesView itemBeingEdited];
|
2003-12-24 02:50:34 +00:00
|
|
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
|
|
|
|
|
2002-07-22 15:24:37 +00:00
|
|
|
|
// if the class being edited is a custom class, then allow the deletion...
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([classManager isCustomClass: itemBeingEdited])
|
2002-07-22 15:24:37 +00:00
|
|
|
|
{
|
2003-01-09 06:17:07 +00:00
|
|
|
|
NSString *name = [anitem getName];
|
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([classesView editType] == Actions)
|
2002-07-22 15:24:37 +00:00
|
|
|
|
{
|
|
|
|
|
// if this action is an action on the class, not it's superclass
|
|
|
|
|
// allow the deletion...
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([classManager isAction: name
|
2002-07-22 15:24:37 +00:00
|
|
|
|
ofClass: itemBeingEdited])
|
|
|
|
|
{
|
2003-01-09 06:17:07 +00:00
|
|
|
|
BOOL removed = [self removeConnectionsWithLabel: name
|
|
|
|
|
forClassNamed: itemBeingEdited
|
|
|
|
|
isAction: YES];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (removed)
|
2003-01-09 07:03:36 +00:00
|
|
|
|
{
|
|
|
|
|
[classManager removeAction: name
|
|
|
|
|
fromClassNamed: itemBeingEdited];
|
|
|
|
|
[classesView removeItemAtRow: i];
|
2003-12-24 02:50:34 +00:00
|
|
|
|
[nc postNotificationName: GormDidModifyClassNotification
|
|
|
|
|
object: classManager];
|
2003-01-09 07:03:36 +00:00
|
|
|
|
}
|
2002-07-22 15:24:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-02-13 13:32:59 +00:00
|
|
|
|
else if ([classesView editType] == Outlets)
|
2002-07-22 15:24:37 +00:00
|
|
|
|
{
|
|
|
|
|
// if this outlet is an outlet on the class, not it's superclass
|
|
|
|
|
// allow the deletion...
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([classManager isOutlet: name
|
2002-07-22 15:24:37 +00:00
|
|
|
|
ofClass: itemBeingEdited])
|
|
|
|
|
{
|
2003-01-09 06:17:07 +00:00
|
|
|
|
BOOL removed = [self removeConnectionsWithLabel: name
|
|
|
|
|
forClassNamed: itemBeingEdited
|
|
|
|
|
isAction: NO];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (removed)
|
2003-01-09 07:03:36 +00:00
|
|
|
|
{
|
|
|
|
|
[classManager removeOutlet: name
|
|
|
|
|
fromClassNamed: itemBeingEdited];
|
|
|
|
|
[classesView removeItemAtRow: i];
|
2003-12-24 02:50:34 +00:00
|
|
|
|
[nc postNotificationName: GormDidModifyClassNotification
|
|
|
|
|
object: classManager];
|
2003-01-09 07:03:36 +00:00
|
|
|
|
}
|
2002-07-22 15:24:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NSArray *subclasses = [classManager subClassesOf: anitem];
|
|
|
|
|
// if the class has no subclasses, then delete.
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([subclasses count] == 0)
|
2002-07-22 15:24:37 +00:00
|
|
|
|
{
|
|
|
|
|
// if the class being edited is a custom class, then allow the deletion...
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([classManager isCustomClass: anitem])
|
2002-07-22 15:24:37 +00:00
|
|
|
|
{
|
2003-01-09 06:17:07 +00:00
|
|
|
|
BOOL removed = [self removeConnectionsForClassNamed: anitem];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (removed)
|
2003-01-09 07:03:36 +00:00
|
|
|
|
{
|
|
|
|
|
[classManager removeClassNamed: anitem];
|
|
|
|
|
[classesView reloadData];
|
|
|
|
|
}
|
2002-07-22 15:24:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NSString *message = [NSString stringWithFormat:
|
2003-05-24 12:40:54 +00:00
|
|
|
|
_(@"The class %@ has subclasses which must be removed"), anitem];
|
|
|
|
|
NSRunAlertPanel(_(@"Problem removing class"),
|
2002-07-22 15:24:37 +00:00
|
|
|
|
message,
|
|
|
|
|
nil, nil, nil);
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-07-12 05:46:29 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2001-12-19 07:13:54 +00:00
|
|
|
|
- (id) loadClass: (id)sender
|
|
|
|
|
{
|
|
|
|
|
NSArray *fileTypes = [NSArray arrayWithObjects: @"h", @"H", nil];
|
|
|
|
|
NSOpenPanel *oPanel = [NSOpenPanel openPanel];
|
|
|
|
|
int result;
|
|
|
|
|
|
|
|
|
|
[oPanel setAllowsMultipleSelection: NO];
|
|
|
|
|
[oPanel setCanChooseFiles: YES];
|
|
|
|
|
[oPanel setCanChooseDirectories: NO];
|
|
|
|
|
result = [oPanel runModalForDirectory: nil
|
|
|
|
|
file: nil
|
|
|
|
|
types: fileTypes];
|
|
|
|
|
if (result == NSOKButton)
|
|
|
|
|
{
|
|
|
|
|
return [self parseHeader: [oPanel filename]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
2001-05-08 09:43:11 +00:00
|
|
|
|
- (id) editClass: (id)sender
|
|
|
|
|
{
|
|
|
|
|
[self changeCurrentClass: sender];
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-06 17:10:51 +00:00
|
|
|
|
- (id) createClassFiles: (id)sender
|
|
|
|
|
{
|
|
|
|
|
NSSavePanel *sp;
|
2002-12-22 00:33:44 +00:00
|
|
|
|
int row = [classesView selectedRow];
|
|
|
|
|
id className = [classesView itemAtRow: row];
|
2001-07-06 17:10:51 +00:00
|
|
|
|
int result;
|
2002-12-22 00:33:44 +00:00
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([className isKindOfClass: [GormOutletActionHolder class]])
|
2002-12-22 00:33:44 +00:00
|
|
|
|
{
|
|
|
|
|
className = [classesView itemBeingEdited];
|
|
|
|
|
}
|
2002-11-23 22:52:27 +00:00
|
|
|
|
|
2001-07-06 17:10:51 +00:00
|
|
|
|
sp = [NSSavePanel savePanel];
|
|
|
|
|
[sp setRequiredFileType: @"m"];
|
2003-05-24 12:40:54 +00:00
|
|
|
|
[sp setTitle: _(@"Save source file as...")];
|
2001-07-06 17:10:51 +00:00
|
|
|
|
if (documentPath == nil)
|
2002-12-22 00:33:44 +00:00
|
|
|
|
{
|
|
|
|
|
result = [sp runModalForDirectory: NSHomeDirectory()
|
|
|
|
|
file: [className stringByAppendingPathExtension: @"m"]];
|
|
|
|
|
}
|
2001-07-06 17:10:51 +00:00
|
|
|
|
else
|
2002-12-22 00:33:44 +00:00
|
|
|
|
{
|
|
|
|
|
result = [sp runModalForDirectory:
|
|
|
|
|
[documentPath stringByDeletingLastPathComponent]
|
|
|
|
|
file: [className stringByAppendingPathExtension: @"m"]];
|
|
|
|
|
}
|
2001-07-06 17:10:51 +00:00
|
|
|
|
|
|
|
|
|
if (result == NSOKButton)
|
|
|
|
|
{
|
|
|
|
|
NSString *sourceName = [sp filename];
|
|
|
|
|
NSString *headerName;
|
|
|
|
|
|
|
|
|
|
[sp setRequiredFileType: @"h"];
|
2003-05-24 12:40:54 +00:00
|
|
|
|
[sp setTitle: _(@"Save header file as...")];
|
2001-07-06 17:10:51 +00:00
|
|
|
|
result = [sp runModalForDirectory:
|
|
|
|
|
[sourceName stringByDeletingLastPathComponent]
|
|
|
|
|
file:
|
|
|
|
|
[[[sourceName lastPathComponent]
|
|
|
|
|
stringByDeletingPathExtension]
|
|
|
|
|
stringByAppendingString: @".h"]];
|
|
|
|
|
if (result == NSOKButton)
|
|
|
|
|
{
|
|
|
|
|
headerName = [sp filename];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
NSDebugLog(@"Saving %@", className);
|
2002-11-23 22:52:27 +00:00
|
|
|
|
if (![classManager makeSourceAndHeaderFilesForClass: className
|
|
|
|
|
withName: sourceName
|
|
|
|
|
and: headerName])
|
2001-07-06 17:10:51 +00:00
|
|
|
|
{
|
2003-05-24 12:40:54 +00:00
|
|
|
|
NSRunAlertPanel(_(@"Alert"),
|
|
|
|
|
_(@"Could not create the class's file"),
|
2002-11-23 22:52:27 +00:00
|
|
|
|
nil, nil, nil);
|
2001-07-06 17:10:51 +00:00
|
|
|
|
}
|
2002-11-23 22:52:27 +00:00
|
|
|
|
|
|
|
|
|
return self;
|
2001-07-06 17:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-10 21:19:25 +00:00
|
|
|
|
- (void) editor: (id<IBEditors,IBSelectionOwners>)anEditor didCloseForObject: (id)anObject
|
2000-01-04 16:25:39 +00:00
|
|
|
|
{
|
|
|
|
|
NSArray *links;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If there is a link from this editor to a parent, remove it.
|
|
|
|
|
*/
|
|
|
|
|
links = [self connectorsForSource: anEditor
|
|
|
|
|
ofClass: [GormEditorToParent class]];
|
|
|
|
|
NSAssert([links count] < 2, NSInternalInconsistencyException);
|
|
|
|
|
if ([links count] == 1)
|
|
|
|
|
{
|
|
|
|
|
[connections removeObjectIdenticalTo: [links objectAtIndex: 0]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Remove the connection linking the object to this editor
|
|
|
|
|
*/
|
|
|
|
|
links = [self connectorsForSource: anObject
|
|
|
|
|
ofClass: [GormObjectToEditor class]];
|
|
|
|
|
NSAssert([links count] < 2, NSInternalInconsistencyException);
|
2002-08-14 00:01:42 +00:00
|
|
|
|
if ([links count] == 1)
|
|
|
|
|
{
|
|
|
|
|
[connections removeObjectIdenticalTo: [links objectAtIndex: 0]];
|
|
|
|
|
}
|
2000-01-04 16:25:39 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Make sure that this editor is not the selection owner.
|
|
|
|
|
*/
|
2003-05-25 19:08:36 +00:00
|
|
|
|
if ([(id<IB>)NSApp selectionOwner] ==
|
2003-05-10 21:19:25 +00:00
|
|
|
|
anEditor)
|
2000-01-04 16:25:39 +00:00
|
|
|
|
{
|
|
|
|
|
[self resignSelectionForEditor: anEditor];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id<IBEditors>) editorForObject: (id)anObject
|
|
|
|
|
create: (BOOL)flag
|
|
|
|
|
{
|
|
|
|
|
return [self editorForObject: anObject inEditor: nil create: flag];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id<IBEditors>) editorForObject: (id)anObject
|
|
|
|
|
inEditor: (id<IBEditors>)anEditor
|
|
|
|
|
create: (BOOL)flag
|
|
|
|
|
{
|
|
|
|
|
NSArray *links;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Look up the editor links for the object to see if it already has an
|
|
|
|
|
* editor. If it does return it, otherwise create a new editor and a
|
|
|
|
|
* link to it if the flag is set.
|
|
|
|
|
*/
|
|
|
|
|
links = [self connectorsForSource: anObject
|
|
|
|
|
ofClass: [GormObjectToEditor class]];
|
|
|
|
|
if ([links count] == 0 && flag == YES)
|
|
|
|
|
{
|
|
|
|
|
Class eClass;
|
|
|
|
|
id<IBEditors> editor;
|
|
|
|
|
id<IBConnectors> link;
|
|
|
|
|
|
|
|
|
|
eClass = NSClassFromString([anObject editorClassName]);
|
|
|
|
|
editor = [[eClass alloc] initWithObject: anObject inDocument: self];
|
|
|
|
|
link = [GormObjectToEditor new];
|
|
|
|
|
[link setSource: anObject];
|
|
|
|
|
[link setDestination: editor];
|
|
|
|
|
[connections addObject: link];
|
|
|
|
|
RELEASE(link);
|
2000-01-14 13:34:15 +00:00
|
|
|
|
if (anEditor == nil)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* By default all editors are owned by the top-level editor of
|
|
|
|
|
* the document.
|
|
|
|
|
*/
|
|
|
|
|
anEditor = objectsView;
|
|
|
|
|
}
|
|
|
|
|
if (anEditor != editor)
|
2000-01-04 16:25:39 +00:00
|
|
|
|
{
|
|
|
|
|
/*
|
2000-01-14 13:34:15 +00:00
|
|
|
|
* Link to the parent of the editor.
|
2000-01-04 16:25:39 +00:00
|
|
|
|
*/
|
|
|
|
|
link = [GormEditorToParent new];
|
|
|
|
|
[link setSource: editor];
|
|
|
|
|
[link setDestination: anEditor];
|
|
|
|
|
[connections addObject: link];
|
|
|
|
|
RELEASE(link);
|
|
|
|
|
}
|
2002-08-14 00:01:42 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2002-12-27 23:57:35 +00:00
|
|
|
|
NSDebugLog(@"WARNING anEditor = editor");
|
2002-08-14 00:01:42 +00:00
|
|
|
|
}
|
|
|
|
|
[editor activate];
|
2003-05-10 21:19:25 +00:00
|
|
|
|
RELEASE((NSObject *)editor);
|
2000-01-04 16:25:39 +00:00
|
|
|
|
return editor;
|
|
|
|
|
}
|
2002-08-14 00:01:42 +00:00
|
|
|
|
else if ([links count] == 0)
|
|
|
|
|
{
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
2000-01-04 16:25:39 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2002-08-14 00:01:42 +00:00
|
|
|
|
[[[links lastObject] destination] activate];
|
2000-01-04 16:25:39 +00:00
|
|
|
|
return [[links lastObject] destination];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-03 11:00:14 +00:00
|
|
|
|
- (void) endArchiving
|
|
|
|
|
{
|
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
|
id<IBConnectors> con;
|
|
|
|
|
id obj;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Restore removed objects.
|
|
|
|
|
*/
|
|
|
|
|
[nameTable setObject: filesOwner forKey: @"NSOwner"];
|
2000-12-27 09:00:32 +00:00
|
|
|
|
NSMapInsert(objToName, (void*)filesOwner, (void*)@"NSOwner");
|
2002-10-26 03:39:55 +00:00
|
|
|
|
|
2000-01-03 11:00:14 +00:00
|
|
|
|
[nameTable setObject: firstResponder forKey: @"NSFirst"];
|
2000-12-27 09:00:32 +00:00
|
|
|
|
NSMapInsert(objToName, (void*)firstResponder, (void*)@"NSFirst");
|
2002-10-26 03:39:55 +00:00
|
|
|
|
|
2000-01-03 11:00:14 +00:00
|
|
|
|
if (fontManager != nil)
|
|
|
|
|
{
|
|
|
|
|
[nameTable setObject: fontManager forKey: @"NSFont"];
|
2000-12-27 09:00:32 +00:00
|
|
|
|
NSMapInsert(objToName, (void*)fontManager, (void*)@"NSFont");
|
2000-01-03 11:00:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Map all connector source and destination names to their objects.
|
|
|
|
|
*/
|
|
|
|
|
enumerator = [connections objectEnumerator];
|
|
|
|
|
while ((con = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
NSString *name;
|
|
|
|
|
name = (NSString*)[con source];
|
|
|
|
|
obj = [self objectForName: name];
|
|
|
|
|
[con setSource: obj];
|
|
|
|
|
name = (NSString*)[con destination];
|
|
|
|
|
obj = [self objectForName: name];
|
|
|
|
|
[con setDestination: obj];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Restore editor links and reactivate the editors.
|
|
|
|
|
*/
|
|
|
|
|
[connections addObjectsFromArray: savedEditors];
|
|
|
|
|
enumerator = [savedEditors objectEnumerator];
|
|
|
|
|
while ((con = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
2002-09-21 15:24:59 +00:00
|
|
|
|
if ([[con source] isKindOfClass: [NSView class]] == NO)
|
|
|
|
|
[[con destination] activate];
|
2000-01-03 11:00:14 +00:00
|
|
|
|
}
|
|
|
|
|
[savedEditors removeAllObjects];
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-14 19:55:18 +00:00
|
|
|
|
- (void) handleNotification: (NSNotification*)aNotification
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
1999-12-15 15:29:27 +00:00
|
|
|
|
NSString *name = [aNotification name];
|
|
|
|
|
|
|
|
|
|
if ([name isEqual: NSWindowWillCloseNotification] == YES)
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
1999-12-14 19:55:18 +00:00
|
|
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
|
id obj;
|
1999-12-08 15:04:57 +00:00
|
|
|
|
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[nc postNotificationName: IBWillCloseDocumentNotification
|
|
|
|
|
object: self];
|
2000-01-04 16:25:39 +00:00
|
|
|
|
|
1999-12-14 19:55:18 +00:00
|
|
|
|
enumerator = [nameTable objectEnumerator];
|
|
|
|
|
while ((obj = [enumerator nextObject]) != nil)
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
2001-11-03 06:04:57 +00:00
|
|
|
|
if ([obj isKindOfClass: [NSMenu class]] == YES)
|
1999-12-14 19:55:18 +00:00
|
|
|
|
{
|
2001-11-03 06:04:57 +00:00
|
|
|
|
if ([[obj window] isVisible] == YES)
|
|
|
|
|
{
|
|
|
|
|
[hidden addObject: obj];
|
|
|
|
|
[obj close];
|
|
|
|
|
}
|
1999-12-14 19:55:18 +00:00
|
|
|
|
}
|
2001-11-03 06:04:57 +00:00
|
|
|
|
else if ([obj isKindOfClass: [NSWindow class]] == YES)
|
2000-01-04 16:25:39 +00:00
|
|
|
|
{
|
2001-11-03 06:04:57 +00:00
|
|
|
|
if ([obj isVisible] == YES)
|
|
|
|
|
{
|
|
|
|
|
[hidden addObject: obj];
|
|
|
|
|
[obj orderOut: self];
|
|
|
|
|
}
|
2000-01-04 16:25:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-03 06:04:57 +00:00
|
|
|
|
[self setDocumentActive: NO];
|
2004-02-19 05:44:16 +00:00
|
|
|
|
[self setSelectionFromEditor: nil];
|
2000-01-04 16:25:39 +00:00
|
|
|
|
}
|
|
|
|
|
else if ([name isEqual: NSWindowDidBecomeKeyNotification] == YES)
|
|
|
|
|
{
|
|
|
|
|
[self setDocumentActive: YES];
|
|
|
|
|
}
|
|
|
|
|
else if ([name isEqual: NSWindowWillMiniaturizeNotification] == YES)
|
|
|
|
|
{
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[self setDocumentActive: NO];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
2000-01-04 16:25:39 +00:00
|
|
|
|
else if ([name isEqual: NSWindowDidDeminiaturizeNotification] == YES)
|
|
|
|
|
{
|
|
|
|
|
[self setDocumentActive: YES];
|
|
|
|
|
}
|
1999-12-15 15:29:27 +00:00
|
|
|
|
else if ([name isEqual: IBWillBeginTestingInterfaceNotification] == YES)
|
|
|
|
|
{
|
|
|
|
|
if ([window isVisible] == YES)
|
|
|
|
|
{
|
2000-02-03 17:04:37 +00:00
|
|
|
|
[hidden addObject: window];
|
1999-12-15 15:29:27 +00:00
|
|
|
|
[window setExcludedFromWindowsMenu: YES];
|
|
|
|
|
[window orderOut: self];
|
2000-02-03 17:04:37 +00:00
|
|
|
|
}
|
|
|
|
|
if ([(id<IB>)NSApp activeDocument] == self)
|
|
|
|
|
{
|
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
|
id obj;
|
|
|
|
|
|
|
|
|
|
enumerator = [nameTable objectEnumerator];
|
|
|
|
|
while ((obj = [enumerator nextObject]) != nil)
|
1999-12-15 15:29:27 +00:00
|
|
|
|
{
|
2000-02-03 17:04:37 +00:00
|
|
|
|
if ([obj isKindOfClass: [NSMenu class]] == YES)
|
1999-12-15 15:29:27 +00:00
|
|
|
|
{
|
2000-02-03 17:04:37 +00:00
|
|
|
|
if ([[obj window] isVisible] == YES)
|
1999-12-15 15:29:27 +00:00
|
|
|
|
{
|
2000-02-03 17:04:37 +00:00
|
|
|
|
[hidden addObject: obj];
|
|
|
|
|
[obj close];
|
1999-12-15 15:29:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2000-02-03 17:04:37 +00:00
|
|
|
|
else if ([obj isKindOfClass: [NSWindow class]] == YES)
|
1999-12-15 15:29:27 +00:00
|
|
|
|
{
|
2000-02-03 17:04:37 +00:00
|
|
|
|
if ([obj isVisible] == YES)
|
|
|
|
|
{
|
|
|
|
|
[hidden addObject: obj];
|
|
|
|
|
[obj orderOut: self];
|
|
|
|
|
}
|
1999-12-15 15:29:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ([name isEqual: IBWillEndTestingInterfaceNotification] == YES)
|
|
|
|
|
{
|
2000-02-03 17:04:37 +00:00
|
|
|
|
if ([hidden count] > 0)
|
1999-12-15 15:29:27 +00:00
|
|
|
|
{
|
2000-02-03 17:04:37 +00:00
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
|
id obj;
|
1999-12-15 15:29:27 +00:00
|
|
|
|
|
2000-02-03 17:04:37 +00:00
|
|
|
|
enumerator = [hidden objectEnumerator];
|
|
|
|
|
while ((obj = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
if ([obj isKindOfClass: [NSMenu class]] == YES)
|
|
|
|
|
{
|
|
|
|
|
[obj display];
|
|
|
|
|
}
|
|
|
|
|
else if ([obj isKindOfClass: [NSWindow class]] == YES)
|
1999-12-15 15:29:27 +00:00
|
|
|
|
{
|
2000-02-03 17:04:37 +00:00
|
|
|
|
[obj orderFront: self];
|
1999-12-15 15:29:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2000-02-03 17:04:37 +00:00
|
|
|
|
[hidden removeAllObjects];
|
1999-12-15 15:29:27 +00:00
|
|
|
|
[window setExcludedFromWindowsMenu: NO];
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-05-08 09:43:11 +00:00
|
|
|
|
else if ([name isEqual: IBClassNameChangedNotification] == YES)
|
|
|
|
|
{
|
2004-02-13 03:38:01 +00:00
|
|
|
|
if ([aNotification object] == classManager)
|
|
|
|
|
{
|
|
|
|
|
[classesView reloadData];
|
|
|
|
|
}
|
2001-05-08 09:43:11 +00:00
|
|
|
|
}
|
2003-06-07 19:31:48 +00:00
|
|
|
|
else if ([name isEqual: IBInspectorDidModifyObjectNotification] == YES)
|
|
|
|
|
{
|
2004-02-13 03:38:01 +00:00
|
|
|
|
if ([aNotification object] == classManager)
|
|
|
|
|
{
|
|
|
|
|
[classesView reloadData];
|
|
|
|
|
}
|
2003-06-07 19:31:48 +00:00
|
|
|
|
}
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
|
{
|
|
|
|
|
self = [super init];
|
|
|
|
|
if (self != nil)
|
|
|
|
|
{
|
1999-12-14 19:55:18 +00:00
|
|
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
2003-04-18 05:40:25 +00:00
|
|
|
|
NSRect winrect = NSMakeRect(100,100,342,256);
|
|
|
|
|
NSRect selectionRect = {{6, 188}, {234, 64}};
|
1999-12-14 19:55:18 +00:00
|
|
|
|
NSRect scrollRect = {{0, 0}, {340, 188}};
|
|
|
|
|
NSRect mainRect = {{20, 0}, {320, 188}};
|
|
|
|
|
NSImage *image;
|
2003-04-18 05:40:25 +00:00
|
|
|
|
GormDisplayCell *cell;
|
2001-05-08 09:43:11 +00:00
|
|
|
|
NSTableColumn *tableColumn;
|
1999-12-14 19:55:18 +00:00
|
|
|
|
unsigned style;
|
2002-07-08 04:45:23 +00:00
|
|
|
|
NSColor *salmonColor =
|
|
|
|
|
[NSColor colorWithCalibratedRed: 0.850980
|
|
|
|
|
green: 0.737255
|
|
|
|
|
blue: 0.576471
|
|
|
|
|
alpha: 1.0 ];
|
2003-01-02 06:17:15 +00:00
|
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
|
2001-05-08 09:43:11 +00:00
|
|
|
|
classManager = [[GormClassManager alloc] init];
|
|
|
|
|
classEditor = [[GormClassEditor alloc] initWithDocument: self];
|
2000-12-27 09:00:32 +00:00
|
|
|
|
/*
|
|
|
|
|
* NB. We must retain the map values (object names) as the nameTable
|
|
|
|
|
* may not hold identical name objects, but merely equal strings.
|
|
|
|
|
*/
|
2002-10-29 18:30:05 +00:00
|
|
|
|
objToName = NSCreateMapTableWithZone(NSObjectMapKeyCallBacks,
|
2000-12-27 09:00:32 +00:00
|
|
|
|
NSObjectMapValueCallBacks, 128, [self zone]);
|
2003-08-23 01:04:36 +00:00
|
|
|
|
|
2002-10-13 06:04:05 +00:00
|
|
|
|
// for saving the editors when the gorm file is persisted.
|
2000-01-03 11:00:14 +00:00
|
|
|
|
savedEditors = [NSMutableArray new];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
|
2002-11-18 20:54:26 +00:00
|
|
|
|
// sounds & images
|
2002-11-04 13:52:31 +00:00
|
|
|
|
sounds = [NSMutableSet new];
|
2002-11-18 20:54:26 +00:00
|
|
|
|
images = [NSMutableSet new];
|
2002-11-04 13:52:31 +00:00
|
|
|
|
|
1999-12-14 19:55:18 +00:00
|
|
|
|
style = NSTitledWindowMask | NSClosableWindowMask
|
|
|
|
|
| NSResizableWindowMask | NSMiniaturizableWindowMask;
|
|
|
|
|
window = [[NSWindow alloc] initWithContentRect: winrect
|
|
|
|
|
styleMask: style
|
|
|
|
|
backing: NSBackingStoreRetained
|
|
|
|
|
defer: NO];
|
|
|
|
|
[window setMinSize: [window frame].size];
|
2003-05-24 12:40:54 +00:00
|
|
|
|
[window setTitle: _(@"UNTITLED")];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
|
|
|
|
|
[window setDelegate: self];
|
2000-01-04 16:25:39 +00:00
|
|
|
|
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[nc addObserver: self
|
|
|
|
|
selector: @selector(handleNotification:)
|
|
|
|
|
name: NSWindowWillCloseNotification
|
|
|
|
|
object: window];
|
2000-01-04 16:25:39 +00:00
|
|
|
|
[nc addObserver: self
|
|
|
|
|
selector: @selector(handleNotification:)
|
|
|
|
|
name: NSWindowDidBecomeKeyNotification
|
|
|
|
|
object: window];
|
|
|
|
|
[nc addObserver: self
|
|
|
|
|
selector: @selector(handleNotification:)
|
|
|
|
|
name: NSWindowWillMiniaturizeNotification
|
|
|
|
|
object: window];
|
|
|
|
|
[nc addObserver: self
|
|
|
|
|
selector: @selector(handleNotification:)
|
|
|
|
|
name: NSWindowDidDeminiaturizeNotification
|
|
|
|
|
object: window];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
[nc addObserver: self
|
|
|
|
|
selector: @selector(handleNotification:)
|
|
|
|
|
name: IBClassNameChangedNotification
|
|
|
|
|
object: nil];
|
2003-06-07 19:31:48 +00:00
|
|
|
|
[nc addObserver: self
|
|
|
|
|
selector: @selector(handleNotification:)
|
|
|
|
|
name: IBInspectorDidModifyObjectNotification
|
|
|
|
|
object: nil];
|
2003-06-08 04:38:59 +00:00
|
|
|
|
/*
|
|
|
|
|
[nc addObserver: self
|
|
|
|
|
selector: @selector(handleNotification:)
|
|
|
|
|
name: GormDidModifyClassNotification
|
|
|
|
|
object: nil];
|
|
|
|
|
*/
|
1999-12-14 19:55:18 +00:00
|
|
|
|
selectionView = [[NSMatrix alloc] initWithFrame: selectionRect
|
|
|
|
|
mode: NSRadioModeMatrix
|
2003-04-18 05:40:25 +00:00
|
|
|
|
cellClass: [GormDisplayCell class]
|
1999-12-14 19:55:18 +00:00
|
|
|
|
numberOfRows: 1
|
|
|
|
|
numberOfColumns: 4];
|
|
|
|
|
[selectionView setTarget: self];
|
|
|
|
|
[selectionView setAction: @selector(changeView:)];
|
|
|
|
|
[selectionView setAutosizesCells: NO];
|
|
|
|
|
[selectionView setCellSize: NSMakeSize(64,64)];
|
2003-04-18 05:40:25 +00:00
|
|
|
|
[selectionView setIntercellSpacing: NSMakeSize(24,0)];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[selectionView setAutoresizingMask: NSViewMinYMargin|NSViewWidthSizable];
|
|
|
|
|
|
|
|
|
|
if ((image = objectsImage) != nil)
|
|
|
|
|
{
|
|
|
|
|
cell = [selectionView cellAtRow: 0 column: 0];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
[cell setTag: 0];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[cell setImage: image];
|
2003-05-24 12:40:54 +00:00
|
|
|
|
[cell setTitle: _(@"Objects")];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[cell setBordered: NO];
|
|
|
|
|
[cell setAlignment: NSCenterTextAlignment];
|
|
|
|
|
[cell setImagePosition: NSImageAbove];
|
2003-04-18 05:40:25 +00:00
|
|
|
|
[cell setButtonType: NSOnOffButton];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((image = imagesImage) != nil)
|
|
|
|
|
{
|
|
|
|
|
cell = [selectionView cellAtRow: 0 column: 1];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
[cell setTag: 1];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[cell setImage: image];
|
2003-05-24 12:40:54 +00:00
|
|
|
|
[cell setTitle: _(@"Images")];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[cell setBordered: NO];
|
|
|
|
|
[cell setAlignment: NSCenterTextAlignment];
|
|
|
|
|
[cell setImagePosition: NSImageAbove];
|
2003-04-18 05:40:25 +00:00
|
|
|
|
[cell setButtonType: NSOnOffButton];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((image = soundsImage) != nil)
|
|
|
|
|
{
|
|
|
|
|
cell = [selectionView cellAtRow: 0 column: 2];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
[cell setTag: 2];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[cell setImage: image];
|
2003-05-24 12:40:54 +00:00
|
|
|
|
[cell setTitle: _(@"Sounds")];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[cell setBordered: NO];
|
|
|
|
|
[cell setAlignment: NSCenterTextAlignment];
|
|
|
|
|
[cell setImagePosition: NSImageAbove];
|
2003-04-18 05:40:25 +00:00
|
|
|
|
[cell setButtonType: NSOnOffButton];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((image = classesImage) != nil)
|
|
|
|
|
{
|
|
|
|
|
cell = [selectionView cellAtRow: 0 column: 3];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
[cell setTag: 3];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[cell setImage: image];
|
2003-05-24 12:40:54 +00:00
|
|
|
|
[cell setTitle: _(@"Classes")];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[cell setBordered: NO];
|
|
|
|
|
[cell setAlignment: NSCenterTextAlignment];
|
|
|
|
|
[cell setImagePosition: NSImageAbove];
|
2003-04-18 05:40:25 +00:00
|
|
|
|
[cell setButtonType: NSOnOffButton];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[window contentView] addSubview: selectionView];
|
|
|
|
|
RELEASE(selectionView);
|
|
|
|
|
|
2001-05-08 09:43:11 +00:00
|
|
|
|
selectionBox = [[NSBox alloc] initWithFrame: scrollRect];
|
|
|
|
|
[selectionBox setTitlePosition: NSNoTitle];
|
|
|
|
|
[selectionBox setBorderType: NSNoBorder];
|
|
|
|
|
[selectionBox setAutoresizingMask:
|
|
|
|
|
NSViewHeightSizable|NSViewWidthSizable];
|
|
|
|
|
[[window contentView] addSubview: selectionBox];
|
|
|
|
|
RELEASE(selectionBox);
|
2002-11-04 13:52:31 +00:00
|
|
|
|
|
|
|
|
|
// objects...
|
|
|
|
|
mainRect.origin = NSMakePoint(0,0);
|
1999-12-14 19:55:18 +00:00
|
|
|
|
scrollView = [[NSScrollView alloc] initWithFrame: scrollRect];
|
|
|
|
|
[scrollView setHasVerticalScroller: YES];
|
2004-02-15 00:50:50 +00:00
|
|
|
|
[scrollView setHasHorizontalScroller: YES];
|
2003-03-02 19:26:51 +00:00
|
|
|
|
[scrollView setAutoresizingMask:
|
|
|
|
|
NSViewHeightSizable|NSViewWidthSizable];
|
|
|
|
|
[scrollView setBorderType: NSBezelBorder];
|
|
|
|
|
|
1999-12-14 19:55:18 +00:00
|
|
|
|
objectsView = [[GormObjectEditor alloc] initWithObject: nil
|
2003-03-02 19:26:51 +00:00
|
|
|
|
inDocument: self];
|
2002-01-14 04:19:01 +00:00
|
|
|
|
AUTORELEASE(objectsView);
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[objectsView setFrame: mainRect];
|
2003-03-02 19:26:51 +00:00
|
|
|
|
[objectsView setAutoresizingMask:
|
|
|
|
|
NSViewHeightSizable|NSViewWidthSizable];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[scrollView setDocumentView: objectsView];
|
|
|
|
|
RELEASE(objectsView);
|
|
|
|
|
|
2002-11-18 20:54:26 +00:00
|
|
|
|
// images...
|
|
|
|
|
mainRect.origin = NSMakePoint(0,0);
|
|
|
|
|
imagesScrollView = [[NSScrollView alloc] initWithFrame: scrollRect];
|
|
|
|
|
[imagesScrollView setHasVerticalScroller: YES];
|
|
|
|
|
[imagesScrollView setHasHorizontalScroller: NO];
|
2003-03-02 19:26:51 +00:00
|
|
|
|
[imagesScrollView setAutoresizingMask:
|
|
|
|
|
NSViewHeightSizable|NSViewWidthSizable];
|
|
|
|
|
[imagesScrollView setBorderType: NSBezelBorder];
|
|
|
|
|
|
2002-11-18 20:54:26 +00:00
|
|
|
|
imagesView = [[GormImageEditor alloc] initWithObject: nil
|
2003-03-02 19:26:51 +00:00
|
|
|
|
inDocument: self];
|
2002-11-18 20:54:26 +00:00
|
|
|
|
AUTORELEASE(imagesView);
|
|
|
|
|
[imagesView setFrame: mainRect];
|
|
|
|
|
[imagesView setAutoresizingMask: NSViewHeightSizable|NSViewWidthSizable];
|
|
|
|
|
[imagesScrollView setDocumentView: imagesView];
|
|
|
|
|
RELEASE(imagesView);
|
|
|
|
|
|
2002-11-04 13:52:31 +00:00
|
|
|
|
// sounds...
|
|
|
|
|
mainRect.origin = NSMakePoint(0,0);
|
|
|
|
|
soundsScrollView = [[NSScrollView alloc] initWithFrame: scrollRect];
|
|
|
|
|
[soundsScrollView setHasVerticalScroller: YES];
|
|
|
|
|
[soundsScrollView setHasHorizontalScroller: NO];
|
2003-03-02 19:26:51 +00:00
|
|
|
|
[soundsScrollView setAutoresizingMask:
|
|
|
|
|
NSViewHeightSizable|NSViewWidthSizable];
|
|
|
|
|
[soundsScrollView setBorderType: NSBezelBorder];
|
|
|
|
|
|
2002-11-04 13:52:31 +00:00
|
|
|
|
soundsView = [[GormSoundEditor alloc] initWithObject: nil
|
2003-03-02 19:26:51 +00:00
|
|
|
|
inDocument: self];
|
2002-11-04 13:52:31 +00:00
|
|
|
|
AUTORELEASE(soundsView);
|
|
|
|
|
[soundsView setFrame: mainRect];
|
|
|
|
|
[soundsView setAutoresizingMask: NSViewHeightSizable|NSViewWidthSizable];
|
|
|
|
|
[soundsScrollView setDocumentView: soundsView];
|
|
|
|
|
RELEASE(soundsView);
|
|
|
|
|
|
|
|
|
|
// classes...
|
2001-05-08 09:43:11 +00:00
|
|
|
|
classesScrollView = [[NSScrollView alloc] initWithFrame: scrollRect];
|
|
|
|
|
[classesScrollView setHasVerticalScroller: YES];
|
|
|
|
|
[classesScrollView setHasHorizontalScroller: NO];
|
|
|
|
|
[classesScrollView setAutoresizingMask:
|
2003-03-02 19:26:51 +00:00
|
|
|
|
NSViewHeightSizable|NSViewWidthSizable];
|
|
|
|
|
[classesScrollView setBorderType: NSBezelBorder];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
|
|
|
|
|
mainRect.origin = NSMakePoint(0,0);
|
2002-07-08 04:45:23 +00:00
|
|
|
|
classesView = [[GormOutlineView alloc] initWithFrame: mainRect];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
[classesView setMenu: [(Gorm*)NSApp classMenu]];
|
|
|
|
|
[classesView setDataSource: self];
|
2002-07-14 23:54:05 +00:00
|
|
|
|
[classesView setDelegate: self];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
[classesView setAutoresizesAllColumnsToFit: YES];
|
2001-10-29 12:52:09 +00:00
|
|
|
|
[classesView setAllowsColumnResizing: NO];
|
2002-03-25 01:44:01 +00:00
|
|
|
|
[classesView setDrawsGrid: NO];
|
|
|
|
|
[classesView setIndentationMarkerFollowsCell: YES];
|
|
|
|
|
[classesView setAutoresizesOutlineColumn: YES];
|
|
|
|
|
[classesView setIndentationPerLevel: 10];
|
2002-07-08 04:45:23 +00:00
|
|
|
|
[classesView setAttributeOffset: 30];
|
|
|
|
|
[classesView setBackgroundColor: salmonColor ];
|
2002-07-12 05:46:29 +00:00
|
|
|
|
[classesView setRowHeight: 18];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
[classesScrollView setDocumentView: classesView];
|
|
|
|
|
RELEASE(classesView);
|
|
|
|
|
|
|
|
|
|
tableColumn = [[NSTableColumn alloc] initWithIdentifier: @"classes"];
|
2003-05-24 12:40:54 +00:00
|
|
|
|
[[tableColumn headerCell] setStringValue: _(@"Classes")];
|
2002-12-22 00:33:44 +00:00
|
|
|
|
[tableColumn setMinWidth: 190];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
[tableColumn setResizable: YES];
|
|
|
|
|
[tableColumn setEditable: YES];
|
2002-03-25 01:44:01 +00:00
|
|
|
|
[classesView addTableColumn: tableColumn];
|
|
|
|
|
[classesView setOutlineTableColumn: tableColumn];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
RELEASE(tableColumn);
|
|
|
|
|
|
|
|
|
|
tableColumn = [[NSTableColumn alloc] initWithIdentifier: @"outlets"];
|
2003-05-24 12:40:54 +00:00
|
|
|
|
[[tableColumn headerCell] setStringValue: _(@"Outlet")];
|
2002-12-22 00:33:44 +00:00
|
|
|
|
[tableColumn setWidth: 50];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
[tableColumn setResizable: NO];
|
2002-07-14 23:54:05 +00:00
|
|
|
|
[tableColumn setEditable: NO];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
[classesView addTableColumn: tableColumn];
|
2002-07-08 04:45:23 +00:00
|
|
|
|
[classesView setOutletColumn: tableColumn];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
RELEASE(tableColumn);
|
|
|
|
|
|
|
|
|
|
tableColumn = [[NSTableColumn alloc] initWithIdentifier: @"actions"];
|
2003-05-24 12:40:54 +00:00
|
|
|
|
[[tableColumn headerCell] setStringValue: _(@"Action")];
|
2002-12-22 00:33:44 +00:00
|
|
|
|
[tableColumn setWidth: 50];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
[tableColumn setResizable: NO];
|
2002-07-14 23:54:05 +00:00
|
|
|
|
[tableColumn setEditable: NO];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
[classesView addTableColumn: tableColumn];
|
2002-07-08 04:45:23 +00:00
|
|
|
|
[classesView setActionColumn: tableColumn];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
RELEASE(tableColumn);
|
|
|
|
|
|
2002-03-26 17:15:26 +00:00
|
|
|
|
[classesView sizeToFit];
|
|
|
|
|
|
2002-03-25 01:44:01 +00:00
|
|
|
|
// expand all of the items in the classesView...
|
|
|
|
|
[classesView expandItem: @"NSObject"];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
|
|
|
|
|
[selectionBox setContentView: scrollView];
|
|
|
|
|
|
1999-12-13 17:01:35 +00:00
|
|
|
|
/*
|
1999-12-14 19:55:18 +00:00
|
|
|
|
* Set up special-case dummy objects and add them to the objects view.
|
1999-12-13 17:01:35 +00:00
|
|
|
|
*/
|
|
|
|
|
filesOwner = [GormFilesOwner new];
|
|
|
|
|
[self setName: @"NSOwner" forObject: filesOwner];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[objectsView addObject: filesOwner];
|
1999-12-13 17:01:35 +00:00
|
|
|
|
firstResponder = [GormFirstResponder new];
|
|
|
|
|
[self setName: @"NSFirst" forObject: firstResponder];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[objectsView addObject: firstResponder];
|
1999-12-13 17:01:35 +00:00
|
|
|
|
fontManager = [GormFontManager new];
|
1999-12-19 06:19:31 +00:00
|
|
|
|
[self setName: @"NSFont" forObject: fontManager];
|
2003-01-09 05:52:19 +00:00
|
|
|
|
// [objectsView addObject: fontManager];
|
1999-12-15 15:29:27 +00:00
|
|
|
|
|
2001-02-08 07:15:15 +00:00
|
|
|
|
/*
|
|
|
|
|
* Set image for this miniwindow.
|
|
|
|
|
*/
|
|
|
|
|
[window setMiniwindowImage: [(id)filesOwner imageForViewer]];
|
|
|
|
|
|
2000-02-03 17:04:37 +00:00
|
|
|
|
hidden = [NSMutableArray new];
|
1999-12-15 15:29:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* Watch to see when we are starting/ending testing.
|
|
|
|
|
*/
|
|
|
|
|
[nc addObserver: self
|
|
|
|
|
selector: @selector(handleNotification:)
|
|
|
|
|
name: IBWillBeginTestingInterfaceNotification
|
|
|
|
|
object: nil];
|
|
|
|
|
[nc addObserver: self
|
|
|
|
|
selector: @selector(handleNotification:)
|
|
|
|
|
name: IBWillEndTestingInterfaceNotification
|
|
|
|
|
object: nil];
|
2003-01-02 06:17:15 +00:00
|
|
|
|
|
|
|
|
|
// preload headers...
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([defaults boolForKey: @"PreloadHeaders"])
|
2003-01-02 06:17:15 +00:00
|
|
|
|
{
|
|
|
|
|
NSArray *headerList = [defaults arrayForKey: @"HeaderList"];
|
|
|
|
|
NSEnumerator *en = [headerList objectEnumerator];
|
|
|
|
|
id obj = nil;
|
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
while ((obj = [en nextObject]) != nil)
|
2003-01-02 06:17:15 +00:00
|
|
|
|
{
|
2003-07-15 04:20:09 +00:00
|
|
|
|
NSDebugLog(@"Preloading %@", obj);
|
2003-01-02 06:17:15 +00:00
|
|
|
|
[self parseHeader: (NSString *)obj];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2001-05-08 09:43:11 +00:00
|
|
|
|
- (id) instantiateClass: (id)sender
|
|
|
|
|
{
|
2002-10-26 02:59:02 +00:00
|
|
|
|
NSDebugLog(@"document -> instantiateClass: ");
|
2001-05-08 09:43:11 +00:00
|
|
|
|
|
|
|
|
|
if ([[selectionView selectedCell] tag] == 3)
|
|
|
|
|
{
|
|
|
|
|
int i = [classesView selectedRow];
|
|
|
|
|
|
2002-03-25 01:44:01 +00:00
|
|
|
|
if (i >= 0)
|
2001-05-08 09:43:11 +00:00
|
|
|
|
{
|
2002-03-25 01:44:01 +00:00
|
|
|
|
id className = [classesView itemAtRow: i];
|
2003-06-20 03:54:19 +00:00
|
|
|
|
GSNibItem *item = nil;
|
2003-05-25 19:08:36 +00:00
|
|
|
|
|
|
|
|
|
if([className isEqualToString: @"FirstResponder"])
|
|
|
|
|
return nil;
|
|
|
|
|
|
2003-06-20 03:54:19 +00:00
|
|
|
|
item = [[GormObjectProxy alloc] initWithClassName: className
|
|
|
|
|
frame: NSMakeRect(0,0,0,0)];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
|
|
|
|
|
[self setName: nil forObject: item];
|
|
|
|
|
[self attachObject: item toParent: nil];
|
|
|
|
|
RELEASE(item);
|
|
|
|
|
|
|
|
|
|
[selectionView selectCellWithTag: 0];
|
|
|
|
|
[selectionBox setContentView: scrollView];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-25 19:08:36 +00:00
|
|
|
|
return self;
|
2001-05-08 09:43:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-04 16:25:39 +00:00
|
|
|
|
- (BOOL) isActive
|
|
|
|
|
{
|
|
|
|
|
return isActive;
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
- (NSString*) nameForObject: (id)anObject
|
|
|
|
|
{
|
1999-12-13 17:01:35 +00:00
|
|
|
|
return (NSString*)NSMapGet(objToName, (void*)anObject);
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) objectForName: (NSString*)name
|
|
|
|
|
{
|
1999-12-13 17:01:35 +00:00
|
|
|
|
return [nameTable objectForKey: name];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-03 11:00:14 +00:00
|
|
|
|
- (BOOL) objectIsVisibleAtLaunch: (id)anObject
|
|
|
|
|
{
|
|
|
|
|
return [[nameTable objectForKey: @"NSVisible"] containsObject: anObject];
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
- (NSArray*) objects
|
|
|
|
|
{
|
|
|
|
|
return [nameTable allValues];
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-04 17:46:26 +00:00
|
|
|
|
/*
|
|
|
|
|
* NB. This assumes we have an empty document to start with - the loaded
|
|
|
|
|
* document is merged in to it.
|
|
|
|
|
*/
|
|
|
|
|
- (id) loadDocument: (NSString*)aFile
|
|
|
|
|
{
|
|
|
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
|
|
|
|
NSMutableDictionary *nt;
|
2002-11-30 00:49:55 +00:00
|
|
|
|
NSMutableDictionary *cc;
|
2000-01-04 17:46:26 +00:00
|
|
|
|
NSData *data;
|
|
|
|
|
NSUnarchiver *u;
|
|
|
|
|
GSNibContainer *c;
|
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
|
id <IBConnectors> con;
|
2004-01-14 06:37:54 +00:00
|
|
|
|
NSString *ownerClass; // , *key;
|
2002-10-31 15:00:17 +00:00
|
|
|
|
NSFileManager *mgr = [NSFileManager defaultManager];
|
|
|
|
|
BOOL isDir = NO;
|
2002-11-04 13:52:31 +00:00
|
|
|
|
NSDirectoryEnumerator *dirEnumerator;
|
2002-11-30 00:49:55 +00:00
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([mgr fileExistsAtPath: aFile isDirectory: &isDir])
|
2002-10-31 15:00:17 +00:00
|
|
|
|
{
|
2003-03-03 09:15:48 +00:00
|
|
|
|
// if the data is in a directory, then load from objects.gorm
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (isDir == NO)
|
2002-10-31 15:00:17 +00:00
|
|
|
|
{
|
|
|
|
|
data = [NSData dataWithContentsOfFile: aFile];
|
|
|
|
|
NSDebugLog(@"Loaded data from file...");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2003-03-03 09:15:48 +00:00
|
|
|
|
NSString *newFileName;
|
|
|
|
|
|
|
|
|
|
newFileName = [aFile stringByAppendingPathComponent: @"objects.gorm"];
|
2002-10-31 15:00:17 +00:00
|
|
|
|
data = [NSData dataWithContentsOfFile: newFileName];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
NSDebugLog(@"Loaded data from %@...", newFileName);
|
2002-10-31 15:00:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// no file exists...
|
|
|
|
|
data = nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check the data...
|
2000-01-04 17:46:26 +00:00
|
|
|
|
if (data == nil)
|
|
|
|
|
{
|
|
|
|
|
NSRunAlertPanel(NULL,
|
|
|
|
|
[NSString stringWithFormat: @"Could not read '%@' data", aFile],
|
|
|
|
|
@"OK", NULL, NULL);
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Create an unarchiver, and use it to unarchive the nib file while
|
|
|
|
|
* handling class replacement so that standard objects understood
|
|
|
|
|
* by the gui library are converted to their Gorm internal equivalents.
|
|
|
|
|
*/
|
|
|
|
|
u = AUTORELEASE([[NSUnarchiver alloc] initForReadingWithData: data]);
|
2003-12-30 05:39:20 +00:00
|
|
|
|
|
|
|
|
|
// classes
|
2003-05-11 06:06:38 +00:00
|
|
|
|
[u decodeClassName: @"GSNibContainer"
|
|
|
|
|
asClassName: @"GormDocument"];
|
|
|
|
|
[u decodeClassName: @"GSNibItem"
|
|
|
|
|
asClassName: @"GormObjectProxy"];
|
|
|
|
|
[u decodeClassName: @"GSCustomView"
|
|
|
|
|
asClassName: @"GormCustomView"];
|
|
|
|
|
[u decodeClassName: @"NSMenu"
|
|
|
|
|
asClassName: @"GormNSMenu"];
|
|
|
|
|
[u decodeClassName: @"NSWindow"
|
|
|
|
|
asClassName: @"GormNSWindow"];
|
|
|
|
|
[u decodeClassName: @"NSPanel"
|
|
|
|
|
asClassName: @"GormNSPanel"];
|
2003-05-23 02:25:34 +00:00
|
|
|
|
[u decodeClassName: @"NSPopUpButton"
|
|
|
|
|
asClassName: @"GormNSPopUpButton"];
|
|
|
|
|
[u decodeClassName: @"NSPopUpButtonCell"
|
|
|
|
|
asClassName: @"GormNSPopUpButtonCell"];
|
2003-05-11 06:06:38 +00:00
|
|
|
|
[u decodeClassName: @"NSBrowser"
|
|
|
|
|
asClassName: @"GormNSBrowser"];
|
|
|
|
|
[u decodeClassName: @"NSTableView"
|
|
|
|
|
asClassName: @"GormNSTableView"];
|
|
|
|
|
[u decodeClassName: @"NSOutlineView"
|
|
|
|
|
asClassName: @"GormNSOutlineView"];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
|
2000-01-04 17:46:26 +00:00
|
|
|
|
c = [u decodeObject];
|
|
|
|
|
if (c == nil || [c isKindOfClass: [GSNibContainer class]] == NO)
|
|
|
|
|
{
|
2003-05-24 12:40:54 +00:00
|
|
|
|
NSRunAlertPanel(NULL, _(@"Could not unarchive document data"),
|
|
|
|
|
_(@"OK"), NULL, NULL);
|
2000-01-04 17:46:26 +00:00
|
|
|
|
return nil;
|
|
|
|
|
}
|
2002-11-18 06:15:06 +00:00
|
|
|
|
|
|
|
|
|
// retrieve the custom class data...
|
2002-12-22 00:33:44 +00:00
|
|
|
|
cc = [[c nameTable] objectForKey: GSCustomClassMap];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (cc == nil)
|
2002-11-30 00:49:55 +00:00
|
|
|
|
{
|
|
|
|
|
cc = [NSMutableDictionary dictionary]; // create an empty one.
|
2002-12-22 00:33:44 +00:00
|
|
|
|
[[c nameTable] setObject: cc forKey: GSCustomClassMap];
|
2002-11-30 00:49:55 +00:00
|
|
|
|
}
|
|
|
|
|
[classManager setCustomClassMap: cc];
|
2003-08-28 04:32:41 +00:00
|
|
|
|
NSDebugLog(@"cc = %@", cc);
|
|
|
|
|
NSDebugLog(@"customClasses = %@", [classManager customClassMap]);
|
2002-11-18 06:15:06 +00:00
|
|
|
|
|
2002-11-30 00:49:55 +00:00
|
|
|
|
// convert from old file format...
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (isDir == NO)
|
2002-10-31 15:00:17 +00:00
|
|
|
|
{
|
2003-03-03 09:15:48 +00:00
|
|
|
|
NSString *s;
|
|
|
|
|
|
|
|
|
|
s = [aFile stringByDeletingPathExtension];
|
|
|
|
|
s = [s stringByAppendingPathExtension: @"classes"];
|
|
|
|
|
if (![classManager loadCustomClasses: s])
|
2002-10-31 15:00:17 +00:00
|
|
|
|
{
|
2003-05-24 12:40:54 +00:00
|
|
|
|
NSRunAlertPanel(NULL, _(@"Could not open the associated classes file.\n"
|
|
|
|
|
@"You won't be able to edit connections on custom classes"),
|
|
|
|
|
_(@"OK"), NULL, NULL);
|
2002-10-31 15:00:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2001-05-08 09:43:11 +00:00
|
|
|
|
{
|
2003-03-03 09:15:48 +00:00
|
|
|
|
NSString *s;
|
|
|
|
|
|
|
|
|
|
s = [aFile stringByAppendingPathComponent: @"data.classes"];
|
|
|
|
|
if (![classManager loadCustomClasses: s])
|
2002-10-31 15:00:17 +00:00
|
|
|
|
{
|
2003-05-24 12:40:54 +00:00
|
|
|
|
NSRunAlertPanel(NULL, _(@"Could not open the associated classes file.\n"
|
|
|
|
|
@"You won't be able to edit connections on custom classes"),
|
|
|
|
|
_(@"OK"), NULL, NULL);
|
2002-10-31 15:00:17 +00:00
|
|
|
|
}
|
2001-05-08 09:43:11 +00:00
|
|
|
|
}
|
2002-10-31 15:00:17 +00:00
|
|
|
|
|
2001-05-08 09:43:11 +00:00
|
|
|
|
[classesView reloadData];
|
2000-01-04 17:46:26 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* In the newly loaded nib container, we change all the connectors
|
|
|
|
|
* to hold the objects rather than their names (using our own dummy
|
|
|
|
|
* object as the 'NSOwner'.
|
|
|
|
|
*/
|
2001-06-20 16:00:19 +00:00
|
|
|
|
ownerClass = [[c nameTable] objectForKey: @"NSOwner"];
|
|
|
|
|
if (ownerClass)
|
|
|
|
|
[filesOwner setClassName: ownerClass];
|
2000-01-04 17:46:26 +00:00
|
|
|
|
[[c nameTable] setObject: filesOwner forKey: @"NSOwner"];
|
|
|
|
|
[[c nameTable] setObject: firstResponder forKey: @"NSFirst"];
|
2000-12-27 09:00:32 +00:00
|
|
|
|
|
2002-11-18 06:15:06 +00:00
|
|
|
|
/* Iterate over the contents of nameTable and create the connections */
|
2000-01-04 17:46:26 +00:00
|
|
|
|
nt = [c nameTable];
|
|
|
|
|
enumerator = [[c connections] objectEnumerator];
|
|
|
|
|
while ((con = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
NSString *name;
|
|
|
|
|
id obj;
|
|
|
|
|
|
|
|
|
|
name = (NSString*)[con source];
|
|
|
|
|
obj = [nt objectForKey: name];
|
|
|
|
|
[con setSource: obj];
|
|
|
|
|
name = (NSString*)[con destination];
|
|
|
|
|
obj = [nt objectForKey: name];
|
|
|
|
|
[con setDestination: obj];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Now we merge the objects from the nib container into our own data
|
|
|
|
|
* structures, taking care not to overwrite our NSOwner and NSFirst.
|
|
|
|
|
*/
|
|
|
|
|
[nt removeObjectForKey: @"NSOwner"];
|
|
|
|
|
[nt removeObjectForKey: @"NSFirst"];
|
|
|
|
|
[connections addObjectsFromArray: [c connections]];
|
|
|
|
|
[nameTable addEntriesFromDictionary: nt];
|
|
|
|
|
|
2002-11-13 16:10:22 +00:00
|
|
|
|
[self rebuildObjToNameMapping];
|
2000-01-13 21:19:03 +00:00
|
|
|
|
|
2000-01-04 17:46:26 +00:00
|
|
|
|
/*
|
2002-11-04 13:52:31 +00:00
|
|
|
|
* set our new file name
|
2000-01-04 17:46:26 +00:00
|
|
|
|
*/
|
|
|
|
|
ASSIGN(documentPath, aFile);
|
|
|
|
|
[window setTitleWithRepresentedFilename: documentPath];
|
2002-10-13 06:04:05 +00:00
|
|
|
|
|
2002-11-04 13:52:31 +00:00
|
|
|
|
/*
|
2003-02-13 13:32:59 +00:00
|
|
|
|
* read in all of the sounds in the .gorm wrapper and
|
|
|
|
|
* load them into the editor.
|
2002-11-04 13:52:31 +00:00
|
|
|
|
*/
|
|
|
|
|
dirEnumerator = [mgr enumeratorAtPath: documentPath];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (dirEnumerator)
|
2002-11-04 13:52:31 +00:00
|
|
|
|
{
|
|
|
|
|
NSString *file = nil;
|
|
|
|
|
NSArray *fileTypes = [NSSound soundUnfilteredFileTypes];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
while ((file = [dirEnumerator nextObject]))
|
2002-11-04 13:52:31 +00:00
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([fileTypes containsObject: [file pathExtension]])
|
2002-11-04 13:52:31 +00:00
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
NSString *soundPath;
|
|
|
|
|
|
|
|
|
|
NSDebugLog(@"Add the sound %@", file);
|
|
|
|
|
soundPath = [documentPath stringByAppendingPathComponent: file];
|
2002-11-04 13:52:31 +00:00
|
|
|
|
[soundsView addObject: [self _createSoundPlaceHolder: soundPath]];
|
|
|
|
|
[sounds addObject: soundPath];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-18 20:54:26 +00:00
|
|
|
|
/*
|
2003-02-13 13:32:59 +00:00
|
|
|
|
* read in all of the images in the .gorm wrapper and
|
|
|
|
|
* load them into the editor.
|
2002-11-18 20:54:26 +00:00
|
|
|
|
*/
|
|
|
|
|
dirEnumerator = [mgr enumeratorAtPath: documentPath];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (dirEnumerator)
|
2002-11-18 20:54:26 +00:00
|
|
|
|
{
|
|
|
|
|
NSString *file = nil;
|
|
|
|
|
NSArray *fileTypes = [NSImage imageFileTypes];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
while ((file = [dirEnumerator nextObject]))
|
2002-11-18 20:54:26 +00:00
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([fileTypes containsObject: [file pathExtension]])
|
2002-11-18 20:54:26 +00:00
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
NSString *imagePath;
|
|
|
|
|
id placeHolder;
|
|
|
|
|
|
|
|
|
|
imagePath = [documentPath stringByAppendingPathComponent: file];
|
|
|
|
|
placeHolder = [self _createImagePlaceHolder: imagePath];
|
2002-11-18 20:54:26 +00:00
|
|
|
|
if (placeHolder)
|
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
NSDebugLog(@"Add the image %@", file);
|
2002-11-18 20:54:26 +00:00
|
|
|
|
[imagesView addObject: placeHolder];
|
|
|
|
|
[images addObject: imagePath];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-15 18:17:53 +00:00
|
|
|
|
NSDebugLog(@"nameTable = %@",[c nameTable]);
|
2002-10-13 06:04:05 +00:00
|
|
|
|
|
2004-01-11 18:03:45 +00:00
|
|
|
|
/*
|
2003-05-23 02:25:34 +00:00
|
|
|
|
enumerator = [[c nameTable] keyEnumerator];
|
|
|
|
|
while ((key = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
id o = [[c nameTable] objectForKey: key];
|
|
|
|
|
if ([o respondsToSelector: @selector(awakeFromDocument:)])
|
|
|
|
|
{
|
|
|
|
|
[o awakeFromDocument: self];
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-01-11 18:03:45 +00:00
|
|
|
|
*/
|
2003-05-23 02:25:34 +00:00
|
|
|
|
|
2003-11-19 05:59:55 +00:00
|
|
|
|
// this is the last thing we should do...
|
|
|
|
|
[nc postNotificationName: IBDidOpenDocumentNotification
|
|
|
|
|
object: self];
|
|
|
|
|
|
2000-01-04 17:46:26 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-13 16:10:22 +00:00
|
|
|
|
/*
|
|
|
|
|
* Build our reverse mapping information and other initialisation
|
|
|
|
|
*/
|
|
|
|
|
- (void) rebuildObjToNameMapping
|
|
|
|
|
{
|
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
|
NSString *name;
|
|
|
|
|
|
|
|
|
|
NSResetMapTable(objToName);
|
|
|
|
|
NSMapInsert(objToName, (void*)filesOwner, (void*)@"NSOwner");
|
|
|
|
|
NSMapInsert(objToName, (void*)firstResponder, (void*)@"NSFirst");
|
|
|
|
|
enumerator = [nameTable keyEnumerator];
|
|
|
|
|
while ((name = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
id obj = [nameTable objectForKey: name];
|
|
|
|
|
|
|
|
|
|
NSMapInsert(objToName, (void*)obj, (void*)name);
|
|
|
|
|
if ([obj isKindOfClass: [NSMenu class]] == YES)
|
|
|
|
|
{
|
|
|
|
|
if ([name isEqual: @"NSMenu"] == YES)
|
|
|
|
|
{
|
|
|
|
|
NSRect frame = [[NSScreen mainScreen] frame];
|
|
|
|
|
|
|
|
|
|
[[obj window] setFrameTopLeftPoint:
|
|
|
|
|
NSMakePoint(1, frame.size.height-200)];
|
|
|
|
|
[[self openEditorForObject: obj] activate];
|
|
|
|
|
[objectsView addObject: obj];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ([obj isKindOfClass: [NSWindow class]] == YES)
|
|
|
|
|
{
|
|
|
|
|
[objectsView addObject: obj];
|
|
|
|
|
[[self openEditorForObject: obj] activate];
|
|
|
|
|
}
|
|
|
|
|
else if ([obj isKindOfClass: [GSNibItem class]] == YES
|
2003-02-13 13:32:59 +00:00
|
|
|
|
&& [obj isKindOfClass: [GormCustomView class]] == NO)
|
2002-11-13 16:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
[objectsView addObject: obj];
|
|
|
|
|
//[[self openEditorForObject: obj] activate];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
/*
|
|
|
|
|
* NB. This assumes we have an empty document to start with - the loaded
|
|
|
|
|
* document is merged in to it.
|
|
|
|
|
*/
|
|
|
|
|
- (id) openDocument: (id)sender
|
|
|
|
|
{
|
2000-01-04 12:37:00 +00:00
|
|
|
|
NSArray *fileTypes;
|
1999-12-08 15:04:57 +00:00
|
|
|
|
NSOpenPanel *oPanel = [NSOpenPanel openPanel];
|
|
|
|
|
int result;
|
2002-04-07 22:02:41 +00:00
|
|
|
|
NSString *pth = [[NSUserDefaults standardUserDefaults]
|
|
|
|
|
objectForKey:@"OpenDir"];
|
2003-01-02 06:17:15 +00:00
|
|
|
|
|
|
|
|
|
fileTypes = [NSArray arrayWithObjects: @"gorm", @"gmodel", nil];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
[oPanel setAllowsMultipleSelection: NO];
|
|
|
|
|
[oPanel setCanChooseFiles: YES];
|
|
|
|
|
[oPanel setCanChooseDirectories: NO];
|
2002-04-07 22:02:41 +00:00
|
|
|
|
result = [oPanel runModalForDirectory: pth
|
1999-12-08 15:04:57 +00:00
|
|
|
|
file: nil
|
|
|
|
|
types: fileTypes];
|
|
|
|
|
if (result == NSOKButton)
|
|
|
|
|
{
|
2002-11-05 05:42:45 +00:00
|
|
|
|
NSString *filename = [oPanel filename];
|
|
|
|
|
NSString *ext = [filename pathExtension];
|
|
|
|
|
|
2002-10-08 20:17:17 +00:00
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject: [oPanel directory]
|
|
|
|
|
forKey:@"OpenDir"];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([ext isEqualToString:@"gorm"] || [ext isEqualToString:@"nib"])
|
2002-11-05 05:42:45 +00:00
|
|
|
|
{
|
|
|
|
|
return [self loadDocument: filename];
|
|
|
|
|
}
|
2003-02-13 13:32:59 +00:00
|
|
|
|
else if ([ext isEqualToString:@"gmodel"])
|
2002-11-05 05:42:45 +00:00
|
|
|
|
{
|
|
|
|
|
return [self openGModel: filename];
|
|
|
|
|
}
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
return nil; /* Failed */
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-08 15:19:11 +00:00
|
|
|
|
- (id<IBEditors>) openEditorForObject: (id)anObject
|
|
|
|
|
{
|
1999-12-14 17:38:17 +00:00
|
|
|
|
id<IBEditors> e = [self editorForObject: anObject create: YES];
|
2002-08-14 00:01:42 +00:00
|
|
|
|
id<IBEditors, IBSelectionOwners> p = [self parentEditorForEditor: e];
|
1999-12-14 17:38:17 +00:00
|
|
|
|
|
2000-01-14 13:34:15 +00:00
|
|
|
|
if (p != nil && p != objectsView)
|
1999-12-14 17:38:17 +00:00
|
|
|
|
{
|
|
|
|
|
[self openEditorForObject: [p editedObject]];
|
|
|
|
|
}
|
2000-01-03 11:00:14 +00:00
|
|
|
|
[e orderFront];
|
|
|
|
|
[[e window] makeKeyAndOrderFront: self];
|
1999-12-14 17:38:17 +00:00
|
|
|
|
return e;
|
1999-12-08 15:19:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-08-14 00:01:42 +00:00
|
|
|
|
- (id<IBEditors, IBSelectionOwners>) parentEditorForEditor: (id<IBEditors>)anEditor
|
1999-12-08 15:19:11 +00:00
|
|
|
|
{
|
1999-12-14 17:38:17 +00:00
|
|
|
|
NSArray *links;
|
|
|
|
|
GormObjectToEditor *con;
|
|
|
|
|
|
|
|
|
|
links = [self connectorsForSource: anEditor
|
2002-08-14 00:01:42 +00:00
|
|
|
|
ofClass: [GormEditorToParent class]];
|
1999-12-14 17:38:17 +00:00
|
|
|
|
con = [links lastObject];
|
|
|
|
|
return [con destination];
|
1999-12-08 15:19:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
- (id) parentOfObject: (id)anObject
|
|
|
|
|
{
|
|
|
|
|
NSArray *old;
|
|
|
|
|
id<IBConnectors> con;
|
|
|
|
|
|
1999-12-13 17:01:35 +00:00
|
|
|
|
old = [self connectorsForSource: anObject ofClass: [NSNibConnector class]];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
con = [old lastObject];
|
1999-12-13 17:01:35 +00:00
|
|
|
|
if ([con destination] != filesOwner && [con destination] != firstResponder)
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
|
|
|
|
return [con destination];
|
|
|
|
|
}
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSArray*) pasteType: (NSString*)aType
|
|
|
|
|
fromPasteboard: (NSPasteboard*)aPasteboard
|
|
|
|
|
parent: (id)parent
|
|
|
|
|
{
|
2000-01-14 13:34:15 +00:00
|
|
|
|
NSData *data;
|
|
|
|
|
NSArray *objects;
|
|
|
|
|
NSEnumerator *enumerator;
|
1999-12-08 15:04:57 +00:00
|
|
|
|
NSPoint filePoint;
|
|
|
|
|
NSPoint screenPoint;
|
2002-03-01 14:42:15 +00:00
|
|
|
|
NSUnarchiver *u;
|
1999-12-08 15:04:57 +00:00
|
|
|
|
|
2000-01-14 13:34:15 +00:00
|
|
|
|
data = [aPasteboard dataForType: aType];
|
|
|
|
|
if (data == nil)
|
|
|
|
|
{
|
2004-02-21 18:48:48 +00:00
|
|
|
|
NSDebugLog(@"Pasteboard %@ doesn't contain data of %@", aPasteboard, aType);
|
2000-01-14 13:34:15 +00:00
|
|
|
|
return nil;
|
|
|
|
|
}
|
2002-03-01 14:42:15 +00:00
|
|
|
|
u = AUTORELEASE([[NSUnarchiver alloc] initForReadingWithData: data]);
|
|
|
|
|
[u decodeClassName: @"GSCustomView"
|
|
|
|
|
asClassName: @"GormCustomView"];
|
|
|
|
|
objects = [u decodeObject];
|
2000-01-14 13:34:15 +00:00
|
|
|
|
enumerator = [objects objectEnumerator];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
filePoint = [window mouseLocationOutsideOfEventStream];
|
|
|
|
|
screenPoint = [window convertBaseToScreen: filePoint];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
|
2000-01-04 12:21:17 +00:00
|
|
|
|
/*
|
2000-01-14 17:07:44 +00:00
|
|
|
|
* Windows and panels are a special case - for a multiple window paste,
|
2000-01-04 12:21:17 +00:00
|
|
|
|
* the windows need to be positioned so they are not on top of each other.
|
|
|
|
|
*/
|
1999-12-08 15:04:57 +00:00
|
|
|
|
if ([aType isEqualToString: IBWindowPboardType] == YES)
|
|
|
|
|
{
|
|
|
|
|
NSWindow *win;
|
|
|
|
|
|
|
|
|
|
while ((win = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
[win setFrameTopLeftPoint: screenPoint];
|
2000-01-04 12:21:17 +00:00
|
|
|
|
screenPoint.x += 10;
|
|
|
|
|
screenPoint.y -= 10;
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-08-03 09:01:11 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NSEnumerator *enumerator = [objects objectEnumerator];
|
|
|
|
|
id obj;
|
|
|
|
|
NSRect frame;
|
|
|
|
|
while ((obj = [enumerator nextObject]) != nil)
|
2003-08-10 19:55:04 +00:00
|
|
|
|
{
|
2003-08-23 01:04:36 +00:00
|
|
|
|
// check to see if the object has a frame. If so, then
|
|
|
|
|
// modify it. If not, simply iterate to the next object
|
|
|
|
|
if([obj respondsToSelector: @selector(frame)])
|
2003-08-10 19:55:04 +00:00
|
|
|
|
{
|
2003-08-23 01:04:36 +00:00
|
|
|
|
frame = [obj frame];
|
|
|
|
|
frame.origin.x -= 6;
|
|
|
|
|
frame.origin.y -= 6;
|
|
|
|
|
[obj setFrame: frame];
|
2003-08-10 19:55:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-08-03 09:01:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
[self attachObjects: objects toParent: parent];
|
|
|
|
|
[self touch];
|
|
|
|
|
return objects;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) removeConnector: (id<IBConnectors>)aConnector
|
|
|
|
|
{
|
2003-06-06 06:24:46 +00:00
|
|
|
|
// issue pre notification..
|
2003-05-23 02:25:34 +00:00
|
|
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
|
|
|
|
[nc postNotificationName: IBWillRemoveConnectorNotification
|
2003-05-24 05:29:35 +00:00
|
|
|
|
object: self];
|
2003-06-06 06:24:46 +00:00
|
|
|
|
// mark the document as changed.
|
|
|
|
|
[self touch];
|
|
|
|
|
// issue port notification..
|
1999-12-08 15:04:57 +00:00
|
|
|
|
[connections removeObjectIdenticalTo: aConnector];
|
2003-05-23 02:25:34 +00:00
|
|
|
|
[nc postNotificationName: IBDidRemoveConnectorNotification
|
2003-05-24 05:29:35 +00:00
|
|
|
|
object: self];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-12-08 15:19:11 +00:00
|
|
|
|
- (void) resignSelectionForEditor: (id<IBEditors>)editor
|
|
|
|
|
{
|
1999-12-14 17:38:17 +00:00
|
|
|
|
NSEnumerator *enumerator = [connections objectEnumerator];
|
|
|
|
|
Class editClass = [GormObjectToEditor class];
|
|
|
|
|
id<IBConnectors> c;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This editor wants to give up the selection. Go through all the known
|
|
|
|
|
* editors (with links in the connections array) and try to find one
|
|
|
|
|
* that wants to take over the selection. Activate whatever editor we
|
1999-12-15 11:12:52 +00:00
|
|
|
|
* find (if any).
|
1999-12-14 17:38:17 +00:00
|
|
|
|
*/
|
|
|
|
|
while ((c = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
if ([c class] == editClass)
|
|
|
|
|
{
|
|
|
|
|
id<IBEditors> e = [c destination];
|
|
|
|
|
|
|
|
|
|
if (e != editor && [e wantsSelection] == YES)
|
|
|
|
|
{
|
1999-12-15 11:12:52 +00:00
|
|
|
|
[e activate];
|
2000-01-04 12:21:17 +00:00
|
|
|
|
[self setSelectionFromEditor: e];
|
2000-01-04 16:25:39 +00:00
|
|
|
|
return;
|
1999-12-14 17:38:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-01-04 16:25:39 +00:00
|
|
|
|
/*
|
|
|
|
|
* No editor available to take the selection - set a nil owner.
|
|
|
|
|
*/
|
|
|
|
|
[self setSelectionFromEditor: nil];
|
1999-12-08 15:19:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-13 21:19:03 +00:00
|
|
|
|
- (void) setupDefaults: (NSString*)type
|
|
|
|
|
{
|
|
|
|
|
if (hasSetDefaults == YES)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
hasSetDefaults = YES;
|
|
|
|
|
if ([type isEqual: @"Application"] == YES)
|
|
|
|
|
{
|
2002-04-07 22:02:41 +00:00
|
|
|
|
NSMenu *aMenu;
|
2000-01-13 21:19:03 +00:00
|
|
|
|
NSWindow *aWindow;
|
|
|
|
|
NSRect frame = [[NSScreen mainScreen] frame];
|
|
|
|
|
unsigned style = NSTitledWindowMask | NSClosableWindowMask
|
|
|
|
|
| NSResizableWindowMask | NSMiniaturizableWindowMask;
|
|
|
|
|
|
2002-04-07 22:02:41 +00:00
|
|
|
|
if ([NSMenu respondsToSelector: @selector(allocSubstitute)])
|
|
|
|
|
{
|
|
|
|
|
aMenu = [[NSMenu allocSubstitute] init];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
aMenu = [[NSMenu alloc] init];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([NSWindow respondsToSelector: @selector(allocSubstitute)])
|
|
|
|
|
{
|
|
|
|
|
aWindow = [[NSWindow allocSubstitute]
|
|
|
|
|
initWithContentRect: NSMakeRect(0,0,600, 400)
|
|
|
|
|
styleMask: style
|
|
|
|
|
backing: NSBackingStoreRetained
|
|
|
|
|
defer: NO];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
aWindow = [[NSWindow alloc]
|
|
|
|
|
initWithContentRect: NSMakeRect(0,0,600, 400)
|
|
|
|
|
styleMask: style
|
|
|
|
|
backing: NSBackingStoreRetained
|
|
|
|
|
defer: NO];
|
|
|
|
|
}
|
2000-01-13 21:19:03 +00:00
|
|
|
|
[aWindow setFrameTopLeftPoint:
|
|
|
|
|
NSMakePoint(220, frame.size.height-100)];
|
2003-05-24 12:40:54 +00:00
|
|
|
|
[aWindow setTitle: _(@"My Window")];
|
2000-01-14 17:26:25 +00:00
|
|
|
|
[self setName: @"My Window" forObject: aWindow];
|
2000-01-13 21:19:03 +00:00
|
|
|
|
[self attachObject: aWindow toParent: nil];
|
2000-01-14 17:07:44 +00:00
|
|
|
|
[self setObject: aWindow isVisibleAtLaunch: YES];
|
2000-01-13 21:19:03 +00:00
|
|
|
|
RELEASE(aWindow);
|
|
|
|
|
|
2003-05-24 12:40:54 +00:00
|
|
|
|
[aMenu setTitle: _(@"Main Menu")];
|
|
|
|
|
[aMenu addItemWithTitle: _(@"Hide")
|
2000-01-13 21:19:03 +00:00
|
|
|
|
action: @selector(hide:)
|
|
|
|
|
keyEquivalent: @"h"];
|
2003-05-24 12:40:54 +00:00
|
|
|
|
[aMenu addItemWithTitle: _(@"Quit")
|
2000-01-13 21:19:03 +00:00
|
|
|
|
action: @selector(terminate:)
|
2002-04-07 22:02:41 +00:00
|
|
|
|
keyEquivalent: @"q"];
|
2000-01-13 21:19:03 +00:00
|
|
|
|
[self setName: @"NSMenu" forObject: aMenu];
|
|
|
|
|
[self attachObject: aMenu toParent: nil];
|
2002-04-07 22:02:41 +00:00
|
|
|
|
[objectsView addObject: aMenu];
|
2000-01-13 21:19:03 +00:00
|
|
|
|
[[aMenu window] setFrameTopLeftPoint:
|
|
|
|
|
NSMakePoint(1, frame.size.height-200)];
|
|
|
|
|
RELEASE(aMenu);
|
|
|
|
|
}
|
2000-01-14 17:07:44 +00:00
|
|
|
|
else if ([type isEqual: @"Inspector"] == YES)
|
|
|
|
|
{
|
|
|
|
|
NSWindow *aWindow;
|
|
|
|
|
NSRect frame = [[NSScreen mainScreen] frame];
|
|
|
|
|
unsigned style = NSTitledWindowMask | NSClosableWindowMask;
|
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
aWindow = [[NSWindow alloc] initWithContentRect: NSMakeRect(0,0, IVW, IVH)
|
2000-01-14 17:07:44 +00:00
|
|
|
|
styleMask: style
|
|
|
|
|
backing: NSBackingStoreRetained
|
|
|
|
|
defer: NO];
|
|
|
|
|
[aWindow setFrameTopLeftPoint:
|
|
|
|
|
NSMakePoint(220, frame.size.height-100)];
|
2003-05-24 12:40:54 +00:00
|
|
|
|
[aWindow setTitle: _(@"Inspector Window")];
|
2000-01-14 17:26:25 +00:00
|
|
|
|
[self setName: @"InspectorWin" forObject: aWindow];
|
2000-01-14 17:07:44 +00:00
|
|
|
|
[self attachObject: aWindow toParent: nil];
|
|
|
|
|
RELEASE(aWindow);
|
|
|
|
|
}
|
|
|
|
|
else if ([type isEqual: @"Palette"] == YES)
|
|
|
|
|
{
|
|
|
|
|
NSWindow *aWindow;
|
|
|
|
|
NSRect frame = [[NSScreen mainScreen] frame];
|
|
|
|
|
unsigned style = NSTitledWindowMask | NSClosableWindowMask;
|
|
|
|
|
|
|
|
|
|
aWindow = [[NSWindow alloc] initWithContentRect: NSMakeRect(0,0,272,192)
|
|
|
|
|
styleMask: style
|
|
|
|
|
backing: NSBackingStoreRetained
|
|
|
|
|
defer: NO];
|
|
|
|
|
[aWindow setFrameTopLeftPoint:
|
|
|
|
|
NSMakePoint(220, frame.size.height-100)];
|
2003-05-24 12:40:54 +00:00
|
|
|
|
[aWindow setTitle: _(@"Palette Window")];
|
2000-01-14 17:26:25 +00:00
|
|
|
|
[self setName: @"PaletteWin" forObject: aWindow];
|
2000-01-14 17:07:44 +00:00
|
|
|
|
[self attachObject: aWindow toParent: nil];
|
|
|
|
|
RELEASE(aWindow);
|
|
|
|
|
}
|
2000-01-13 21:19:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
- (void) setName: (NSString*)aName forObject: (id)object
|
|
|
|
|
{
|
|
|
|
|
id oldObject;
|
|
|
|
|
NSString *oldName;
|
2004-03-04 06:02:24 +00:00
|
|
|
|
NSMutableDictionary *cc = [classManager customClassMap];
|
|
|
|
|
NSString *className = nil;
|
1999-12-08 15:04:57 +00:00
|
|
|
|
|
|
|
|
|
if (object == nil)
|
|
|
|
|
{
|
2004-02-21 18:48:48 +00:00
|
|
|
|
NSDebugLog(@"Attempt to set name for nil object");
|
1999-12-08 15:04:57 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (aName == nil)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* No name given - so we must generate one unless we already have one.
|
|
|
|
|
*/
|
|
|
|
|
oldName = [self nameForObject: object];
|
|
|
|
|
if (oldName == nil)
|
|
|
|
|
{
|
|
|
|
|
NSString *base;
|
|
|
|
|
unsigned i = 0;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Generate a sensible name for the object based on its class.
|
|
|
|
|
*/
|
2001-05-08 09:43:11 +00:00
|
|
|
|
if ([object isKindOfClass: [GSNibItem class]])
|
|
|
|
|
{
|
|
|
|
|
// use the actual class name for proxies
|
|
|
|
|
base = [(id)object className];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
base = NSStringFromClass([object class]);
|
|
|
|
|
}
|
1999-12-08 15:04:57 +00:00
|
|
|
|
if ([base hasPrefix: @"NS"] || [base hasPrefix: @"GS"])
|
|
|
|
|
{
|
|
|
|
|
base = [base substringFromIndex: 2];
|
|
|
|
|
}
|
|
|
|
|
aName = base;
|
|
|
|
|
while ([nameTable objectForKey: aName] != nil)
|
|
|
|
|
{
|
|
|
|
|
aName = [base stringByAppendingFormat: @"%u", ++i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return; /* Already named ... nothing to do */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
oldObject = [nameTable objectForKey: aName];
|
|
|
|
|
if (oldObject != nil)
|
|
|
|
|
{
|
2004-02-21 18:48:48 +00:00
|
|
|
|
NSDebugLog(@"Attempt to re-use name '%@'", aName);
|
1999-12-08 15:04:57 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
oldName = [self nameForObject: object];
|
|
|
|
|
if (oldName != nil)
|
|
|
|
|
{
|
|
|
|
|
if ([oldName isEqual: aName] == YES)
|
|
|
|
|
{
|
2000-02-25 17:26:57 +00:00
|
|
|
|
return; /* Already have this name ... nothing to do */
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
2000-02-25 17:26:57 +00:00
|
|
|
|
RETAIN(object);
|
|
|
|
|
AUTORELEASE(object);
|
|
|
|
|
[nameTable removeObjectForKey: oldName];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
NSMapRemove(objToName, (void*)object);
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-12-27 09:00:32 +00:00
|
|
|
|
aName = [aName copy]; /* Make sure it's immutable */
|
1999-12-08 15:04:57 +00:00
|
|
|
|
[nameTable setObject: object forKey: aName];
|
|
|
|
|
NSMapInsert(objToName, (void*)object, (void*)aName);
|
|
|
|
|
if (oldName != nil)
|
|
|
|
|
{
|
|
|
|
|
[nameTable removeObjectForKey: oldName];
|
|
|
|
|
}
|
1999-12-22 10:13:18 +00:00
|
|
|
|
if ([objectsView containsObject: object] == YES)
|
|
|
|
|
{
|
|
|
|
|
[objectsView refreshCells];
|
|
|
|
|
}
|
2004-03-04 06:02:24 +00:00
|
|
|
|
|
|
|
|
|
// check the custom classes map and replace the appropriate
|
|
|
|
|
// object, if a mapping exists.
|
|
|
|
|
if(cc != nil)
|
|
|
|
|
{
|
|
|
|
|
className = [cc objectForKey: oldName];
|
|
|
|
|
if(className != nil)
|
|
|
|
|
{
|
|
|
|
|
[cc removeObjectForKey: oldName];
|
|
|
|
|
[cc setObject: className forKey: aName];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
RELEASE(aName);
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-03 11:00:14 +00:00
|
|
|
|
- (void) setObject: (id)anObject isVisibleAtLaunch: (BOOL)flag
|
|
|
|
|
{
|
|
|
|
|
NSMutableArray *a = [nameTable objectForKey: @"NSVisible"];
|
|
|
|
|
|
|
|
|
|
if (flag == YES)
|
|
|
|
|
{
|
|
|
|
|
if (a == nil)
|
|
|
|
|
{
|
|
|
|
|
a = [NSMutableArray new];
|
|
|
|
|
[nameTable setObject: a forKey: @"NSVisible"];
|
2003-05-10 17:34:45 +00:00
|
|
|
|
RELEASE(a);
|
2000-01-03 11:00:14 +00:00
|
|
|
|
}
|
|
|
|
|
if ([a containsObject: anObject] == NO)
|
|
|
|
|
{
|
|
|
|
|
[a addObject: anObject];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
[a removeObject: anObject];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-16 04:09:07 +00:00
|
|
|
|
- (void) setObject: (id)anObject isDeferred: (BOOL)flag
|
2002-10-13 06:04:05 +00:00
|
|
|
|
{
|
2003-01-16 04:09:07 +00:00
|
|
|
|
NSMutableArray *a = [nameTable objectForKey: @"NSDeferred"];
|
|
|
|
|
|
2002-10-13 06:04:05 +00:00
|
|
|
|
if (flag == YES)
|
|
|
|
|
{
|
2003-01-16 04:09:07 +00:00
|
|
|
|
if (a == nil)
|
|
|
|
|
{
|
|
|
|
|
a = [NSMutableArray new];
|
|
|
|
|
[nameTable setObject: a forKey: @"NSDeferred"];
|
|
|
|
|
RELEASE(a);
|
|
|
|
|
}
|
|
|
|
|
if ([a containsObject: anObject] == NO)
|
2002-10-13 06:04:05 +00:00
|
|
|
|
{
|
2003-01-16 04:09:07 +00:00
|
|
|
|
[a addObject: anObject];
|
2002-10-13 06:04:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2003-01-16 04:09:07 +00:00
|
|
|
|
[a removeObject: anObject];
|
2002-10-13 06:04:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-16 04:09:07 +00:00
|
|
|
|
- (BOOL) objectIsDeferred: (id)anObject
|
2002-10-13 06:04:05 +00:00
|
|
|
|
{
|
2003-01-16 04:09:07 +00:00
|
|
|
|
return [[nameTable objectForKey: @"NSDeferred"] containsObject: anObject];
|
2002-10-13 06:04:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-09-28 23:31:35 +00:00
|
|
|
|
// windows / services menus...
|
|
|
|
|
- (void) setWindowsMenu: (NSMenu *)anObject
|
|
|
|
|
{
|
|
|
|
|
if(anObject != nil)
|
|
|
|
|
{
|
|
|
|
|
[nameTable setObject: anObject forKey: @"NSWindowsMenu"];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
[nameTable removeObjectForKey: @"NSWindowsMenu"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSMenu *) windowsMenu
|
|
|
|
|
{
|
|
|
|
|
return [nameTable objectForKey: @"NSWindowsMenu"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setServicesMenu: (NSMenu *)anObject
|
|
|
|
|
{
|
|
|
|
|
if(anObject != nil)
|
|
|
|
|
{
|
|
|
|
|
[nameTable setObject: anObject forKey: @"NSServicesMenu"];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
[nameTable removeObjectForKey: @"NSServicesMenu"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSMenu *) servicesMenu
|
|
|
|
|
{
|
|
|
|
|
return [nameTable objectForKey: @"NSServicesMenu"];
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-04 17:46:26 +00:00
|
|
|
|
/*
|
|
|
|
|
* To revert to a saved version, we actually load a new document and
|
|
|
|
|
* close the original document, returning the id of the new document.
|
|
|
|
|
*/
|
|
|
|
|
- (id) revertDocument: (id)sender
|
|
|
|
|
{
|
|
|
|
|
GormDocument *reverted = AUTORELEASE([GormDocument new]);
|
|
|
|
|
|
|
|
|
|
if ([reverted loadDocument: documentPath] != nil)
|
|
|
|
|
{
|
|
|
|
|
NSRect frame = [window frame];
|
|
|
|
|
|
|
|
|
|
[window setReleasedWhenClosed: YES];
|
|
|
|
|
[window close];
|
|
|
|
|
[[reverted window] setFrame: frame display: YES];
|
|
|
|
|
return reverted;
|
|
|
|
|
}
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-20 03:57:37 +00:00
|
|
|
|
- (BOOL) saveAsDocument: (id)sender
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
2000-01-04 12:21:17 +00:00
|
|
|
|
NSSavePanel *sp;
|
|
|
|
|
int result;
|
1999-12-08 15:04:57 +00:00
|
|
|
|
|
|
|
|
|
sp = [NSSavePanel savePanel];
|
2003-01-02 06:17:15 +00:00
|
|
|
|
[sp setRequiredFileType: @"gorm"];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
result = [sp runModalForDirectory: NSHomeDirectory() file: @""];
|
|
|
|
|
if (result == NSOKButton)
|
|
|
|
|
{
|
|
|
|
|
NSFileManager *mgr = [NSFileManager defaultManager];
|
|
|
|
|
NSString *path = [sp filename];
|
|
|
|
|
NSString *old = documentPath;
|
|
|
|
|
|
|
|
|
|
if ([path isEqual: documentPath] == NO
|
|
|
|
|
&& [mgr fileExistsAtPath: path] == YES)
|
|
|
|
|
{
|
2002-11-12 21:44:48 +00:00
|
|
|
|
/* NSSavePanel has already asked if it's ok to replace */
|
|
|
|
|
NSString *bPath = [path stringByAppendingString: @"~"];
|
|
|
|
|
|
|
|
|
|
[mgr removeFileAtPath: bPath handler: nil];
|
|
|
|
|
[mgr movePath: path toPath: bPath handler: nil];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
documentPath = RETAIN(path);
|
2003-05-20 03:57:37 +00:00
|
|
|
|
[self saveGormDocument: sender];
|
2003-04-18 05:40:25 +00:00
|
|
|
|
RELEASE(old);
|
2003-05-20 03:57:37 +00:00
|
|
|
|
|
|
|
|
|
return YES;
|
2003-04-18 05:40:25 +00:00
|
|
|
|
/* FIXME - need to update files window title etc */
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
2003-05-20 03:57:37 +00:00
|
|
|
|
return NO;
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-08-23 01:04:36 +00:00
|
|
|
|
//
|
|
|
|
|
// Private method which iterates through the list of custom classes and instructs
|
|
|
|
|
// the archiver to replace the actual object with template during the archiving
|
|
|
|
|
// process.
|
|
|
|
|
//
|
|
|
|
|
- (void) _replaceObjectsWithTemplates: (NSArchiver *)archiver
|
|
|
|
|
{
|
|
|
|
|
GormClassManager *cm = [self classManager];
|
2003-08-24 17:10:05 +00:00
|
|
|
|
NSEnumerator *en = [[cm customClassMap] keyEnumerator];
|
2003-08-23 01:04:36 +00:00
|
|
|
|
id key = nil;
|
2003-10-08 05:00:21 +00:00
|
|
|
|
|
|
|
|
|
// loop through all objects.
|
2003-08-23 01:04:36 +00:00
|
|
|
|
while((key = [en nextObject]) != nil)
|
|
|
|
|
{
|
2003-08-24 17:10:05 +00:00
|
|
|
|
id customClass = [cm customClassForName: key];
|
2003-10-08 05:00:21 +00:00
|
|
|
|
id object = [self objectForName: key];
|
2003-08-23 01:04:36 +00:00
|
|
|
|
NSString *superClass = [cm nonCustomSuperClassOf: customClass];
|
2003-10-28 05:25:14 +00:00
|
|
|
|
id template = [GSTemplateFactory templateForObject: object
|
|
|
|
|
withClassName: customClass // [customClass copy]
|
2003-10-08 05:00:21 +00:00
|
|
|
|
withSuperClassName: superClass];
|
|
|
|
|
|
|
|
|
|
// if the object is deferrable, then set the flag appropriately.
|
|
|
|
|
if([template respondsToSelector: @selector(setDeferFlag:)])
|
|
|
|
|
{
|
|
|
|
|
[template setDeferFlag: [self objectIsDeferred: object]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// replace the object with the template.
|
2003-08-23 01:04:36 +00:00
|
|
|
|
[archiver replaceObject: object withObject: template];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-20 03:57:37 +00:00
|
|
|
|
- (BOOL) saveGormDocument: (id)sender
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
1999-12-08 15:19:11 +00:00
|
|
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
1999-12-15 11:12:52 +00:00
|
|
|
|
BOOL archiveResult;
|
2001-05-08 09:43:11 +00:00
|
|
|
|
NSArchiver *archiver;
|
|
|
|
|
NSMutableData *archiverData;
|
2002-10-31 15:00:17 +00:00
|
|
|
|
NSString *gormPath;
|
|
|
|
|
NSString *classesPath;
|
|
|
|
|
NSFileManager *mgr = [NSFileManager defaultManager];
|
|
|
|
|
BOOL isDir;
|
|
|
|
|
BOOL fileExists;
|
1999-12-08 15:19:11 +00:00
|
|
|
|
|
2000-01-04 17:46:26 +00:00
|
|
|
|
if (documentPath == nil)
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
2003-05-20 03:57:37 +00:00
|
|
|
|
if (! [self saveAsDocument: sender] )
|
|
|
|
|
return NO;
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
1999-12-08 15:19:11 +00:00
|
|
|
|
|
|
|
|
|
[nc postNotificationName: IBWillSaveDocumentNotification
|
|
|
|
|
object: self];
|
|
|
|
|
|
2000-01-03 11:00:14 +00:00
|
|
|
|
[self beginArchiving];
|
1999-12-15 11:12:52 +00:00
|
|
|
|
|
2002-10-31 15:00:17 +00:00
|
|
|
|
// set up the necessary paths...
|
|
|
|
|
gormPath = [documentPath stringByAppendingPathComponent: @"objects.gorm"];
|
2002-11-18 06:15:06 +00:00
|
|
|
|
classesPath = [documentPath stringByAppendingPathComponent: @"data.classes"];
|
2001-05-08 09:43:11 +00:00
|
|
|
|
|
|
|
|
|
archiverData = [NSMutableData dataWithCapacity: 0];
|
|
|
|
|
archiver = [[NSArchiver alloc] initForWritingWithMutableData: archiverData];
|
2002-11-18 06:15:06 +00:00
|
|
|
|
|
|
|
|
|
/* Special gorm classes to their archive equivalents. */
|
|
|
|
|
[archiver encodeClassName: @"GormObjectProxy"
|
|
|
|
|
intoClassName: @"GSNibItem"];
|
2002-03-31 15:59:18 +00:00
|
|
|
|
[archiver encodeClassName: @"GormCustomView"
|
2002-11-18 06:15:06 +00:00
|
|
|
|
intoClassName: @"GSCustomView"];
|
2002-04-07 22:02:41 +00:00
|
|
|
|
[archiver encodeClassName: @"GormNSMenu"
|
2004-01-14 06:37:54 +00:00
|
|
|
|
intoClassName: @"NSMenu"];
|
2002-03-31 15:59:18 +00:00
|
|
|
|
[archiver encodeClassName: @"GormNSWindow"
|
2002-11-18 06:15:06 +00:00
|
|
|
|
intoClassName: @"NSWindow"];
|
2003-01-05 06:03:14 +00:00
|
|
|
|
[archiver encodeClassName: @"GormNSPanel"
|
|
|
|
|
intoClassName: @"NSPanel"];
|
2002-09-21 15:24:59 +00:00
|
|
|
|
[archiver encodeClassName: @"GormNSPopUpButton"
|
2002-11-18 06:15:06 +00:00
|
|
|
|
intoClassName: @"NSPopUpButton"];
|
2002-09-21 15:24:59 +00:00
|
|
|
|
[archiver encodeClassName: @"GormNSPopUpButtonCell"
|
2002-11-18 06:15:06 +00:00
|
|
|
|
intoClassName: @"NSPopUpButtonCell"];
|
2003-05-23 02:25:34 +00:00
|
|
|
|
[archiver encodeClassName: @"GormNSBrowser"
|
|
|
|
|
intoClassName: @"NSBrowser"];
|
|
|
|
|
[archiver encodeClassName: @"GormNSTableView"
|
|
|
|
|
intoClassName: @"NSTableView"];
|
|
|
|
|
[archiver encodeClassName: @"GormNSOutlineView"
|
|
|
|
|
intoClassName: @"NSOutlineView"];
|
2002-10-13 06:04:05 +00:00
|
|
|
|
|
2003-08-23 01:04:36 +00:00
|
|
|
|
[self _replaceObjectsWithTemplates: archiver];
|
2003-05-23 02:25:34 +00:00
|
|
|
|
|
2001-05-08 09:43:11 +00:00
|
|
|
|
[archiver encodeRootObject: self];
|
2003-08-28 04:32:41 +00:00
|
|
|
|
NSDebugLog(@"nameTable = %@",nameTable);
|
2003-08-24 17:10:05 +00:00
|
|
|
|
|
2003-08-28 04:32:41 +00:00
|
|
|
|
NSDebugLog(@"customClasses = %@", [classManager customClassMap]);
|
2003-08-24 17:10:05 +00:00
|
|
|
|
|
2002-10-31 15:00:17 +00:00
|
|
|
|
fileExists = [mgr fileExistsAtPath: documentPath isDirectory: &isDir];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (fileExists)
|
2002-10-31 15:00:17 +00:00
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (isDir == NO)
|
2002-10-31 15:00:17 +00:00
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
NSString *saveFilePath;
|
2002-10-31 15:00:17 +00:00
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
saveFilePath = [documentPath stringByAppendingPathExtension: @"save"];
|
2002-10-31 15:00:17 +00:00
|
|
|
|
// move the old file to something...
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (![mgr movePath: documentPath toPath: saveFilePath handler: nil])
|
2002-10-31 15:00:17 +00:00
|
|
|
|
{
|
2004-02-21 18:48:48 +00:00
|
|
|
|
NSDebugLog(@"Error moving old %@ file to %@",
|
2003-02-13 13:32:59 +00:00
|
|
|
|
documentPath, saveFilePath);
|
2002-10-31 15:00:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create the new directory..
|
2003-02-13 13:32:59 +00:00
|
|
|
|
archiveResult = [mgr createDirectoryAtPath: documentPath
|
|
|
|
|
attributes: nil];
|
2002-10-31 15:00:17 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// set to yes since the directory is already present.
|
|
|
|
|
archiveResult = YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// create the directory...
|
|
|
|
|
archiveResult = [mgr createDirectoryAtPath: documentPath attributes: nil];
|
|
|
|
|
}
|
2003-07-20 20:26:20 +00:00
|
|
|
|
|
|
|
|
|
RELEASE(archiver); // We're done with the archiver here..
|
2002-10-31 15:00:17 +00:00
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (archiveResult)
|
2002-10-31 15:00:17 +00:00
|
|
|
|
{
|
|
|
|
|
// save the data...
|
|
|
|
|
archiveResult = [archiverData writeToFile: gormPath atomically: YES];
|
|
|
|
|
if (archiveResult)
|
|
|
|
|
{
|
|
|
|
|
// save the custom classes.. and we're done...
|
|
|
|
|
archiveResult = [classManager saveToFile: classesPath];
|
2002-11-04 13:52:31 +00:00
|
|
|
|
|
|
|
|
|
// copy sounds into the new folder...
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (archiveResult)
|
2002-11-04 13:52:31 +00:00
|
|
|
|
{
|
|
|
|
|
NSEnumerator *en = [sounds objectEnumerator];
|
|
|
|
|
id object = nil;
|
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
while ((object = [en nextObject]) != nil)
|
2002-11-04 13:52:31 +00:00
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
NSString *soundPath;
|
2003-07-20 20:26:20 +00:00
|
|
|
|
BOOL copied = NO;
|
2003-02-13 13:32:59 +00:00
|
|
|
|
|
2003-07-20 22:00:34 +00:00
|
|
|
|
soundPath = [documentPath stringByAppendingPathComponent:
|
|
|
|
|
[object lastPathComponent]];
|
|
|
|
|
if(![object isEqualToString: soundPath])
|
2003-07-20 20:26:20 +00:00
|
|
|
|
{
|
|
|
|
|
copied = [mgr copyPath: object
|
|
|
|
|
toPath: soundPath
|
|
|
|
|
handler: nil];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// mark as copied if paths are equal...
|
|
|
|
|
copied = YES;
|
|
|
|
|
}
|
2002-11-04 13:52:31 +00:00
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (!copied)
|
2002-11-04 13:52:31 +00:00
|
|
|
|
{
|
2004-02-21 18:48:48 +00:00
|
|
|
|
NSDebugLog(@"Could not find sound at path %@", object);
|
2002-11-04 13:52:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-11-18 20:54:26 +00:00
|
|
|
|
|
|
|
|
|
en = [images objectEnumerator];
|
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
while ((object = [en nextObject]) != nil)
|
2002-11-18 20:54:26 +00:00
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
NSString *imagePath;
|
2003-07-20 20:26:20 +00:00
|
|
|
|
BOOL copied = NO;
|
2002-11-18 20:54:26 +00:00
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
imagePath = [documentPath stringByAppendingPathComponent:
|
|
|
|
|
[object lastPathComponent]];
|
2003-07-20 20:26:20 +00:00
|
|
|
|
|
|
|
|
|
if(![object isEqualToString: imagePath])
|
|
|
|
|
{
|
|
|
|
|
copied = [mgr copyPath: object
|
|
|
|
|
toPath: imagePath
|
|
|
|
|
handler: nil];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// mark it as copied if paths are equal.
|
|
|
|
|
copied = YES;
|
|
|
|
|
}
|
2003-02-13 13:32:59 +00:00
|
|
|
|
|
|
|
|
|
if (!copied)
|
2002-11-18 20:54:26 +00:00
|
|
|
|
{
|
2004-02-21 18:48:48 +00:00
|
|
|
|
NSDebugLog(@"Could not find image at path %@", object);
|
2002-11-18 20:54:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-04 13:52:31 +00:00
|
|
|
|
}
|
2002-10-31 15:00:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1999-12-15 11:12:52 +00:00
|
|
|
|
|
2003-07-15 04:20:09 +00:00
|
|
|
|
[self endArchiving];
|
1999-12-15 11:12:52 +00:00
|
|
|
|
|
|
|
|
|
if (archiveResult == NO)
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
2003-05-24 12:40:54 +00:00
|
|
|
|
NSRunAlertPanel(NULL,_( @"Could not save document"),
|
|
|
|
|
_(@"OK"), NULL, NULL);
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
2003-04-18 05:40:25 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
[window setDocumentEdited: NO];
|
|
|
|
|
[window setTitleWithRepresentedFilename: documentPath];
|
1999-12-15 11:12:52 +00:00
|
|
|
|
|
2003-04-18 05:40:25 +00:00
|
|
|
|
[nc postNotificationName: IBDidSaveDocumentNotification
|
|
|
|
|
object: self];
|
|
|
|
|
}
|
2003-05-20 03:57:37 +00:00
|
|
|
|
return YES;
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setDocumentActive: (BOOL)flag
|
|
|
|
|
{
|
2000-01-04 16:25:39 +00:00
|
|
|
|
if (flag != isActive)
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
2000-01-04 16:25:39 +00:00
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
|
id obj;
|
|
|
|
|
|
|
|
|
|
enumerator = [nameTable objectEnumerator];
|
|
|
|
|
if (flag == YES)
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
2000-01-04 16:25:39 +00:00
|
|
|
|
[(GormDocument*)[(id<IB>)NSApp activeDocument] setDocumentActive: NO];
|
|
|
|
|
isActive = YES;
|
|
|
|
|
while ((obj = [enumerator nextObject]) != nil)
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
2000-01-04 16:25:39 +00:00
|
|
|
|
if ([obj isKindOfClass: [NSWindow class]] == YES)
|
|
|
|
|
{
|
|
|
|
|
[obj orderFront: self];
|
|
|
|
|
}
|
|
|
|
|
else if ([obj isKindOfClass: [NSMenu class]] == YES)
|
|
|
|
|
{
|
|
|
|
|
[obj display];
|
|
|
|
|
}
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2000-01-04 16:25:39 +00:00
|
|
|
|
else
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
2000-01-04 16:25:39 +00:00
|
|
|
|
isActive = NO;
|
|
|
|
|
while ((obj = [enumerator nextObject]) != nil)
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
2000-01-04 16:25:39 +00:00
|
|
|
|
if ([obj isKindOfClass: [NSWindow class]] == YES)
|
|
|
|
|
{
|
|
|
|
|
[obj orderOut: self];
|
|
|
|
|
}
|
|
|
|
|
else if ([obj isKindOfClass: [NSMenu class]] == YES)
|
|
|
|
|
{
|
|
|
|
|
[obj close];
|
|
|
|
|
}
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-08 15:19:11 +00:00
|
|
|
|
- (void) setSelectionFromEditor: (id<IBEditors>)anEditor
|
|
|
|
|
{
|
1999-12-14 17:38:17 +00:00
|
|
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
2002-08-14 00:01:42 +00:00
|
|
|
|
NSDebugLog(@"setSelectionFromEditor %@", anEditor);
|
2003-05-10 21:19:25 +00:00
|
|
|
|
if ([(NSObject *)anEditor respondsToSelector: @selector(window)])
|
2002-08-20 04:46:07 +00:00
|
|
|
|
{
|
|
|
|
|
[[anEditor window] makeFirstResponder: anEditor];
|
|
|
|
|
}
|
1999-12-14 17:38:17 +00:00
|
|
|
|
[nc postNotificationName: IBSelectionChangedNotification
|
|
|
|
|
object: anEditor];
|
1999-12-08 15:19:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
- (void) touch
|
|
|
|
|
{
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[window setDocumentEdited: YES];
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-18 08:55:31 +00:00
|
|
|
|
- (NSWindow*) windowAndRect: (NSRect*)r forObject: (id)object
|
|
|
|
|
{
|
2000-01-13 21:19:03 +00:00
|
|
|
|
/*
|
|
|
|
|
* Get the window and rectangle for which link markup should be drawn.
|
|
|
|
|
*/
|
1999-12-18 08:55:31 +00:00
|
|
|
|
if ([objectsView containsObject: object] == YES)
|
|
|
|
|
{
|
2000-01-13 21:19:03 +00:00
|
|
|
|
/*
|
|
|
|
|
* objects that exist in the document objects view must have their link
|
|
|
|
|
* markup drawn there, so we ask the view for the required rectangle.
|
|
|
|
|
*/
|
|
|
|
|
*r = [objectsView rectForObject: object];
|
1999-12-18 08:55:31 +00:00
|
|
|
|
return [objectsView window];
|
|
|
|
|
}
|
2000-01-13 21:19:03 +00:00
|
|
|
|
else if ([object isKindOfClass: [NSMenuItem class]] == YES)
|
1999-12-18 08:55:31 +00:00
|
|
|
|
{
|
2000-01-13 21:19:03 +00:00
|
|
|
|
NSArray *links;
|
|
|
|
|
NSMenu *menu;
|
|
|
|
|
id editor;
|
1999-12-18 08:55:31 +00:00
|
|
|
|
|
2000-01-13 21:19:03 +00:00
|
|
|
|
/*
|
|
|
|
|
* Menu items must have their markup drawn in the window of the
|
|
|
|
|
* editor of the parent menu.
|
|
|
|
|
*/
|
|
|
|
|
links = [self connectorsForSource: object
|
|
|
|
|
ofClass: [NSNibConnector class]];
|
|
|
|
|
menu = [[links lastObject] destination];
|
|
|
|
|
editor = [self editorForObject: menu create: NO];
|
|
|
|
|
*r = [editor rectForObject: object];
|
|
|
|
|
return [editor window];
|
|
|
|
|
}
|
|
|
|
|
else if ([object isKindOfClass: [NSView class]] == YES)
|
|
|
|
|
{
|
|
|
|
|
/*
|
2002-08-14 00:01:42 +00:00
|
|
|
|
* Normal view objects just get link markup drawn on them.
|
2000-01-13 21:19:03 +00:00
|
|
|
|
*/
|
2002-08-14 00:01:42 +00:00
|
|
|
|
id temp = object;
|
|
|
|
|
id editor = [self editorForObject: temp create: NO];
|
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
while ((temp != nil) && (editor == nil))
|
2002-08-14 00:01:42 +00:00
|
|
|
|
{
|
|
|
|
|
temp = [temp superview];
|
|
|
|
|
editor = [self editorForObject: temp create: NO];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (temp == nil)
|
|
|
|
|
{
|
|
|
|
|
*r = [object convertRect: [object bounds] toView: nil];
|
|
|
|
|
}
|
|
|
|
|
else if ([editor respondsToSelector:
|
|
|
|
|
@selector(windowAndRect:forObject:)])
|
|
|
|
|
{
|
|
|
|
|
return [editor windowAndRect: r forObject: object];
|
|
|
|
|
}
|
1999-12-18 08:55:31 +00:00
|
|
|
|
}
|
2002-03-29 16:30:01 +00:00
|
|
|
|
else if ([object isKindOfClass: [NSTableColumn class]] == YES)
|
|
|
|
|
{
|
|
|
|
|
NSTableView *tv = [[(NSTableColumn*)object dataCell] controlView];
|
|
|
|
|
NSTableHeaderView *th = [tv headerView];
|
|
|
|
|
int index;
|
|
|
|
|
|
|
|
|
|
if (th == nil || tv == nil)
|
|
|
|
|
{
|
2004-02-21 18:48:48 +00:00
|
|
|
|
NSDebugLog(@"fail 1 %@ %@ %@", [(NSTableColumn*)object headerCell], th, tv);
|
2002-03-29 16:30:01 +00:00
|
|
|
|
*r = NSZeroRect;
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
index = [[tv tableColumns] indexOfObject: object];
|
|
|
|
|
|
|
|
|
|
if (index == NSNotFound)
|
|
|
|
|
{
|
2004-02-21 18:48:48 +00:00
|
|
|
|
NSDebugLog(@"fail 2");
|
2002-03-29 16:30:01 +00:00
|
|
|
|
*r = NSZeroRect;
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*r = [th convertRect: [th headerRectOfColumn: index]
|
|
|
|
|
toView: nil];
|
|
|
|
|
return [th window];
|
|
|
|
|
}
|
1999-12-18 08:55:31 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*r = NSZeroRect;
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
2002-08-14 00:01:42 +00:00
|
|
|
|
|
|
|
|
|
// never reached, keeps gcc happy
|
|
|
|
|
return nil;
|
1999-12-18 08:55:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-04 16:25:39 +00:00
|
|
|
|
- (NSWindow*) window
|
|
|
|
|
{
|
|
|
|
|
return window;
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-20 03:57:37 +00:00
|
|
|
|
- (BOOL) couldCloseDocument
|
1999-12-14 19:55:18 +00:00
|
|
|
|
{
|
|
|
|
|
if ([window isDocumentEdited] == YES)
|
|
|
|
|
{
|
|
|
|
|
NSString *msg;
|
|
|
|
|
int result;
|
|
|
|
|
|
2000-01-04 17:46:26 +00:00
|
|
|
|
if (documentPath == nil)
|
1999-12-14 19:55:18 +00:00
|
|
|
|
{
|
2003-05-24 12:40:54 +00:00
|
|
|
|
msg = _(@"Document 'UNTITLED' has been modified");
|
1999-12-14 19:55:18 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2003-05-24 12:40:54 +00:00
|
|
|
|
msg = [NSString stringWithFormat: _(@"Document '%@' has been modified"),
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[documentPath lastPathComponent]];
|
|
|
|
|
}
|
2003-05-24 12:40:54 +00:00
|
|
|
|
result = NSRunAlertPanel(NULL, msg, _(@"Save"), _(@"Don't Save"), _(@"Cancel"));
|
2003-05-20 03:57:37 +00:00
|
|
|
|
|
|
|
|
|
if (result == NSAlertDefaultReturn)
|
|
|
|
|
{
|
|
|
|
|
//Save
|
|
|
|
|
if (! [self saveGormDocument: self] )
|
|
|
|
|
return NO;
|
1999-12-14 19:55:18 +00:00
|
|
|
|
}
|
2003-05-20 03:57:37 +00:00
|
|
|
|
|
|
|
|
|
//Cancel
|
|
|
|
|
else if (result == NSAlertOtherReturn)
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-14 19:55:18 +00:00
|
|
|
|
return YES;
|
2003-05-20 03:57:37 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
- (BOOL) windowShouldClose: (id)sender
|
|
|
|
|
{
|
|
|
|
|
return [self couldCloseDocument];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-15 05:58:01 +00:00
|
|
|
|
// convenience methods for formatting outlets/actions
|
2004-01-05 03:36:24 +00:00
|
|
|
|
+ (NSString*) identifierString: (NSString*)str
|
2002-03-25 01:44:01 +00:00
|
|
|
|
{
|
2003-11-08 22:51:21 +00:00
|
|
|
|
NSCharacterSet *illegal = [[NSCharacterSet characterSetWithCharactersInString:
|
|
|
|
|
@"_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"]
|
|
|
|
|
invertedSet];
|
|
|
|
|
NSCharacterSet *numeric = [NSCharacterSet characterSetWithCharactersInString:
|
|
|
|
|
@"0123456789"];
|
2002-07-14 23:54:05 +00:00
|
|
|
|
NSRange r;
|
|
|
|
|
NSMutableString *m;
|
2003-11-08 22:51:21 +00:00
|
|
|
|
|
2002-07-14 23:54:05 +00:00
|
|
|
|
if (str == nil)
|
|
|
|
|
{
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
m = [str mutableCopy];
|
|
|
|
|
r = [str rangeOfCharacterFromSet: illegal];
|
|
|
|
|
while (r.length > 0)
|
|
|
|
|
{
|
|
|
|
|
[m deleteCharactersInRange: r];
|
|
|
|
|
r = [m rangeOfCharacterFromSet: illegal];
|
|
|
|
|
}
|
|
|
|
|
r = [str rangeOfCharacterFromSet: numeric];
|
|
|
|
|
while (r.length > 0 && r.location == 0)
|
|
|
|
|
{
|
|
|
|
|
[m deleteCharactersInRange: r];
|
|
|
|
|
r = [m rangeOfCharacterFromSet: numeric];
|
|
|
|
|
}
|
|
|
|
|
str = [m copy];
|
|
|
|
|
RELEASE(m);
|
|
|
|
|
AUTORELEASE(str);
|
|
|
|
|
|
|
|
|
|
return str;
|
2002-03-25 01:44:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-05 03:36:24 +00:00
|
|
|
|
+ (NSString *)formatAction: (NSString *)action
|
2002-07-13 19:12:15 +00:00
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
NSString *identifier;
|
|
|
|
|
|
2004-01-05 03:36:24 +00:00
|
|
|
|
identifier = [[self identifierString: action] stringByAppendingString: @":"];
|
2002-07-14 23:54:05 +00:00
|
|
|
|
return identifier;
|
2002-07-13 19:12:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-05 03:36:24 +00:00
|
|
|
|
+ (NSString *)formatOutlet: (NSString *)outlet
|
2002-07-13 19:12:15 +00:00
|
|
|
|
{
|
2004-01-05 03:36:24 +00:00
|
|
|
|
NSString *identifier = [self identifierString: outlet];
|
2002-07-14 23:54:05 +00:00
|
|
|
|
return identifier;
|
2002-07-13 19:12:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-11-23 23:33:17 +00:00
|
|
|
|
- (BOOL) removeConnectionsWithLabel: (NSString *)name
|
2002-11-23 04:45:04 +00:00
|
|
|
|
forClassNamed: (NSString *)className
|
|
|
|
|
isAction: (BOOL)action
|
|
|
|
|
{
|
|
|
|
|
NSEnumerator *en = [connections objectEnumerator];
|
|
|
|
|
id<IBConnectors> c = nil;
|
2002-11-23 23:33:17 +00:00
|
|
|
|
BOOL removed = YES;
|
2002-11-23 04:45:04 +00:00
|
|
|
|
|
|
|
|
|
// remove all.
|
2003-02-13 13:32:59 +00:00
|
|
|
|
while ((c = [en nextObject]) != nil)
|
2002-11-23 04:45:04 +00:00
|
|
|
|
{
|
|
|
|
|
id proxy = nil;
|
|
|
|
|
NSString *label = [c label];
|
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (action)
|
2002-11-23 04:45:04 +00:00
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (![label hasSuffix: @":"])
|
2002-11-23 04:45:04 +00:00
|
|
|
|
continue;
|
|
|
|
|
proxy = [c destination];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([label hasSuffix: @":"])
|
2002-11-23 04:45:04 +00:00
|
|
|
|
continue;
|
|
|
|
|
proxy = [c source];
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([label isEqualToString: name] &&
|
2002-11-23 04:45:04 +00:00
|
|
|
|
[[proxy className] isEqualToString: className])
|
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
NSString *title;
|
|
|
|
|
NSString *msg;
|
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
|
|
title = [NSString stringWithFormat:
|
|
|
|
|
@"Modifying %@",(action==YES?@"Action":@"Outlet")];
|
|
|
|
|
msg = [NSString stringWithFormat:
|
2003-05-24 12:40:54 +00:00
|
|
|
|
_(@"This will break all connections to '%@'. Continue?"), name];
|
|
|
|
|
retval = NSRunAlertPanel(title, msg,_(@"OK"),_(@"Cancel"), nil, nil);
|
2003-02-13 13:32:59 +00:00
|
|
|
|
|
|
|
|
|
if (retval == NSAlertDefaultReturn)
|
2002-11-23 23:33:17 +00:00
|
|
|
|
{
|
|
|
|
|
removed = YES;
|
|
|
|
|
[self removeConnector: c];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
removed = NO;
|
|
|
|
|
}
|
2002-11-23 04:45:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// done...
|
2003-02-13 13:32:59 +00:00
|
|
|
|
NSDebugLog(@"Removed references to %@ on %@", name, className);
|
2002-11-23 23:33:17 +00:00
|
|
|
|
return removed;
|
2002-11-23 04:45:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-11-30 00:49:55 +00:00
|
|
|
|
- (BOOL) removeConnectionsForClassNamed: (NSString *)className
|
|
|
|
|
{
|
|
|
|
|
NSEnumerator *en = [connections objectEnumerator];
|
|
|
|
|
id<IBConnectors> c = nil;
|
|
|
|
|
BOOL removed = YES;
|
|
|
|
|
int retval = -1;
|
2003-05-24 12:40:54 +00:00
|
|
|
|
NSString *title = [NSString stringWithFormat: _(@"Modifying Class")];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
NSString *msg;
|
|
|
|
|
|
2003-05-24 12:40:54 +00:00
|
|
|
|
msg = [NSString stringWithFormat: _(@"This will break all connections to "
|
|
|
|
|
@"actions/outlets to instances of class '%@'. Continue?"), className];
|
2002-11-30 00:49:55 +00:00
|
|
|
|
|
|
|
|
|
// ask the user if he/she wants to continue...
|
2003-05-24 12:40:54 +00:00
|
|
|
|
retval = NSRunAlertPanel(title, msg,_(@"OK"),_(@"Cancel"), nil, nil);
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (retval == NSAlertDefaultReturn)
|
2002-11-30 00:49:55 +00:00
|
|
|
|
{
|
|
|
|
|
removed = YES;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
removed = NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// remove all.
|
2003-02-13 13:32:59 +00:00
|
|
|
|
while ((c = [en nextObject]) != nil)
|
2002-11-30 00:49:55 +00:00
|
|
|
|
{
|
|
|
|
|
// check both...
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([[[c source] className] isEqualToString: className]
|
|
|
|
|
|| [[[c destination] className] isEqualToString: className])
|
2002-11-30 00:49:55 +00:00
|
|
|
|
{
|
|
|
|
|
[self removeConnector: c];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// done...
|
2003-02-13 13:32:59 +00:00
|
|
|
|
NSDebugLog(@"Removed references to actions/outlets for objects of %@",
|
|
|
|
|
className);
|
2002-11-30 00:49:55 +00:00
|
|
|
|
return removed;
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-05 05:23:08 +00:00
|
|
|
|
- (BOOL) renameConnectionsForClassNamed: (NSString *)className
|
|
|
|
|
toName: (NSString *)newName
|
|
|
|
|
{
|
|
|
|
|
NSEnumerator *en = [connections objectEnumerator];
|
|
|
|
|
id<IBConnectors> c = nil;
|
|
|
|
|
BOOL removed = YES;
|
|
|
|
|
int retval = -1;
|
2003-05-24 12:40:54 +00:00
|
|
|
|
NSString *title = [NSString stringWithFormat: _(@"Modifying Class")];
|
2002-12-05 05:23:08 +00:00
|
|
|
|
NSString *msg = [NSString stringWithFormat:
|
2003-05-24 12:40:54 +00:00
|
|
|
|
_(@"Change class name '%@' to '%@'. Continue?"),
|
2002-12-05 05:23:08 +00:00
|
|
|
|
className, newName];
|
|
|
|
|
|
|
|
|
|
// ask the user if he/she wants to continue...
|
2003-05-24 12:40:54 +00:00
|
|
|
|
retval = NSRunAlertPanel(title, msg,_(@"OK"),_(@"Cancel"), nil, nil);
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (retval == NSAlertDefaultReturn)
|
2002-12-05 05:23:08 +00:00
|
|
|
|
{
|
|
|
|
|
removed = YES;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
removed = NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// remove all.
|
2003-02-13 13:32:59 +00:00
|
|
|
|
while ((c = [en nextObject]) != nil)
|
2002-12-05 05:23:08 +00:00
|
|
|
|
{
|
|
|
|
|
id source = [c source];
|
|
|
|
|
id destination = [c destination];
|
|
|
|
|
|
|
|
|
|
// check both...
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([[[c source] className] isEqualToString: className])
|
2002-12-05 05:23:08 +00:00
|
|
|
|
{
|
|
|
|
|
[source setClassName: newName];
|
2002-12-15 18:17:53 +00:00
|
|
|
|
NSDebugLog(@"Found matching source");
|
2002-12-05 05:23:08 +00:00
|
|
|
|
}
|
2003-02-13 13:32:59 +00:00
|
|
|
|
else if ([[[c destination] className] isEqualToString: className])
|
2002-12-05 05:23:08 +00:00
|
|
|
|
{
|
|
|
|
|
[destination setClassName: newName];
|
2002-12-15 18:17:53 +00:00
|
|
|
|
NSDebugLog(@"Found matching destination");
|
2002-12-05 05:23:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get the object from the object editor so that we can change the name
|
|
|
|
|
// there too.
|
|
|
|
|
|
|
|
|
|
// done...
|
|
|
|
|
NSDebugLog(@"Changed references to actions/outlets for objects of %@", className);
|
|
|
|
|
return removed;
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-15 05:58:01 +00:00
|
|
|
|
// --- NSOutlineView dataSource ---
|
2002-07-22 15:24:37 +00:00
|
|
|
|
- (id) outlineView: (NSOutlineView *)anOutlineView
|
2002-07-15 05:58:01 +00:00
|
|
|
|
objectValueForTableColumn: (NSTableColumn *)aTableColumn
|
2002-07-22 15:24:37 +00:00
|
|
|
|
byItem: item
|
2002-07-15 05:58:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (anOutlineView == classesView)
|
|
|
|
|
{
|
|
|
|
|
id identifier = [aTableColumn identifier];
|
|
|
|
|
id className = item;
|
|
|
|
|
|
|
|
|
|
if ([identifier isEqualToString: @"classes"])
|
|
|
|
|
{
|
|
|
|
|
return className;
|
|
|
|
|
}
|
|
|
|
|
else if ([identifier isEqualToString: @"outlets"])
|
|
|
|
|
{
|
|
|
|
|
return [NSString stringWithFormat: @"%d",
|
|
|
|
|
[[classManager allOutletsForClassNamed: className] count]];
|
|
|
|
|
}
|
|
|
|
|
else if ([identifier isEqualToString: @"actions"])
|
|
|
|
|
{
|
|
|
|
|
return [NSString stringWithFormat: @"%d",
|
|
|
|
|
[[classManager allActionsForClassNamed: className] count]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return @"";
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-11 05:50:04 +00:00
|
|
|
|
- (void) outlineView: (NSOutlineView *)anOutlineView
|
|
|
|
|
setObjectValue: (id)anObject
|
|
|
|
|
forTableColumn: (NSTableColumn *)aTableColumn
|
|
|
|
|
byItem: (id)item
|
|
|
|
|
{
|
2002-10-13 06:04:05 +00:00
|
|
|
|
GormOutlineView *gov = (GormOutlineView *)anOutlineView;
|
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([item isKindOfClass: [GormOutletActionHolder class]])
|
2002-07-11 05:50:04 +00:00
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (![anObject isEqualToString: @""])
|
2002-07-11 05:50:04 +00:00
|
|
|
|
{
|
2002-07-13 19:12:15 +00:00
|
|
|
|
NSString *name = [item getName];
|
2003-08-23 05:49:26 +00:00
|
|
|
|
|
|
|
|
|
// retain the name and add the action/outlet...
|
|
|
|
|
RETAIN(name);
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([gov editType] == Actions)
|
2002-07-13 19:12:15 +00:00
|
|
|
|
{
|
2004-01-05 03:36:24 +00:00
|
|
|
|
NSString *formattedAction = [GormDocument formatAction: anObject];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (![classManager isAction: formattedAction
|
2002-10-13 06:04:05 +00:00
|
|
|
|
ofClass: [gov itemBeingEdited]])
|
2002-07-22 15:24:37 +00:00
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
BOOL removed;
|
|
|
|
|
|
|
|
|
|
removed = [self removeConnectionsWithLabel: name
|
|
|
|
|
forClassNamed: [gov itemBeingEdited] isAction: YES];
|
|
|
|
|
if (removed)
|
2002-11-23 04:45:04 +00:00
|
|
|
|
{
|
|
|
|
|
[classManager replaceAction: name
|
|
|
|
|
withAction: formattedAction
|
|
|
|
|
forClassNamed: [gov itemBeingEdited]];
|
|
|
|
|
[(GormOutletActionHolder *)item setName: formattedAction];
|
|
|
|
|
}
|
2002-07-22 15:24:37 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
NSString *message;
|
|
|
|
|
|
|
|
|
|
message = [NSString stringWithFormat:
|
2003-05-24 12:40:54 +00:00
|
|
|
|
_(@"The class %@ already has an action named %@"),
|
2003-02-13 13:32:59 +00:00
|
|
|
|
[gov itemBeingEdited], formattedAction];
|
|
|
|
|
|
2003-05-24 12:40:54 +00:00
|
|
|
|
NSRunAlertPanel(_(@"Problem Adding Action"),
|
2003-02-13 13:32:59 +00:00
|
|
|
|
message, nil, nil, nil);
|
2002-07-22 15:24:37 +00:00
|
|
|
|
|
|
|
|
|
}
|
2002-07-13 19:12:15 +00:00
|
|
|
|
}
|
2003-02-13 13:32:59 +00:00
|
|
|
|
else if ([gov editType] == Outlets)
|
2002-07-13 19:12:15 +00:00
|
|
|
|
{
|
2004-01-05 03:36:24 +00:00
|
|
|
|
NSString *formattedOutlet = [GormDocument formatOutlet: anObject];
|
2002-07-22 15:24:37 +00:00
|
|
|
|
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (![classManager isOutlet: formattedOutlet
|
|
|
|
|
ofClass: [gov itemBeingEdited]])
|
2002-07-22 15:24:37 +00:00
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
BOOL removed;
|
|
|
|
|
|
|
|
|
|
removed = [self removeConnectionsWithLabel: name
|
|
|
|
|
forClassNamed: [gov itemBeingEdited] isAction: NO];
|
|
|
|
|
if (removed)
|
2002-11-23 04:45:04 +00:00
|
|
|
|
{
|
|
|
|
|
[classManager replaceOutlet: name
|
|
|
|
|
withOutlet: formattedOutlet
|
|
|
|
|
forClassNamed: [gov itemBeingEdited]];
|
|
|
|
|
[(GormOutletActionHolder *)item setName: formattedOutlet];
|
|
|
|
|
}
|
2002-07-22 15:24:37 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
NSString *message;
|
|
|
|
|
|
|
|
|
|
message = [NSString stringWithFormat:
|
2003-05-24 12:40:54 +00:00
|
|
|
|
_(@"The class %@ already has an outlet named %@"),
|
2003-02-13 13:32:59 +00:00
|
|
|
|
[gov itemBeingEdited], formattedOutlet];
|
2003-05-24 12:40:54 +00:00
|
|
|
|
NSRunAlertPanel(_(@"Problem Adding Outlet"),
|
2003-02-13 13:32:59 +00:00
|
|
|
|
message, nil, nil, nil);
|
2002-07-22 15:24:37 +00:00
|
|
|
|
|
|
|
|
|
}
|
2002-07-13 19:12:15 +00:00
|
|
|
|
}
|
2002-07-11 05:50:04 +00:00
|
|
|
|
}
|
2002-07-12 05:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2003-05-20 03:57:37 +00:00
|
|
|
|
if ( ( ![anObject isEqualToString: @""] ) && ( ! [anObject isEqualToString:item] ) )
|
2002-07-13 19:12:15 +00:00
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
BOOL rename;
|
|
|
|
|
|
|
|
|
|
rename = [self renameConnectionsForClassNamed: item toName: anObject];
|
|
|
|
|
if (rename)
|
2002-11-30 00:49:55 +00:00
|
|
|
|
{
|
2002-12-06 06:10:11 +00:00
|
|
|
|
int row = 0;
|
2003-08-23 05:49:26 +00:00
|
|
|
|
|
|
|
|
|
RETAIN(item); // retain the new name
|
2002-11-30 00:49:55 +00:00
|
|
|
|
[classManager renameClassNamed: item newName: anObject];
|
|
|
|
|
[gov reloadData];
|
2002-12-06 06:10:11 +00:00
|
|
|
|
row = [gov rowForItem: anObject];
|
|
|
|
|
[gov scrollRowToVisible: row];
|
2002-11-30 00:49:55 +00:00
|
|
|
|
}
|
2002-07-13 19:12:15 +00:00
|
|
|
|
}
|
2002-07-11 05:50:04 +00:00
|
|
|
|
}
|
2002-12-06 06:10:11 +00:00
|
|
|
|
|
2002-10-13 06:04:05 +00:00
|
|
|
|
[gov setNeedsDisplay: YES];
|
2002-07-11 05:50:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-25 01:44:01 +00:00
|
|
|
|
- (int) outlineView: (NSOutlineView *)anOutlineView
|
|
|
|
|
numberOfChildrenOfItem: (id)item
|
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (item == nil)
|
2002-03-25 01:44:01 +00:00
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NSArray *subclasses = [classManager subClassesOf: item];
|
|
|
|
|
return [subclasses count];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) outlineView: (NSOutlineView *)anOutlineView
|
|
|
|
|
isItemExpandable: (id)item
|
|
|
|
|
{
|
|
|
|
|
NSArray *subclasses = nil;
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (item == nil)
|
2002-03-25 01:44:01 +00:00
|
|
|
|
return YES;
|
|
|
|
|
|
|
|
|
|
subclasses = [classManager subClassesOf: item];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([subclasses count] > 0)
|
2002-03-25 01:44:01 +00:00
|
|
|
|
return YES;
|
|
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) outlineView: (NSOutlineView *)anOutlineView
|
|
|
|
|
child: (int)index
|
|
|
|
|
ofItem: (id)item
|
2001-05-08 09:43:11 +00:00
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (item == nil && index == 0)
|
2002-03-25 01:44:01 +00:00
|
|
|
|
{
|
|
|
|
|
return @"NSObject";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NSArray *subclasses = [classManager subClassesOf: item];
|
|
|
|
|
return [subclasses objectAtIndex: index];
|
|
|
|
|
}
|
2001-05-08 09:43:11 +00:00
|
|
|
|
|
2002-03-25 01:44:01 +00:00
|
|
|
|
return nil;
|
2001-05-08 09:43:11 +00:00
|
|
|
|
}
|
2002-07-08 04:45:23 +00:00
|
|
|
|
|
2002-07-15 05:58:01 +00:00
|
|
|
|
// GormOutlineView data source methods...
|
2002-07-11 05:50:04 +00:00
|
|
|
|
- (NSArray *)outlineView: (NSOutlineView *)anOutlineView
|
2002-07-08 04:45:23 +00:00
|
|
|
|
actionsForItem: (id)item
|
|
|
|
|
{
|
|
|
|
|
NSArray *actions = [classManager allActionsForClassNamed: item];
|
|
|
|
|
return actions;
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-11 05:50:04 +00:00
|
|
|
|
- (NSArray *)outlineView: (NSOutlineView *)anOutlineView
|
2002-07-08 04:45:23 +00:00
|
|
|
|
outletsForItem: (id)item
|
|
|
|
|
{
|
|
|
|
|
NSArray *outlets = [classManager allOutletsForClassNamed: item];
|
|
|
|
|
return outlets;
|
|
|
|
|
}
|
2002-07-12 05:46:29 +00:00
|
|
|
|
|
2002-07-14 23:54:05 +00:00
|
|
|
|
- (NSString *)outlineView: (NSOutlineView *)anOutlineView
|
|
|
|
|
addNewActionForClass: (id)item
|
|
|
|
|
{
|
2002-10-13 06:04:05 +00:00
|
|
|
|
GormOutlineView *gov = (GormOutlineView *)anOutlineView;
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (![classManager isCustomClass: [gov itemBeingEdited]])
|
2002-07-14 23:54:05 +00:00
|
|
|
|
{
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
2003-06-07 05:21:16 +00:00
|
|
|
|
|
2002-07-14 23:54:05 +00:00
|
|
|
|
return [classManager addNewActionToClassNamed: item];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSString *)outlineView: (NSOutlineView *)anOutlineView
|
|
|
|
|
addNewOutletForClass: (id)item
|
2002-07-12 05:46:29 +00:00
|
|
|
|
{
|
2002-10-13 06:04:05 +00:00
|
|
|
|
GormOutlineView *gov = (GormOutlineView *)anOutlineView;
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (![classManager isCustomClass: [gov itemBeingEdited]])
|
2002-07-14 23:54:05 +00:00
|
|
|
|
{
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
2003-06-07 05:21:16 +00:00
|
|
|
|
|
|
|
|
|
if([item isEqualToString: @"FirstResponder"])
|
|
|
|
|
return nil;
|
|
|
|
|
|
2002-07-14 23:54:05 +00:00
|
|
|
|
return [classManager addNewOutletToClassNamed: item];
|
2002-07-12 05:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-14 23:54:05 +00:00
|
|
|
|
// Delegate methods
|
|
|
|
|
- (BOOL) outlineView: (NSOutlineView *)outlineView
|
|
|
|
|
shouldEditTableColumn: (NSTableColumn *)tableColumn
|
|
|
|
|
item: (id)item
|
2002-07-12 05:46:29 +00:00
|
|
|
|
{
|
2002-07-14 23:54:05 +00:00
|
|
|
|
BOOL result = NO;
|
2002-10-13 06:04:05 +00:00
|
|
|
|
GormOutlineView *gov = (GormOutlineView *)outlineView;
|
2002-07-14 23:54:05 +00:00
|
|
|
|
|
2002-12-15 18:17:53 +00:00
|
|
|
|
NSDebugLog(@"in the delegate %@", [tableColumn identifier]);
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (tableColumn == [gov outlineTableColumn])
|
2002-07-14 23:54:05 +00:00
|
|
|
|
{
|
2002-12-15 18:17:53 +00:00
|
|
|
|
NSDebugLog(@"outline table col");
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if (![item isKindOfClass: [GormOutletActionHolder class]])
|
2002-07-14 23:54:05 +00:00
|
|
|
|
{
|
|
|
|
|
result = [classManager isCustomClass: item];
|
2003-06-06 06:24:46 +00:00
|
|
|
|
[self editClass: item];
|
2002-07-14 23:54:05 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2002-10-13 06:04:05 +00:00
|
|
|
|
id itemBeingEdited = [gov itemBeingEdited];
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([classManager isCustomClass: itemBeingEdited])
|
2002-07-14 23:54:05 +00:00
|
|
|
|
{
|
2003-02-13 13:32:59 +00:00
|
|
|
|
if ([gov editType] == Actions)
|
2002-07-14 23:54:05 +00:00
|
|
|
|
{
|
|
|
|
|
result = [classManager isAction: [item getName]
|
|
|
|
|
ofClass: itemBeingEdited];
|
|
|
|
|
}
|
2003-02-13 13:32:59 +00:00
|
|
|
|
else if ([gov editType] == Outlets)
|
2002-07-14 23:54:05 +00:00
|
|
|
|
{
|
|
|
|
|
result = [classManager isOutlet: [item getName]
|
|
|
|
|
ofClass: itemBeingEdited];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
2002-07-12 05:46:29 +00:00
|
|
|
|
}
|
2002-07-14 23:54:05 +00:00
|
|
|
|
|
2003-06-06 06:24:46 +00:00
|
|
|
|
- (void) outlineViewSelectionDidChange: (NSNotification *)notification
|
|
|
|
|
{
|
|
|
|
|
id object = [notification object];
|
2003-06-07 19:52:12 +00:00
|
|
|
|
int row = [object selectedRow];
|
|
|
|
|
|
|
|
|
|
if(row != -1)
|
2003-06-06 06:24:46 +00:00
|
|
|
|
{
|
2003-06-07 19:52:12 +00:00
|
|
|
|
id item = [object itemAtRow: [object selectedRow]];
|
|
|
|
|
if (![item isKindOfClass: [GormOutletActionHolder class]])
|
|
|
|
|
{
|
|
|
|
|
[self editClass: item];
|
|
|
|
|
}
|
2003-06-06 06:24:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-14 00:01:42 +00:00
|
|
|
|
// for debuging purpose
|
|
|
|
|
- (void) printAllEditors
|
|
|
|
|
{
|
|
|
|
|
NSMutableSet *set = [NSMutableSet setWithCapacity: 16];
|
|
|
|
|
NSEnumerator *enumerator = [connections objectEnumerator];
|
|
|
|
|
id<IBConnectors> c;
|
|
|
|
|
|
|
|
|
|
while ((c = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
if ([GormObjectToEditor class] == [c class])
|
|
|
|
|
{
|
|
|
|
|
[set addObject: [c destination]];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSLog(@"all editors %@", set);
|
|
|
|
|
}
|
2002-11-04 13:52:31 +00:00
|
|
|
|
|
|
|
|
|
// sound support...
|
|
|
|
|
- (id) openSound: (id)sender
|
|
|
|
|
{
|
|
|
|
|
NSArray *fileTypes = [NSSound soundUnfilteredFileTypes];
|
2003-06-29 17:23:39 +00:00
|
|
|
|
NSArray *filenames;
|
|
|
|
|
NSString *filename;
|
2002-11-04 13:52:31 +00:00
|
|
|
|
NSOpenPanel *oPanel = [NSOpenPanel openPanel];
|
|
|
|
|
int result;
|
2003-06-29 17:23:39 +00:00
|
|
|
|
int i;
|
2002-11-04 13:52:31 +00:00
|
|
|
|
|
2003-06-29 17:23:39 +00:00
|
|
|
|
[oPanel setAllowsMultipleSelection: YES];
|
2002-11-04 13:52:31 +00:00
|
|
|
|
[oPanel setCanChooseFiles: YES];
|
|
|
|
|
[oPanel setCanChooseDirectories: NO];
|
|
|
|
|
result = [oPanel runModalForDirectory: nil
|
|
|
|
|
file: nil
|
|
|
|
|
types: fileTypes];
|
|
|
|
|
if (result == NSOKButton)
|
|
|
|
|
{
|
2003-06-29 17:23:39 +00:00
|
|
|
|
filenames = [oPanel filenames];
|
|
|
|
|
for (i=0; i<[filenames count]; i++)
|
|
|
|
|
{
|
|
|
|
|
filename = [filenames objectAtIndex:i];
|
|
|
|
|
NSDebugLog(@"Loading sound file: %@",filenames);
|
|
|
|
|
[soundsView addObject: [self _createSoundPlaceHolder: filename]];
|
|
|
|
|
[sounds addObject: filename];
|
|
|
|
|
}
|
2002-11-04 13:52:31 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
2002-11-05 05:42:45 +00:00
|
|
|
|
|
2003-06-29 17:23:39 +00:00
|
|
|
|
// image support...
|
2002-11-18 20:54:26 +00:00
|
|
|
|
- (id) openImage: (id)sender
|
|
|
|
|
{
|
|
|
|
|
NSArray *fileTypes = [NSImage imageFileTypes];
|
2003-06-29 17:23:39 +00:00
|
|
|
|
NSArray *filenames;
|
2002-11-18 20:54:26 +00:00
|
|
|
|
NSOpenPanel *oPanel = [NSOpenPanel openPanel];
|
2003-06-29 17:23:39 +00:00
|
|
|
|
NSString *filename;
|
2002-11-18 20:54:26 +00:00
|
|
|
|
int result;
|
2003-06-29 17:23:39 +00:00
|
|
|
|
int i;
|
2002-11-18 20:54:26 +00:00
|
|
|
|
|
2003-06-29 17:23:39 +00:00
|
|
|
|
[oPanel setAllowsMultipleSelection: YES];
|
2002-11-18 20:54:26 +00:00
|
|
|
|
[oPanel setCanChooseFiles: YES];
|
|
|
|
|
[oPanel setCanChooseDirectories: NO];
|
|
|
|
|
result = [oPanel runModalForDirectory: nil
|
|
|
|
|
file: nil
|
|
|
|
|
types: fileTypes];
|
|
|
|
|
if (result == NSOKButton)
|
|
|
|
|
{
|
2003-06-29 17:23:39 +00:00
|
|
|
|
filenames = [oPanel filenames];
|
|
|
|
|
for (i=0; i<[filenames count]; i++)
|
|
|
|
|
{
|
|
|
|
|
filename = [filenames objectAtIndex:i];
|
|
|
|
|
NSDebugLog(@"Loading image file: %@",filename);
|
|
|
|
|
[imagesView addObject: [self _createImagePlaceHolder: filename]];
|
|
|
|
|
[images addObject: filename];
|
|
|
|
|
}
|
2002-11-18 20:54:26 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) addImage: (NSString*) path
|
|
|
|
|
{
|
|
|
|
|
[images addObject: path];
|
|
|
|
|
}
|
2003-10-18 06:20:45 +00:00
|
|
|
|
|
|
|
|
|
- (NSString *) description
|
|
|
|
|
{
|
|
|
|
|
return [NSString stringWithFormat: @"<%s: %lx> = %@",
|
|
|
|
|
GSClassNameFromObject(self),
|
|
|
|
|
(unsigned long)self,
|
|
|
|
|
nameTable];
|
|
|
|
|
}
|
2003-12-24 02:50:34 +00:00
|
|
|
|
|
|
|
|
|
- (BOOL) isTopLevelObject: (id)obj
|
|
|
|
|
{
|
|
|
|
|
BOOL result = NO;
|
|
|
|
|
|
|
|
|
|
if ([obj isKindOfClass: [NSMenu class]] == YES)
|
|
|
|
|
{
|
|
|
|
|
if ([self objectForName: @"NSMenu"] == obj)
|
|
|
|
|
{
|
|
|
|
|
result = YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ([obj isKindOfClass: [NSWindow class]] == YES)
|
|
|
|
|
{
|
|
|
|
|
result = YES;
|
|
|
|
|
}
|
|
|
|
|
else if ([obj isKindOfClass: [GSNibItem class]] == YES &&
|
|
|
|
|
[obj isKindOfClass: [GormCustomView class]] == NO)
|
|
|
|
|
{
|
|
|
|
|
result = YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
1999-12-08 15:04:57 +00:00
|
|
|
|
@end
|
2003-01-01 17:50:17 +00:00
|
|
|
|
|
|
|
|
|
@implementation GormDocument (MenuValidation)
|
|
|
|
|
- (BOOL) isEditingObjects
|
|
|
|
|
{
|
|
|
|
|
return ([selectionBox contentView] == scrollView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) isEditingImages
|
|
|
|
|
{
|
|
|
|
|
return ([selectionBox contentView] == imagesScrollView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) isEditingSounds
|
|
|
|
|
{
|
|
|
|
|
return ([selectionBox contentView] == soundsScrollView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) isEditingClasses
|
|
|
|
|
{
|
|
|
|
|
return ([selectionBox contentView] == classesScrollView);
|
|
|
|
|
}
|
|
|
|
|
@end
|