mirror of
https://github.com/gnustep/apps-gorm.git
synced 2025-02-23 11:41:05 +00:00
Removed GormResourcesManager
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@5511 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
f08b53bd83
commit
01100bd4b6
9 changed files with 208 additions and 322 deletions
|
@ -1,3 +1,7 @@
|
|||
Tue Dec 14 19:53:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
Removed GormResourcesManager - merged functionality into GormDocument
|
||||
|
||||
Tue Dec 14 17:33:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* GormDocument.m: Major changes - nearly all methods implemented to
|
||||
|
|
|
@ -69,8 +69,7 @@ Gorm_OBJC_FILES = \
|
|||
GormObjectEditor.m \
|
||||
GormWindowEditor.m \
|
||||
GormInspectorsManager.m \
|
||||
GormPalettesManager.m \
|
||||
GormResourcesManager.m
|
||||
GormPalettesManager.m
|
||||
|
||||
-include GNUmakefile.preamble
|
||||
|
||||
|
|
2
Gorm.h
2
Gorm.h
|
@ -143,8 +143,6 @@ extern NSString *IBDidEndTestingInterfaceNotification;
|
|||
- (void) detachObject: (id)anObject;
|
||||
- (void) detachObjects: (NSArray*)anArray;
|
||||
- (NSString*) documentPath;
|
||||
- (BOOL) documentShouldClose;
|
||||
- (void) documentWillClose;
|
||||
- (void) editor: (id<IBEditors>)anEditor didCloseForObject: (id)anObject;
|
||||
- (id<IBEditors>) editorForObject: (id)anObject
|
||||
create: (BOOL)flag;
|
||||
|
|
14
Gorm.m
14
Gorm.m
|
@ -35,13 +35,13 @@
|
|||
|
||||
- (BOOL) applicationShouldTerminate: (NSApplication*)sender
|
||||
{
|
||||
NSEnumerator *enumerator = [documents objectEnumerator];
|
||||
GormDocument *doc;
|
||||
NSEnumerator *enumerator = [[self windows] objectEnumerator];
|
||||
NSWindow *win;
|
||||
BOOL edited = NO;
|
||||
|
||||
while ((doc = [enumerator nextObject]) != nil)
|
||||
while ((win = [enumerator nextObject]) != nil)
|
||||
{
|
||||
if ([[[doc resourcesManager] window] isDocumentEdited] == YES)
|
||||
if ([win isDocumentEdited] == YES)
|
||||
{
|
||||
edited = YES;
|
||||
}
|
||||
|
@ -58,11 +58,9 @@
|
|||
}
|
||||
else if (result != NSAlertOtherReturn)
|
||||
{
|
||||
enumerator = [documents objectEnumerator];
|
||||
while ((doc = [enumerator nextObject]) != nil)
|
||||
enumerator = [[self windows] objectEnumerator];
|
||||
while ((win = [enumerator nextObject]) != nil)
|
||||
{
|
||||
NSWindow *win = [[doc resourcesManager] window];
|
||||
|
||||
if ([win isDocumentEdited] == YES)
|
||||
{
|
||||
[win performClose: self];
|
||||
|
|
|
@ -21,13 +21,15 @@
|
|||
|
||||
@interface GormDocument : GSNibContainer <IBDocuments>
|
||||
{
|
||||
GormResourcesManager *resourcesManager;
|
||||
GormFilesOwner *filesOwner;
|
||||
GormFirstResponder *firstResponder;
|
||||
GormFontManager *fontManager;
|
||||
NSString *documentPath;
|
||||
NSMapTable *objToName;
|
||||
id owner; /* Dummy object */
|
||||
NSWindow *window;
|
||||
NSMatrix *selectionView;
|
||||
NSScrollView *scrollView;
|
||||
id objectsView;
|
||||
}
|
||||
- (void) addConnector: (id<IBConnectors>)aConnector;
|
||||
- (NSArray*) allConnectors;
|
||||
|
@ -50,8 +52,7 @@
|
|||
- (void) detachObject: (id)anObject;
|
||||
- (void) detachObjects: (NSArray*)anArray;
|
||||
- (NSString*) documentPath;
|
||||
- (BOOL) documentShouldClose;
|
||||
- (void) documentWillClose;
|
||||
- (void) handleNotification: (NSNotification*)aNotification;
|
||||
- (NSString*) nameForObject: (id)anObject;
|
||||
- (id) objectForName: (NSString*)aString;
|
||||
- (NSArray*) objects;
|
||||
|
@ -60,13 +61,13 @@
|
|||
- (NSArray*) pasteType: (NSString*)aType
|
||||
fromPasteboard: (NSPasteboard*)aPasteboard
|
||||
parent: (id)parent;
|
||||
- (GormResourcesManager*) resourcesManager;
|
||||
- (void) removeConnector: (id<IBConnectors>)aConnector;
|
||||
- (id) saveAsDocument: (id)sender;
|
||||
- (id) saveDocument: (id)sender;
|
||||
- (void) setDocumentActive: (BOOL)flag;
|
||||
- (void) setName: (NSString*)aName forObject: (id)object;
|
||||
- (void) touch; /* Mark document as having been changed. */
|
||||
- (BOOL) windowShouldClose;
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
|
258
GormDocument.m
258
GormDocument.m
|
@ -29,6 +29,8 @@ NSString *IBWillSaveDocumentNotification = @"IBWillSaveDocumentNotification";
|
|||
NSString *IBDidSaveDocumentNotification = @"IBDidSaveDocumentNotification";
|
||||
NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
||||
|
||||
@class GormObjectEditor;
|
||||
|
||||
/*
|
||||
* Each document has a GormFilesOwner object that is used as a placeholder
|
||||
* for the owner of the document.
|
||||
|
@ -126,10 +128,39 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
|
||||
@implementation GormDocument
|
||||
|
||||
static NSImage *objectsImage = nil;
|
||||
static NSImage *imagesImage = nil;
|
||||
static NSImage *soundsImage = nil;
|
||||
static NSImage *classesImage = nil;
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [GormDocument class])
|
||||
{
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,7 +208,7 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
if ([anObject isKindOfClass: [NSWindow class]] == YES
|
||||
|| [anObject isKindOfClass: [NSMenu class]] == YES)
|
||||
{
|
||||
[resourcesManager addObject: anObject];
|
||||
[objectsView addObject: anObject];
|
||||
[[self openEditorForObject: anObject] activate];
|
||||
}
|
||||
}
|
||||
|
@ -290,8 +321,9 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
|
||||
- (void) dealloc
|
||||
{
|
||||
[[resourcesManager window] performClose: self];
|
||||
RELEASE(resourcesManager);
|
||||
[window setDelegate: nil];
|
||||
[window performClose: self];
|
||||
RELEASE(window);
|
||||
RELEASE(filesOwner);
|
||||
RELEASE(firstResponder);
|
||||
RELEASE(fontManager);
|
||||
|
@ -320,7 +352,7 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
if ([anObject isKindOfClass: [NSWindow class]] == YES
|
||||
|| [anObject isKindOfClass: [NSMenu class]] == YES)
|
||||
{
|
||||
[resourcesManager removeObject: anObject];
|
||||
[objectsView removeObject: anObject];
|
||||
}
|
||||
[nameTable removeObjectForKey: name];
|
||||
}
|
||||
|
@ -341,57 +373,31 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
return documentPath;
|
||||
}
|
||||
|
||||
- (BOOL) documentShouldClose
|
||||
- (void) handleNotification: (NSNotification*)aNotification
|
||||
{
|
||||
if ([[resourcesManager window] isDocumentEdited] == YES)
|
||||
if ([[aNotification name] isEqual: NSWindowWillCloseNotification] == YES)
|
||||
{
|
||||
NSString *msg;
|
||||
int result;
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||
Class winClass = [NSWindow class];
|
||||
NSEnumerator *enumerator;
|
||||
id obj;
|
||||
|
||||
if (documentPath == nil || [documentPath isEqualToString: @""])
|
||||
[nc postNotificationName: IBWillCloseDocumentNotification
|
||||
object: self];
|
||||
/*
|
||||
* Close all open windows in this document befoew we go away.
|
||||
*/
|
||||
enumerator = [nameTable objectEnumerator];
|
||||
while ((obj = [enumerator nextObject]) != nil)
|
||||
{
|
||||
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];
|
||||
if ([obj isKindOfClass: winClass] == YES)
|
||||
{
|
||||
[obj setReleasedWhenClosed: YES];
|
||||
[obj close];
|
||||
}
|
||||
}
|
||||
[self setDocumentActive: NO];
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void) documentWillClose
|
||||
{
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||
Class winClass = [NSWindow class];
|
||||
NSEnumerator *enumerator;
|
||||
id obj;
|
||||
|
||||
[nc postNotificationName: IBWillCloseDocumentNotification
|
||||
object: self];
|
||||
/*
|
||||
* Close all open windows in this document befoew we go away.
|
||||
*/
|
||||
enumerator = [nameTable objectEnumerator];
|
||||
while ((obj = [enumerator nextObject]) != nil)
|
||||
{
|
||||
if ([obj isKindOfClass: winClass] == YES)
|
||||
{
|
||||
[obj setReleasedWhenClosed: YES];
|
||||
[obj close];
|
||||
}
|
||||
}
|
||||
[self setDocumentActive: NO];
|
||||
}
|
||||
|
||||
- (void) editor: (id<IBEditors>)anEditor didCloseForObject: (id)anObject
|
||||
|
@ -576,19 +582,113 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
self = [super init];
|
||||
if (self != nil)
|
||||
{
|
||||
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;
|
||||
|
||||
objToName = NSCreateMapTableWithZone(NSNonRetainedObjectMapKeyCallBacks,
|
||||
NSNonRetainedObjectMapValueCallBacks, 128, [self zone]);
|
||||
|
||||
resourcesManager = [GormResourcesManager newManagerForDocument: self];
|
||||
|
||||
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];
|
||||
[nc addObserver: self
|
||||
selector: @selector(handleNotification:)
|
||||
name: NSWindowWillCloseNotification
|
||||
object: window];
|
||||
|
||||
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);
|
||||
|
||||
/*
|
||||
* Set up special-case dummy objects and add them to the resources mgr.
|
||||
* Set up special-case dummy objects and add them to the objects view.
|
||||
*/
|
||||
filesOwner = [GormFilesOwner new];
|
||||
[self setName: @"NSOwner" forObject: filesOwner];
|
||||
[resourcesManager addObject: filesOwner];
|
||||
[objectsView addObject: filesOwner];
|
||||
firstResponder = [GormFirstResponder new];
|
||||
[self setName: @"NSFirst" forObject: firstResponder];
|
||||
[resourcesManager addObject: firstResponder];
|
||||
[objectsView addObject: firstResponder];
|
||||
fontManager = [GormFontManager new];
|
||||
}
|
||||
return self;
|
||||
|
@ -709,7 +809,7 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
if ([obj isKindOfClass: [NSWindow class]] == YES
|
||||
|| [obj isKindOfClass: [NSMenu class]] == YES)
|
||||
{
|
||||
[resourcesManager addObject: obj];
|
||||
[objectsView addObject: obj];
|
||||
[[self openEditorForObject: obj] activate];
|
||||
}
|
||||
}
|
||||
|
@ -718,7 +818,7 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
* Finally, we set our new file name
|
||||
*/
|
||||
ASSIGN(documentPath, aFile);
|
||||
[[resourcesManager window] setTitleWithRepresentedFilename: documentPath];
|
||||
[window setTitleWithRepresentedFilename: documentPath];
|
||||
[nc postNotificationName: IBDidOpenDocumentNotification
|
||||
object: self];
|
||||
return self;
|
||||
|
@ -773,8 +873,8 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
NSPoint filePoint;
|
||||
NSPoint screenPoint;
|
||||
|
||||
filePoint = [[resourcesManager window] mouseLocationOutsideOfEventStream];
|
||||
screenPoint = [[resourcesManager window] convertBaseToScreen: filePoint];
|
||||
filePoint = [window mouseLocationOutsideOfEventStream];
|
||||
screenPoint = [window convertBaseToScreen: filePoint];
|
||||
|
||||
if ([aType isEqualToString: IBWindowPboardType] == YES)
|
||||
{
|
||||
|
@ -830,11 +930,6 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
[editor activate];
|
||||
}
|
||||
|
||||
- (GormResourcesManager*) resourcesManager
|
||||
{
|
||||
return resourcesManager;
|
||||
}
|
||||
|
||||
- (void) setName: (NSString*)aName forObject: (id)object
|
||||
{
|
||||
id oldObject;
|
||||
|
@ -969,8 +1064,8 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
@"OK", NULL, NULL);
|
||||
return nil;
|
||||
}
|
||||
[[resourcesManager window] setDocumentEdited: NO];
|
||||
[[resourcesManager window] setTitleWithRepresentedFilename: documentPath];
|
||||
[window setDocumentEdited: NO];
|
||||
[window setTitleWithRepresentedFilename: documentPath];
|
||||
|
||||
[nc postNotificationName: IBWillSaveDocumentNotification
|
||||
object: self];
|
||||
|
@ -992,7 +1087,7 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
[obj orderFront: self];
|
||||
}
|
||||
}
|
||||
[[resourcesManager window] orderFront: self];
|
||||
[window orderFront: self];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1003,7 +1098,7 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
[obj orderOut: self];
|
||||
}
|
||||
}
|
||||
[[resourcesManager window] orderOut: self];
|
||||
[window orderOut: self];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1017,7 +1112,36 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
|
||||
- (void) touch
|
||||
{
|
||||
[[resourcesManager window] setDocumentEdited: YES];
|
||||
[window setDocumentEdited: YES];
|
||||
}
|
||||
|
||||
- (BOOL) windowShouldClose
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -4,14 +4,12 @@
|
|||
@class GormDocument;
|
||||
@class GormInspectorsManager;
|
||||
@class GormPalettesManager;
|
||||
@class GormResourcesManager;
|
||||
|
||||
#include "Gorm.h"
|
||||
|
||||
#include "GormDocument.h"
|
||||
#include "GormInspectorsManager.h"
|
||||
#include "GormPalettesManager.h"
|
||||
#include "GormResourcesManager.h"
|
||||
|
||||
@interface Gorm : NSApplication <IB>
|
||||
{
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
#ifndef GORMRESOURCESMANAGER_H
|
||||
#define GORMRESOURCESMANAGER_H
|
||||
|
||||
@interface GormResourcesManager : NSObject
|
||||
{
|
||||
NSWindow *window;
|
||||
NSMatrix *selectionView;
|
||||
NSScrollView *scrollView;
|
||||
id objectsView;
|
||||
id<IBDocuments> document;
|
||||
}
|
||||
+ (GormResourcesManager*) newManagerForDocument: (id<IBDocuments>)doc;
|
||||
- (void) addObject: (id)anObject;
|
||||
- (id<IBDocuments>) document;
|
||||
- (void) removeObject: (id)anObject;
|
||||
- (NSWindow*) window;
|
||||
- (BOOL) windowShouldClose: (NSWindow*)aWindow;
|
||||
- (void) windowWillClose: (NSNotification*)aNotification;
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -1,215 +0,0 @@
|
|||
/* GormResourcesManager.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"
|
||||
|
||||
@class GormObjectEditor;
|
||||
|
||||
@implementation GormResourcesManager
|
||||
|
||||
static NSImage *objectsImage = nil;
|
||||
static NSImage *imagesImage = nil;
|
||||
static NSImage *soundsImage = nil;
|
||||
static NSImage *classesImage = nil;
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [GormResourcesManager class])
|
||||
{
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+ (GormResourcesManager*) newManagerForDocument: (id<IBDocuments>)doc
|
||||
{
|
||||
GormResourcesManager *mgr;
|
||||
|
||||
mgr = [self alloc];
|
||||
mgr->document = doc;
|
||||
mgr = [mgr init];
|
||||
return mgr;
|
||||
}
|
||||
|
||||
- (void) addObject: (id)anObject
|
||||
{
|
||||
[objectsView addObject: anObject];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[window performClose: self];
|
||||
RELEASE(window);
|
||||
RELEASE(objectsView);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id<IBDocuments>) document
|
||||
{
|
||||
return document;
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil)
|
||||
{
|
||||
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 = NSTitledWindowMask | NSClosableWindowMask
|
||||
| NSResizableWindowMask | NSMiniaturizableWindowMask;
|
||||
|
||||
window = [[NSWindow alloc] initWithContentRect: winrect
|
||||
styleMask: style
|
||||
backing: NSBackingStoreRetained
|
||||
defer: NO];
|
||||
[window setDelegate: self];
|
||||
[window setMinSize: [window frame].size];
|
||||
[window setTitle: @"UNTITLED"];
|
||||
|
||||
[nc addObserver: self
|
||||
selector: @selector(windowWillClose:)
|
||||
name: NSWindowWillCloseNotification
|
||||
object: window];
|
||||
|
||||
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: document];
|
||||
[objectsView setFrame: mainRect];
|
||||
[objectsView setAutoresizingMask: NSViewHeightSizable|NSViewWidthSizable];
|
||||
[scrollView setDocumentView: objectsView];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) removeObject: (id)anObject
|
||||
{
|
||||
[objectsView removeObject: anObject];
|
||||
}
|
||||
|
||||
- (NSWindow*) window
|
||||
{
|
||||
return window;
|
||||
}
|
||||
|
||||
- (BOOL) windowShouldClose: (NSWindow*)aWindow
|
||||
{
|
||||
return [document documentShouldClose];
|
||||
}
|
||||
|
||||
- (void) windowWillClose: (NSNotification*)aNotification
|
||||
{
|
||||
[document documentWillClose];
|
||||
}
|
||||
@end
|
||||
|
Loading…
Reference in a new issue