Revision: 22399
http://sourceforge.net/p/bibdesk/svn/22399
Author: hofman
Date: 2018-07-10 14:56:13 +0000 (Tue, 10 Jul 2018)
Log Message:
-----------
Cache whether the linked file has Skim notes, update when Skim saves a file
Modified Paths:
--------------
trunk/bibdesk/BDSKAppController.m
trunk/bibdesk/BDSKLinkedFile.h
trunk/bibdesk/BDSKLinkedFile.m
trunk/bibdesk/BibDocument.h
trunk/bibdesk/BibDocument.m
trunk/bibdesk/BibItem.m
Modified: trunk/bibdesk/BDSKAppController.m
===================================================================
--- trunk/bibdesk/BDSKAppController.m 2018-07-10 13:31:43 UTC (rev 22398)
+++ trunk/bibdesk/BDSKAppController.m 2018-07-10 14:56:13 UTC (rev 22399)
@@ -91,6 +91,7 @@
#define BDSKHistoryByDateKey @"BDSKHistoryByDate"
#define BDSKIsRelaunchKey @"BDSKIsRelaunch"
#define BDSKDidMigrateLocalUrlFormatDefaultsKey
@"BDSKDidMigrateLocalUrlFormatDefaultsKey"
+#define SKSkimFileDidSaveNotification @"SKSkimFileDidSaveNotification"
enum {
BDSKStartupOpenUntitledFile,
@@ -103,6 +104,7 @@
@interface BDSKAppController (Private)
- (void)doSpotlightImportIfNeeded;
- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event
withReplyEvent:(NSAppleEventDescriptor *)replyEvent;
+- (void)handleSkimFileDidSaveNotification:(NSNotification *)note;
@end
@implementation BDSKAppController
@@ -357,6 +359,8 @@
[history loadFromURL:[NSURL fileURLWithPath:historyPath] error:NULL];
[WebHistory setOptionalSharedHistory:history];
+ [[NSDistributedNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleSkimFileDidSaveNotification:)
name:SKSkimFileDidSaveNotification object:nil];
+
[[NSColorPanel sharedColorPanel] setShowsAlpha:YES];
}
@@ -871,4 +875,10 @@
}
}
+#pragma mark Skim Files
+
+- (void)handleSkimFileDidSaveNotification:(NSNotification *)note {
+ [[NSApp orderedDocuments]
makeObjectsPerformSelector:@selector(SkimFileDidSave:) withObject:[note
object]];
+}
+
@end
Modified: trunk/bibdesk/BDSKLinkedFile.h
===================================================================
--- trunk/bibdesk/BDSKLinkedFile.h 2018-07-10 13:31:43 UTC (rev 22398)
+++ trunk/bibdesk/BDSKLinkedFile.h 2018-07-10 14:56:13 UTC (rev 22399)
@@ -75,6 +75,10 @@
- (void)updateWithPath:(NSString *)aPath;
+- (BOOL)hasSkimNotes;
+
+- (void)updateSkimNotesForPath:(NSString *)path;
+
@end
Modified: trunk/bibdesk/BDSKLinkedFile.m
===================================================================
--- trunk/bibdesk/BDSKLinkedFile.m 2018-07-10 13:31:43 UTC (rev 22398)
+++ trunk/bibdesk/BDSKLinkedFile.m 2018-07-10 14:56:13 UTC (rev 22399)
@@ -40,6 +40,7 @@
#import <CoreServices/CoreServices.h>
#import "BDSKRuntime.h"
#import "NSData_BDSKExtensions.h"
+#import "NSURL_BDSKExtensions.h"
#define BDSKSaveLinkedFilesAsRelativePathOnlyKey
@"BDSKSaveLinkedFilesAsRelativePathOnly"
@@ -71,6 +72,7 @@
NSString *relativePath;
NSURL *fileURL;
BOOL isInitial;
+ char hasSkimNotes;
id delegate;
}
@@ -192,8 +194,12 @@
- (BOOL)isFile { return NO; }
+- (BOOL)hasSkimNotes { return NO; }
+
- (void)updateWithPath:(NSString *)aPath {}
+- (void)updateSkimNotesForPath:(NSString *)path {}
+
- (NSString *)relativePath { return nil; }
- (void)setDelegate:(id<BDSKLinkedFileDelegate>)aDelegate {}
@@ -277,6 +283,7 @@
delegate = aDelegate;
fileURL = nil;
isInitial = YES;
+ hasSkimNotes = -1;
}
return self;
}
@@ -464,6 +471,7 @@
if (aURL != fileURL) {
[fileURL release];
fileURL = [aURL retain];
+ hasSkimNotes = -1;
if (isInitial == NO)
[delegate performSelector:@selector(linkedFileURLChanged:)
withObject:self afterDelay:0.0];
}
@@ -560,6 +568,12 @@
return displayURL;
}
+- (BOOL)hasSkimNotes {
+ if (hasSkimNotes == -1)
+ hasSkimNotes = [[fileURL SkimNotes] count] > 0;
+ return hasSkimNotes == 1;
+}
+
- (NSData *)aliasDataRelativeToPath:(NSString *)basePath;
{
// make sure the fileRef is valid
@@ -684,6 +698,14 @@
relativePath = [[path relativePathFromPath:basePath] retain];
}
+- (void)updateSkimNotesForPath:(NSString *)path {
+ if ([path isEqualToString:[fileURL path]]) {
+ hasSkimNotes = -1;
+ if (isInitial == NO)
+ [delegate performSelector:@selector(linkedFileURLChanged:)
withObject:self afterDelay:0.0];
+ }
+}
+
@end
#pragma mark -
Modified: trunk/bibdesk/BibDocument.h
===================================================================
--- trunk/bibdesk/BibDocument.h 2018-07-10 13:31:43 UTC (rev 22398)
+++ trunk/bibdesk/BibDocument.h 2018-07-10 14:56:13 UTC (rev 22399)
@@ -432,4 +432,6 @@
- (BOOL)openLinkedFileURL:(NSURL *)url;
+- (void)SkimFileDidSave:(NSString *)path;
+
@end
Modified: trunk/bibdesk/BibDocument.m
===================================================================
--- trunk/bibdesk/BibDocument.m 2018-07-10 13:31:43 UTC (rev 22398)
+++ trunk/bibdesk/BibDocument.m 2018-07-10 14:56:13 UTC (rev 22399)
@@ -2694,4 +2694,10 @@
return [[NSWorkspace sharedWorkspace] openURL:url
withSearchString:searchString];
}
+#pragma mark Skim file did save
+
+- (void)SkimFileDidSave:(NSString *)path {
+ [[[self publications] valueForKeyPath:@"@unionOfArrays.localFiles"]
makeObjectsPerformSelector:@selector(updateSkimNotesForPath:) withObject:path];
+}
+
@end
Modified: trunk/bibdesk/BibItem.m
===================================================================
--- trunk/bibdesk/BibItem.m 2018-07-10 13:31:43 UTC (rev 22398)
+++ trunk/bibdesk/BibItem.m 2018-07-10 14:56:13 UTC (rev 22399)
@@ -1469,16 +1469,15 @@
}else if([field isEqualToString:BDSKLocalFileString]){
NSArray *localFiles = [self localFiles];
NSUInteger count = [localFiles count];
- NSArray *fileURLs = [localFiles valueForKey:@"URL"];
NSDictionary *cellDictionary = nil;
if (count > 0) {
NSString *label = 1 == count ? NSLocalizedString(@"1 item", @"") :
[NSString stringWithFormat:NSLocalizedString(@"%ld items", @""), (long)count];
BOOL hasMissingFile = NO;
BOOL hasSkimNotes = NO;
- for (NSURL *fileURL in fileURLs) {
- if ([fileURL isEqual:[NSNull null]])
+ for (BDSKLinkedFile *file in localFiles) {
+ if ([file URL] == nil)
hasMissingFile == YES;
- else if (hasSkimNotes == NO && [[fileURL SkimNotes] count] > 0)
+ else if (hasSkimNotes == NO && [file hasSkimNotes])
hasSkimNotes = YES;
}
NSImage *image = hasSkimNotes ? (hasMissingFile ? [NSImage
redAnnotatedPaperclipImage] : [NSImage annotatedPaperclipImage]) :
(hasMissingFile ? [NSImage redPaperclipImage] : [NSImage paperclipImage]);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit