Rearrangement, refactoring and a memory leak fix.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@19296 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2004-05-13 05:13:36 +00:00
parent 4b58c2c8c1
commit a840e3a7ee
12 changed files with 227 additions and 174 deletions

View file

@ -1,3 +1,30 @@
2004-05-13 01:03 Gregory John Casamento <greg_casamento@yahoo.com>
NOTE: These changes might unstabilize things a bit.
* Gorm.m: The document is now autoreleased when it is instantiated.
This change was made in [Gorm application:openFile:],[Gorm open:],
[Gorm newGormDocument:].
* GormDocument.m: Addition of a method called
[GormDocument _closeAllEditors] this closes all of the editors from
the handleNotification method before the any objects are ultimately
released. Removal of old, commented out GormFontManager implementation.
Streamlined the dealloc method to make certain everything is released.
Also changed the window in the init method so that it doesn't release itself
when it's closed by the user. This allows for a more controlled shutdown.
* GormDocument.h: Minor code cleanup.
* GormGenericEditor.[hm]: Added activate, closed ivars. Also added code
in close and activate to make use of them. Added code in dealloc to call
[GormGenericEditor close] if there the flag indicates the editor is
open. Also moved some common, trivial, operations to the parent class
implementation of initWithObject:inDocument:.
* GormObjectEditor.m: Added code in close to remove the document from the
map. This eliminates a crash which was occurring.
* GormSoundEditor.m: Same.
* GormImageEditor.m: Same.
* GormViewEditor.m: Re-arranged the initWithObject:inDocument:.
* GormWindowEditor.m: Same.
* GormMenuEditor.m: Same.
2004-05-10 21:45 Gregory John Casamento <greg_casamento@yahoo.com>
* GormDocument.m: [GormDocument handleNotification:] was failing

23
Gorm.m
View file

@ -117,7 +117,6 @@ NSString *GormResizeCellNotification = @"GormResizeCellNotification";
// do not decode super (it would try to morph into theClass ! )
[aCoder decodeValueOfObjCType: @encode(id) at: &theClass];
theFrame = [aCoder decodeRect];
//NSLog(@"Decoding proxy : %@", theClass);
RETAIN(theClass); // release in dealloc of GSNibItem...
return self;
@ -129,7 +128,6 @@ NSString *GormResizeCellNotification = @"GormResizeCellNotification";
theFrame = [aCoder decodeRect];
[aCoder decodeValueOfObjCType: @encode(unsigned int)
at: &autoresizingMask];
//NSLog(@"Decoding proxy : %@", theClass);
RETAIN(theClass); // release in dealloc of GSNibItem...
return self;
@ -578,10 +576,10 @@ NSString *GormResizeCellNotification = @"GormResizeCellNotification";
/***********************************************************************/
- (void) open: (id) sender
{
GormDocument *doc = [GormDocument new];
GormDocument *doc = AUTORELEASE([GormDocument new]);
[documents addObject: doc];
RELEASE(doc);
// RELEASE(doc);
if ([doc openDocument: sender] == nil)
{
[documents removeObjectIdenticalTo: doc];
@ -614,9 +612,9 @@ NSString *GormResizeCellNotification = @"GormResizeCellNotification";
//include Modules Menu
- (void) newGormDocument : (id) sender
{
id doc = [GormDocument new];
id doc = AUTORELEASE([GormDocument new]);
[documents addObject: doc];
RELEASE(doc);
// RELEASE(doc);
switch ([sender tag])
{
case 0:
@ -678,13 +676,15 @@ NSString *GormResizeCellNotification = @"GormResizeCellNotification";
if (doc != nil)
{
[documents addObject: doc];
// RELEASE(doc);
[[doc window] makeKeyAndOrderFront: self];
}
}
- (void) close: (id)sender
{
NSWindow *window = [(GormDocument *)[self activeDocument] window];
GormDocument *document = (GormDocument *)[self activeDocument];
NSWindow *window = [document window];
[window setReleasedWhenClosed: YES];
[window performClose: self];
@ -1137,14 +1137,11 @@ NSString *GormResizeCellNotification = @"GormResizeCellNotification";
}
else if ([name isEqual: IBWillCloseDocumentNotification])
{
RETAIN(obj); // release below...
[documents removeObjectIdenticalTo: obj];
AUTORELEASE(obj);
// AUTORELEASE(obj); // let the document go, once everything is done...
}
}
- (void) awakeFromNib
{
// set the menu...
@ -1192,10 +1189,10 @@ NSString *GormResizeCellNotification = @"GormResizeCellNotification";
- (BOOL)application:(NSApplication *)application openFile:(NSString *)fileName
{
GormDocument *doc = [GormDocument new];
GormDocument *doc = AUTORELEASE([GormDocument new]);
[documents addObject: doc];
RELEASE(doc);
// RELEASE(doc);
if ([doc loadDocument: fileName] == nil)
{
[documents removeObjectIdenticalTo: doc];

View file

@ -69,7 +69,7 @@
NSMutableArray *hidden;
NSMutableSet *sounds;
NSMutableSet *images;
// NSFileWrapper *wrapper;
// NSMutableArray *editors;
}
- (void) addConnector: (id<IBConnectors>)aConnector;
- (NSArray*) allConnectors;

View file

@ -107,44 +107,6 @@ NSString *GSCustomClassMap = @"GSCustomClassMap";
}
@end
/*
@implementation GormFontManager
- (NSImage*) imageForViewer
{
static NSImage *image = nil;
if (image == nil)
{
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForImageResource: @"GormFontManager"];
image = [[NSImage alloc] initWithContentsOfFile: path];
}
return image;
}
- (NSString*) inspectorClassName
{
return @"GormNotApplicableInspector";
}
- (NSString*) connectInspectorClassName
{
return @"GormConnectionInspector";
}
- (NSString*) sizeInspectorClassName
{
return @"GormNotApplicableInspector";
}
- (NSString*) classInspectorClassName
{
return @"GormNotApplicableInspector";
}
- (NSString *)className
{
return @"NSFontManager";
}
@end
*/
/*
@ -205,14 +167,6 @@ static NSImage *classesImage = nil;
}
}
/*
- (void) awakeWithContext: (NSDictionary *)context
{
// do nothing.. This is defined to override the one in GSNibContainer.
NSLog(@"In awakeWithContext");
}
*/
- (void) addConnector: (id<IBConnectors>)aConnector
{
if ([connections indexOfObjectIdenticalTo: aConnector] == NSNotFound)
@ -295,7 +249,6 @@ static NSImage *classesImage = nil;
[[self openEditorForObject: anObject] activate];
if ([anObject isKindOfClass: [NSWindow class]] == YES)
{
// RETAIN(anObject);
[anObject setReleasedWhenClosed: NO];
}
}
@ -701,7 +654,7 @@ static NSImage *classesImage = nil;
toPasteboard: (NSPasteboard*)aPasteboard
{
NSEnumerator *enumerator;
NSMutableSet *editors;
NSMutableSet *editorSet;
id obj;
NSMutableData *data;
NSArchiver *archiver;
@ -710,14 +663,14 @@ static NSImage *classesImage = nil;
* Remove all editors from the selected objects before archiving
* and restore them afterwards.
*/
editors = [NSMutableSet new];
editorSet = [NSMutableSet new];
enumerator = [anArray objectEnumerator];
while ((obj = [enumerator nextObject]) != nil)
{
id editor = [self editorForObject: obj create: NO];
if (editor != nil)
{
[editors addObject: editor];
[editorSet addObject: editor];
[editor deactivate];
}
}
@ -730,12 +683,12 @@ static NSImage *classesImage = nil;
[archiver encodeRootObject: anArray];
// reactivate
enumerator = [editors objectEnumerator];
enumerator = [editorSet objectEnumerator];
while ((obj = [enumerator nextObject]) != nil)
{
[obj activate];
}
RELEASE(editors);
RELEASE(editorSet);
[aPasteboard declareTypes: [NSArray arrayWithObject: aType]
owner: self];
@ -772,6 +725,21 @@ static NSImage *classesImage = nil;
return self;
}
/*
// For debugging
- (id) retain
{
NSLog(@"Document being retained... %d: %@", [self retainCount], self);
return [super retain];
}
- (oneway void) release
{
NSLog(@"Document being released... %d: %@", [self retainCount], self);
[super release];
}
*/
- (void) pasteboardChangedOwner: (NSPasteboard*)sender
{
NSDebugLog(@"Owner changed for %@", sender);
@ -780,8 +748,6 @@ static NSImage *classesImage = nil;
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver: self];
[window setDelegate: nil];
[window performClose: self];
RELEASE(classManager);
RELEASE(classEditor);
RELEASE(hidden);
@ -796,6 +762,7 @@ static NSImage *classesImage = nil;
RELEASE(savedEditors);
RELEASE(scrollView);
RELEASE(classesScrollView);
RELEASE(window);
[super dealloc];
}
@ -1357,6 +1324,11 @@ static NSImage *classesImage = nil;
[connections removeObjectIdenticalTo: [links objectAtIndex: 0]];
}
/*
* Add to the master list of editors for this document
*/
// [editors removeObjectIdenticalTo: anEditor];
/*
* Make sure that this editor is not the selection owner.
*/
@ -1398,6 +1370,15 @@ static NSImage *classesImage = nil;
[link setSource: anObject];
[link setDestination: editor];
[connections addObject: link];
// add to the list...
/*
if(![editors containsObject: editor])
{
[editors addObject: editor];
}
*/
RELEASE(link);
if (anEditor == nil)
{
@ -1480,6 +1461,28 @@ static NSImage *classesImage = nil;
[savedEditors removeAllObjects];
}
- (void) _closeAllEditors
{
NSEnumerator *enumerator;
id con;
// close all editors attached to objects...
enumerator = [connections objectEnumerator];
while ((con = [enumerator nextObject]) != nil)
{
if ([con isKindOfClass: [GormObjectToEditor class]] == YES)
{
[[con destination] close];
}
}
// close the editors in the document window...
[objectsView close];
[imagesView close];
[soundsView close];
}
- (void) handleNotification: (NSNotification*)aNotification
{
NSString *name = [aNotification name];
@ -1490,9 +1493,6 @@ static NSImage *classesImage = nil;
NSEnumerator *enumerator;
id obj;
[nc postNotificationName: IBWillCloseDocumentNotification
object: self];
enumerator = [nameTable objectEnumerator];
while ((obj = [enumerator nextObject]) != nil)
{
@ -1506,6 +1506,7 @@ static NSImage *classesImage = nil;
}
else if ([obj isKindOfClass: [NSWindow class]] == YES)
{
[obj setReleasedWhenClosed: NO];
if ([obj isVisible] == YES)
{
[hidden addObject: obj];
@ -1514,8 +1515,13 @@ static NSImage *classesImage = nil;
}
}
// deactivate the document...
[self setDocumentActive: NO];
[self setSelectionFromEditor: nil];
[self _closeAllEditors];
// [editors makeObjectsPerformSelector: @selector(close)]; // close all of the editors...
[nc postNotificationName: IBWillCloseDocumentNotification
object: self];
[nc removeObserver: self]; // stop listening to all notifications.
}
else if ([name isEqual: NSWindowDidBecomeKeyNotification] == YES)
@ -1633,8 +1639,10 @@ static NSImage *classesImage = nil;
alpha: 1.0 ];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// editors = [NSMutableArray new];
classManager = [[GormClassManager alloc] init];
classEditor = [[GormClassEditor alloc] initWithDocument: self];
/*
* NB. We must retain the map values (object names) as the nameTable
* may not hold identical name objects, but merely equal strings.
@ -1657,7 +1665,7 @@ static NSImage *classesImage = nil;
defer: NO];
[window setMinSize: [window frame].size];
[window setTitle: _(@"UNTITLED")];
[window setReleasedWhenClosed: NO];
[window setDelegate: self];
[nc addObserver: self
@ -1770,7 +1778,6 @@ static NSImage *classesImage = nil;
objectsView = [[GormObjectEditor alloc] initWithObject: nil
inDocument: self];
AUTORELEASE(objectsView);
[objectsView setFrame: mainRect];
[objectsView setAutoresizingMask:
NSViewHeightSizable|NSViewWidthSizable];
@ -1788,7 +1795,6 @@ static NSImage *classesImage = nil;
imagesView = [[GormImageEditor alloc] initWithObject: nil
inDocument: self];
AUTORELEASE(imagesView);
[imagesView setFrame: mainRect];
[imagesView setAutoresizingMask: NSViewHeightSizable|NSViewWidthSizable];
[imagesScrollView setDocumentView: imagesView];
@ -1805,7 +1811,6 @@ static NSImage *classesImage = nil;
soundsView = [[GormSoundEditor alloc] initWithObject: nil
inDocument: self];
AUTORELEASE(soundsView);
[soundsView setFrame: mainRect];
[soundsView setAutoresizingMask: NSViewHeightSizable|NSViewWidthSizable];
[soundsScrollView setDocumentView: soundsView];
@ -1912,6 +1917,13 @@ static NSImage *classesImage = nil;
}
}
/*
// add editors here to the list...
// [editors addObject: classEditor];
[editors addObject: objectsView];
[editors addObject: imagesView];
[editors addObject: soundsView];
*/
}
return self;
}
@ -3310,8 +3322,8 @@ static NSImage *classesImage = nil;
}
return YES;
}
- (BOOL) windowShouldClose: (id)sender
{
return [self couldCloseDocument];

View file

@ -22,6 +22,7 @@
- (BOOL) activate
{
activated = YES;
[[self window] makeKeyAndOrderFront: self];
return YES;
}
@ -87,6 +88,7 @@
- (void) close
{
closed = YES;
[self deactivate];
[self closeSubeditors];
}
@ -103,6 +105,13 @@
- (id) initWithObject: (id)anObject inDocument: (id<IBDocuments>)aDocument
{
if((self = [super init]) != nil)
{
// don't retain the document...
document = aDocument;
closed = NO;
activated = NO;
}
return self;
}
@ -117,6 +126,7 @@
- (void) deactivate
{
activated = NO;
}
- (void) copySelection
@ -130,7 +140,10 @@
- (void) dealloc
{
RELEASE(objects);
if(closed == NO)
[self close];
// RELEASE(objects); // FIXME: This will leak...
[super dealloc];
}

View file

@ -194,13 +194,11 @@ static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperat
return self;
}
self = [super init];
self = [super initWithObject: anObject inDocument: aDocument];
if (self != nil)
{
NSButtonCell *proto;
document = aDocument;
[self registerForDraggedTypes: [NSArray arrayWithObjects:
NSFilenamesPboardType, nil]];
@ -238,6 +236,13 @@ static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperat
return self;
}
- (void) close
{
[super close];
[[NSNotificationCenter defaultCenter] removeObserver: self];
NSMapRemove(docMap,document);
}
- (void) makeSelectionVisible: (BOOL)flag
{
if (flag == YES && selected != nil)
@ -489,6 +494,7 @@ static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperat
RELEASE(name);
RELEASE(path);
RELEASE(image);
[super dealloc];
}
- (void) setImageName: (NSString *)aName

View file

@ -111,9 +111,6 @@ static NSMapTable *docMap = 0;
return NO;
}
- (void) copySelection
{
if (selected != nil)
@ -252,10 +249,10 @@ static NSMapTable *docMap = 0;
{
}
- (void) handleNotification: (NSNotification*)aNotification
{
NSString *name = [aNotification name];
if([name isEqual: GormResizeCellNotification])
{
NSDebugLog(@"Recieved notification");
@ -263,7 +260,6 @@ static NSMapTable *docMap = 0;
}
}
/*
* Initialisation - register to receive DnD with our own types.
*/
@ -279,7 +275,7 @@ static NSMapTable *docMap = 0;
return self;
}
self = [super init];
self = [super initWithObject: anObject inDocument: aDocument];
if (self != nil)
{
NSButtonCell *proto;
@ -324,6 +320,13 @@ static NSMapTable *docMap = 0;
return self;
}
- (void) close
{
[super close];
[[NSNotificationCenter defaultCenter] removeObserver: self];
NSMapRemove(docMap,document);
}
- (void) makeSelectionVisible: (BOOL)flag
{
if (flag == YES && selected != nil)

View file

@ -175,6 +175,8 @@ extern NSString *GormResizeCellNotification;
id selected;
NSPasteboard *dragPb;
NSString *dragType;
BOOL closed;
BOOL activated;
}
// selection methods...
- (void) selectObjects: (NSArray*)objects;
@ -214,15 +216,9 @@ extern NSString *GormResizeCellNotification;
- (id) changeSelection: (id)sender;
@end
@interface GormObjectEditor : GormGenericEditor // <IBEditors, IBSelectionOwners>
@interface GormObjectEditor : GormGenericEditor
{
// NSMutableArray *objects;
// id<IBDocuments> document;
// id selected;
// NSPasteboard *dragPb;
// NSString *dragType;
}
// + (GormObjectEditor*) editorForDocument: (id<IBDocuments>)aDocument;
- (void) draggedImage: (NSImage*)i endedAt: (NSPoint)p deposited: (BOOL)f;
- (unsigned int) draggingSourceOperationMaskForLocal: (BOOL)flag;
- (BOOL) acceptsTypeFromArray: (NSArray*)types;
@ -230,13 +226,8 @@ extern NSString *GormResizeCellNotification;
- (void) resetObject: (id)anObject;
@end
@interface GormSoundEditor : GormGenericEditor // <IBEditors, IBSelectionOwners>
@interface GormSoundEditor : GormGenericEditor
{
// NSMutableArray *objects;
// id<IBDocuments> document;
// id selected;
// NSPasteboard *dragPb;
// NSString *dragType;
}
// don't redeclare methods already declared in protocols.
+ (GormSoundEditor*) editorForDocument: (id<IBDocuments>)aDocument;
@ -244,7 +235,7 @@ extern NSString *GormResizeCellNotification;
- (unsigned int) draggingSourceOperationMaskForLocal: (BOOL)flag;
@end
@interface GormImageEditor : GormGenericEditor // <IBEditors, IBSelectionOwners>
@interface GormImageEditor : GormGenericEditor
{
}
// don't redeclare methods already declared in protocols.

View file

@ -171,6 +171,7 @@ static NSMapTable *docMap = 0;
- (void) handleNotification: (NSNotification*)aNotification
{
NSString *name = [aNotification name];
if([name isEqual: GormResizeCellNotification])
{
NSDebugLog(@"Recieved notification");
@ -193,13 +194,11 @@ static NSMapTable *docMap = 0;
return self;
}
self = [super init];
self = [super initWithObject: anObject inDocument: aDocument];
if (self != nil)
{
NSButtonCell *proto;
document = aDocument;
[self registerForDraggedTypes: [NSArray arrayWithObjects:
IBObjectPboardType, GormLinkPboardType, nil]];
@ -237,6 +236,13 @@ static NSMapTable *docMap = 0;
return self;
}
- (void) close
{
[super close];
[[NSNotificationCenter defaultCenter] removeObserver: self];
NSMapRemove(docMap,document);
}
- (void) makeSelectionVisible: (BOOL)flag
{
if (flag == YES && selected != nil)

View file

@ -213,7 +213,6 @@ static BOOL currently_displaying = NO;
- (void) close
{
if (closed == NO)
{
[self deactivate];
@ -248,7 +247,6 @@ static BOOL currently_displaying = NO;
if (closed == NO)
[self close];
// RELEASE(_editedObject);
[super dealloc];
}
@ -256,18 +254,15 @@ static BOOL currently_displaying = NO;
inDocument: (id<IBDocuments>)aDocument
{
NSMutableArray *draggedTypes;
_editedObject = (NSView*)anObject;
if ((self = [super initWithFrame: [_editedObject frame]]) == nil)
return nil;
RETAIN(_editedObject);
ASSIGN(_editedObject, (NSView*)anObject);
if ((self = [super initWithFrame: [_editedObject frame]]) != nil)
{
// we do not retain the document...
document = aDocument;
draggedTypes = [NSMutableArray arrayWithObject: GormLinkPboardType];
if ([_editedObject respondsToSelector: @selector(setImage:)])
{
[draggedTypes addObject: GormImagePboardType];
@ -279,14 +274,13 @@ static BOOL currently_displaying = NO;
[self registerForDraggedTypes: draggedTypes];
activated = NO;
closed = NO;
}
return self;
}
- (void) editedObjectFrameDidChange: (id) sender
{
[self setFrame: [_editedObject frame]];

View file

@ -227,13 +227,12 @@
- (void) dealloc
{
if (closed == NO)
{
[self close];
}
RELEASE(edited);
// RELEASE(edited);
RELEASE(selection);
RELEASE(subeditors);
RELEASE(document);
// RELEASE(document);
[super dealloc];
}
@ -282,13 +281,21 @@
- (id) initWithObject: (id)anObject
inDocument: (id<IBDocuments>)aDocument
{
_displaySelection = YES;
_editedObject = (NSView*)anObject;
edited = anObject;
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
if ((self = [super initWithFrame: NSZeroRect]) == nil)
return nil;
[nc addObserver: self
selector: @selector(handleNotification:)
name: IBWillCloseDocumentNotification
object: aDocument];
_displaySelection = YES;
_editedObject = (NSView*)anObject;
ASSIGN(edited, anObject);
RETAIN(edited);
// we don't retain the document...
document = aDocument;
[self registerForDraggedTypes: [NSArray arrayWithObjects:
@ -400,5 +407,4 @@
// [document setSelectionFromEditor: self];
[self makeSelectionVisible: NO];
}
@end

View file

@ -384,7 +384,6 @@
- (BOOL) activate
{
// NSAssert(isClosed == NO, NSInternalInconsistencyException);
if (original == nil)
{
NSWindow *w;
@ -435,7 +434,6 @@
- (void) close
{
// NSAssert(isClosed == NO, NSInternalInconsistencyException);
isClosed = YES;
[[NSNotificationCenter defaultCenter] removeObserver: self];
@ -446,11 +444,8 @@
}
[self closeSubeditors];
[self deactivate];
[edited close];
[document editor: self didCloseForObject: edited];
}
@ -503,10 +498,9 @@
{
[self close];
}
RELEASE(edited);
// RELEASE(edited);
RELEASE(selection);
RELEASE(subeditor);
RELEASE(document);
[super dealloc];
}
@ -666,10 +660,14 @@ void _attachAll(NSMenu *menu, id document)
- (id) initWithObject: (id)anObject inDocument: (id<IBDocuments>)aDocument
{
self = [super init];
ASSIGN(document, aDocument);
if(self != nil)
{
document = aDocument;
ASSIGN(edited, anObject);
RETAIN(edited);
selection = [NSMutableArray new];
rep = [edited menuRepresentation];
/*
* Permit views and connections to be dragged in to the window.
*/
@ -680,7 +678,7 @@ void _attachAll(NSMenu *menu, id document)
* Make sure that all our menu items are attached in the document.
*/
_attachAll(edited, document);
// [document attachObjects: [edited itemArray] toParent: edited];
}
return self;
}