1999-12-08 15:04:57 +00:00
|
|
|
/* Gorm.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-15 15:29:27 +00:00
|
|
|
NSString *IBWillBeginTestingInterfaceNotification
|
|
|
|
= @"IBWillBeginTestingInterfaceNotification";
|
|
|
|
NSString *IBDidBeginTestingInterfaceNotification
|
|
|
|
= @"IBDidBeginTestingInterfaceNotification";
|
|
|
|
NSString *IBWillEndTestingInterfaceNotification
|
|
|
|
= @"IBWillEndTestingInterfaceNotification";
|
|
|
|
NSString *IBDidEndTestingInterfaceNotification
|
|
|
|
= @"IBDidEndTestingInterfaceNotification";
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
@class InfoPanel;
|
|
|
|
|
|
|
|
@implementation Gorm
|
|
|
|
|
|
|
|
- (id<IBDocuments>) activeDocument
|
|
|
|
{
|
1999-12-08 15:19:11 +00:00
|
|
|
return activeDocument;
|
1999-12-08 15:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) applicationShouldTerminate: (NSApplication*)sender
|
|
|
|
{
|
1999-12-14 19:55:18 +00:00
|
|
|
NSEnumerator *enumerator = [[self windows] objectEnumerator];
|
|
|
|
NSWindow *win;
|
1999-12-08 15:04:57 +00:00
|
|
|
BOOL edited = NO;
|
|
|
|
|
1999-12-14 19:55:18 +00:00
|
|
|
while ((win = [enumerator nextObject]) != nil)
|
1999-12-08 15:04:57 +00:00
|
|
|
{
|
1999-12-14 19:55:18 +00:00
|
|
|
if ([win isDocumentEdited] == YES)
|
1999-12-08 15:04:57 +00:00
|
|
|
{
|
|
|
|
edited = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (edited == YES)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
result = NSRunAlertPanel(NULL, @"There are edited windows",
|
|
|
|
@"Review Unsaved", @"Cancel", @"Quit Anyway");
|
|
|
|
if (result == NSAlertAlternateReturn)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
else if (result != NSAlertOtherReturn)
|
|
|
|
{
|
1999-12-14 19:55:18 +00:00
|
|
|
enumerator = [[self windows] objectEnumerator];
|
|
|
|
while ((win = [enumerator nextObject]) != nil)
|
1999-12-08 15:04:57 +00:00
|
|
|
{
|
|
|
|
if ([win isDocumentEdited] == YES)
|
|
|
|
{
|
|
|
|
[win performClose: self];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
1999-12-15 15:29:27 +00:00
|
|
|
- (id) beginTesting: (id)sender
|
|
|
|
{
|
|
|
|
if (isTesting == YES)
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
|
|
|
|
|
|
|
[nc postNotificationName: IBWillBeginTestingInterfaceNotification
|
|
|
|
object: self];
|
|
|
|
isTesting = YES;
|
1999-12-15 21:43:57 +00:00
|
|
|
if ([selectionOwner conformsToProtocol: @protocol(IBEditors)] == YES)
|
|
|
|
{
|
|
|
|
[(id<IBEditors>)selectionOwner makeSelectionVisible: NO];
|
|
|
|
}
|
1999-12-15 15:29:27 +00:00
|
|
|
[nc postNotificationName: IBDidBeginTestingInterfaceNotification
|
|
|
|
object: self];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
|
|
|
|
|
|
|
[nc removeObserver: self];
|
1999-12-15 15:29:27 +00:00
|
|
|
RELEASE(gormMenu);
|
1999-12-08 15:04:57 +00:00
|
|
|
RELEASE(infoPanel);
|
|
|
|
RELEASE(inspectorsManager);
|
|
|
|
RELEASE(palettesManager);
|
|
|
|
RELEASE(documents);
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
1999-12-15 15:29:27 +00:00
|
|
|
- (id) endTesting: (id)sender
|
|
|
|
{
|
|
|
|
if (isTesting == NO)
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
|
|
|
|
|
|
|
[nc postNotificationName: IBWillEndTestingInterfaceNotification
|
|
|
|
object: self];
|
|
|
|
isTesting = NO;
|
1999-12-15 21:43:57 +00:00
|
|
|
if ([selectionOwner conformsToProtocol: @protocol(IBEditors)] == YES)
|
|
|
|
{
|
|
|
|
[(id<IBEditors>)selectionOwner makeSelectionVisible: YES];
|
|
|
|
}
|
1999-12-15 15:29:27 +00:00
|
|
|
[nc postNotificationName: IBDidEndTestingInterfaceNotification
|
|
|
|
object: self];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSMenu*) gormMenu
|
|
|
|
{
|
|
|
|
return gormMenu;
|
|
|
|
}
|
|
|
|
|
1999-12-08 15:19:11 +00:00
|
|
|
- (void) handleNotification: (NSNotification*)notification
|
|
|
|
{
|
|
|
|
NSString *name = [notification name];
|
|
|
|
id obj = [notification object];
|
|
|
|
|
|
|
|
if ([name isEqual: IBSelectionChangedNotification])
|
|
|
|
{
|
|
|
|
selectionOwner = [notification object];
|
|
|
|
[[self inspectorsManager] updateSelection];
|
|
|
|
}
|
|
|
|
else if ([name isEqual: IBWillCloseDocumentNotification])
|
|
|
|
{
|
|
|
|
RETAIN(obj);
|
|
|
|
[documents removeObjectIdenticalTo: obj];
|
|
|
|
AUTORELEASE(obj);
|
|
|
|
if (obj == (id)activeDocument)
|
|
|
|
{
|
|
|
|
activeDocument = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self != nil)
|
|
|
|
{
|
|
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
|
|
|
|
|
|
|
documents = [NSMutableArray new];
|
|
|
|
[nc addObserver: self
|
1999-12-08 15:19:11 +00:00
|
|
|
selector: @selector(handleNotification:)
|
1999-12-08 15:04:57 +00:00
|
|
|
name: IBSelectionChangedNotification
|
|
|
|
object: nil];
|
1999-12-08 15:19:11 +00:00
|
|
|
[nc addObserver: self
|
|
|
|
selector: @selector(handleNotification:)
|
|
|
|
name: IBWillCloseDocumentNotification
|
|
|
|
object: nil];
|
1999-12-08 20:54:05 +00:00
|
|
|
|
1999-12-15 15:29:27 +00:00
|
|
|
gormMenu = [[NSMenu alloc] initWithTitle: @"Gorm"];
|
|
|
|
|
1999-12-08 20:54:05 +00:00
|
|
|
/*
|
|
|
|
* Make sure the palettes manager exists, so that the editors and
|
|
|
|
* inspectors provided in the standard palettes are available.
|
|
|
|
*/
|
|
|
|
[self palettesManager];
|
1999-12-08 15:04:57 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (GormInspectorsManager*) inspectorsManager
|
|
|
|
{
|
|
|
|
if (inspectorsManager == nil)
|
|
|
|
{
|
|
|
|
inspectorsManager = [GormInspectorsManager new];
|
|
|
|
}
|
|
|
|
return inspectorsManager;
|
|
|
|
}
|
|
|
|
|
1999-12-15 15:29:27 +00:00
|
|
|
- (BOOL) isTestingInterface
|
|
|
|
{
|
|
|
|
return isTesting;
|
|
|
|
}
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
- (id) makeNewDocument: (id) sender
|
|
|
|
{
|
|
|
|
id doc = [GormDocument new];
|
|
|
|
|
|
|
|
[documents addObject: doc];
|
|
|
|
[doc setDocumentActive: YES];
|
1999-12-08 15:19:11 +00:00
|
|
|
activeDocument = doc;
|
1999-12-08 15:04:57 +00:00
|
|
|
RELEASE(doc);
|
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) openDocument: (id) sender
|
|
|
|
{
|
|
|
|
GormDocument *doc = [GormDocument new];
|
|
|
|
|
|
|
|
[documents addObject: doc];
|
|
|
|
RELEASE(doc);
|
|
|
|
if ([doc openDocument: sender] == nil)
|
|
|
|
{
|
|
|
|
[documents removeObjectIdenticalTo: doc];
|
|
|
|
doc = nil;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[doc setDocumentActive: YES];
|
1999-12-08 15:19:11 +00:00
|
|
|
activeDocument = doc;
|
1999-12-08 15:04:57 +00:00
|
|
|
}
|
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) openPalette: (id) sender
|
|
|
|
{
|
|
|
|
return [[self palettesManager] openPalette: sender];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (GormPalettesManager*) palettesManager
|
|
|
|
{
|
|
|
|
if (palettesManager == nil)
|
|
|
|
{
|
|
|
|
palettesManager = [GormPalettesManager new];
|
|
|
|
}
|
|
|
|
return palettesManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) runInfoPanel: (id) sender
|
|
|
|
{
|
|
|
|
if (infoPanel == nil)
|
|
|
|
{
|
|
|
|
infoPanel = [InfoPanel new];
|
|
|
|
}
|
|
|
|
[infoPanel orderFront: nil];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) runGormInspectors: (id) sender
|
|
|
|
{
|
|
|
|
[[[self inspectorsManager] panel] orderFront: nil];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) runGormPalettes: (id) sender
|
|
|
|
{
|
|
|
|
[[[self palettesManager] panel] orderFront: self];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1999-12-15 15:29:27 +00:00
|
|
|
- (id) revertToSaved: (id)sender
|
|
|
|
{
|
|
|
|
NSLog(@"Revert to save not yet implemented");
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) saveAll: (id)sender
|
|
|
|
{
|
|
|
|
NSEnumerator *e = [documents objectEnumerator];
|
|
|
|
id doc;
|
|
|
|
|
|
|
|
while ((doc = [e nextObject]) != nil)
|
|
|
|
{
|
|
|
|
if ([[doc window] isDocumentEdited] == YES)
|
|
|
|
{
|
|
|
|
[doc saveDocument: sender];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
- (id) saveAsDocument: (id)sender
|
|
|
|
{
|
1999-12-08 15:19:11 +00:00
|
|
|
return [(id)activeDocument saveAsDocument: sender];
|
1999-12-08 15:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) saveDocument: (id)sender
|
|
|
|
{
|
1999-12-08 15:19:11 +00:00
|
|
|
return [(id)activeDocument saveDocument: sender];
|
1999-12-08 15:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id<IBSelectionOwners>) selectionOwner
|
|
|
|
{
|
|
|
|
return selectionOwner;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) selectedObject
|
|
|
|
{
|
|
|
|
return [[selectionOwner selection] lastObject];
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
NSAutoreleasePool *pool;
|
|
|
|
NSMenu *aMenu;
|
|
|
|
NSMenu *mainMenu;
|
|
|
|
NSMenu *windowsMenu;
|
|
|
|
NSMenuItem *menuItem;
|
1999-12-15 15:29:27 +00:00
|
|
|
Gorm *theApp;
|
1999-12-08 15:04:57 +00:00
|
|
|
|
|
|
|
pool = [NSAutoreleasePool new];
|
|
|
|
initialize_gnustep_backend ();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Install an instance of Gorm as the application so that the app
|
|
|
|
* can conform to the IB protocol
|
|
|
|
*/
|
1999-12-15 15:29:27 +00:00
|
|
|
NSApp = theApp = [Gorm new];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
1999-12-15 15:29:27 +00:00
|
|
|
mainMenu = [theApp gormMenu];
|
1999-12-08 15:04:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up info menu.
|
|
|
|
*/
|
|
|
|
aMenu = [NSMenu new];
|
|
|
|
[aMenu addItemWithTitle: @"Info Panel..."
|
|
|
|
action: @selector(runInfoPanel:)
|
|
|
|
keyEquivalent: @""];
|
|
|
|
[aMenu addItemWithTitle: @"Help..."
|
|
|
|
action: NULL
|
|
|
|
keyEquivalent: @"?"];
|
|
|
|
menuItem = [mainMenu addItemWithTitle: @"Info"
|
|
|
|
action: NULL
|
|
|
|
keyEquivalent: @""];
|
|
|
|
[mainMenu setSubmenu: aMenu forItem: menuItem];
|
|
|
|
RELEASE(aMenu);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up document menu.
|
|
|
|
*/
|
|
|
|
aMenu = [NSMenu new];
|
|
|
|
[aMenu addItemWithTitle: @"Open..."
|
|
|
|
action: @selector(openDocument:)
|
|
|
|
keyEquivalent: @"o"];
|
|
|
|
[aMenu addItemWithTitle: @"New Application"
|
|
|
|
action: @selector(makeNewDocument:)
|
|
|
|
keyEquivalent: @"n"];
|
|
|
|
[aMenu addItemWithTitle: @"Save"
|
|
|
|
action: @selector(saveDocument:)
|
|
|
|
keyEquivalent: @"s"];
|
|
|
|
[aMenu addItemWithTitle: @"Save As..."
|
|
|
|
action: @selector(saveAsDocument:)
|
|
|
|
keyEquivalent: @"S"];
|
1999-12-15 15:29:27 +00:00
|
|
|
[aMenu addItemWithTitle: @"Save All"
|
|
|
|
action: @selector(saveAll:)
|
|
|
|
keyEquivalent: @""];
|
|
|
|
[aMenu addItemWithTitle: @"Revert to Saved"
|
|
|
|
action: @selector(revertToSaved:)
|
|
|
|
keyEquivalent: @"u"];
|
|
|
|
[aMenu addItemWithTitle: @"Test Interface"
|
|
|
|
action: @selector(beginTesting:)
|
|
|
|
keyEquivalent: @"r"];
|
1999-12-08 15:04:57 +00:00
|
|
|
menuItem = [mainMenu addItemWithTitle: @"Document"
|
|
|
|
action: NULL
|
|
|
|
keyEquivalent: @""];
|
|
|
|
[mainMenu setSubmenu: aMenu forItem: menuItem];
|
|
|
|
RELEASE(aMenu);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up tools menu.
|
|
|
|
*/
|
|
|
|
aMenu = [NSMenu new];
|
|
|
|
[aMenu addItemWithTitle: @"Inspector..."
|
|
|
|
action: @selector(runGormInspectors:)
|
|
|
|
keyEquivalent: @""];
|
|
|
|
[aMenu addItemWithTitle: @"Palettes..."
|
|
|
|
action: @selector(runGormPalettes:)
|
|
|
|
keyEquivalent: @""];
|
|
|
|
[aMenu addItemWithTitle: @"Load Palette..."
|
|
|
|
action: @selector(openPalette:)
|
|
|
|
keyEquivalent: @""];
|
|
|
|
menuItem = [mainMenu addItemWithTitle: @"Tools"
|
|
|
|
action: NULL
|
|
|
|
keyEquivalent: @""];
|
|
|
|
[mainMenu setSubmenu: aMenu forItem: menuItem];
|
|
|
|
RELEASE(aMenu);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up Windows menu
|
|
|
|
*/
|
|
|
|
windowsMenu = [NSMenu new];
|
|
|
|
[windowsMenu addItemWithTitle: @"Arrange"
|
|
|
|
action: @selector(arrangeInFront:)
|
|
|
|
keyEquivalent: @""];
|
|
|
|
[windowsMenu addItemWithTitle: @"Miniaturize"
|
|
|
|
action: @selector(performMiniaturize:)
|
|
|
|
keyEquivalent: @"m"];
|
|
|
|
[windowsMenu addItemWithTitle: @"Close"
|
|
|
|
action: @selector(performClose:)
|
|
|
|
keyEquivalent: @"w"];
|
|
|
|
menuItem = [mainMenu addItemWithTitle: @"Windows"
|
|
|
|
action: NULL
|
|
|
|
keyEquivalent: @""];
|
|
|
|
[mainMenu setSubmenu: windowsMenu forItem: menuItem];
|
|
|
|
RELEASE(windowsMenu);
|
|
|
|
|
|
|
|
[mainMenu addItemWithTitle: @"Quit"
|
|
|
|
action: @selector(terminate:)
|
|
|
|
keyEquivalent: @"q"];
|
|
|
|
|
|
|
|
|
|
|
|
[NSApp setMainMenu: mainMenu];
|
|
|
|
[NSApp setWindowsMenu: windowsMenu];
|
|
|
|
[mainMenu display];
|
|
|
|
|
|
|
|
{
|
|
|
|
extern BOOL NSImageDoesCaching;
|
|
|
|
extern BOOL NSImageForceCaching;
|
|
|
|
|
|
|
|
NSImageDoesCaching = YES;
|
|
|
|
//[NSObject enableDoubleReleaseCheck: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set Gorm up as its own delegate
|
|
|
|
*/
|
|
|
|
[NSApp setDelegate: NSApp];
|
1999-12-08 20:54:05 +00:00
|
|
|
|
1999-12-08 15:04:57 +00:00
|
|
|
[NSApp run];
|
|
|
|
[pool release];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|