More connection improvements

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@5592 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1999-12-21 08:13:35 +00:00
parent 88ba65dc4e
commit e40f8fce22
12 changed files with 384 additions and 142 deletions

View file

@ -1,3 +1,8 @@
Tue Dec 21 8:10:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
Added inspector for files owner so we can create connections from
objects inside the nib to the files owner.
Mon Dec 20 14:16:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
Added connections inspector so connecting objects should work.

View file

@ -66,6 +66,7 @@ Gorm_OBJC_FILES = \
IBPalette.m \
InfoPanel.m \
GormViewKnobs.m \
GormFilesOwner.m \
GormObjectEditor.m \
GormWindowEditor.m \
GormClassManager.m \

46
Gorm.h
View file

@ -261,6 +261,11 @@ extern NSString *IBDidEndTestingInterfaceNotification;
- (NSString*) editorClassName;
@end
#define IVH 388 /* Standard height of inspector view. */
#define IVW 272 /* Standard width of inspector view. */
#define IVB 40 /* Standard height of buttons area. */
@interface IBInspector : NSObject
{
id object;
@ -268,13 +273,54 @@ extern NSString *IBDidEndTestingInterfaceNotification;
NSButton *okButton;
NSButton *revertButton;
}
/*
* The object being inspected.
*/
- (id) object;
/*
* Action to take when user clicks the OK button
*/
- (void) ok: (id)sender;
/*
* Inspector supplied button - the inspectors manager will position this
* button for you.
*/
- (NSButton*) okButton;
/*
* Action to take when user clicks the revert button
*/
- (void) revert: (id)sender;
/*
* Inspector supplied button - the inspectors manager will position this
* button for you.
*/
- (NSButton*) revertButton;
/*
* Extension - not in NeXTstep - this message is sent to your inspector to
* tell it to set its edited object and make any changes to its UI needed.
*/
- (void) setObject: (id)anObject;
/*
* Method to mark the inspector as needing saving (ok or revert).
*/
- (void) touch: (id)sender;
/*
* If this method returns YES, the manager will partition off a section of
* the inspector panel for display of 'ok' and 'revert' buttons, which
* your inspector must supply.
*/
- (BOOL) wantsButtons;
/*
* The window that the UI of the inspector exists in.
*/
- (NSWindow*) window;
@end

View file

@ -7,6 +7,7 @@
}
- (NSArray*) allActionsForClassNamed: (NSString*)className;
- (NSArray*) allActionsForObject: (NSObject*)anObject;
- (NSArray*) allClassNames;
- (NSArray*) allOutletsForClassNamed: (NSString*)className;
- (NSArray*) allOutletsForObject: (NSObject*)anObject;
@end

View file

@ -121,6 +121,12 @@
return nil;
}
- (NSArray*) allClassNames
{
return [[classInformation allKeys] sortedArrayUsingSelector:
@selector(compare:)];
}
- (NSArray*) allOutletsForObject: (NSObject*)obj
{
NSString *className;
@ -288,3 +294,4 @@
@end

View file

@ -1,18 +1,6 @@
#ifndef GORMDOCUMENT_H
#define GORMDOCUMENT_H
/*
* Each document has a GormFilesOwner object that is used as a placeholder
* for the owner of the document.
*/
@interface GormFilesOwner : NSObject
{
NSString *className;
}
- (NSString*) className;
- (void) setClassName: (NSString*)aName;
@end
/*
* Each document has a GormFirstResponder object that is used as a placeholder
* for the first responder at any instant.

View file

@ -29,45 +29,6 @@ NSString *IBWillSaveDocumentNotification = @"IBWillSaveDocumentNotification";
NSString *IBDidSaveDocumentNotification = @"IBDidSaveDocumentNotification";
NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
@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;
}
- (void) setClassName: (NSString*)aName
{
ASSIGN(className, aName);
}
@end
@implementation GormFirstResponder
- (NSImage*) imageForViewer
{

16
GormFilesOwner.h Normal file
View file

@ -0,0 +1,16 @@
#ifndef GORMFILESOWNER_H
#define GORMFILESOWNER_H
/*
* Each document has a GormFilesOwner object that is used as a placeholder
* for the owner of the document.
*/
@interface GormFilesOwner : NSObject
{
NSString *className;
}
- (NSString*) className;
- (void) setClassName: (NSString*)aName;
@end
#endif

225
GormFilesOwner.m Normal file
View file

@ -0,0 +1,225 @@
/* 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.
*/
#include "GormPrivate.h"
@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";
}
- (void) setClassName: (NSString*)aName
{
ASSIGN(className, aName);
}
@end
@interface GormFilesOwnerInspector : IBInspector
{
NSBrowser *browser;
NSArray *classes;
BOOL hasConnections;
}
@end
@implementation GormFilesOwnerInspector
- (int) browser: (NSBrowser*)sender numberOfRowsInColumn: (int)column
{
return [classes count];
}
- (NSString*) browser: (NSBrowser*)sender titleOfColumn: (int)column
{
return @"Class";
}
- (BOOL) browser: (NSBrowser*)sender
selectCellWithString: (NSString*)title
inColumn: (int)col
{
if (hasConnections > 0 && [title isEqual: [object className]] == NO)
{
if (NSRunAlertPanel(0, @"This operation will break existing connection",
@"OK", @"Cancel", NULL) != NSAlertDefaultReturn)
{
unsigned pos = [classes indexOfObject: [object className]];
if (pos != NSNotFound)
{
[browser selectRow: pos inColumn: 0];
}
return NO;
}
else
{
NSArray *array;
id doc = [(id<IB>)NSApp activeDocument];
unsigned i;
array = [doc connectorsForSource: object
ofClass: [NSNibControlConnector class]];
for (i = 0; i < [array count]; i++)
{
id<IBConnectors> con = [array objectAtIndex: i];
[doc removeConnector: con];
}
array = [doc connectorsForSource: object
ofClass: [NSNibOutletConnector class]];
for (i = 0; i < [array count]; i++)
{
id<IBConnectors> con = [array objectAtIndex: i];
[doc removeConnector: con];
}
hasConnections = NO;
}
}
[object setClassName: title];
return YES;
}
- (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);
RELEASE(window);
[super dealloc];
}
- (id) init
{
self = [super init];
if (self != nil)
{
NSView *contents;
NSRect rect;
rect = NSMakeRect(0, 0, IVW, IVH);
window = [[NSWindow alloc] initWithContentRect: rect
styleMask: NSBorderlessWindowMask
backing: NSBackingStoreRetained
defer: NO];
contents = [window contentView];
browser = [[NSBrowser alloc] initWithFrame: rect];
[browser setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
[browser setMaxVisibleColumns: 1];
[browser setAllowsMultipleSelection: NO];
[browser setHasHorizontalScroller: NO];
[browser setDelegate: self];
[contents addSubview: browser];
RELEASE(browser);
}
return self;
}
- (void) setObject: (id)anObject
{
if (anObject != nil && anObject != object)
{
NSArray *array;
unsigned pos;
ASSIGN(object, anObject);
hasConnections = NO;
/*
* Create list of existing connections for selected object.
*/
array = [[(id<IB>)NSApp activeDocument] connectorsForSource: object
ofClass: [NSNibControlConnector class]];
if ([array count] > 0)
hasConnections = YES;
array = [[(id<IB>)NSApp activeDocument] connectorsForSource: object
ofClass: [NSNibOutletConnector class]];
if ([array count] > 0)
hasConnections = YES;
ASSIGN(classes, [[NSApp classManager] allClassNames]);
[browser loadColumnZero];
pos = [classes indexOfObject: [object className]];
if (pos != NSNotFound)
{
[browser selectRow: pos inColumn: 0];
}
}
}
@end

View file

@ -24,9 +24,6 @@
#include "GormPrivate.h"
#define IVW 272
#define IVH 388
/*
* The GormEmptyInspector is a placeholder for an empty selection.
*/
@ -404,9 +401,9 @@
NSButton *revert;
buttonsRect = rect;
buttonsRect.size.height = 40;
rect.origin.y += 40;
rect.size.height -= 40;
buttonsRect.size.height = IVB;
rect.origin.y += IVB;
rect.size.height -= IVB;
buttonView = [[NSView alloc] initWithFrame: buttonsRect];
[buttonView setAutoresizingMask:
@ -415,36 +412,24 @@
RELEASE(buttonView);
ok = [inspector okButton];
if (ok == nil)
if (ok != nil)
{
ok = AUTORELEASE([[NSButton alloc] initWithFrame: bRect]);
[ok setAutoresizingMask: NSViewMaxYMargin | NSViewMinXMargin];
[ok setTitle: @"Ok"];
[ok setAction: @selector(ok:)];
[ok setTarget: inspector];
bRect = [ok frame];
bRect.origin.y = 10;
bRect.origin.x = buttonsRect.size.width - 10 - bRect.size.width;
[ok setFrame: bRect];
[buttonView addSubview: ok];
}
revert = [inspector revertButton];
if (revert == nil)
if (revert != nil)
{
revert = AUTORELEASE([[NSButton alloc] initWithFrame: bRect]);
[revert setAutoresizingMask: NSViewMaxYMargin | NSViewMinXMargin];
[revert setTitle: @"Revert"];
[revert setAction: @selector(revert:)];
[revert setTarget: inspector];
bRect = [revert frame];
bRect.origin.y = 10;
bRect.origin.x = 10;
[revert setFrame: bRect];
[buttonView addSubview: revert];
}
bRect = [ok frame];
bRect.origin.y = 10;
bRect.origin.x = buttonsRect.size.width - 10 - bRect.size.width;
[ok setFrame: bRect];
bRect = [revert frame];
bRect.origin.y = 10;
bRect.origin.x = 10;
[revert setFrame: bRect];
[buttonView addSubview: ok];
[buttonView addSubview: revert];
}
else
{
@ -460,10 +445,12 @@
[newView setFrame: rect];
[inspectorView addSubview: newView];
}
[inspector setObject: obj];
}
@end
@interface GormConnectionInspector : IBInspector
{
@ -765,24 +752,7 @@ selectCellWithString: (NSString*)title
{
NSView *contents;
NSSplitView *split;
NSArray *array;
NSRect rect;
id obj;
obj = [[[(Gorm*)NSApp selectionOwner] selection] lastObject];
/*
* Create list of existing connections for selected object.
*/
connectors = [NSMutableArray new];
array = [[(id<IB>)NSApp activeDocument] connectorsForSource: obj
ofClass: [NSNibControlConnector class]];
[connectors addObjectsFromArray: array];
array = [[(id<IB>)NSApp activeDocument] connectorsForSource: obj
ofClass: [NSNibOutletConnector class]];
[connectors addObjectsFromArray: array];
outlets = RETAIN([[NSApp classManager] allOutletsForObject: obj]);
rect = NSMakeRect(0, 0, IVW, IVH);
window = [[NSWindow alloc] initWithContentRect: rect
@ -817,6 +787,64 @@ selectCellWithString: (NSString*)title
[contents addSubview: split];
RELEASE(split);
okButton = [[NSButton alloc] initWithFrame: NSMakeRect(0,0,60,20)];
[okButton setAutoresizingMask: NSViewMaxYMargin | NSViewMinXMargin];
[okButton setAction: @selector(ok:)];
[okButton setTarget: self];
[okButton setTitle: @"Connect"];
[okButton setEnabled: NO];
revertButton = [[NSButton alloc] initWithFrame: NSMakeRect(0,0,60,20)];
[revertButton setAutoresizingMask: NSViewMaxYMargin | NSViewMinXMargin];
[revertButton setAction: @selector(revert:)];
[revertButton setTarget: self];
[revertButton setTitle: @"Revert"];
[revertButton setEnabled: NO];
}
return self;
}
- (void) ok: (id)sender
{
if ([connectors containsObject: currentConnector] == YES)
{
[[(id<IB>)NSApp activeDocument] removeConnector: currentConnector];
[connectors removeObject: currentConnector];
}
else
{
[connectors addObject: currentConnector];
[[(id<IB>)NSApp activeDocument] addConnector: currentConnector];
}
[oldBrowser loadColumnZero];
[self updateButtons];
}
- (void) setObject: (id)anObject
{
if (anObject != nil && anObject != object)
{
NSArray *array;
ASSIGN(object, anObject);
DESTROY(currentConnector);
RELEASE(connectors);
/*
* Create list of existing connections for selected object.
*/
connectors = [NSMutableArray new];
array = [[(id<IB>)NSApp activeDocument] connectorsForSource: object
ofClass: [NSNibControlConnector class]];
[connectors addObjectsFromArray: array];
array = [[(id<IB>)NSApp activeDocument] connectorsForSource: object
ofClass: [NSNibOutletConnector class]];
[connectors addObjectsFromArray: array];
RELEASE(outlets);
outlets = RETAIN([[NSApp classManager] allOutletsForObject: object]);
DESTROY(actions);
[oldBrowser loadColumnZero];
/*
* See if we can do initial selection based on pre-existing connections.
*/
@ -838,20 +866,7 @@ selectCellWithString: (NSString*)title
}
}
okButton = [[NSButton alloc] initWithFrame: NSMakeRect(0,0,60,20)];
[okButton setAutoresizingMask: NSViewMaxYMargin | NSViewMinXMargin];
[okButton setAction: @selector(ok:)];
[okButton setTarget: self];
[okButton setTitle: @"Connect"];
[okButton setEnabled: NO];
revertButton = [[NSButton alloc] initWithFrame: NSMakeRect(0,0,60,20)];
[revertButton setAutoresizingMask: NSViewMaxYMargin | NSViewMinXMargin];
[revertButton setAction: @selector(revert:)];
[revertButton setTarget: self];
[revertButton setTitle: @"Revert"];
[revertButton setEnabled: NO];
[newBrowser loadColumnZero];
if (currentConnector == nil)
{
if ([outlets count] == 1)
@ -861,22 +876,6 @@ selectCellWithString: (NSString*)title
}
[self updateButtons];
}
return self;
}
- (void) ok: (id)sender
{
if ([connectors containsObject: currentConnector] == YES)
{
[[(id<IB>)NSApp activeDocument] removeConnector: currentConnector];
[connectors removeObject: currentConnector];
}
else
{
[connectors addObject: currentConnector];
[[(id<IB>)NSApp activeDocument] addConnector: currentConnector];
}
[self updateButtons];
}
- (void) updateButtons

View file

@ -7,6 +7,7 @@
#include "Gorm.h"
#include "GormFilesOwner.h"
#include "GormDocument.h"
#include "GormInspectorsManager.h"
#include "GormClassManager.h"

View file

@ -38,19 +38,6 @@ NSString *IBSelectionChangedNotification
[super dealloc];
}
- (id) init
{
self = [super init];
if (self != nil)
{
/*
* Ask our manager for the selection for which we have been created.
*/
object = RETAIN([(id<IB>)NSApp selectedObject]);
}
return self;
}
- (id) object
{
return object;
@ -74,6 +61,11 @@ NSString *IBSelectionChangedNotification
return revertButton;
}
- (void) setObject: (id)anObject
{
ASSIGN(object, anObject);
}
- (void) touch: (id)sender
{
[window setDocumentEdited: YES];