1999-12-21 08:13:35 +00:00
|
|
|
/* GormFilesOwner.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.
|
|
|
|
*/
|
|
|
|
|
2003-05-23 02:25:34 +00:00
|
|
|
#include <AppKit/NSNibConnector.h>
|
1999-12-21 08:13:35 +00:00
|
|
|
#include "GormPrivate.h"
|
|
|
|
|
2004-03-13 12:40:44 +00:00
|
|
|
@class GormCustomView;
|
|
|
|
|
1999-12-21 08:13:35 +00:00
|
|
|
@implementation GormFilesOwner
|
|
|
|
- (NSString*) className
|
|
|
|
{
|
|
|
|
return className;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
RELEASE(className);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSImage*) imageForViewer
|
|
|
|
{
|
|
|
|
static NSImage *image = nil;
|
|
|
|
|
|
|
|
if (image == nil)
|
|
|
|
{
|
|
|
|
NSBundle *bundle = [NSBundle mainBundle];
|
|
|
|
NSString *path = [bundle pathForImageResource: @"GormFilesOwner"];
|
|
|
|
|
|
|
|
image = [[NSImage alloc] initWithContentsOfFile: path];
|
|
|
|
}
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
[self setClassName: @"NSApplication"];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) inspectorClassName
|
|
|
|
{
|
|
|
|
return @"GormFilesOwnerInspector";
|
|
|
|
}
|
|
|
|
|
2002-11-24 05:52:50 +00:00
|
|
|
- (NSString*) classInspectorClassName
|
|
|
|
{
|
2004-03-05 03:55:09 +00:00
|
|
|
return @"GormFilesOwnerInspector";
|
2002-11-24 05:52:50 +00:00
|
|
|
}
|
|
|
|
|
1999-12-21 08:13:35 +00:00
|
|
|
- (void) setClassName: (NSString*)aName
|
|
|
|
{
|
|
|
|
ASSIGN(className, aName);
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GormFilesOwnerInspector
|
|
|
|
|
|
|
|
- (int) browser: (NSBrowser*)sender numberOfRowsInColumn: (int)column
|
|
|
|
{
|
|
|
|
return [classes count];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) browser: (NSBrowser*)sender titleOfColumn: (int)column
|
|
|
|
{
|
|
|
|
return @"Class";
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) browser: (NSBrowser*)sender
|
|
|
|
willDisplayCell: (id)aCell
|
|
|
|
atRow: (int)row
|
|
|
|
column: (int)col
|
|
|
|
{
|
|
|
|
if (row >= 0 && row < [classes count])
|
|
|
|
{
|
|
|
|
[aCell setStringValue: [classes objectAtIndex: row]];
|
|
|
|
[aCell setEnabled: YES];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[aCell setStringValue: @""];
|
|
|
|
[aCell setEnabled: NO];
|
|
|
|
}
|
|
|
|
[aCell setLeaf: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
RELEASE(classes);
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2003-06-30 02:15:00 +00:00
|
|
|
- (void) _classAdded: (NSNotification *)notification
|
|
|
|
{
|
|
|
|
[self setObject: object];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _classDeleted: (NSNotification *)notification
|
|
|
|
{
|
|
|
|
[self setObject: object];
|
|
|
|
}
|
|
|
|
|
1999-12-21 08:13:35 +00:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self != nil)
|
|
|
|
{
|
|
|
|
NSView *contents;
|
|
|
|
NSRect rect;
|
2004-03-05 03:55:09 +00:00
|
|
|
NSRect browserRect;
|
1999-12-21 08:13:35 +00:00
|
|
|
|
|
|
|
rect = NSMakeRect(0, 0, IVW, IVH);
|
|
|
|
window = [[NSWindow alloc] initWithContentRect: rect
|
|
|
|
styleMask: NSBorderlessWindowMask
|
|
|
|
backing: NSBackingStoreRetained
|
|
|
|
defer: NO];
|
|
|
|
contents = [window contentView];
|
|
|
|
|
2004-03-05 03:55:09 +00:00
|
|
|
browserRect = NSMakeRect(31,56,203,299);
|
|
|
|
browser = [[NSBrowser alloc] initWithFrame: browserRect];
|
1999-12-21 08:13:35 +00:00
|
|
|
[browser setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
|
|
|
|
[browser setMaxVisibleColumns: 1];
|
|
|
|
[browser setAllowsMultipleSelection: NO];
|
|
|
|
[browser setHasHorizontalScroller: NO];
|
|
|
|
[browser setDelegate: self];
|
1999-12-23 07:49:27 +00:00
|
|
|
[browser setTarget: self];
|
|
|
|
[browser setAction: @selector(takeClassFrom:)];
|
1999-12-21 08:13:35 +00:00
|
|
|
|
|
|
|
[contents addSubview: browser];
|
|
|
|
RELEASE(browser);
|
2003-06-30 02:15:00 +00:00
|
|
|
|
|
|
|
// add observers for relavent notifications.
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
addObserver: self
|
|
|
|
selector: @selector(_classAdded:)
|
|
|
|
name: GormDidAddClassNotification
|
|
|
|
object: [NSApp classManager]];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
addObserver: self
|
|
|
|
selector: @selector(_classDeleted:)
|
|
|
|
name: GormDidDeleteClassNotification
|
|
|
|
object: [NSApp classManager]];
|
1999-12-21 08:13:35 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setObject: (id)anObject
|
|
|
|
{
|
2004-03-13 12:40:44 +00:00
|
|
|
// filter the classes to view only when a custom view is selected.
|
|
|
|
if([anObject isKindOfClass: [GormCustomView class]])
|
|
|
|
{
|
|
|
|
ASSIGN(classes, [[NSApp classManager] allSubclassesOf: @"NSView"]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ASSIGN(classes, [[NSApp classManager] allClassNames]);
|
|
|
|
}
|
|
|
|
|
2003-06-30 02:15:00 +00:00
|
|
|
if (anObject != nil)
|
1999-12-21 08:13:35 +00:00
|
|
|
{
|
|
|
|
NSArray *array;
|
|
|
|
unsigned pos;
|
|
|
|
|
|
|
|
ASSIGN(object, anObject);
|
|
|
|
hasConnections = NO;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create list of existing connections for selected object.
|
|
|
|
*/
|
|
|
|
array = [[(id<IB>)NSApp activeDocument] connectorsForSource: object
|
2004-11-12 23:09:54 +00:00
|
|
|
ofClass: [NSNibOutletConnector class]];
|
1999-12-21 08:13:35 +00:00
|
|
|
if ([array count] > 0)
|
|
|
|
hasConnections = YES;
|
2004-11-12 23:09:54 +00:00
|
|
|
array = [[(id<IB>)NSApp activeDocument] connectorsForDestination: object
|
|
|
|
ofClass: [NSNibControlConnector class]];
|
1999-12-21 08:13:35 +00:00
|
|
|
if ([array count] > 0)
|
|
|
|
hasConnections = YES;
|
|
|
|
|
|
|
|
[browser loadColumnZero];
|
|
|
|
pos = [classes indexOfObject: [object className]];
|
|
|
|
if (pos != NSNotFound)
|
|
|
|
{
|
|
|
|
[browser selectRow: pos inColumn: 0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-23 07:49:27 +00:00
|
|
|
- (void) takeClassFrom: (id)sender
|
|
|
|
{
|
|
|
|
NSString *title = [[browser selectedCell] stringValue];
|
|
|
|
|
2004-03-04 04:01:09 +00:00
|
|
|
NSDebugLog(@"Selected %d, %@", [browser selectedRowInColumn: 0], title);
|
1999-12-23 07:49:27 +00:00
|
|
|
if (hasConnections > 0 && [title isEqual: [object className]] == NO)
|
|
|
|
{
|
2004-12-18 15:06:18 +00:00
|
|
|
if (NSRunAlertPanel(nil, _(@"This operation will break existing connection"),
|
|
|
|
_(@"OK"), _(@"Cancel"), nil) != NSAlertDefaultReturn)
|
1999-12-23 07:49:27 +00:00
|
|
|
{
|
|
|
|
unsigned pos = [classes indexOfObject: [object className]];
|
|
|
|
|
|
|
|
[browser selectRow: pos inColumn: 0];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSArray *array;
|
|
|
|
id doc = [(id<IB>)NSApp activeDocument];
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
array = [doc connectorsForSource: object
|
2004-11-12 23:09:54 +00:00
|
|
|
ofClass: [NSNibOutletConnector class]];
|
1999-12-23 07:49:27 +00:00
|
|
|
for (i = 0; i < [array count]; i++)
|
|
|
|
{
|
|
|
|
id<IBConnectors> con = [array objectAtIndex: i];
|
|
|
|
|
|
|
|
[doc removeConnector: con];
|
|
|
|
}
|
2004-11-12 23:09:54 +00:00
|
|
|
array = [doc connectorsForDestination: object
|
|
|
|
ofClass: [NSNibControlConnector class]];
|
1999-12-23 07:49:27 +00:00
|
|
|
for (i = 0; i < [array count]; i++)
|
|
|
|
{
|
|
|
|
id<IBConnectors> con = [array objectAtIndex: i];
|
|
|
|
|
|
|
|
[doc removeConnector: con];
|
|
|
|
}
|
|
|
|
hasConnections = NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[object setClassName: title];
|
|
|
|
}
|
|
|
|
|
1999-12-21 08:13:35 +00:00
|
|
|
@end
|
|
|
|
|