1999-12-08 15:04:57 +00:00
/ * Gorm . m
*
2003-05-23 02:25:34 +00:00
* Copyright ( C ) 1999 , 2003 Free Software Foundation , Inc .
1999-12-08 15:04:57 +00:00
*
* Author : Richard Frith - Macdonald < richard @ brainstrom . co . uk >
2003-05-23 02:25:34 +00:00
* Author : Gregory John Casamento < greg_casamento @ yahoo . com >
2004-04-26 03:26:23 +00:00
* Date : 1999 , 2003 , 2004
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"
2003-05-13 04:10:12 +00:00
# include "GormPrefController.h"
2003-06-10 01:38:38 +00:00
# include "GormFontViewController.h"
2003-09-09 01:28:46 +00:00
# include "GormSetNameController.h"
2003-10-25 20:56:14 +00:00
# include "GNUstepGUI/GSNibCompatibility.h"
2004-07-16 01:50:40 +00:00
# include "GNUstepBase/GSObjCRuntime.h"
1999-12-08 15:04:57 +00:00
2002-10-13 06:04:05 +00:00
// for templates . . .
# include < AppKit / NSControl . h >
# include < AppKit / NSButton . h >
2003-05-20 03:57:37 +00:00
NSString * GormToggleGuidelineNotification = @ "GormToggleGuidelineNotification" ;
2003-06-08 04:38:59 +00:00
NSString * GormDidModifyClassNotification = @ "GormDidModifyClassNotification" ;
2003-06-30 02:15:00 +00:00
NSString * GormDidAddClassNotification = @ "GormDidAddClassNotification" ;
NSString * GormDidDeleteClassNotification = @ "GormDidDeleteClassNotification" ;
2003-10-19 04:56:07 +00:00
NSString * GormWillDetachObjectFromDocumentNotification = @ "GormWillDetachObjectFromDocumentNotification" ;
2004-02-15 00:50:50 +00:00
NSString * GormResizeCellNotification = @ "GormResizeCellNotification" ;
1999-12-17 17:22:18 +00:00
2004-08-28 15:05:35 +00:00
// Define this as "NO" initially . We only want to turn this on while loading or testing .
static BOOL _isInInterfaceBuilder = NO ;
2004-09-13 00:05:58 +00:00
static NSImage * gormImage = nil ;
static NSImage * testingImage = nil ;
1999-12-08 15:04:57 +00:00
@ class InfoPanel ;
2002-08-14 00:01:42 +00:00
// we had this include for grouping / ungrouping selectors
2003-03-03 09:15:48 +00:00
# include "GormViewWithContentViewEditor.h"
2002-08-14 00:01:42 +00:00
2001-08-21 13:32:24 +00:00
@ implementation NSCell ( GormAdditions )
/ *
* this methods is directly coming from NSCell . m
* The only additions is [ textObject setUsesFontPanel : NO ]
* We do this because we want to have control over the font panel changes
* /
- ( NSText * ) setUpFieldEditorAttributes : ( NSText * ) textObject
{
[ textObject setUsesFontPanel : NO ] ;
[ textObject setTextColor : [ self textColor ] ] ;
if ( _cell . contents_is _attributed _string = = NO )
{
/ * TODO : Manage scrollable attribute * /
[ textObject setFont : _font ] ;
[ textObject setAlignment : _cell . text_align ] ;
}
else
{
2004-09-06 21:41:32 +00:00
/ * TODO : What do we do if we are an attributed string .
2001-08-21 13:32:24 +00:00
Think about what happens when the user ends editing .
2004-09-06 21:41:32 +00:00
Allows editing text attributes . . . Formatter . * /
2001-08-21 13:32:24 +00:00
}
[ textObject setEditable : _cell . is_editable ] ;
[ textObject setSelectable : _cell . is_selectable || _cell . is_editable ] ;
[ textObject setRichText : _cell . is_rich _text ] ;
[ textObject setImportsGraphics : _cell . imports_graphics ] ;
[ textObject setSelectedRange : NSMakeRange ( 0 , 0 ) ] ;
return textObject ;
}
@ end
2001-05-08 09:43:11 +00:00
@ implementation GSNibItem ( GormAdditions )
- initWithClassName : ( NSString * ) className frame : ( NSRect ) frame
{
self = [ super init ] ;
theClass = [ className copy ] ;
theFrame = frame ;
return self ;
}
- ( NSString * ) className
{
return theClass ;
}
@ end
2005-02-16 04:19:50 +00:00
@ interface NSObject ( GormPrivate )
+ ( void ) poseAsClass : ( Class ) aClassObject ;
@ end
@ implementation NSObject ( GormPrivate )
+ ( void ) poseAsClass : ( Class ) aClassObject
{
// disable poseAs : while in Gorm .
// class_pose _as ( self , aClassObject ) ;
}
@ end
2001-05-08 09:43:11 +00:00
@ implementation GormObjectProxy
/ *
* Perhaps this would be better to have a dummy initProxyWithCoder
* in GSNibItem class , so that we are not dependent on actual coding
* order of the ivars ?
* /
- ( id ) initWithCoder : ( NSCoder * ) aCoder
{
2002-03-04 18:15:26 +00:00
int version = [ aCoder versionForClassName :
2002-03-04 20:28:20 +00:00
NSStringFromClass ( [ GSNibItem class ] ) ] ;
if ( version = = NSNotFound )
{
NSLog ( @ "no GSNibItem" ) ;
version = [ aCoder versionForClassName :
NSStringFromClass ( [ GormObjectProxy class ] ) ] ;
}
2001-05-08 09:43:11 +00:00
2002-03-04 20:28:20 +00:00
if ( version = = 0 )
2002-03-04 18:15:26 +00:00
{
// do not decode super ( it would try to morph into theClass ! )
[ aCoder decodeValueOfObjCType : @ encode ( id ) at : & theClass ] ;
theFrame = [ aCoder decodeRect ] ;
2004-05-08 15:42:27 +00:00
RETAIN ( theClass ) ; // release in dealloc of GSNibItem . . .
2002-03-04 18:15:26 +00:00
return self ;
}
2002-03-04 20:28:20 +00:00
else if ( version = = 1 )
2002-03-04 18:15:26 +00:00
{
// do not decode super ( it would try to morph into theClass ! )
[ aCoder decodeValueOfObjCType : @ encode ( id ) at : & theClass ] ;
theFrame = [ aCoder decodeRect ] ;
[ aCoder decodeValueOfObjCType : @ encode ( unsigned int )
at : & autoresizingMask ] ;
2004-05-08 15:42:27 +00:00
RETAIN ( theClass ) ; // release in dealloc of GSNibItem . . .
2002-03-04 18:15:26 +00:00
return self ;
}
else
{
2002-03-04 20:28:20 +00:00
NSLog ( @ "no initWithCoder for version %d" , version ) ;
2002-03-04 18:15:26 +00:00
RELEASE ( self ) ;
return nil ;
}
2001-05-08 09:43:11 +00:00
}
2002-11-24 06:56:05 +00:00
2002-12-27 23:57:35 +00:00
- ( NSString * ) inspectorClassName
{
return @ "GormNotApplicableInspector" ;
}
2002-11-24 06:56:05 +00:00
- ( NSString * ) classInspectorClassName
{
return @ "GormNotApplicableInspector" ;
}
2002-12-05 05:23:08 +00:00
- ( void ) setClassName : ( NSString * ) className
{
RELEASE ( theClass ) ;
theClass = [ className copy ] ;
}
2004-03-22 04:20:17 +00:00
- ( NSImage * ) imageForViewer
{
NSImage * image = [ super imageForViewer ] ;
if ( [ theClass isEqual : @ "NSFontManager" ] )
{
NSBundle * bundle = [ NSBundle mainBundle ] ;
NSString * path = [ bundle pathForImageResource : @ "GormFontManager" ] ;
image = [ [ NSImage alloc ] initWithContentsOfFile : path ] ;
}
return image ;
}
2001-05-08 09:43:11 +00:00
@ end
2002-10-13 06:04:05 +00:00
// define the class proxy . . .
@ implementation GormClassProxy
2001-05-08 09:43:11 +00:00
- ( id ) initWithClassName : ( NSString * ) n
{
self = [ super init ] ;
if ( self ! = nil )
{
ASSIGN ( name , n ) ;
}
return self ;
}
- ( void ) dealloc
{
RELEASE ( name ) ;
[ super dealloc ] ;
}
- ( NSString * ) className
{
return name ;
}
- ( NSString * ) inspectorClassName
{
2003-06-06 06:24:46 +00:00
return @ "GormClassInspector" ;
2002-11-24 05:03:51 +00:00
}
- ( NSString * ) classInspectorClassName
{
2002-11-24 04:55:50 +00:00
return @ "GormNotApplicableInspector" ;
2001-05-08 09:43:11 +00:00
}
- ( NSString * ) connectInspectorClassName
{
return @ "GormNotApplicableInspector" ;
}
- ( NSString * ) sizeInspectorClassName
{
return @ "GormNotApplicableInspector" ;
}
@ end
2004-03-21 15:33:28 +00:00
1999-12-08 15:04:57 +00:00
@ implementation Gorm
- ( id < IBDocuments > ) activeDocument
{
2000-01-04 16:25:39 +00:00
unsigned i = [ documents count ] ;
if ( i > 0 )
{
while ( i - - > 0 )
{
id doc = [ documents objectAtIndex : i ] ;
2003-08-03 09:01:48 +00:00
if ( [ doc isActive ] = = YES )
2000-01-04 16:25:39 +00:00
{
return doc ;
}
}
}
return nil ;
1999-12-08 15:04:57 +00:00
}
2003-08-03 09:01:48 +00:00
/ *
NSApp
* /
- ( id ) init
{
self = [ super init ] ;
if ( self ! = nil )
{
NSNotificationCenter * nc = [ NSNotificationCenter defaultCenter ] ;
NSBundle * bundle = [ NSBundle mainBundle ] ;
NSString * path ;
path = [ bundle pathForImageResource : @ "GormLinkImage" ] ;
linkImage = [ [ NSImage alloc ] initWithContentsOfFile : path ] ;
path = [ bundle pathForImageResource : @ "GormSourceTag" ] ;
sourceImage = [ [ NSImage alloc ] initWithContentsOfFile : path ] ;
path = [ bundle pathForImageResource : @ "GormTargetTag" ] ;
targetImage = [ [ NSImage alloc ] initWithContentsOfFile : path ] ;
2004-09-13 00:05:58 +00:00
path = [ bundle pathForImageResource : @ "Gorm" ] ;
gormImage = [ [ NSImage alloc ] initWithContentsOfFile : path ] ;
path = [ bundle pathForImageResource : @ "GormTesting" ] ;
testingImage = [ [ NSImage alloc ] initWithContentsOfFile : path ] ;
2003-08-03 09:01:48 +00:00
documents = [ NSMutableArray new ] ;
[ nc addObserver : self
selector : @ selector ( handleNotification : )
name : IBSelectionChangedNotification
object : nil ] ;
[ nc addObserver : self
selector : @ selector ( handleNotification : )
name : IBWillCloseDocumentNotification
object : nil ] ;
/ *
* Make sure the palettes manager exists , so that the editors and
* inspectors provided in the standard palettes are available .
* /
[ self palettesManager ] ;
// load the interface . . .
if ( ! [ NSBundle loadNibNamed : @ "Gorm" owner : self ] )
{
NSLog ( @ "Failed to load interface" ) ;
exit ( -1 ) ;
}
}
return self ;
}
- ( void ) dealloc
{
NSNotificationCenter * nc = [ NSNotificationCenter defaultCenter ] ;
[ nc removeObserver : self ] ;
RELEASE ( infoPanel ) ;
RELEASE ( inspectorsManager ) ;
RELEASE ( palettesManager ) ;
RELEASE ( documents ) ;
RELEASE ( classManager ) ;
2003-10-25 20:56:14 +00:00
[ super dealloc ] ;
2003-08-03 09:01:48 +00:00
}
2002-09-21 16:20:13 +00:00
- ( void ) applicationDidFinishLaunching : ( NSApplication * ) sender
{
2004-01-01 03:52:40 +00:00
NSUserDefaults * defaults = [ NSUserDefaults standardUserDefaults ] ;
NSArray * a = nil ;
2004-07-16 01:50:40 +00:00
2004-01-01 03:52:40 +00:00
if ( [ defaults boolForKey : @ "ShowInspectors" ] )
2002-09-21 16:20:13 +00:00
{
[ [ [ self inspectorsManager ] panel ] makeKeyAndOrderFront : self ] ;
}
2004-01-01 03:52:40 +00:00
if ( [ defaults boolForKey : @ "ShowPalettes" ] )
2002-09-21 16:20:13 +00:00
{
[ [ [ self palettesManager ] panel ] makeKeyAndOrderFront : self ] ;
}
2004-01-01 03:52:40 +00:00
if ( ( a = [ defaults arrayForKey : @ "GSAppKitUserBundles" ] ) ! = nil )
{
if ( [ a count ] > 0 )
{
2004-01-03 07:04:47 +00:00
NSLog ( @ "WARNING: Gorm has detected that you are using user bundles. Please make certain that these are compatible with Gorm as some bundles can cause issues which may corrupt your .gorm files." ) ;
2004-01-01 03:52:40 +00:00
}
}
2004-07-16 01:50:40 +00:00
if ( GSGetMethod ( [ GSNibContainer class ] , @ selector ( awakeWithContext : ) , YES , YES ) = = NULL )
{
NSRunAlertPanel ( _ ( @ "Incorrect GNUstep Version" ) ,
_ ( @ "The version of GNUstep you are using is too old for this version of Gorm, please update." ) ,
2004-12-18 15:06:18 +00:00
_ ( @ "OK" ) , nil , nil ) ;
2004-07-16 01:50:40 +00:00
[ self terminate : self ] ;
}
2002-09-21 16:20:13 +00:00
}
- ( void ) applicationWillTerminate : ( NSApplication * ) sender
{
2003-05-13 04:10:12 +00:00
// [ [ NSUserDefaults standardUserDefaults ]
// setBool : [ [ [ self inspectorsManager ] panel ] isVisible ]
// forKey : @ "ShowInspectors" ] ;
// [ [ NSUserDefaults standardUserDefaults ]
// setBool : [ [ [ self palettesManager ] panel ] isVisible ]
// forKey : @ "ShowPalettes" ] ;
2002-09-21 16:20:13 +00:00
}
1999-12-08 15:04:57 +00:00
- ( BOOL ) applicationShouldTerminate : ( NSApplication * ) sender
{
2003-05-20 03:57:37 +00:00
id doc ;
BOOL edited = NO ;
NSEnumerator * enumerator = [ documents objectEnumerator ] ;
1999-12-08 15:04:57 +00:00
2003-05-20 03:57:37 +00:00
2002-09-21 15:24:59 +00:00
if ( isTesting = = YES )
{
2003-05-20 03:57:37 +00:00
[ self endTesting : sender ] ;
return NO ;
2002-09-21 15:24:59 +00:00
}
2003-05-20 03:57:37 +00:00
while ( ( doc = [ enumerator nextObject ] ) ! = nil )
1999-12-08 15:04:57 +00:00
{
2003-05-20 03:57:37 +00:00
if ( [ [ doc window ] isDocumentEdited ] = = YES )
{
edited = YES ;
break ;
}
1999-12-08 15:04:57 +00:00
}
2003-05-20 03:57:37 +00:00
if ( edited = = YES )
{
int result ;
2005-02-05 14:11:57 +00:00
result = NSRunAlertPanel ( _ ( @ "Quit" ) ,
_ ( @ "There are edited windows" ) ,
_ ( @ "Review Unsaved" ) ,
_ ( @ "Quit Anyway" ) ,
_ ( @ "Cancel" ) ) ;
2003-05-20 03:57:37 +00:00
if ( result = = NSAlertDefaultReturn )
{
enumerator = [ documents objectEnumerator ] ;
while ( ( doc = [ enumerator nextObject ] ) ! = nil )
{
if ( [ [ doc window ] isDocumentEdited ] = = YES )
{
if ( ! [ doc couldCloseDocument ] )
return NO ;
}
}
1999-12-08 15:04:57 +00:00
}
2003-05-20 03:57:37 +00:00
else if ( result = = NSAlertOtherReturn )
return NO ;
}
return YES ;
1999-12-08 15:04:57 +00:00
}
2003-05-20 03:57:37 +00:00
1999-12-20 14:20:06 +00:00
- ( GormClassManager * ) classManager
{
2001-05-08 09:43:11 +00:00
id document = [ self activeDocument ] ;
if ( document ! = nil ) return [ document classManager ] ;
/ * kept in the case one want access to the classManager without document * /
else if ( classManager = = nil )
1999-12-20 14:20:06 +00:00
{
classManager = [ GormClassManager new ] ;
}
return classManager ;
2001-05-08 09:43:11 +00:00
1999-12-20 14:20:06 +00:00
}
1999-12-17 17:22:18 +00:00
- ( id ) connectDestination
{
return connectDestination ;
}
- ( id ) connectSource
{
return connectSource ;
}
2003-08-03 09:01:48 +00:00
- ( void ) displayConnectionBetween : ( id ) source
and : ( id ) destination
1999-12-17 17:22:18 +00:00
{
2003-08-03 09:01:48 +00:00
NSWindow * window ;
NSRect rect ;
2002-09-21 15:24:59 +00:00
1999-12-18 08:55:31 +00:00
if ( source ! = connectSource )
{
if ( connectSource ! = nil )
{
2004-12-13 01:58:43 +00:00
window = [ ( GormDocument * ) [ self activeDocument ] windowAndRect : & rect
forObject : connectSource ] ;
2003-08-03 09:01:48 +00:00
if ( window ! = nil )
1999-12-18 08:55:31 +00:00
{
2003-08-03 09:01:48 +00:00
NSView * view = [ [ window contentView ] superview ] ;
2002-09-21 15:24:59 +00:00
2003-08-03 09:01:48 +00:00
rect . origin . x - - ;
rect . size . width + + ;
2002-09-21 15:24:59 +00:00
2003-08-03 09:01:48 +00:00
rect . size . height + + ;
1999-12-18 08:55:31 +00:00
2003-08-03 09:01:48 +00:00
[ window disableFlushWindow ] ;
[ view displayRect : rect ] ;
2002-09-21 15:24:59 +00:00
2003-08-03 09:01:48 +00:00
[ window enableFlushWindow ] ;
[ window flushWindow ] ;
1999-12-18 08:55:31 +00:00
}
}
connectSource = source ;
1999-12-19 06:19:31 +00:00
}
1999-12-18 08:55:31 +00:00
if ( destination ! = connectDestination )
{
if ( connectDestination ! = nil )
{
2004-12-13 01:58:43 +00:00
window = [ ( GormDocument * ) [ self activeDocument ] windowAndRect : & rect
forObject : connectDestination ] ;
2003-08-03 09:01:48 +00:00
if ( window ! = nil )
1999-12-18 08:55:31 +00:00
{
2003-08-03 09:01:48 +00:00
NSView * view = [ [ window contentView ] superview ] ;
1999-12-18 08:55:31 +00:00
/ *
* Erase image from old location .
* /
2003-08-03 09:01:48 +00:00
rect . origin . x - - ;
rect . size . width + + ;
rect . size . height + + ;
[ view lockFocus ] ;
[ view displayRect : rect ] ;
[ view unlockFocus ] ;
[ window flushWindow ] ;
1999-12-18 08:55:31 +00:00
}
}
connectDestination = destination ;
1999-12-19 06:19:31 +00:00
}
2002-09-21 15:24:59 +00:00
if ( connectSource ! = nil )
{
2004-12-13 01:58:43 +00:00
window = [ ( GormDocument * ) [ self activeDocument ] windowAndRect : & rect forObject : connectSource ] ;
2003-08-03 09:01:48 +00:00
if ( window ! = nil )
2002-09-21 15:24:59 +00:00
{
2003-08-03 09:01:48 +00:00
NSView * view = [ [ window contentView ] superview ] ;
2004-12-31 13:21:30 +00:00
NSRect imageRect = rect ;
imageRect . origin . x + + ;
// rect . size . width - - ;
// rect . size . height - - ;
2003-08-03 09:01:48 +00:00
[ view lockFocus ] ;
2002-09-21 15:24:59 +00:00
[ [ NSColor greenColor ] set ] ;
2004-12-31 13:21:30 +00:00
NSFrameRectWithWidth ( rect , 1 ) ;
2002-09-21 15:24:59 +00:00
2004-12-31 13:21:30 +00:00
[ sourceImage compositeToPoint : imageRect . origin
2002-09-21 15:24:59 +00:00
operation : NSCompositeSourceOver ] ;
2003-08-03 09:01:48 +00:00
[ view unlockFocus ] ;
[ window flushWindow ] ;
2002-09-21 15:24:59 +00:00
}
}
if ( connectDestination ! = nil && connectDestination = = connectSource )
{
2004-12-13 01:58:43 +00:00
window = [ ( GormDocument * ) [ self activeDocument ] windowAndRect : & rect
forObject : connectDestination ] ;
2003-08-03 09:01:48 +00:00
if ( window ! = nil )
2002-09-21 15:24:59 +00:00
{
2003-08-03 09:01:48 +00:00
NSView * view = [ [ window contentView ] superview ] ;
2004-12-31 13:21:30 +00:00
NSRect imageRect = rect ;
2002-09-21 15:24:59 +00:00
2004-12-31 13:21:30 +00:00
imageRect . origin . x + = 3 ;
imageRect . origin . y + = 2 ;
// rect . size . width - = 5 ;
// rect . size . height - = 5 ;
2003-08-03 09:01:48 +00:00
[ view lockFocus ] ;
2002-09-21 15:24:59 +00:00
[ [ NSColor purpleColor ] set ] ;
2004-12-31 13:21:30 +00:00
NSFrameRectWithWidth ( rect , 1 ) ;
2002-09-21 15:24:59 +00:00
2004-12-31 13:21:30 +00:00
imageRect . origin . x + = [ targetImage size ] . width ;
[ targetImage compositeToPoint : imageRect . origin
2002-09-21 15:24:59 +00:00
operation : NSCompositeSourceOver ] ;
2003-08-03 09:01:48 +00:00
[ view unlockFocus ] ;
[ window flushWindow ] ;
2002-09-21 15:24:59 +00:00
}
}
else if ( connectDestination ! = nil )
1999-12-19 06:19:31 +00:00
{
2004-12-13 01:58:43 +00:00
window = [ ( GormDocument * ) [ self activeDocument ] windowAndRect : & rect
forObject : connectDestination ] ;
2003-08-03 09:01:48 +00:00
if ( window ! = nil )
1999-12-18 08:55:31 +00:00
{
2003-08-03 09:01:48 +00:00
NSView * view = [ [ window contentView ] superview ] ;
2004-12-31 13:21:30 +00:00
NSRect imageRect = rect ;
1999-12-18 08:55:31 +00:00
2004-12-31 13:21:30 +00:00
imageRect . origin . x + + ;
// rect . size . width - - ;
// rect . size . height - - ;
2003-08-03 09:01:48 +00:00
[ view lockFocus ] ;
2002-09-21 15:24:59 +00:00
[ [ NSColor purpleColor ] set ] ;
2004-12-31 13:21:30 +00:00
NSFrameRectWithWidth ( rect , 1 ) ;
2002-09-21 15:24:59 +00:00
2004-12-31 13:21:30 +00:00
[ targetImage compositeToPoint : imageRect . origin
2002-09-21 15:24:59 +00:00
operation : NSCompositeSourceOver ] ;
2003-08-03 09:01:48 +00:00
[ view unlockFocus ] ;
[ window flushWindow ] ;
1999-12-18 08:55:31 +00:00
}
}
1999-12-17 17:22:18 +00:00
}
2004-12-28 02:25:18 +00:00
/ * * Info Menu Actions * /
2002-07-12 05:46:29 +00:00
2003-08-03 09:01:48 +00:00
- ( void ) preferencesPanel : ( id ) sender
2001-07-06 17:10:51 +00:00
{
2003-08-03 09:01:48 +00:00
if ( ! preferencesController )
{
preferencesController = [ [ GormPrefController alloc ] initWithWindowNibName : @ "GormPreferences" ] ;
}
[ [ preferencesController window ] makeKeyAndOrderFront : nil ] ;
2001-07-06 17:10:51 +00:00
}
2004-12-28 02:25:18 +00:00
/ * * Document Menu Actions * /
2001-07-06 17:10:51 +00:00
2003-08-03 09:01:48 +00:00
- ( void ) open : ( id ) sender
2002-09-21 15:24:59 +00:00
{
2004-05-13 05:13:36 +00:00
GormDocument * doc = AUTORELEASE ( [ GormDocument new ] ) ;
2002-09-21 15:24:59 +00:00
2003-08-03 09:01:48 +00:00
[ documents addObject : doc ] ;
if ( [ doc openDocument : sender ] = = nil )
1999-12-15 15:29:27 +00:00
{
2004-05-15 15:39:57 +00:00
[ doc closeAllEditors ] ;
2003-08-03 09:01:48 +00:00
[ documents removeObjectIdenticalTo : doc ] ;
doc = nil ;
1999-12-15 15:29:27 +00:00
}
else
{
2003-08-03 09:01:48 +00:00
[ [ doc window ] makeKeyAndOrderFront : self ] ;
}
}
1999-12-15 15:29:27 +00:00
2003-08-03 09:01:48 +00:00
- ( void ) newGormDocument : ( id ) sender
{
2004-05-13 05:13:36 +00:00
id doc = AUTORELEASE ( [ GormDocument new ] ) ;
2003-08-03 09:01:48 +00:00
[ documents addObject : doc ] ;
switch ( [ sender tag ] )
{
case 0 :
[ doc setupDefaults : @ "Application" ] ;
break ;
case 1 :
[ doc setupDefaults : @ "Empty" ] ;
break ;
case 2 :
[ doc setupDefaults : @ "Inspector" ] ;
break ;
case 3 :
[ doc setupDefaults : @ "Palette" ] ;
break ;
2000-01-03 11:00:14 +00:00
2003-08-03 09:01:48 +00:00
default :
printf ( "unknow newGormDocument tag" ) ;
}
if ( NSEqualPoints ( cascadePoint , NSZeroPoint ) )
{
NSRect frame = [ [ doc window ] frame ] ;
cascadePoint = NSMakePoint ( frame . origin . x , NSMaxY ( frame ) ) ;
}
cascadePoint = [ [ doc window ] cascadeTopLeftFromPoint : cascadePoint ] ;
[ [ doc window ] makeKeyAndOrderFront : self ] ;
}
2003-05-23 02:25:34 +00:00
2003-08-03 09:01:48 +00:00
- ( void ) save : ( id ) sender
{
[ ( GormDocument * ) [ self activeDocument ] saveGormDocument : sender ] ;
}
2000-01-03 11:00:14 +00:00
2003-08-03 09:01:48 +00:00
- ( void ) saveAs : ( id ) sender
{
[ ( GormDocument * ) [ self activeDocument ] saveAsDocument : sender ] ;
}
2000-01-03 11:00:14 +00:00
2003-08-03 09:01:48 +00:00
- ( void ) saveAll : ( id ) sender
{
NSEnumerator * enumerator = [ documents objectEnumerator ] ;
id doc ;
while ( ( doc = [ enumerator nextObject ] ) ! = nil )
{
if ( [ [ doc window ] isDocumentEdited ] = = YES )
1999-12-15 21:43:57 +00:00
{
2003-08-03 09:01:48 +00:00
if ( ! [ doc saveGormDocument : sender ] )
NSLog ( @ "can not save %@" , doc ) ;
1999-12-15 21:43:57 +00:00
}
1999-12-15 15:29:27 +00:00
}
}
2003-08-03 09:01:48 +00:00
- ( void ) revertToSaved : ( id ) sender
2000-01-07 11:11:08 +00:00
{
2003-08-03 09:01:48 +00:00
id doc = [ ( GormDocument * ) [ self activeDocument ] revertDocument : sender ] ;
2000-01-07 11:11:08 +00:00
2003-08-03 09:01:48 +00:00
if ( doc ! = nil )
2000-01-07 11:11:08 +00:00
{
2003-08-03 09:01:48 +00:00
[ documents addObject : doc ] ;
2004-05-13 05:13:36 +00:00
// RELEASE ( doc ) ;
2003-08-03 09:01:48 +00:00
[ [ doc window ] makeKeyAndOrderFront : self ] ;
}
}
2000-01-07 11:11:08 +00:00
2003-08-03 09:01:48 +00:00
- ( void ) close : ( id ) sender
{
2004-05-13 05:13:36 +00:00
GormDocument * document = ( GormDocument * ) [ self activeDocument ] ;
NSWindow * window = [ document window ] ;
2003-08-03 09:01:48 +00:00
[ window performClose : self ] ;
}
- ( void ) debug : ( id ) sender
{
[ [ self activeDocument ] performSelector : @ selector ( printAllEditors ) ] ;
}
- ( void ) loadSound : ( id ) sender
{
[ ( GormDocument * ) [ self activeDocument ] openSound : sender ] ;
}
- ( void ) loadImage : ( id ) sender
{
[ ( GormDocument * ) [ self activeDocument ] openImage : sender ] ;
}
- ( void ) testInterface : ( id ) sender
{
if ( isTesting = = YES )
{
return ;
}
else
{
2003-12-24 02:50:34 +00:00
NS_DURING
2003-08-03 09:01:48 +00:00
{
2004-05-25 10:54:06 +00:00
NSUserDefaults * defaults ;
2003-12-24 02:50:34 +00:00
NSNotificationCenter * notifCenter = [ NSNotificationCenter defaultCenter ] ;
2005-02-05 14:11:57 +00:00
GormDocument * activeDoc = ( GormDocument * ) [ self activeDocument ] ;
2004-05-25 10:54:06 +00:00
NSData * data ;
NSArchiver * archiver ;
2005-02-05 14:11:57 +00:00
NSEnumerator * en ;
id obj ;
// which windows were open when testing started . . .
testingWindows = [ [ NSMutableArray alloc ] init ] ;
en = [ [ self windows ] objectEnumerator ] ;
while ( ( obj = [ en nextObject ] ) ! = nil )
{
if ( [ obj isVisible ] )
{
[ testingWindows addObject : obj ] ;
}
}
2003-12-24 02:50:34 +00:00
isTesting = YES ; // set here , so that beginArchiving and endArchiving do not use templates .
2004-09-13 00:05:58 +00:00
[ self setApplicationIconImage : testingImage ] ;
2003-12-24 02:50:34 +00:00
archiver = [ [ NSArchiver alloc ] init ] ;
2005-02-05 14:11:57 +00:00
[ activeDoc beginArchiving ] ;
2003-12-25 04:48:32 +00:00
[ archiver encodeClassName : @ "GormCustomView"
intoClassName : @ "GormTestCustomView" ] ;
[ archiver encodeClassName : @ "GormNSMenu"
2003-12-24 02:50:34 +00:00
intoClassName : @ "NSMenu" ] ;
2003-12-25 04:48:32 +00:00
[ archiver encodeClassName : @ "GormNSWindow"
intoClassName : @ "NSWindow" ] ;
[ archiver encodeClassName : @ "GormNSPanel"
intoClassName : @ "NSPanel" ] ;
2003-12-24 02:50:34 +00:00
[ archiver encodeClassName : @ "GormNSPopUpButton"
intoClassName : @ "NSPopUpButton" ] ;
[ archiver encodeClassName : @ "GormNSPopUpButtonCell"
intoClassName : @ "NSPopUpButtonCell" ] ;
2004-06-03 04:40:48 +00:00
/ *
2003-12-25 04:48:32 +00:00
[ archiver encodeClassName : @ "GormNSBrowser"
intoClassName : @ "NSBrowser" ] ;
[ archiver encodeClassName : @ "GormNSTableView"
intoClassName : @ "NSTableView" ] ;
[ archiver encodeClassName : @ "GormNSOutlineView"
intoClassName : @ "NSOutlineView" ] ;
2004-06-03 04:40:48 +00:00
* /
2004-08-28 15:05:35 +00:00
[ GSClassSwapper setIsInInterfaceBuilder : YES ] ; // do not allow custom classes during testing .
2005-02-05 14:11:57 +00:00
[ archiver encodeRootObject : activeDoc ] ;
2004-05-08 15:42:27 +00:00
data = RETAIN ( [ archiver archiverData ] ) ; // Released below . . .
2005-02-05 14:11:57 +00:00
[ activeDoc endArchiving ] ;
2003-12-24 02:50:34 +00:00
RELEASE ( archiver ) ;
2004-08-28 15:05:35 +00:00
[ GSClassSwapper setIsInInterfaceBuilder : NO ] ; // beginal allowing custom classes . . .
2003-12-24 02:50:34 +00:00
[ notifCenter postNotificationName : IBWillBeginTestingInterfaceNotification
object : self ] ;
if ( [ selectionOwner conformsToProtocol : @ protocol ( IBEditors ) ] = = YES )
2003-08-03 09:01:48 +00:00
{
2004-04-11 14:05:41 +00:00
[ selectionOwner makeSelectionVisible : NO ] ;
2003-08-03 09:01:48 +00:00
}
2003-12-24 02:50:34 +00:00
defaults = [ NSUserDefaults standardUserDefaults ] ;
menuLocations = [ [ defaults objectForKey : @ "NSMenuLocations" ] copy ] ;
[ defaults removeObjectForKey : @ "NSMenuLocations" ] ;
2004-05-25 10:54:06 +00:00
servicesMenu = [ self servicesMenu ] ;
2003-12-24 02:50:34 +00:00
testContainer = [ NSUnarchiver unarchiveObjectWithData : data ] ;
if ( testContainer ! = nil )
{
2004-06-27 12:34:40 +00:00
NSMutableDictionary * nameTable = [ testContainer nameTable ] ;
[ nameTable removeObjectForKey : @ "NSServicesMenu" ] ;
[ nameTable removeObjectForKey : @ "NSWindowsMenu" ] ;
2004-06-29 03:27:37 +00:00
[ testContainer awakeWithContext : nil ] ;
2004-05-08 15:42:27 +00:00
RETAIN ( testContainer ) ; // released in endTesting :
2003-12-24 02:50:34 +00:00
}
/ *
* If the NIB didn ' t have a main menu , create one ,
* otherwise , ensure that ' quit ' ends testing mode .
* /
if ( [ self mainMenu ] = = mainMenu )
2003-08-03 09:01:48 +00:00
{
2003-12-24 02:50:34 +00:00
NSMenu * testMenu ;
2004-09-13 00:05:58 +00:00
testMenu = [ [ NSMenu alloc ] initWithTitle : _ ( @ "Test Menu (Gorm)" ) ] ;
[ testMenu addItemWithTitle : _ ( @ "Quit Test" )
2003-08-03 09:01:48 +00:00
action : @ selector ( deferredEndTesting : )
keyEquivalent : @ "q" ] ;
2004-05-16 21:45:19 +00:00
[ self setMainMenu : testMenu ] ; // released , when the menu is reset in endTesting .
2003-08-03 09:01:48 +00:00
}
2003-12-24 02:50:34 +00:00
else
{
NSMenu * testMenu = [ self mainMenu ] ;
2004-09-13 00:05:58 +00:00
id item ;
NSString * newTitle = [ [ testMenu title ] stringByAppendingString : @ " (Gorm)" ] ;
// set the menu up so that it ' s easy to tell we ' re testing and how to quit .
[ testMenu setTitle : newTitle ] ;
2003-12-24 02:50:34 +00:00
item = [ testMenu itemWithTitle : _ ( @ "Quit" ) ] ;
if ( item ! = nil )
{
2004-09-13 00:05:58 +00:00
[ item setTitle : _ ( @ "Quit Test" ) ] ;
2003-12-24 02:50:34 +00:00
[ item setAction : @ selector ( deferredEndTesting : ) ] ;
}
else
{
2004-09-13 00:05:58 +00:00
[ testMenu addItemWithTitle : _ ( @ "Quit Test" )
2003-12-24 02:50:34 +00:00
action : @ selector ( deferredEndTesting : )
keyEquivalent : @ "q" ] ;
}
}
2004-05-16 21:20:14 +00:00
2004-05-30 03:02:05 +00:00
// so we don ' t get the warning . . .
[ self setServicesMenu : nil ] ;
2004-05-25 10:54:06 +00:00
2004-05-16 21:20:14 +00:00
// display the current main menu . . .
[ [ self mainMenu ] display ] ;
2005-02-05 14:11:57 +00:00
2003-12-24 02:50:34 +00:00
[ notifCenter postNotificationName : IBDidBeginTestingInterfaceNotification
object : self ] ;
RELEASE ( data ) ;
2000-01-07 11:11:08 +00:00
}
2003-12-24 02:50:34 +00:00
NS_HANDLER
{
// reset the application after the error .
NSLog ( @ "Error while testing interface: %@" ,
[ localException reason ] ) ;
2004-12-18 15:06:18 +00:00
NSRunAlertPanel ( _ ( @ "An Error Occurred" ) ,
[ NSString stringWithFormat :
@ "Problem testing interface. Make sure connections are to appropriate objects. Exception: %@" ,
[ localException reason ] ] ,
_ ( @ "OK" ) , nil , nil ) ;
2003-12-24 02:50:34 +00:00
[ self endTesting : self ] ;
}
NS_ENDHANDLER ;
2000-01-07 11:11:08 +00:00
}
2003-08-03 09:01:48 +00:00
}
2000-01-07 11:11:08 +00:00
2003-08-03 09:01:48 +00:00
2004-12-28 02:25:18 +00:00
/ * * Edit Menu Actions * /
2003-08-03 09:01:48 +00:00
- ( void ) copy : ( id ) sender
{
if ( [ [ selectionOwner selection ] count ] = = 0
|| [ selectionOwner respondsToSelector : @ selector ( copySelection ) ] = = NO )
return ;
2004-12-28 02:25:18 +00:00
if ( [ self isConnecting ] )
{
[ self stopConnecting ] ;
}
2004-12-14 11:13:59 +00:00
[ ( id < IBSelectionOwners , IBEditors > ) selectionOwner copySelection ] ;
2000-01-07 11:11:08 +00:00
}
2003-08-03 09:01:48 +00:00
- ( void ) cut : ( id ) sender
1999-12-08 15:19:11 +00:00
{
2003-08-03 09:01:48 +00:00
if ( [ [ selectionOwner selection ] count ] = = 0
|| [ selectionOwner respondsToSelector : @ selector ( copySelection ) ] = = NO
|| [ selectionOwner respondsToSelector : @ selector ( deleteSelection ) ] = = NO )
return ;
2004-12-28 02:25:18 +00:00
if ( [ self isConnecting ] )
{
[ self stopConnecting ] ;
}
2004-12-14 11:13:59 +00:00
[ ( id < IBSelectionOwners , IBEditors > ) selectionOwner copySelection ] ;
[ ( id < IBSelectionOwners , IBEditors > ) selectionOwner deleteSelection ] ;
2003-08-03 09:01:48 +00:00
}
1999-12-08 15:19:11 +00:00
2003-08-03 09:01:48 +00:00
- ( void ) paste : ( id ) sender
{
if ( [ selectionOwner respondsToSelector : @ selector ( pasteInSelection ) ] = = NO )
return ;
2004-12-28 02:25:18 +00:00
if ( [ self isConnecting ] )
{
[ self stopConnecting ] ;
}
2004-12-14 11:13:59 +00:00
[ ( id < IBSelectionOwners , IBEditors > ) selectionOwner pasteInSelection ] ;
2003-08-03 09:01:48 +00:00
}
- ( void ) delete : ( id ) sender
{
if ( [ [ selectionOwner selection ] count ] = = 0
|| [ selectionOwner respondsToSelector : @ selector ( deleteSelection ) ] = = NO )
return ;
2004-12-28 02:25:18 +00:00
if ( [ self isConnecting ] )
{
[ self stopConnecting ] ;
}
2004-12-14 11:13:59 +00:00
[ ( id < IBSelectionOwners , IBEditors > ) selectionOwner deleteSelection ] ;
2003-08-03 09:01:48 +00:00
}
- ( void ) selectAllItems : ( id ) sender
{
2004-09-06 21:41:32 +00:00
/ * TODO : Select all items in the current selection owner . * /
2003-08-03 09:01:48 +00:00
return ;
}
- ( void ) setName : ( id ) sender
{
2003-09-09 01:28:46 +00:00
GormSetNameController * panel ;
2003-08-03 09:01:48 +00:00
int returnPanel ;
NSTextField * textField ;
NSArray * selectionArray = [ selectionOwner selection ] ;
id obj = [ selectionArray objectAtIndex : 0 ] ;
NSString * name ;
2003-12-24 02:50:34 +00:00
if ( [ ( GormDocument * ) [ self activeDocument ] isTopLevelObject : obj ] )
1999-12-08 15:19:11 +00:00
{
2003-12-24 02:50:34 +00:00
panel = [ GormSetNameController new ] ;
returnPanel = [ panel runAsModal ] ;
textField = [ panel textField ] ;
if ( returnPanel = = NSAlertDefaultReturn )
1999-12-17 21:53:06 +00:00
{
2003-12-24 02:50:34 +00:00
name = [ [ textField stringValue ] stringByTrimmingSpaces ] ;
if ( name ! = nil && [ name isEqual : @ "" ] = = NO )
{
[ [ self activeDocument ] setName : name forObject : obj ] ;
}
1999-12-17 21:53:06 +00:00
}
2003-12-24 02:50:34 +00:00
RELEASE ( panel ) ;
1999-12-08 15:19:11 +00:00
}
2003-08-03 09:01:48 +00:00
}
- ( void ) guideline : ( id ) sender
{
[ [ NSNotificationCenter defaultCenter ] postNotificationName : GormToggleGuidelineNotification
object : nil ] ;
if ( [ guideLineMenuItem tag ] = = 0 )
1999-12-08 15:19:11 +00:00
{
2003-08-03 09:01:48 +00:00
[ guideLineMenuItem setTitle : _ ( @ "Enable GuideLine" ) ] ;
[ guideLineMenuItem setTag : 1 ] ;
}
else if ( [ guideLineMenuItem tag ] = = 1 )
{
[ guideLineMenuItem setTitle : _ ( @ "Disable GuideLine" ) ] ;
[ guideLineMenuItem setTag : 0 ] ;
1999-12-08 15:19:11 +00:00
}
}
2003-08-03 09:01:48 +00:00
- ( void ) orderFrontFontPanel : ( id ) sender
1999-12-16 18:06:22 +00:00
{
2003-08-03 09:01:48 +00:00
NSFontPanel * fontPanel = [ NSFontPanel sharedFontPanel ] ;
2003-09-07 14:42:24 +00:00
GormFontViewController * gfvc =
[ GormFontViewController sharedGormFontViewController ] ;
2003-08-03 09:01:48 +00:00
[ fontPanel setAccessoryView : [ gfvc view ] ] ;
[ [ NSFontManager sharedFontManager ] orderFrontFontPanel : self ] ;
1999-12-16 18:06:22 +00:00
}
2004-12-28 02:25:18 +00:00
/ * * Grouping * /
2003-08-03 09:01:48 +00:00
- ( void ) groupSelectionInSplitView : ( id ) sender
2003-01-02 06:17:15 +00:00
{
2003-08-03 09:01:48 +00:00
if ( [ [ selectionOwner selection ] count ] < 2
|| [ selectionOwner respondsToSelector : @ selector ( groupSelectionInSplitView ) ] = = NO )
return ;
[ ( GormGenericEditor * ) selectionOwner groupSelectionInSplitView ] ;
}
- ( void ) groupSelectionInBox : ( id ) sender
{
if ( [ selectionOwner respondsToSelector : @ selector ( groupSelectionInBox ) ] = = NO )
return ;
[ ( GormGenericEditor * ) selectionOwner groupSelectionInBox ] ;
}
- ( void ) groupSelectionInScrollView : ( id ) sender
{
if ( [ selectionOwner respondsToSelector : @ selector ( groupSelectionInScrollView ) ] = = NO )
return ;
[ ( GormGenericEditor * ) selectionOwner groupSelectionInScrollView ] ;
}
- ( void ) ungroup : ( id ) sender
{
NSLog ( @ "ungroup: selectionOwner %@" , selectionOwner ) ;
if ( [ selectionOwner respondsToSelector : @ selector ( ungroup ) ] = = NO )
return ;
[ ( GormGenericEditor * ) selectionOwner ungroup ] ;
}
2004-12-28 02:25:18 +00:00
/ * * Classes actions * /
2003-08-03 09:01:48 +00:00
- ( void ) createSubclass : ( id ) sender
{
[ ( GormDocument * ) [ self activeDocument ] createSubclass : sender ] ;
}
- ( void ) loadClass : ( id ) sender
{
// Call the current document and create the class
// descibed by the header
[ ( GormDocument * ) [ self activeDocument ] loadClass : sender ] ;
}
- ( void ) createClassFiles : ( id ) sender
{
[ ( GormDocument * ) [ self activeDocument ] createClassFiles : sender ] ;
}
- ( void ) instantiateClass : ( id ) sender
{
[ ( GormDocument * ) [ self activeDocument ] instantiateClass : sender ] ;
}
- ( void ) addAttributeToClass : ( id ) sender
{
[ ( GormDocument * ) [ self activeDocument ] addAttributeToClass : sender ] ;
}
- ( void ) remove : ( id ) sender
{
[ ( GormDocument * ) [ self activeDocument ] remove : sender ] ;
}
2004-12-28 02:25:18 +00:00
/ * * Palettes Actions . . . * /
2003-08-03 09:01:48 +00:00
- ( void ) inspector : ( id ) sender
{
[ [ [ self inspectorsManager ] panel ] makeKeyAndOrderFront : self ] ;
}
- ( void ) palettes : ( id ) sender
{
[ [ [ self palettesManager ] panel ] makeKeyAndOrderFront : self ] ;
}
- ( void ) loadPalette : ( id ) sender
{
[ [ self palettesManager ] openPalette : sender ] ;
}
2004-12-28 02:25:18 +00:00
/ * * Testing methods . . . * /
2004-07-27 06:20:45 +00:00
2003-08-03 09:01:48 +00:00
- ( void ) deferredEndTesting : ( id ) sender
{
[ [ NSRunLoop currentRunLoop ]
performSelector : @ selector ( endTesting : )
target : self
argument : nil
order : 5000
modes : [ NSArray arrayWithObjects :
NSDefaultRunLoopMode ,
NSModalPanelRunLoopMode ,
NSEventTrackingRunLoopMode , nil ] ] ;
}
- ( id ) endTesting : ( id ) sender
{
if ( isTesting = = NO )
2003-01-02 06:17:15 +00:00
{
2003-08-03 09:01:48 +00:00
return nil ;
}
else
{
NSNotificationCenter * nc = [ NSNotificationCenter defaultCenter ] ;
NSUserDefaults * defaults ;
NSEnumerator * e ;
id val ;
2005-02-05 14:11:57 +00:00
2003-08-03 09:01:48 +00:00
CREATE_AUTORELEASE _POOL ( pool ) ;
[ nc postNotificationName : IBWillEndTestingInterfaceNotification
object : self ] ;
/ *
* Make sure windows will go away when the container is destroyed .
* /
e = [ [ testContainer nameTable ] objectEnumerator ] ;
while ( ( val = [ e nextObject ] ) ! = nil )
{
if ( [ val isKindOfClass : [ NSWindow class ] ] = = YES )
{
[ val close ] ;
}
}
2005-02-05 14:11:57 +00:00
/ *
* Make sure any peripheral windows : font panels , etc . which are brought
* up by the interface being tested are also closed .
* /
e = [ [ self windows ] objectEnumerator ] ;
while ( ( val = [ e nextObject ] ) ! = nil )
{
if ( [ testingWindows containsObject : val ] = = NO &&
[ val isKindOfClass : [ NSWindow class ] ] &&
[ val isVisible ] )
{
[ val orderOut : self ] ;
}
}
2003-08-03 09:01:48 +00:00
// prevent saving of this , if the menuLocations have not previously been set .
if ( menuLocations ! = nil )
{
defaults = [ NSUserDefaults standardUserDefaults ] ;
[ defaults setObject : menuLocations forKey : @ "NSMenuLocations" ] ;
DESTROY ( menuLocations ) ;
}
[ self setMainMenu : mainMenu ] ;
2004-09-13 00:05:58 +00:00
[ self setApplicationIconImage : gormImage ] ;
2004-05-30 03:02:05 +00:00
NS_DURING
{
[ self setServicesMenu : servicesMenu ] ;
}
NS_HANDLER
{
NSDebugLog ( @ "Exception while setting services menu" ) ;
}
NS_ENDHANDLER
2004-09-13 00:05:58 +00:00
2004-05-16 21:20:14 +00:00
[ mainMenu display ] ; // bring it to the front . . .
2003-08-03 09:01:48 +00:00
isTesting = NO ;
if ( [ selectionOwner conformsToProtocol : @ protocol ( IBEditors ) ] = = YES )
{
2004-04-11 14:05:41 +00:00
[ selectionOwner makeSelectionVisible : YES ] ;
2003-08-03 09:01:48 +00:00
}
[ nc postNotificationName : IBDidEndTestingInterfaceNotification
object : self ] ;
2004-05-08 15:42:27 +00:00
2005-02-05 14:11:57 +00:00
DESTROY ( testingWindows ) ;
2003-08-03 09:01:48 +00:00
RELEASE ( pool ) ;
2004-05-08 15:42:27 +00:00
2003-08-03 09:01:48 +00:00
return self ;
}
}
- ( void ) finishLaunching
{
NSBundle * bundle ;
NSString * path ;
/ *
* establish registration domain defaults from file .
* /
bundle = [ NSBundle mainBundle ] ;
path = [ bundle pathForResource : @ "Defaults" ofType : @ "plist" ] ;
if ( path ! = nil )
{
NSDictionary * dict ;
dict = [ NSDictionary dictionaryWithContentsOfFile : path ] ;
if ( dict ! = nil )
{
NSUserDefaults * defaults = [ NSUserDefaults standardUserDefaults ] ;
[ defaults registerDefaults : dict ] ;
}
2003-01-02 06:17:15 +00:00
}
2003-08-03 09:01:48 +00:00
[ self setDelegate : self ] ;
[ super finishLaunching ] ;
2003-01-02 06:17:15 +00:00
}
2003-08-03 09:01:48 +00:00
- ( void ) handleNotification : ( NSNotification * ) notification
2003-01-09 05:52:19 +00:00
{
2003-08-03 09:01:48 +00:00
NSString * name = [ notification name ] ;
id obj = [ notification object ] ;
2003-01-09 05:52:19 +00:00
2003-08-03 09:01:48 +00:00
if ( [ name isEqual : IBSelectionChangedNotification ] )
1999-12-08 15:04:57 +00:00
{
1999-12-08 20:54:05 +00:00
/ *
2003-08-03 09:01:48 +00:00
* If we are connecting - stop it - a change in selection must mean
* that the connection process has ended .
1999-12-08 20:54:05 +00:00
* /
2003-08-03 09:01:48 +00:00
if ( [ self isConnecting ] = = YES )
2003-01-01 17:50:17 +00:00
{
2003-08-03 09:01:48 +00:00
[ self stopConnecting ] ;
2003-01-01 17:50:17 +00:00
}
2003-08-03 09:01:48 +00:00
[ selectionOwner makeSelectionVisible : NO ] ;
selectionOwner = obj ;
[ [ self inspectorsManager ] updateSelection ] ;
}
else if ( [ name isEqual : IBWillCloseDocumentNotification ] )
{
[ documents removeObjectIdenticalTo : obj ] ;
1999-12-08 15:04:57 +00:00
}
}
2003-01-17 03:55:55 +00:00
- ( void ) awakeFromNib
{
// set the menu . . .
mainMenu = ( NSMenu * ) gormMenu ;
2003-05-24 11:11:18 +00:00
// for cascadePoint
cascadePoint = NSZeroPoint ;
2003-01-17 03:55:55 +00:00
}
1999-12-16 18:06:22 +00:00
1999-12-08 15:04:57 +00:00
- ( GormInspectorsManager * ) inspectorsManager
{
if ( inspectorsManager = = nil )
{
2004-12-19 13:39:56 +00:00
inspectorsManager = ( GormInspectorsManager * ) [ GormInspectorsManager sharedInspectorManager ] ;
1999-12-08 15:04:57 +00:00
}
return inspectorsManager ;
}
2001-05-08 09:43:11 +00:00
1999-12-17 17:22:18 +00:00
- ( BOOL ) isConnecting
1999-12-15 15:29:27 +00:00
{
1999-12-17 21:53:06 +00:00
return isConnecting ;
1999-12-15 15:29:27 +00:00
}
1999-12-17 17:22:18 +00:00
- ( BOOL ) isTestingInterface
1999-12-17 12:48:37 +00:00
{
1999-12-17 17:22:18 +00:00
return isTesting ;
1999-12-17 12:48:37 +00:00
}
1999-12-17 21:53:06 +00:00
- ( NSImage * ) linkImage
{
return linkImage ;
}
2002-11-18 20:54:26 +00:00
2000-01-04 16:25:39 +00:00
- ( id ) miniaturize : ( id ) sender
{
2003-05-10 21:19:25 +00:00
NSWindow * window = [ ( GormDocument * ) [ self activeDocument ] window ] ;
2000-01-04 16:25:39 +00:00
[ window miniaturize : self ] ;
return nil ;
}
1999-12-08 15:04:57 +00:00
2001-07-06 17:10:51 +00:00
- ( BOOL ) application : ( NSApplication * ) application openFile : ( NSString * ) fileName
{
2004-05-13 05:13:36 +00:00
GormDocument * doc = AUTORELEASE ( [ GormDocument new ] ) ;
2001-07-06 17:10:51 +00:00
[ documents addObject : doc ] ;
if ( [ doc loadDocument : fileName ] = = nil )
{
[ documents removeObjectIdenticalTo : doc ] ;
doc = nil ;
}
else
{
2003-11-11 22:25:13 +00:00
[ [ doc window ] orderFrontRegardless ] ;
[ [ doc window ] makeKeyWindow ] ;
2001-07-06 17:10:51 +00:00
}
return ( doc ! = nil ) ;
}
1999-12-08 15:04:57 +00:00
- ( GormPalettesManager * ) palettesManager
{
if ( palettesManager = = nil )
{
palettesManager = [ GormPalettesManager new ] ;
}
return palettesManager ;
}
- ( id < IBSelectionOwners > ) selectionOwner
{
2003-05-10 21:19:25 +00:00
return ( id < IBSelectionOwners > ) selectionOwner ;
1999-12-08 15:04:57 +00:00
}
- ( id ) selectedObject
{
return [ [ selectionOwner selection ] lastObject ] ;
}
1999-12-16 18:06:22 +00:00
1999-12-17 21:53:06 +00:00
- ( void ) startConnecting
1999-12-17 12:48:37 +00:00
{
1999-12-17 21:53:06 +00:00
if ( isConnecting = = YES )
{
1999-12-18 08:55:31 +00:00
return ;
1999-12-17 21:53:06 +00:00
}
if ( connectDestination = = nil || connectSource = = nil )
{
return ;
}
2000-01-04 16:25:39 +00:00
if ( [ [ self activeDocument ] containsObject : connectDestination ] = = NO )
1999-12-17 21:53:06 +00:00
{
NSLog ( @ "Oops - connectDestination not in active document" ) ;
return ;
}
2000-01-04 16:25:39 +00:00
if ( [ [ self activeDocument ] containsObject : connectSource ] = = NO )
1999-12-17 21:53:06 +00:00
{
NSLog ( @ "Oops - connectSource not in active document" ) ;
return ;
}
isConnecting = YES ;
[ [ self inspectorsManager ] updateSelection ] ;
1999-12-17 12:48:37 +00:00
}
1999-12-17 17:22:18 +00:00
- ( void ) stopConnecting
{
1999-12-18 08:55:31 +00:00
[ self displayConnectionBetween : nil and : nil ] ;
1999-12-17 21:53:06 +00:00
isConnecting = NO ;
2005-01-31 06:32:16 +00:00
connectSource = nil ;
connectDestination = nil ;
1999-12-17 12:48:37 +00:00
}
1999-12-16 18:06:22 +00:00
- ( BOOL ) validateMenuItem : ( NSMenuItem * ) item
{
2000-01-04 16:25:39 +00:00
GormDocument * active = ( GormDocument * ) [ self activeDocument ] ;
SEL action = [ item action ] ;
2004-01-01 05:08:28 +00:00
GormClassManager * cm = [ active classManager ] ;
2004-08-13 01:37:18 +00:00
NSArray * s = [ selectionOwner selection ] ;
1999-12-16 18:06:22 +00:00
2004-08-13 22:19:47 +00:00
// temporarily disabling this functionality . . . .
2004-11-27 10:56:40 +00:00
/ *
2004-08-13 22:19:47 +00:00
if ( sel_eq ( action , @ selector ( loadClass : ) ) )
{
return NO ;
}
2004-11-27 10:56:40 +00:00
* /
2004-08-13 22:19:47 +00:00
2000-01-04 16:25:39 +00:00
if ( sel_eq ( action , @ selector ( close : ) )
|| sel_eq ( action , @ selector ( miniaturize : ) )
|| sel_eq ( action , @ selector ( save : ) )
1999-12-16 18:06:22 +00:00
|| sel_eq ( action , @ selector ( saveAs : ) )
|| sel_eq ( action , @ selector ( saveAll : ) ) )
{
2000-01-04 16:25:39 +00:00
if ( active = = nil )
1999-12-16 18:06:22 +00:00
return NO ;
}
2003-12-25 13:04:17 +00:00
else if ( sel_eq ( action , @ selector ( revertToSaved : ) ) )
1999-12-16 18:06:22 +00:00
{
2000-01-04 17:46:26 +00:00
if ( active = = nil || [ active documentPath ] = = nil
|| [ [ active window ] isDocumentEdited ] = = NO )
1999-12-16 18:06:22 +00:00
return NO ;
}
2003-12-25 13:04:17 +00:00
else if ( sel_eq ( action , @ selector ( testInterface : ) ) )
1999-12-16 18:06:22 +00:00
{
2000-01-04 16:25:39 +00:00
if ( active = = nil )
1999-12-16 18:06:22 +00:00
return NO ;
}
2003-12-25 13:04:17 +00:00
else if ( sel_eq ( action , @ selector ( copy : ) ) )
1999-12-16 18:06:22 +00:00
{
2004-08-13 01:37:18 +00:00
if ( [ s count ] = = 0 )
1999-12-16 18:06:22 +00:00
return NO ;
2004-08-13 01:37:18 +00:00
else
{
id o = [ s objectAtIndex : 0 ] ;
NSString * n = [ active nameForObject : o ] ;
if ( [ n isEqual : @ "NSOwner" ] || [ n isEqual : @ "NSFirst" ] )
{
return NO ;
}
}
1999-12-16 18:06:22 +00:00
return [ selectionOwner respondsToSelector : @ selector ( copySelection ) ] ;
}
2003-12-25 13:04:17 +00:00
else if ( sel_eq ( action , @ selector ( cut : ) ) )
1999-12-16 18:06:22 +00:00
{
2004-08-13 01:37:18 +00:00
if ( [ s count ] = = 0 )
1999-12-16 18:06:22 +00:00
return NO ;
2004-08-13 01:37:18 +00:00
else
{
id o = [ s objectAtIndex : 0 ] ;
NSString * n = [ active nameForObject : o ] ;
if ( [ n isEqual : @ "NSOwner" ] || [ n isEqual : @ "NSFirst" ] )
{
return NO ;
}
}
1999-12-16 18:06:22 +00:00
return ( [ selectionOwner respondsToSelector : @ selector ( copySelection ) ]
&& [ selectionOwner respondsToSelector : @ selector ( deleteSelection ) ] ) ;
}
2003-12-25 13:04:17 +00:00
else if ( sel_eq ( action , @ selector ( delete : ) ) )
1999-12-16 18:06:22 +00:00
{
2004-08-13 01:37:18 +00:00
if ( [ s count ] = = 0 )
1999-12-16 18:06:22 +00:00
return NO ;
2004-08-13 01:37:18 +00:00
else
{
id o = [ s objectAtIndex : 0 ] ;
NSString * n = [ active nameForObject : o ] ;
if ( [ n isEqual : @ "NSOwner" ] || [ n isEqual : @ "NSFirst" ] )
{
return NO ;
}
}
1999-12-16 18:06:22 +00:00
return [ selectionOwner respondsToSelector : @ selector ( deleteSelection ) ] ;
}
2003-12-25 13:04:17 +00:00
else if ( sel_eq ( action , @ selector ( paste : ) ) )
1999-12-16 18:06:22 +00:00
{
2004-08-14 00:53:20 +00:00
if ( [ s count ] = = 0 )
return NO ;
else
2004-08-13 01:37:18 +00:00
{
2004-08-14 00:53:20 +00:00
id o = [ s objectAtIndex : 0 ] ;
NSString * n = [ active nameForObject : o ] ;
if ( [ n isEqual : @ "NSOwner" ] || [ n isEqual : @ "NSFirst" ] )
{
return NO ;
}
2004-08-13 01:37:18 +00:00
}
1999-12-16 18:06:22 +00:00
return [ selectionOwner respondsToSelector : @ selector ( pasteInSelection ) ] ;
}
2003-12-25 13:04:17 +00:00
else if ( sel_eq ( action , @ selector ( setName : ) ) )
1999-12-16 18:06:22 +00:00
{
1999-12-22 10:13:18 +00:00
NSString * n ;
id o ;
if ( [ s count ] = = 0 )
{
return NO ;
}
if ( [ s count ] > 1 )
{
return NO ;
}
o = [ s objectAtIndex : 0 ] ;
2000-01-04 16:25:39 +00:00
n = [ active nameForObject : o ] ;
1999-12-22 10:13:18 +00:00
if ( [ n isEqual : @ "NSOwner" ] || [ n isEqual : @ "NSFirst" ]
2003-12-25 05:50:05 +00:00
|| [ n isEqual : @ "NSFont" ] || [ n isEqual : @ "NSMenu" ] )
{
return NO ;
}
2003-12-30 05:39:20 +00:00
else if ( ! [ active isTopLevelObject : o ] )
1999-12-22 10:13:18 +00:00
{
return NO ;
}
1999-12-16 18:06:22 +00:00
}
2003-12-25 13:04:17 +00:00
else if ( sel_eq ( action , @ selector ( createSubclass : ) ) ||
sel_eq ( action , @ selector ( loadClass : ) ) ||
sel_eq ( action , @ selector ( createClassFiles : ) ) ||
sel_eq ( action , @ selector ( instantiateClass : ) ) ||
sel_eq ( action , @ selector ( addAttributeToClass : ) ) ||
sel_eq ( action , @ selector ( remove : ) ) )
2003-01-01 17:50:17 +00:00
{
2003-12-30 05:39:20 +00:00
if ( active = = nil )
2003-01-01 17:50:17 +00:00
{
return NO ;
}
2003-12-30 05:39:20 +00:00
if ( ! [ active isEditingClasses ] )
2003-01-01 17:50:17 +00:00
{
return NO ;
}
2003-12-30 05:39:20 +00:00
2004-05-19 01:36:37 +00:00
if ( sel_eq ( action , @ selector ( createSubclass : ) ) )
{
NSArray * s = [ selectionOwner selection ] ;
id o = nil ;
NSString * name = nil ;
if ( [ s count ] = = 0 || [ s count ] > 1 )
return NO ;
o = [ s objectAtIndex : 0 ] ;
name = [ o className ] ;
if ( [ active classIsSelected ] = = NO )
{
return NO ;
}
if ( [ name isEqual : @ "FirstResponder" ] )
return NO ;
}
2004-01-01 05:08:28 +00:00
2004-11-07 19:32:57 +00:00
if ( sel_eq ( action , @ selector ( createClassFiles : ) ) ||
2004-01-01 05:08:28 +00:00
sel_eq ( action , @ selector ( remove : ) ) )
{
id o = nil ;
NSString * name = nil ;
if ( [ s count ] = = 0 )
{
return NO ;
}
if ( [ s count ] > 1 )
{
return NO ;
}
o = [ s objectAtIndex : 0 ] ;
name = [ o className ] ;
if ( ! [ cm isCustomClass : name ] )
{
return NO ;
}
2004-05-19 01:36:37 +00:00
2004-05-22 16:25:35 +00:00
// if ( [ name isEqual : @ "FirstResponder" ] )
// return NO ;
2004-01-01 05:08:28 +00:00
}
2004-05-19 01:36:37 +00:00
2003-12-30 05:39:20 +00:00
if ( sel_eq ( action , @ selector ( instantiateClass : ) ) )
{
id o = nil ;
NSString * name = nil ;
if ( [ s count ] = = 0 )
{
return NO ;
}
if ( [ s count ] > 1 )
{
return NO ;
}
2004-05-19 01:36:37 +00:00
if ( [ active classIsSelected ] = = NO )
{
return NO ;
}
2003-12-30 05:39:20 +00:00
o = [ s objectAtIndex : 0 ] ;
name = [ o className ] ;
if ( name ! = nil )
{
id cm = [ self classManager ] ;
2004-05-19 01:36:37 +00:00
return [ cm canInstantiateClassNamed : name ] ;
2003-12-30 05:39:20 +00:00
}
}
2003-01-01 17:50:17 +00:00
}
2003-12-25 13:04:17 +00:00
else if ( sel_eq ( action , @ selector ( loadSound : ) ) ||
sel_eq ( action , @ selector ( loadImage : ) ) ||
sel_eq ( action , @ selector ( debug : ) ) )
2003-01-01 17:50:17 +00:00
{
2003-12-30 05:39:20 +00:00
if ( active = = nil )
2003-01-01 17:50:17 +00:00
{
return NO ;
}
}
1999-12-16 18:06:22 +00:00
return YES ;
}
2001-05-08 09:43:11 +00:00
- ( NSMenu * ) classMenu
{
return classMenu ;
}
2004-05-01 13:41:47 +00:00
- ( void ) unhide : ( id ) sender
{
[ super unhide : sender ] ;
2004-05-08 15:42:27 +00:00
if ( ! isTesting )
{
id document = [ self activeDocument ] ;
id window = [ document window ] ;
[ ( GormDocument * ) document setDocumentActive : NO ] ;
[ ( GormDocument * ) document setDocumentActive : YES ] ;
[ window orderFront : sender ] ;
2004-05-16 21:20:14 +00:00
[ [ self mainMenu ] display ] ;
2004-05-08 15:42:27 +00:00
}
2004-05-01 13:41:47 +00:00
}
2004-05-08 20:04:13 +00:00
- ( BOOL ) documentNameIsUnique : ( NSString * ) filename
{
NSEnumerator * en = [ documents objectEnumerator ] ;
id document ;
BOOL unique = YES ;
while ( ( document = [ en nextObject ] ) ! = nil )
{
NSString * docPath = [ document documentPath ] ;
if ( [ docPath isEqual : filename ] )
{
unique = NO ;
break ;
}
}
return unique ;
}
1999-12-08 15:04:57 +00:00
@ end
2003-08-23 01:04:36 +00:00
// custom class additions . . .
@ implementation GSClassSwapper ( GormCustomClassAdditions )
2004-08-28 15:05:35 +00:00
+ ( void ) setIsInInterfaceBuilder : ( BOOL ) flag
{
_isInInterfaceBuilder = flag ;
}
2003-08-23 01:04:36 +00:00
- ( BOOL ) isInInterfaceBuilder
{
2004-08-28 15:05:35 +00:00
return _isInInterfaceBuilder ;
2003-08-23 01:04:36 +00:00
}
@ end
2003-10-25 20:56:14 +00:00
// these are temporary until the deprecated templates are removed . . .
// // // // // // // // // // // // // // // // // // // // // // // // // // // //
// DEPRECATED TEMPLATES //
// // // // // // // // // // // // // // // // // // // // // // // // // // // //
2003-08-23 01:04:36 +00:00
@ interface NSWindowTemplate ( GormCustomClassAdditions )
- ( BOOL ) isInInterfaceBuilder ;
@ end
@ implementation NSWindowTemplate ( GormCustomClassAdditions )
- ( BOOL ) isInInterfaceBuilder
{
return YES ;
}
@ end
2003-10-25 20:56:14 +00:00
@ interface NSViewTemplate ( GormCustomClassAdditions )
- ( BOOL ) isInInterfaceBuilder ;
@ end
@ implementation NSViewTemplate ( GormCustomClassAdditions )
- ( BOOL ) isInInterfaceBuilder
{
return YES ;
}
@ end
@ interface NSTextTemplate ( GormCustomClassAdditions )
- ( BOOL ) isInInterfaceBuilder ;
@ end
@ implementation NSTextTemplate ( GormCustomClassAdditions )
- ( BOOL ) isInInterfaceBuilder
{
return YES ;
}
@ end
@ interface NSTextViewTemplate ( GormCustomClassAdditions )
- ( BOOL ) isInInterfaceBuilder ;
@ end
@ implementation NSTextViewTemplate ( GormCustomClassAdditions )
- ( BOOL ) isInInterfaceBuilder
{
return YES ;
}
@ end
@ interface NSMenuTemplate ( GormCustomClassAdditions )
- ( BOOL ) isInInterfaceBuilder ;
@ end
@ implementation NSMenuTemplate ( GormCustomClassAdditions )
- ( BOOL ) isInInterfaceBuilder
{
return YES ;
}
@ end
@ interface NSControlTemplate ( GormCustomClassAdditions )
- ( BOOL ) isInInterfaceBuilder ;
@ end
@ implementation NSControlTemplate ( GormCustomClassAdditions )
- ( BOOL ) isInInterfaceBuilder
{
return YES ;
}
@ end
@ interface NSButtonTemplate ( GormCustomClassAdditions )
- ( BOOL ) isInInterfaceBuilder ;
@ end
@ implementation NSButtonTemplate ( GormCustomClassAdditions )
- ( BOOL ) isInInterfaceBuilder
{
return YES ;
}
@ end
// // // // // // // // // // // // // // // // // // // // // // // // // // // //
// END OF DEPRECATED TEMPLATES //
// // // // // // // // // // // // // // // // // // // // // // // // // // // //
1999-12-08 15:04:57 +00:00