From: Adam M. <ama...@us...> - 2005-12-30 18:43:43
|
Update of /cvsroot/bibdesk/bibdesk In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13850 Modified Files: Tag: BR_1x BibDocument.m Log Message: Simplify save error handling; only clear change count if a save succeeded, remove save-as override, since this method works for either save type. Index: BibDocument.m =================================================================== RCS file: /cvsroot/bibdesk/bibdesk/BibDocument.m,v retrieving revision 1.307.2.290 retrieving revision 1.307.2.291 diff -C2 -d -r1.307.2.290 -r1.307.2.291 *** BibDocument.m 30 Dec 2005 05:06:38 -0000 1.307.2.290 --- BibDocument.m 30 Dec 2005 18:43:34 -0000 1.307.2.291 *************** *** 544,578 **** // returning NO keeps the document window from closing if the save was initiated by a close // action, so the user gets a second chance at fixing the problem - (BOOL)writeToFile:(NSString *)fileName ofType:(NSString *)docType{ - BOOL success = [super writeToFile:fileName ofType:docType]; - - if([self fileName]){ - // don't pass the fileName parameter, since it's likely a temp file somewhere due to the atomic save operation - NSDictionary *infoDict = [[NSDictionary alloc] initWithObjectsAndKeys:[self publications], @"publications", [self fileName], @"fileName", nil]; - [[NSApp delegate] rebuildMetadataCache:infoDict]; - [infoDict release]; - } - - return success; - } - - (IBAction)saveDocument:(id)sender{ BOOL success = YES; @try{ ! [super saveDocument:sender]; ! if([[OFPreferenceWrapper sharedPreferenceWrapper] integerForKey:BDSKAutoSaveAsRSSKey] == NSOnState && ![[self fileType] isEqualToString:@"Rich Site Summary file"]) ! [self exportAsRSS:nil]; } @catch(id exception){ ! if([exception isKindOfClass:[NSException class]] && [[exception name] isEqualToString:BDSKTeXifyException]) success = NO; ! else @throw; } ! ! // needed because of finalize changes; unfortunately, it messes up NSDocument's save mechanism by overriding the return value from writeToFile:ofType: if(success) [self performSelector:@selector(clearChangeCount) withObject:nil afterDelay:0.01]; ! else NSBeginCriticalAlertSheet(NSLocalizedString(@"Unable to save file completely.", @""), nil, nil, nil, --- 544,569 ---- // returning NO keeps the document window from closing if the save was initiated by a close // action, so the user gets a second chance at fixing the problem + // this method eventually gets called for save or save-as operations - (BOOL)writeToFile:(NSString *)fileName ofType:(NSString *)docType{ BOOL success = YES; + BOOL texified = YES; @try{ ! success = [super writeToFile:fileName ofType:docType]; } @catch(id exception){ ! if([exception isKindOfClass:[NSException class]] && [[exception name] isEqualToString:BDSKTeXifyException]){ success = NO; ! texified = NO; ! } else { @throw; + } } ! ! // needed because of finalize changes; don't send this if the save failed for any reason, though! if(success) [self performSelector:@selector(clearChangeCount) withObject:nil afterDelay:0.01]; ! else if(texified == NO) ! // we present a special sheet if the save failed due to texification; NSDocument still puts up its own save failed sheet, at least for save-as NSBeginCriticalAlertSheet(NSLocalizedString(@"Unable to save file completely.", @""), nil, nil, nil, *************** *** 580,608 **** nil, NULL, NULL, NULL, NSLocalizedString(@"If you are unable to correct the problem, you must save your file in a non-lossy encoding such as UTF-8, with accented character conversion disabled in BibDesk's preferences.", @"")); - - } ! - (IBAction)saveDocumentAs:(id)sender{ ! BOOL success = YES; ! @try{ ! [super saveDocumentAs:sender]; ! } ! @catch(id exception){ ! if([exception isKindOfClass:[NSException class]] && [[exception name] isEqualToString:BDSKTeXifyException]) ! success = NO; ! else ! @throw; } ! ! // needed because of finalize changes ! if(success) ! [self performSelector:@selector(clearChangeCount) withObject:nil afterDelay:0.01]; ! else ! NSBeginCriticalAlertSheet(NSLocalizedString(@"Unable to save file completely.", @""), ! nil, nil, nil, ! documentWindow, ! nil, NULL, NULL, NULL, ! NSLocalizedString(@"If you are unable to correct the problem, you must save your file in a non-lossy encoding such as UTF-8, with accented character conversion disabled in BibDesk's preferences.", @"")); ! } --- 571,590 ---- nil, NULL, NULL, NULL, NSLocalizedString(@"If you are unable to correct the problem, you must save your file in a non-lossy encoding such as UTF-8, with accented character conversion disabled in BibDesk's preferences.", @"")); ! // rebuild metadata cache for this document whenever we save ! if([self fileName]){ ! // don't pass the fileName parameter, since it's likely a temp file somewhere due to the atomic save operation ! NSDictionary *infoDict = [[NSDictionary alloc] initWithObjectsAndKeys:[self publications], @"publications", [self fileName], @"fileName", nil]; ! [[NSApp delegate] rebuildMetadataCache:infoDict]; ! [infoDict release]; } ! ! return success; ! } ! ! - (IBAction)saveDocument:(id)sender{ ! [super saveDocument:sender]; ! if([[OFPreferenceWrapper sharedPreferenceWrapper] integerForKey:BDSKAutoSaveAsRSSKey] == NSOnState && ![[self fileType] isEqualToString:@"Rich Site Summary file"]) ! [self exportAsRSS:nil]; } *************** *** 743,771 **** userInfo:[NSDictionary dictionary]]; NSData *data = nil; ! @try{ ! if ([aType isEqualToString:@"bibTeX database"]){ ! if([self documentStringEncoding] == 0) ! [NSException raise:@"String encoding exception" format:@"Document does not have a specified string encoding."]; ! if([[OFPreferenceWrapper sharedPreferenceWrapper] boolForKey:BDSKAutoSortForCrossrefsKey]) ! [self performSortForCrossrefs]; ! data = [self bibTeXDataForPublications:publications encoding:[self documentStringEncoding] droppingInternal:NO]; ! }else if ([aType isEqualToString:@"Rich Site Summary file"]){ ! data = [self rssDataForPublications:publications]; ! }else if ([aType isEqualToString:@"HTML"]){ ! data = [self htmlDataForSelection:NO]; ! }else if ([aType isEqualToString:@"MODS"]){ ! data = [self MODSDataForPublications:publications]; ! }else if ([aType isEqualToString:@"ATOM"]){ ! data = [self atomDataForPublications:publications]; ! }else if ([aType isEqualToString:@"RIS/Medline File"]){ ! data = [self RISDataForPublications:publications]; ! } ! } ! @catch(id exception){ ! // re-throw to ensure that we don't partially save the file (although maybe that's not a problem with atomic saves?) ! if([exception isKindOfClass:[NSException class]] && [[exception name] isEqualToString:BDSKTeXifyException]) ! data = nil; ! @throw; } return data; } --- 725,747 ---- userInfo:[NSDictionary dictionary]]; NSData *data = nil; ! ! if ([aType isEqualToString:@"bibTeX database"]){ ! if([self documentStringEncoding] == 0) ! [NSException raise:@"String encoding exception" format:@"Document does not have a specified string encoding."]; ! if([[OFPreferenceWrapper sharedPreferenceWrapper] boolForKey:BDSKAutoSortForCrossrefsKey]) ! [self performSortForCrossrefs]; ! data = [self bibTeXDataForPublications:publications encoding:[self documentStringEncoding] droppingInternal:NO]; ! }else if ([aType isEqualToString:@"Rich Site Summary file"]){ ! data = [self rssDataForPublications:publications]; ! }else if ([aType isEqualToString:@"HTML"]){ ! data = [self htmlDataForSelection:NO]; ! }else if ([aType isEqualToString:@"MODS"]){ ! data = [self MODSDataForPublications:publications]; ! }else if ([aType isEqualToString:@"ATOM"]){ ! data = [self atomDataForPublications:publications]; ! }else if ([aType isEqualToString:@"RIS/Medline File"]){ ! data = [self RISDataForPublications:publications]; } + return data; } |