Save/restore fixes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@5517 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1999-12-15 11:12:52 +00:00
parent f6fb99002f
commit 5936da8904
3 changed files with 108 additions and 99 deletions

View file

@ -1,3 +1,7 @@
Wed Dec 15 11:12:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
Archive save/restore fixes.
Tue Dec 14 20:13:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
Enough for today.

View file

@ -428,7 +428,7 @@ static NSImage *classesImage = nil;
}
else
{
NSLog(@"Strange - removing editor without link from edited object");
NSLog(@"Strange - removing editor without link from %@", anObject);
}
}
@ -484,99 +484,6 @@ static NSImage *classesImage = nil;
}
}
- (void) encodeWithCoder: (NSCoder*)aCoder
{
NSMutableArray *editorInfo;
NSEnumerator *enumerator;
id<IBConnectors> con;
id obj;
/*
* Map all connector sources and destinations to their name strings.
*/
editorInfo = [NSMutableArray new];
enumerator = [connections objectEnumerator];
while ((con = [enumerator nextObject]) != nil)
{
if ([con isKindOfClass: [GormObjectToEditor class]] == YES)
{
[editorInfo addObject: con];
}
else if ([con isKindOfClass: [GormEditorToParent class]] == YES)
{
[editorInfo addObject: con];
}
else
{
NSString *name;
id obj;
obj = [con source];
name = [self nameForObject: obj];
[con setSource: name];
obj = [con destination];
name = [self nameForObject: obj];
[con setDestination: name];
}
}
/*
* Remove objects and connections that shouldn't be archived.
* All editors are closed (this removes their links).
*/
enumerator = [editorInfo objectEnumerator];
while ((con = [enumerator nextObject]) != nil)
{
if ([con isKindOfClass: [GormObjectToEditor class]] == YES)
{
[[con destination] close];
}
}
RELEASE(editorInfo);
[nameTable removeObjectForKey: @"NSOwner"];
[nameTable removeObjectForKey: @"NSFirst"];
/*
* Archive self into file
*/
[super encodeWithCoder: aCoder];
/*
* Restore removed objects.
*/
[nameTable setObject: filesOwner forKey: @"NSOwner"];
[nameTable setObject: firstResponder forKey: @"NSFirst"];
/*
* Map all connector source and destination names to their objects.
*/
enumerator = [connections objectEnumerator];
while ((con = [enumerator nextObject]) != nil)
{
NSString *name;
id obj;
name = (NSString*)[con source];
obj = [self objectForName: name];
[con setSource: obj];
name = (NSString*)[con destination];
obj = [self objectForName: name];
[con setDestination: obj];
}
/*
* Restore basic editor information.
*/
enumerator = [nameTable objectEnumerator];
while ((obj = [enumerator nextObject]) != nil)
{
if ([obj isKindOfClass: [NSWindow class]] == YES
|| [obj isKindOfClass: [NSMenu class]] == YES)
{
[[self openEditorForObject: obj] activate];
}
}
}
- (id) init
{
self = [super init];
@ -905,7 +812,7 @@ static NSImage *classesImage = nil;
* This editor wants to give up the selection. Go through all the known
* editors (with links in the connections array) and try to find one
* that wants to take over the selection. Activate whatever editor we
* find (or re-activate the one we already have).
* find (if any).
*/
while ((c = [enumerator nextObject]) != nil)
{
@ -915,12 +822,11 @@ static NSImage *classesImage = nil;
if (e != editor && [e wantsSelection] == YES)
{
editor = e;
[e activate];
break;
}
}
}
[editor activate];
}
- (void) setName: (NSString*)aName forObject: (id)object
@ -1042,6 +948,11 @@ static NSImage *classesImage = nil;
- (id) saveDocument: (id)sender
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
NSMutableArray *editorInfo;
NSEnumerator *enumerator;
id<IBConnectors> con;
id obj;
BOOL archiveResult;
if (documentPath == nil || [documentPath isEqualToString: @""])
{
@ -1051,16 +962,108 @@ static NSImage *classesImage = nil;
[nc postNotificationName: IBWillSaveDocumentNotification
object: self];
if ([NSArchiver archiveRootObject: self toFile: documentPath] == NO)
/*
* Map all connector sources and destinations to their name strings.
*/
editorInfo = [NSMutableArray new];
enumerator = [connections objectEnumerator];
while ((con = [enumerator nextObject]) != nil)
{
if ([con isKindOfClass: [GormObjectToEditor class]] == YES)
{
[editorInfo addObject: con];
}
else if ([con isKindOfClass: [GormEditorToParent class]] == YES)
{
[editorInfo addObject: con];
}
else
{
NSString *name;
id obj;
obj = [con source];
name = [self nameForObject: obj];
[con setSource: name];
obj = [con destination];
name = [self nameForObject: obj];
[con setDestination: name];
}
}
/*
* Remove objects and connections that shouldn't be archived.
* All editors are closed (this removes their links).
*/
enumerator = [editorInfo objectEnumerator];
while ((con = [enumerator nextObject]) != nil)
{
if ([con isKindOfClass: [GormObjectToEditor class]] == YES)
{
[[con destination] close];
}
}
enumerator = [editorInfo objectEnumerator];
while ((con = [enumerator nextObject]) != nil)
{
if ([connections indexOfObjectIdenticalTo: con] != NSNotFound)
{
NSLog(@"Argh - not all editor linkss removed");
break;
}
}
RELEASE(editorInfo);
[nameTable removeObjectForKey: @"NSOwner"];
[nameTable removeObjectForKey: @"NSFirst"];
archiveResult = [NSArchiver archiveRootObject: self toFile: documentPath];
/*
* Restore removed objects.
*/
[nameTable setObject: filesOwner forKey: @"NSOwner"];
[nameTable setObject: firstResponder forKey: @"NSFirst"];
/*
* Map all connector source and destination names to their objects.
*/
enumerator = [connections objectEnumerator];
while ((con = [enumerator nextObject]) != nil)
{
NSString *name;
id obj;
name = (NSString*)[con source];
obj = [self objectForName: name];
[con setSource: obj];
name = (NSString*)[con destination];
obj = [self objectForName: name];
[con setDestination: obj];
}
/*
* Restore basic editor information.
*/
enumerator = [nameTable objectEnumerator];
while ((obj = [enumerator nextObject]) != nil)
{
if ([obj isKindOfClass: [NSWindow class]] == YES
|| [obj isKindOfClass: [NSMenu class]] == YES)
{
[[self openEditorForObject: obj] activate];
}
}
if (archiveResult == NO)
{
NSRunAlertPanel(NULL, @"Could not save document",
@"OK", NULL, NULL);
return nil;
}
[window setDocumentEdited: NO];
[window setTitleWithRepresentedFilename: documentPath];
[nc postNotificationName: IBWillSaveDocumentNotification
[nc postNotificationName: IBDidSaveDocumentNotification
object: self];
return self;
}

View file

@ -116,6 +116,7 @@
NSMutableArray *subeditors;
NSPoint mouseDownPoint;
BOOL shouldBeginDrag;
BOOL isClosed;
NSPasteboard *dragPb;
}
- (BOOL) acceptsTypeFromArray: (NSArray*)types;
@ -244,6 +245,7 @@
{
[document resignSelectionForEditor: self];
}
[document editor: self didCloseForObject: edited];
}
- (void) closeSubeditors