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
|
|
|
|
|
*
|
|
|
|
|
* 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"
|
|
|
|
|
|
1999-12-08 15:19:11 +00:00
|
|
|
|
NSString *IBDidOpenDocumentNotification = @"IBDidOpenDocumentNotification";
|
|
|
|
|
NSString *IBWillSaveDocumentNotification = @"IBWillSaveDocumentNotification";
|
|
|
|
|
NSString *IBDidSaveDocumentNotification = @"IBDidSaveDocumentNotification";
|
|
|
|
|
NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
return @"GormNotApplicableInspector";
|
|
|
|
|
}
|
|
|
|
|
- (NSString*) sizeInspectorClassName
|
|
|
|
|
{
|
|
|
|
|
return @"GormNotApplicableInspector";
|
1999-12-21 11:38:49 +00:00
|
|
|
|
}
|
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;
|
|
|
|
|
}
|
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];
|
|
|
|
|
}
|
1999-12-14 17:38:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
- (void) addConnector: (id<IBConnectors>)aConnector
|
|
|
|
|
{
|
|
|
|
|
if ([connections indexOfObjectIdenticalTo: aConnector] == NSNotFound)
|
|
|
|
|
{
|
|
|
|
|
[connections addObject: aConnector];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSArray*) allConnectors
|
|
|
|
|
{
|
1999-12-14 17:38:17 +00:00
|
|
|
|
return [NSArray arrayWithArray: connections];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) attachObject: (id)anObject toParent: (id)aParent
|
|
|
|
|
{
|
|
|
|
|
NSArray *old;
|
|
|
|
|
|
2000-01-03 11:00:14 +00:00
|
|
|
|
RETAIN(anObject);
|
|
|
|
|
/*
|
|
|
|
|
* remove any old linkage
|
|
|
|
|
*/
|
|
|
|
|
if ([self containsObject: anObject] == YES)
|
|
|
|
|
{
|
|
|
|
|
[self detachObject: anObject];
|
|
|
|
|
}
|
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);
|
|
|
|
|
}
|
|
|
|
|
[self setName: nil forObject: anObject];
|
|
|
|
|
|
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 addObject: anObject];
|
1999-12-14 17:38:17 +00:00
|
|
|
|
[[self openEditorForObject: anObject] activate];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
2000-01-03 11:00:14 +00:00
|
|
|
|
RELEASE(anObject);
|
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];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Remove objects and connections that shouldn't be archived.
|
|
|
|
|
*/
|
|
|
|
|
[nameTable removeObjectForKey: @"NSOwner"];
|
|
|
|
|
[nameTable removeObjectForKey: @"NSFirst"];
|
|
|
|
|
if (fontManager != nil)
|
|
|
|
|
{
|
|
|
|
|
[nameTable removeObjectForKey: @"NSFont"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
NSData *obj = [NSArchiver archivedDataWithRootObject: anArray];
|
|
|
|
|
|
|
|
|
|
[aPasteboard declareTypes: [NSArray arrayWithObject: aType]
|
|
|
|
|
owner: self];
|
|
|
|
|
return [aPasteboard setData: obj forType: aType];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (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];
|
|
|
|
|
RELEASE(window);
|
1999-12-13 17:01:35 +00:00
|
|
|
|
RELEASE(filesOwner);
|
|
|
|
|
RELEASE(firstResponder);
|
|
|
|
|
RELEASE(fontManager);
|
1999-12-08 15:04:57 +00:00
|
|
|
|
NSFreeMapTable(objToName);
|
|
|
|
|
RELEASE(documentPath);
|
2000-01-03 11:00:14 +00:00
|
|
|
|
RELEASE(savedEditors);
|
1999-12-08 15:04:57 +00:00
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) detachObject: (id)anObject
|
|
|
|
|
{
|
|
|
|
|
NSString *name = [self nameForObject: anObject];
|
2000-01-03 11:00:14 +00:00
|
|
|
|
unsigned count;
|
1999-12-08 15:04:57 +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];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
NSMapRemove(objToName, (void*)anObject);
|
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];
|
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
[nameTable removeObjectForKey: name];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) detachObjects: (NSArray*)anArray
|
|
|
|
|
{
|
|
|
|
|
NSEnumerator *enumerator = [anArray objectEnumerator];
|
|
|
|
|
NSObject *obj;
|
|
|
|
|
|
|
|
|
|
while ((obj = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
[self detachObject: obj];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSString*) documentPath
|
|
|
|
|
{
|
|
|
|
|
return documentPath;
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-04 16:25:39 +00:00
|
|
|
|
- (void) editor: (id<IBEditors>)anEditor didCloseForObject: (id)anObject
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
[connections removeObjectIdenticalTo: [links objectAtIndex: 0]];
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Make sure that this editor is not the selection owner.
|
|
|
|
|
*/
|
|
|
|
|
if ([(id<IB>)NSApp selectionOwner] == anEditor)
|
|
|
|
|
{
|
|
|
|
|
[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);
|
|
|
|
|
if (anEditor != nil)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* This editor has a parent - so link to it.
|
|
|
|
|
*/
|
|
|
|
|
link = [GormEditorToParent new];
|
|
|
|
|
[link setSource: editor];
|
|
|
|
|
[link setDestination: anEditor];
|
|
|
|
|
[connections addObject: link];
|
|
|
|
|
RELEASE(link);
|
|
|
|
|
}
|
|
|
|
|
RELEASE(editor);
|
|
|
|
|
return editor;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
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"];
|
|
|
|
|
[nameTable setObject: firstResponder forKey: @"NSFirst"];
|
|
|
|
|
if (fontManager != nil)
|
|
|
|
|
{
|
|
|
|
|
[nameTable setObject: fontManager forKey: @"NSFont"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 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)
|
|
|
|
|
{
|
|
|
|
|
[[con destination] activate];
|
|
|
|
|
}
|
|
|
|
|
[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;
|
2000-01-04 16:25:39 +00:00
|
|
|
|
id<IBConnectors> con;
|
1999-12-14 19:55:18 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
[self setDocumentActive: NO];
|
|
|
|
|
|
1999-12-14 19:55:18 +00:00
|
|
|
|
/*
|
2000-01-04 16:25:39 +00:00
|
|
|
|
* Destroy all windows in this document before we go away.
|
1999-12-14 19:55:18 +00:00
|
|
|
|
*/
|
|
|
|
|
enumerator = [nameTable objectEnumerator];
|
|
|
|
|
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)
|
1999-12-14 19:55:18 +00:00
|
|
|
|
{
|
|
|
|
|
[obj setReleasedWhenClosed: YES];
|
|
|
|
|
[obj close];
|
|
|
|
|
}
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
2000-01-04 16:25:39 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Close all editors.
|
|
|
|
|
*/
|
|
|
|
|
enumerator = [[NSArray arrayWithArray: connections] objectEnumerator];
|
|
|
|
|
while ((con = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
if ([con isKindOfClass: [GormObjectToEditor class]] == YES)
|
|
|
|
|
{
|
|
|
|
|
[[con destination] close];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Remove objects from document.
|
|
|
|
|
*/
|
|
|
|
|
[connections removeAllObjects];
|
|
|
|
|
[nameTable removeAllObjects];
|
|
|
|
|
NSResetMapTable(objToName);
|
|
|
|
|
DESTROY(documentPath);
|
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
hiddenDuringTest = YES;
|
|
|
|
|
[window setExcludedFromWindowsMenu: YES];
|
|
|
|
|
[window orderOut: self];
|
|
|
|
|
/*
|
|
|
|
|
* If this is the active document, we must replace the main menu with
|
|
|
|
|
* our own version using a modified 'Quit' item (to end testing).
|
|
|
|
|
* and we should try to make one of our windows key.
|
|
|
|
|
*/
|
|
|
|
|
if ([(id<IB>)NSApp activeDocument] == self)
|
|
|
|
|
{
|
|
|
|
|
NSWindow *keyWindow = nil;
|
|
|
|
|
NSMenu *testMenu = nil;
|
|
|
|
|
NSMenuItem *item;
|
|
|
|
|
NSArray *links;
|
|
|
|
|
NSEnumerator *e;
|
|
|
|
|
NSNibConnector *con;
|
|
|
|
|
|
1999-12-20 14:20:06 +00:00
|
|
|
|
[connections makeObjectsPerform: @selector(establishConnection)];
|
1999-12-15 15:29:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* Get links for all the top-level objects
|
|
|
|
|
*/
|
|
|
|
|
links = [self connectorsForDestination: filesOwner
|
|
|
|
|
ofClass: [NSNibConnector class]];
|
|
|
|
|
e = [links objectEnumerator];
|
|
|
|
|
while ((con = [e nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
id obj = [con source];
|
|
|
|
|
|
|
|
|
|
if ([obj isKindOfClass: [NSMenu class]] == YES)
|
|
|
|
|
{
|
|
|
|
|
testMenu = obj;
|
|
|
|
|
}
|
|
|
|
|
else if ([obj isKindOfClass: [NSWindow class]] == YES)
|
|
|
|
|
{
|
|
|
|
|
if (keyWindow == nil || [keyWindow isVisible] == NO)
|
|
|
|
|
{
|
|
|
|
|
keyWindow = obj;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (testMenu == nil)
|
|
|
|
|
{
|
|
|
|
|
testMenu = [[NSMenu alloc] initWithTitle: @"Test"];
|
|
|
|
|
AUTORELEASE(testMenu);
|
|
|
|
|
}
|
|
|
|
|
item = [testMenu itemWithTitle: @"Quit"];
|
|
|
|
|
if (item != nil)
|
|
|
|
|
{
|
|
|
|
|
quitItem = RETAIN(item);
|
|
|
|
|
[testMenu removeItem: item];
|
|
|
|
|
}
|
|
|
|
|
[testMenu addItemWithTitle: @"Quit"
|
|
|
|
|
action: @selector(endTesting:)
|
|
|
|
|
keyEquivalent: @"q"];
|
1999-12-16 18:06:22 +00:00
|
|
|
|
savedMenu = RETAIN([NSApp mainMenu]);
|
1999-12-15 15:29:27 +00:00
|
|
|
|
[NSApp setMainMenu: testMenu];
|
|
|
|
|
[keyWindow makeKeyAndOrderFront: self];
|
|
|
|
|
RELEASE(testMenu);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ([name isEqual: IBWillEndTestingInterfaceNotification] == YES)
|
|
|
|
|
{
|
|
|
|
|
if (hiddenDuringTest == YES)
|
|
|
|
|
{
|
|
|
|
|
hiddenDuringTest = NO;
|
|
|
|
|
/*
|
|
|
|
|
* If this is the active document, we must restore the main menu
|
|
|
|
|
* and restore the 'Quit' menu item (which was used to end testing)
|
|
|
|
|
* to its original value.
|
|
|
|
|
*/
|
|
|
|
|
if ([(id<IB>)NSApp activeDocument] == self)
|
|
|
|
|
{
|
|
|
|
|
NSMenu *testMenu = [NSApp mainMenu];
|
|
|
|
|
NSMenuItem *item = [testMenu itemWithTitle: @"Quit"];
|
|
|
|
|
|
|
|
|
|
[testMenu removeItem: item];
|
|
|
|
|
if (quitItem != nil)
|
|
|
|
|
{
|
|
|
|
|
[testMenu addItem: quitItem];
|
|
|
|
|
DESTROY(quitItem);
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* restore the main menu.
|
|
|
|
|
*/
|
1999-12-16 18:06:22 +00:00
|
|
|
|
[NSApp setMainMenu: savedMenu];
|
|
|
|
|
DESTROY(savedMenu);
|
1999-12-15 15:29:27 +00:00
|
|
|
|
}
|
|
|
|
|
[window orderFront: self];
|
|
|
|
|
[window setExcludedFromWindowsMenu: NO];
|
|
|
|
|
}
|
|
|
|
|
}
|
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];
|
|
|
|
|
NSRect winrect = NSMakeRect(100,100,340,252);
|
|
|
|
|
NSRect selectionRect = {{0, 188}, {240, 64}};
|
|
|
|
|
NSRect scrollRect = {{0, 0}, {340, 188}};
|
|
|
|
|
NSRect mainRect = {{20, 0}, {320, 188}};
|
|
|
|
|
NSImage *image;
|
|
|
|
|
NSButtonCell *cell;
|
|
|
|
|
unsigned style;
|
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
objToName = NSCreateMapTableWithZone(NSNonRetainedObjectMapKeyCallBacks,
|
|
|
|
|
NSNonRetainedObjectMapValueCallBacks, 128, [self zone]);
|
1999-12-13 17:01:35 +00:00
|
|
|
|
|
2000-01-03 11:00:14 +00:00
|
|
|
|
savedEditors = [NSMutableArray new];
|
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];
|
|
|
|
|
[window setTitle: @"UNTITLED"];
|
|
|
|
|
|
|
|
|
|
[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];
|
1999-12-14 19:55:18 +00:00
|
|
|
|
|
|
|
|
|
selectionView = [[NSMatrix alloc] initWithFrame: selectionRect
|
|
|
|
|
mode: NSRadioModeMatrix
|
|
|
|
|
cellClass: [NSButtonCell class]
|
|
|
|
|
numberOfRows: 1
|
|
|
|
|
numberOfColumns: 4];
|
|
|
|
|
[selectionView setTarget: self];
|
|
|
|
|
[selectionView setAction: @selector(changeView:)];
|
|
|
|
|
[selectionView setAutosizesCells: NO];
|
|
|
|
|
[selectionView setCellSize: NSMakeSize(64,64)];
|
|
|
|
|
[selectionView setIntercellSpacing: NSMakeSize(28,0)];
|
|
|
|
|
[selectionView setAutoresizingMask: NSViewMinYMargin|NSViewWidthSizable];
|
|
|
|
|
|
|
|
|
|
if ((image = objectsImage) != nil)
|
|
|
|
|
{
|
|
|
|
|
cell = [selectionView cellAtRow: 0 column: 0];
|
|
|
|
|
[cell setImage: image];
|
|
|
|
|
[cell setTitle: @"Objects"];
|
|
|
|
|
[cell setBordered: NO];
|
|
|
|
|
[cell setAlignment: NSCenterTextAlignment];
|
|
|
|
|
[cell setImagePosition: NSImageAbove];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((image = imagesImage) != nil)
|
|
|
|
|
{
|
|
|
|
|
cell = [selectionView cellAtRow: 0 column: 1];
|
|
|
|
|
[cell setImage: image];
|
|
|
|
|
[cell setTitle: @"Images"];
|
|
|
|
|
[cell setBordered: NO];
|
|
|
|
|
[cell setAlignment: NSCenterTextAlignment];
|
|
|
|
|
[cell setImagePosition: NSImageAbove];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((image = soundsImage) != nil)
|
|
|
|
|
{
|
|
|
|
|
cell = [selectionView cellAtRow: 0 column: 2];
|
|
|
|
|
[cell setImage: image];
|
|
|
|
|
[cell setTitle: @"Sounds"];
|
|
|
|
|
[cell setBordered: NO];
|
|
|
|
|
[cell setAlignment: NSCenterTextAlignment];
|
|
|
|
|
[cell setImagePosition: NSImageAbove];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((image = classesImage) != nil)
|
|
|
|
|
{
|
|
|
|
|
cell = [selectionView cellAtRow: 0 column: 3];
|
|
|
|
|
[cell setImage: image];
|
|
|
|
|
[cell setTitle: @"Classes"];
|
|
|
|
|
[cell setBordered: NO];
|
|
|
|
|
[cell setAlignment: NSCenterTextAlignment];
|
|
|
|
|
[cell setImagePosition: NSImageAbove];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[window contentView] addSubview: selectionView];
|
|
|
|
|
RELEASE(selectionView);
|
|
|
|
|
|
|
|
|
|
scrollView = [[NSScrollView alloc] initWithFrame: scrollRect];
|
|
|
|
|
[scrollView setHasVerticalScroller: YES];
|
|
|
|
|
[scrollView setHasHorizontalScroller: NO];
|
|
|
|
|
[scrollView setAutoresizingMask: NSViewHeightSizable|NSViewWidthSizable];
|
|
|
|
|
[[window contentView] addSubview: scrollView];
|
|
|
|
|
RELEASE(scrollView);
|
|
|
|
|
|
|
|
|
|
mainRect.origin = NSMakePoint(0,0);
|
|
|
|
|
objectsView = [[GormObjectEditor alloc] initWithObject: nil
|
|
|
|
|
inDocument: self];
|
|
|
|
|
[objectsView setFrame: mainRect];
|
|
|
|
|
[objectsView setAutoresizingMask: NSViewHeightSizable|NSViewWidthSizable];
|
|
|
|
|
[scrollView setDocumentView: objectsView];
|
|
|
|
|
RELEASE(objectsView);
|
|
|
|
|
|
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];
|
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];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
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];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 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;
|
|
|
|
|
|
2000-01-04 12:37:00 +00:00
|
|
|
|
if ([[NSUserDefaults standardUserDefaults] boolForKey: @"OpenNibs"] == YES)
|
|
|
|
|
{
|
|
|
|
|
fileTypes = [NSArray arrayWithObjects: @"gorm", @"nib", nil];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fileTypes = [NSArray arrayWithObjects: @"gorm", nil];
|
|
|
|
|
}
|
1999-12-08 15:04:57 +00:00
|
|
|
|
[oPanel setAllowsMultipleSelection: NO];
|
|
|
|
|
[oPanel setCanChooseFiles: YES];
|
|
|
|
|
[oPanel setCanChooseDirectories: NO];
|
|
|
|
|
result = [oPanel runModalForDirectory: NSHomeDirectory()
|
|
|
|
|
file: nil
|
|
|
|
|
types: fileTypes];
|
|
|
|
|
if (result == NSOKButton)
|
|
|
|
|
{
|
1999-12-08 15:19:11 +00:00
|
|
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
1999-12-13 17:01:35 +00:00
|
|
|
|
NSMutableDictionary *nt;
|
1999-12-08 15:04:57 +00:00
|
|
|
|
NSString *aFile = [oPanel filename];
|
|
|
|
|
NSData *data;
|
|
|
|
|
NSUnarchiver *u;
|
|
|
|
|
GSNibContainer *c;
|
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
|
id <IBConnectors> con;
|
|
|
|
|
NSString *name;
|
|
|
|
|
|
|
|
|
|
data = [NSData dataWithContentsOfFile: aFile];
|
|
|
|
|
if (data == nil)
|
|
|
|
|
{
|
|
|
|
|
NSRunAlertPanel(NULL,
|
|
|
|
|
[NSString stringWithFormat: @"Could not read '%@' data", aFile],
|
|
|
|
|
@"OK", NULL, NULL);
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
1999-12-13 17:01:35 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
1999-12-08 15:04:57 +00:00
|
|
|
|
u = AUTORELEASE([[NSUnarchiver alloc] initForReadingWithData: data]);
|
1999-12-13 17:01:35 +00:00
|
|
|
|
[u decodeClassName: @"GSNibContainer"
|
|
|
|
|
asClassName: @"GormDocument"];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
c = [u decodeObject];
|
|
|
|
|
if (c == nil || [c isKindOfClass: [GSNibContainer class]] == NO)
|
|
|
|
|
{
|
|
|
|
|
NSRunAlertPanel(NULL, @"Could not unarchive document data",
|
|
|
|
|
@"OK", NULL, NULL);
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 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'.
|
|
|
|
|
*/
|
1999-12-13 17:01:35 +00:00
|
|
|
|
[[c nameTable] setObject: filesOwner forKey: @"NSOwner"];
|
|
|
|
|
[[c nameTable] setObject: firstResponder forKey: @"NSFirst"];
|
1999-12-08 15:04:57 +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];
|
|
|
|
|
}
|
1999-12-13 17:01:35 +00:00
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
/*
|
1999-12-13 17:01:35 +00:00
|
|
|
|
* Now we merge the objects from the nib container into our own data
|
|
|
|
|
* structures, taking care not to overwrite our NSOwner and NSFirst.
|
1999-12-08 15:04:57 +00:00
|
|
|
|
*/
|
1999-12-13 17:01:35 +00:00
|
|
|
|
[nt removeObjectForKey: @"NSOwner"];
|
|
|
|
|
[nt removeObjectForKey: @"NSFirst"];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
[connections addObjectsFromArray: [c connections]];
|
1999-12-13 17:01:35 +00:00
|
|
|
|
[nameTable addEntriesFromDictionary: nt];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Now we build our reverse mapping information and other initialisation
|
|
|
|
|
*/
|
|
|
|
|
NSResetMapTable(objToName);
|
1999-12-13 17:01:35 +00:00
|
|
|
|
NSMapInsert(objToName, (void*)filesOwner, (void*)@"NSOwner");
|
|
|
|
|
NSMapInsert(objToName, (void*)firstResponder, (void*)@"NSFirst");
|
1999-12-08 15:04:57 +00:00
|
|
|
|
enumerator = [nameTable keyEnumerator];
|
|
|
|
|
while ((name = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
id obj = [nameTable objectForKey: name];
|
|
|
|
|
|
|
|
|
|
NSMapInsert(objToName, (void*)obj, (void*)name);
|
|
|
|
|
|
1999-12-13 17:01:35 +00:00
|
|
|
|
if ([obj isKindOfClass: [NSWindow class]] == YES
|
|
|
|
|
|| [obj isKindOfClass: [NSMenu class]] == YES)
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[objectsView addObject: obj];
|
1999-12-14 17:38:17 +00:00
|
|
|
|
[[self openEditorForObject: obj] activate];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Finally, we set our new file name
|
|
|
|
|
*/
|
|
|
|
|
ASSIGN(documentPath, aFile);
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[window setTitleWithRepresentedFilename: documentPath];
|
1999-12-08 15:19:11 +00:00
|
|
|
|
[nc postNotificationName: IBDidOpenDocumentNotification
|
|
|
|
|
object: self];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
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];
|
|
|
|
|
id<IBEditors> p = [self parentEditorForEditor: e];
|
|
|
|
|
|
|
|
|
|
if (p != nil)
|
|
|
|
|
{
|
|
|
|
|
[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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id<IBEditors>) parentEditorForEditor: (id<IBEditors>)anEditor
|
|
|
|
|
{
|
1999-12-14 17:38:17 +00:00
|
|
|
|
NSArray *links;
|
|
|
|
|
GormObjectToEditor *con;
|
|
|
|
|
|
|
|
|
|
links = [self connectorsForSource: anEditor
|
|
|
|
|
ofClass: [GormObjectToEditor class]];
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
NSData *data = [aPasteboard dataForType: aType];
|
|
|
|
|
NSArray *objects = [NSUnarchiver unarchiveObjectWithData: data];
|
|
|
|
|
NSEnumerator *enumerator = [objects objectEnumerator];
|
|
|
|
|
NSPoint filePoint;
|
|
|
|
|
NSPoint screenPoint;
|
|
|
|
|
|
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
|
|
|
|
/*
|
|
|
|
|
* Windows and panels are a special case - they need to be set to be
|
|
|
|
|
* visible at launch time (by default), and for a multiple window paste,
|
|
|
|
|
* 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)
|
|
|
|
|
{
|
2000-01-04 12:21:17 +00:00
|
|
|
|
[self setObject: win isVisibleAtLaunch: YES];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
[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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[self attachObjects: objects toParent: parent];
|
|
|
|
|
[self touch];
|
|
|
|
|
return objects;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) removeConnector: (id<IBConnectors>)aConnector
|
|
|
|
|
{
|
|
|
|
|
[connections removeObjectIdenticalTo: aConnector];
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
- (void) setName: (NSString*)aName forObject: (id)object
|
|
|
|
|
{
|
|
|
|
|
id oldObject;
|
|
|
|
|
NSString *oldName;
|
|
|
|
|
|
|
|
|
|
if (object == nil)
|
|
|
|
|
{
|
|
|
|
|
NSLog(@"Attempt to set name for nil object");
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
base = NSStringFromClass([object class]);
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
NSLog(@"Attempt to re-use name '%@'", aName);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
oldName = [self nameForObject: object];
|
|
|
|
|
if (oldName != nil)
|
|
|
|
|
{
|
|
|
|
|
if ([oldName isEqual: aName] == YES)
|
|
|
|
|
{
|
|
|
|
|
return; /* Already have this namre ... nothing to do */
|
|
|
|
|
}
|
|
|
|
|
NSMapRemove(objToName, (void*)object);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[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];
|
|
|
|
|
}
|
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"];
|
|
|
|
|
RELEASE(a);
|
|
|
|
|
}
|
|
|
|
|
if ([a containsObject: anObject] == NO)
|
|
|
|
|
{
|
|
|
|
|
[a addObject: anObject];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
[a removeObject: anObject];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
- (id) saveAsDocument: (id)sender
|
|
|
|
|
{
|
2000-01-04 12:21:17 +00:00
|
|
|
|
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
|
|
|
|
|
NSSavePanel *sp;
|
|
|
|
|
int result;
|
1999-12-08 15:04:57 +00:00
|
|
|
|
|
|
|
|
|
sp = [NSSavePanel savePanel];
|
|
|
|
|
|
2000-01-04 12:21:17 +00:00
|
|
|
|
if ([defs boolForKey: @"SaveAsNib"] == YES)
|
|
|
|
|
{
|
|
|
|
|
[sp setRequiredFileType: @"nib"];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
[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;
|
|
|
|
|
id retval;
|
|
|
|
|
|
|
|
|
|
if ([path isEqual: documentPath] == NO
|
|
|
|
|
&& [mgr fileExistsAtPath: path] == YES)
|
|
|
|
|
{
|
|
|
|
|
if (NSRunAlertPanel(NULL, @"A document with that name exists",
|
|
|
|
|
@"Replace", @"Cancel", NULL) != NSAlertDefaultReturn)
|
|
|
|
|
{
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NSString *bPath = [path stringByAppendingString: @"~"];
|
|
|
|
|
|
|
|
|
|
[mgr removeFileAtPath: bPath handler: nil];
|
|
|
|
|
[mgr movePath: path toPath: bPath handler: nil];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
documentPath = RETAIN(path);
|
|
|
|
|
retval = [self saveDocument: sender];
|
|
|
|
|
if (retval == nil)
|
|
|
|
|
{
|
|
|
|
|
RELEASE(documentPath);
|
|
|
|
|
documentPath = old;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
RELEASE(old);
|
|
|
|
|
/* FIXME - need to update files window title etc */
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) saveDocument: (id)sender
|
|
|
|
|
{
|
1999-12-08 15:19:11 +00:00
|
|
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
1999-12-15 11:12:52 +00:00
|
|
|
|
BOOL archiveResult;
|
1999-12-08 15:19:11 +00:00
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
|
if (documentPath == nil || [documentPath isEqualToString: @""])
|
|
|
|
|
{
|
|
|
|
|
return [self saveAsDocument: sender];
|
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
|
archiveResult = [NSArchiver archiveRootObject: self toFile: documentPath];
|
|
|
|
|
|
2000-01-03 11:00:14 +00:00
|
|
|
|
[self endArchiving];
|
1999-12-15 11:12:52 +00:00
|
|
|
|
|
|
|
|
|
if (archiveResult == NO)
|
1999-12-08 15:04:57 +00:00
|
|
|
|
{
|
|
|
|
|
NSRunAlertPanel(NULL, @"Could not save document",
|
|
|
|
|
@"OK", NULL, NULL);
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
1999-12-15 11:12:52 +00:00
|
|
|
|
|
1999-12-14 19:55:18 +00:00
|
|
|
|
[window setDocumentEdited: NO];
|
|
|
|
|
[window setTitleWithRepresentedFilename: documentPath];
|
1999-12-08 15:19:11 +00:00
|
|
|
|
|
1999-12-15 11:12:52 +00:00
|
|
|
|
[nc postNotificationName: IBDidSaveDocumentNotification
|
1999-12-08 15:19:11 +00:00
|
|
|
|
object: self];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (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];
|
|
|
|
|
|
|
|
|
|
[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
|
|
|
|
|
{
|
|
|
|
|
if ([objectsView containsObject: object] == YES)
|
|
|
|
|
{
|
|
|
|
|
NSRect rect = [objectsView rectForObject: object];
|
|
|
|
|
|
|
|
|
|
rect = [objectsView convertRect: rect toView: nil];
|
|
|
|
|
*r = rect;
|
|
|
|
|
return [objectsView window];
|
|
|
|
|
}
|
|
|
|
|
else if ([object isKindOfClass: [NSView class]] == YES)
|
|
|
|
|
{
|
|
|
|
|
NSRect rect = [object bounds];
|
|
|
|
|
|
|
|
|
|
rect = [object convertRect: rect toView: nil];
|
|
|
|
|
*r = rect;
|
|
|
|
|
return [object window];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*r = NSZeroRect;
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-04 16:25:39 +00:00
|
|
|
|
- (NSWindow*) window
|
|
|
|
|
{
|
|
|
|
|
return window;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) windowShouldClose: (id)sender
|
1999-12-14 19:55:18 +00:00
|
|
|
|
{
|
|
|
|
|
if ([window isDocumentEdited] == YES)
|
|
|
|
|
{
|
|
|
|
|
NSString *msg;
|
|
|
|
|
int result;
|
|
|
|
|
|
|
|
|
|
if (documentPath == nil || [documentPath isEqualToString: @""])
|
|
|
|
|
{
|
|
|
|
|
msg = @"Document 'UNTITLED' has been modified";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
msg = [NSString stringWithFormat: @"Document '%@' has been modified",
|
|
|
|
|
[documentPath lastPathComponent]];
|
|
|
|
|
}
|
|
|
|
|
result = NSRunAlertPanel(NULL, msg, @"Save", @"Cancel", @"Don't Save");
|
|
|
|
|
if (result == NSAlertAlternateReturn)
|
|
|
|
|
{
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
else if (result != NSAlertOtherReturn)
|
|
|
|
|
{
|
|
|
|
|
[self saveDocument: self];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return YES;
|
1999-12-08 15:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|