Revision: 28223
http://sourceforge.net/p/bibdesk/svn/28223
Author: hofman
Date: 2023-04-19 13:57:33 +0000 (Wed, 19 Apr 2023)
Log Message:
-----------
catch exceptions from tex task launch and fail
Modified Paths:
--------------
trunk/bibdesk/BDSKTeXTask.m
trunk/bibdesk/BibDocument_Actions.m
Modified: trunk/bibdesk/BDSKTeXTask.m
===================================================================
--- trunk/bibdesk/BDSKTeXTask.m 2023-04-16 15:08:36 UTC (rev 28222)
+++ trunk/bibdesk/BDSKTeXTask.m 2023-04-19 13:57:33 UTC (rev 28223)
@@ -499,14 +499,22 @@
currentTask = [[pendingTasks lastObject] retain];
[pendingTasks removeLastObject];
- [[currentTask task] launch];
-
- if (synchronous) {
- [[currentTask task] waitUntilExit];
- success = [self invokePendingTasks];
- } else if (currentTask) {
- [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(taskFinished:) name:NSTaskDidTerminateNotification
object:[currentTask task]];
+ @try {
+ [[currentTask task] launch];
+
+ if (synchronous) {
+ [[currentTask task] waitUntilExit];
+ success = [self invokePendingTasks];
+ } else if (currentTask) {
+ [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(taskFinished:) name:NSTaskDidTerminateNotification
object:[currentTask task]];
+ }
}
+ @catch (id e) {
+ BDSKDESTROY(currentTask);
+ [pendingTasks removeAllObjects];
+ success = NO;
+ [delegate texTask:self finishedWithResult:success];
+ }
} else {
// this was the final task in the queue, or the previous one failed
BDSKDESTROY(currentTask);
Modified: trunk/bibdesk/BibDocument_Actions.m
===================================================================
--- trunk/bibdesk/BibDocument_Actions.m 2023-04-16 15:08:36 UTC (rev 28222)
+++ trunk/bibdesk/BibDocument_Actions.m 2023-04-19 13:57:33 UTC (rev 28223)
@@ -95,9 +95,33 @@
#import "BDSKColorLabelWell.h"
#import "BDSKMergeController.h"
#import "BDSKFindController.h"
+#import "NSSet_BDSKExtensions.h"
#define BDSKLyXPipePathKey @"BDSKLyXPipePath"
+@interface BDSKJournal : NSObject <NSCopying> {
+ NSString *name;
+ NSString *abbreviatedName;
+ NSString *dotlessAbbreviatedName;
+}
+
++ (NSArray *)journals;
++ (BDSKJournal *)journalForName:(NSString *)name;
++ (void)loadJournals;
+
+- (id)initWithName:(NSString *)aName abbreviatedName:(NSString
*)anAbbreviatedName;
+- (id)initWithDictionary:(NSDictionary *)dictionary;
+
+@property (nonatomic, retain) NSString *name;
+@property (nonatomic, retain) NSString *abbreviatedName;
+@property (nonatomic, readonly) NSString *dotlessAbbreviatedName;
+@property (nonatomic, readonly) NSDictionary *dictionaryValue;
+
+- (BOOL)isMatchedBy:(NSString *)name;
+
+@end
+
+
@implementation BibDocument (Actions)
#pragma mark -
@@ -1665,6 +1689,37 @@
}];
}
+- (IBAction)normalizeJournalNames:(id)sender {
+ if ([self numberOfSelectedPubs] == 0 ||
+ [self displaysFileSearch] == NSMixedState ||
+ [self hasGroupTypeSelected:BDSKExternalGroupType] ||
+ [self commitPendingEdits] == NO) {
+ NSBeep();
+ return;
+ }
+
+ NSInteger format = [sender tag];
+ BOOL didChange = NO;
+ NSMutableSet *unknownJournals = [NSMutableSet
setForCaseInsensitiveStrings];
+
+ for (BibItem *pub in [self selectedPublications]) {
+ NSString *journalName = [pub valueOfField:BDSKJournalString
inherit:NO];
+ if ([NSString isEmptyString:journalName]) continue;
+
+ BDSKJournal *journal = [BDSKJournal journalForName:journalName];
+ if (journal == nil) {
+ [unknownJournals addObject:journal];
+ continue;
+ }
+
+ NSString *newJournalName = format == 0 ? [journal name] : format == 1
? [journal abbreviatedName] : [journal dotlessAbbreviatedName];
+ if ([journalName isEqualToString:newJournalName]) continue;
+
+ [pub setField:BDSKJournalString toValue:newJournalName];
+ didChange = YES;
+ }
+}
+
#pragma mark Duplicate and Incomplete searching
// select duplicates, then allow user to delete/copy/whatever
@@ -1841,3 +1896,116 @@
}
@end
+
+#define JOURNAL_NAMES_FILENAME @"JournalNames.plist"
+
+#define NAME_KEY @"name"
+#define ABBREVIATED_KEY @"abbreviated"
+
+@implementation BDSKJournal
+
+@synthesize name, abbreviatedName, dotlessAbbreviatedName;
+@dynamic dictionaryValue;
+
+static NSMutableArray *journals = nil;
+
++ (NSArray *)journals {
+ if (journals == nil)
+ [self loadJournals];
+ return journals;
+}
+
++ (BDSKJournal *)journalForName:(NSString *)name {
+ for (BDSKJournal *journal in [self journals]) {
+ if ([journal isMatchedBy:name])
+ return journal;
+ }
+ return nil;
+}
+
++ (void)loadJournals {
+ NSURL *journalsURL = [[NSBundle mainBundle]
URLForResource:JOURNAL_NAMES_FILENAME withExtension:nil];
+ NSArray *journalDicts = [NSArray arrayWithContentsOfURL:journalsURL];
+ NSMutableArray *names = [NSMutableArray array];
+
+ if (journals == nil)
+ journals = [[NSMutableArray alloc] init];
+ else
+ [journals removeAllObjects];
+ for (NSDictionary *dict in journalDicts) {
+ BDSKJournal *journal = [[BDSKJournal alloc] initWithDictionary:dict];
+ [journals addObject:journal];
+ [names addObject:[[journal name] lowercaseString]];
+ [journal release];
+ }
+
+ journalsURL = [[[NSFileManager defaultManager]
applicationSupportDirectoryURL]
URLByAppendingPathComponent:JOURNAL_NAMES_FILENAME isDirectory:NO];
+ if ([journalsURL checkResourceIsReachableAndReturnError:NULL]) {
+ journalDicts = [NSArray arrayWithContentsOfURL:journalsURL];
+ for (NSDictionary *dict in journalDicts) {
+ BDSKJournal *journal = [[BDSKJournal alloc]
initWithDictionary:dict];
+ NSUInteger i = [names indexOfObject:[[journal name]
lowercaseString]];
+ if (i == NSNotFound)
+ [journals addObject:journal];
+ else
+ [journals replaceObjectAtIndex:i withObject:journal];
+ [journal release];
+ }
+ }
+}
+
+- (id)initWithName:(NSString *)aName abbreviatedName:(NSString
*)anAbbreviatedName {
+ self = [super init];
+ if (self) {
+ name = [aName retain];
+ abbreviatedName = [anAbbreviatedName retain];
+ dotlessAbbreviatedName = [[abbreviatedName
stringByDeletingCharactersInSet:[NSCharacterSet
characterSetWithCharactersInString:@"."]] retain];
+ }
+ return self;
+}
+
+- (id)initWithDictionary:(NSDictionary *)dictionary {
+ return [self initWithName:[dictionary objectForKey:NAME_KEY]
abbreviatedName:[dictionary objectForKey:ABBREVIATED_KEY]];
+}
+
+- (id)copyWithZone:(NSZone *)zone {
+ return [[BDSKJournal allocWithZone:zone] initWithName:[self name]
abbreviatedName:[self abbreviatedName]];
+}
+
+- (void)dealloc {
+ BDSKDESTROY(name);
+ BDSKDESTROY(abbreviatedName);
+ BDSKDESTROY(dotlessAbbreviatedName);
+ [super dealloc];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other)
+ return YES;
+ if (NO == [other isKindOfClass:[self class]])
+ return NO;
+ return [name isEqualToString:[(BDSKJournal *)other name]] &&
[abbreviatedName isEqualToString:[(BDSKJournal *)other abbreviatedName]];
+}
+
+- (NSUInteger)hash {
+ return [name hash];
+}
+
+- (NSDictionary *)dictionaryValue {
+ return [NSDictionary dictionaryWithObjectsAndKeys:name, NAME_KEY,
abbreviatedName, ABBREVIATED_KEY, nil];
+}
+
+- (void)setAbbreviatedName:(NSString *)newAbbreviatedName {
+ if (newAbbreviatedName != abbreviatedName) {
+ [abbreviatedName release];
+ abbreviatedName = [newAbbreviatedName retain];
+ [dotlessAbbreviatedName release];
+ dotlessAbbreviatedName = [[abbreviatedName
stringByDeletingCharactersInSet:[NSCharacterSet
characterSetWithCharactersInString:@"."]] retain];
+ }
+}
+
+- (BOOL)isMatchedBy:(NSString *)aName {
+ return [aName isCaseInsensitiveEqual:[self name]] || [aName
isCaseInsensitiveEqual:[self abbreviatedName]] || [aName
isCaseInsensitiveEqual:[self dotlessAbbreviatedName]];
+}
+
+@end
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit