Revision: 28233
          http://sourceforge.net/p/bibdesk/svn/28233
Author:   hofman
Date:     2023-04-20 15:42:10 +0000 (Thu, 20 Apr 2023)
Log Message:
-----------
keep textask for pboard. Only create a new one when a task is running.

Modified Paths:
--------------
    trunk/bibdesk/BDSKItemPasteboardHelper.h
    trunk/bibdesk/BDSKItemPasteboardHelper.m
    trunk/bibdesk/BibDocument_Actions.m

Modified: trunk/bibdesk/BDSKItemPasteboardHelper.h
===================================================================
--- trunk/bibdesk/BDSKItemPasteboardHelper.h    2023-04-20 14:31:20 UTC (rev 
28232)
+++ trunk/bibdesk/BDSKItemPasteboardHelper.h    2023-04-20 15:42:10 UTC (rev 
28233)
@@ -47,10 +47,12 @@
 - (void)pasteboardHelperDidEndGenerating:(BDSKItemPasteboardHelper 
*)pboardHelper;
 @end
 
+@class BDSKTeXTask;
 
 @interface BDSKItemPasteboardHelper : NSObject <NSPasteboardItemDataProvider> {
     NSMutableDictionary *promisedPboardTypes;
     NSMutableDictionary *texTasks;
+    BDSKTeXTask *texTask;
     id<BDSKItemPasteboardHelperDelegate> delegate;
 }
 

Modified: trunk/bibdesk/BDSKItemPasteboardHelper.m
===================================================================
--- trunk/bibdesk/BDSKItemPasteboardHelper.m    2023-04-20 14:31:20 UTC (rev 
28232)
+++ trunk/bibdesk/BDSKItemPasteboardHelper.m    2023-04-20 15:42:10 UTC (rev 
28233)
@@ -68,8 +68,11 @@
 - (void)dealloc {
     // we should have already cleared everything in the final call to 
removePromisedTypesForPasteboard:
     [[texTasks allValues] makeObjectsPerformSelector:@selector(terminate)];
+    if (texTask && [[texTasks allValues] containsObject:texTask] == NO)
+        [texTask terminate];
     BDSKDESTROY(promisedPboardTypes);
     BDSKDESTROY(texTasks);
+    BDSKDESTROY(texTask);
     [super dealloc];
 }
 
@@ -292,9 +295,9 @@
             if ([type isEqualToString:BDSKPasteboardTypePublications]) {
                 [dict removeObjectForKey:ARCHIVEDDATA_KEY];
             } else {
-                BDSKTeXTask *texTask = [texTasks objectForKey:pbName];
-                if (texTask) {
-                    [texTask terminate];
+                BDSKTeXTask *currentTask = [texTasks objectForKey:pbName];
+                if (currentTask) {
+                    [currentTask cancel];
                     [texTasks removeObjectForKey:pbName];
                 }
                 [dict removeObjectForKey:TEXTASKRESULT_KEY];
@@ -310,9 +313,9 @@
 - (void)removePromisedTypesForPasteboard:(NSPasteboard *)pboard {
     if ([self pasteboardIsValid:pboard]) {
         NSString *pbName = [pboard name];
-        BDSKTeXTask *texTask = [texTasks objectForKey:pbName];
-        if (texTask) {
-            [texTask terminate];
+        BDSKTeXTask *currentTask = [texTasks objectForKey:pbName];
+        if (currentTask) {
+            [currentTask cancel];
             [texTasks removeObjectForKey:pbName];
         }
         [promisedPboardTypes removeObjectForKey:pbName];
@@ -346,28 +349,34 @@
         default: break;
     }
     
-    BDSKTeXTask *texTask = [[BDSKTeXTask alloc] initWithFileName:@"bibcopy"];
-    [texTask setDelegate:self];
+    BDSKTeXTask *currentTask = nil;
     
+    if (texTask && [[texTasks allValues] containsObject:texTask] == NO) {
+        currentTask = texTask;
+    } else {
+        currentTask = [[[BDSKTeXTask alloc] initWithFileName:@"bibcopy"] 
autorelease];
+        [currentTask setDelegate:self];
+        if (texTask == nil)
+            texTask = [currentTask retain];
+    }
+    
     if (texTasks == nil)
         texTasks = [[NSMutableDictionary alloc] init];
-    [texTasks setObject:texTask forKey:[pboard name]];
+    [texTasks setObject:currentTask forKey:[pboard name]];
     
-    [texTask runWithBibTeXString:bibString citeKeys:citeKeys 
generatedType:generatedType];
-    
-    [texTask release];
+    [currentTask runWithBibTeXString:bibString citeKeys:citeKeys 
generatedType:generatedType];
 }
 
-- (void)texTask:(BDSKTeXTask *)texTask finishedWithResult:(BOOL)success {
-    NSString *pbName = [[texTasks allKeysForObject:texTask] firstObject];
+- (void)texTask:(BDSKTeXTask *)aTexTask finishedWithResult:(BOOL)success {
+    NSString *pbName = [[texTasks allKeysForObject:aTexTask] firstObject];
     if (pbName) {
         NSMutableDictionary *dict = [promisedPboardTypes objectForKey:pbName];
         BDSKDragCopyType dragCopyType = [[dict objectForKey:DRAGCOPYTYPE_KEY] 
integerValue];
         id result = nil;
         if (dragCopyType == BDSKDragCopyLaTeX || dragCopyType == 
BDSKDragCopyLTB) {
-            result = [texTask laTeXString];
+            result = [aTexTask laTeXString];
         } else {
-            result = [texTask PDFData];
+            result = [aTexTask PDFData];
             if (dragCopyType == BDSKDragCopyRTF && result) {
                 PDFDocument *pdfDoc = [[PDFDocument alloc] 
initWithData:result];
                 NSUInteger i, count = [pdfDoc pageCount];
@@ -387,10 +396,7 @@
             }
         }
         [dict setObject:result ?: [NSData data] forKey:TEXTASKRESULT_KEY];
-        [texTask terminate];
         [texTasks removeObjectForKey:pbName];
-    } else {
-        [texTask terminate];
     }
 }
 

Modified: trunk/bibdesk/BibDocument_Actions.m
===================================================================
--- trunk/bibdesk/BibDocument_Actions.m 2023-04-20 14:31:20 UTC (rev 28232)
+++ trunk/bibdesk/BibDocument_Actions.m 2023-04-20 15:42:10 UTC (rev 28233)
@@ -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

Reply via email to