Revision: 24020
http://sourceforge.net/p/bibdesk/svn/24020
Author: hofman
Date: 2019-07-14 09:17:07 +0000 (Sun, 14 Jul 2019)
Log Message:
-----------
convenience accessor for single selected local publication
Modified Paths:
--------------
trunk/bibdesk/BibDocument.h
trunk/bibdesk/BibDocument.m
trunk/bibdesk/BibDocument_Actions.m
trunk/bibdesk/BibDocument_DataSource.m
trunk/bibdesk/BibDocument_UI.m
Modified: trunk/bibdesk/BibDocument.h
===================================================================
--- trunk/bibdesk/BibDocument.h 2019-07-14 06:30:11 UTC (rev 24019)
+++ trunk/bibdesk/BibDocument.h 2019-07-14 09:17:07 UTC (rev 24020)
@@ -404,6 +404,8 @@
- (NSArray *)selectedPublications;
- (NSArray *)clickedOrSelectedPublications;
+- (BibItem *)singleSelectedPublication;
+
- (BOOL)selectItemsForCiteKeys:(NSArray *)citeKeys selectLibrary:(BOOL)flag;
- (BOOL)selectItemForPartialItem:(NSDictionary *)partialItem;
Modified: trunk/bibdesk/BibDocument.m
===================================================================
--- trunk/bibdesk/BibDocument.m 2019-07-14 06:30:11 UTC (rev 24019)
+++ trunk/bibdesk/BibDocument.m 2019-07-14 09:17:07 UTC (rev 24020)
@@ -2393,6 +2393,12 @@
return selPubs;
}
+- (BibItem *)singleSelectedPublication {
+ if ([self isDisplayingFileContentSearch] == NO && [self
hasGroupTypeSelected:BDSKExternalGroupType] == NO && [tableView
numberOfSelectedRows] == 1)
+ return [shownPublications objectAtIndex:[tableView selectedRow]];
+ return nil;
+}
+
- (BOOL)selectItemsForCiteKeys:(NSArray *)citeKeys selectLibrary:(BOOL)flag {
// make sure we can see the publication, if it's still in the document
Modified: trunk/bibdesk/BibDocument_Actions.m
===================================================================
--- trunk/bibdesk/BibDocument_Actions.m 2019-07-14 06:30:11 UTC (rev 24019)
+++ trunk/bibdesk/BibDocument_Actions.m 2019-07-14 09:17:07 UTC (rev 24020)
@@ -897,7 +897,8 @@
}
- (IBAction)chooseLinkedFile:(id)sender {
- if ([self isDisplayingFileContentSearch] || [self
hasGroupTypeSelected:BDSKExternalGroupType] || [[self selectedPublications]
count] != 1 || docFlags.showingURLFields) {
+ BibItem *publication = [self singleSelectedPublication];
+ if (publication == nil || docFlags.showingURLFields) {
NSBeep();
return;
}
@@ -930,17 +931,6 @@
[oPanel beginSheetModalForWindow:documentWindow
completionHandler:^(NSInteger result){
if (result == NSFileHandlingPanelOKButton) {
- BibItem *publication = nil;
- if ([self isDisplayingFileContentSearch] == NO && [self
hasGroupTypeSelected:BDSKExternalGroupType] == NO) {
- NSArray *selPubs = [self selectedPublications];
- if ([selPubs count] == 1)
- publication = [selPubs lastObject];
- }
- if (publication == nil) {
- NSBeep();
- return;
- }
-
NSURL *aURL = [[oPanel URLs] objectAtIndex:0];
BOOL shouldAutoFile = [(NSButton *)[oPanel accessoryView] state]
== NSOffState && [[NSUserDefaults standardUserDefaults]
boolForKey:BDSKFilePapersAutomaticallyKey];
if (anIndex != NSNotFound) {
@@ -984,12 +974,7 @@
[urlController setUrlString:urlString];
[urlController beginSheetModalForWindow:documentWindow
completionHandler:^(NSInteger result){
if (result == NSOKButton) {
- BibItem *publication = nil;
- if ([self isDisplayingFileContentSearch] == NO && [self
hasGroupTypeSelected:BDSKExternalGroupType] == NO) {
- NSArray *selPubs = [self selectedPublications];
- if ([selPubs count] == 1)
- publication = [selPubs lastObject];
- }
+ BibItem *publication = [self singleSelectedPublication];
if (publication == nil) {
NSBeep();
return;
Modified: trunk/bibdesk/BibDocument_DataSource.m
===================================================================
--- trunk/bibdesk/BibDocument_DataSource.m 2019-07-14 06:30:11 UTC (rev
24019)
+++ trunk/bibdesk/BibDocument_DataSource.m 2019-07-14 09:17:07 UTC (rev
24020)
@@ -1529,7 +1529,7 @@
}
}
- if ([self isDisplayingFileContentSearch] == NO && [self
hasGroupTypeSelected:BDSKExternalGroupType] == NO && [[self
selectedPublications] count] == 1 && docFlags.showingURLFields == NO) {
+ if ([self singleSelectedPublication] && docFlags.showingURLFields == NO) {
i = [menu indexOfItemWithTag:FVRemoveMenuItemTag];
if (i != NSNotFound && theURL && [[aFileView selectionIndexes] count]
== 1) {
if ([theURL isFileURL]) {
@@ -1561,23 +1561,16 @@
- (BOOL)fileView:(FVFileView *)aFileView moveURLsAtIndexes:(NSIndexSet *)aSet
toIndex:(NSUInteger)anIndex forDrop:(id <NSDraggingInfo>)info
dropOperation:(FVDropOperation)operation {
BDSKASSERT(anIndex != NSNotFound);
- if ([self isDisplayingFileContentSearch] == NO && [self
hasGroupTypeSelected:BDSKExternalGroupType] == NO) {
- NSArray *selPubs = [self selectedPublications];
- if ([selPubs count] == 1) {
- [[selPubs lastObject] moveFilesAtIndexes:aSet toIndex:anIndex];
- return YES;
- }
+ BibItem *publication = [self singleSelectedPublication];
+ if (publication) {
+ [publication moveFilesAtIndexes:aSet toIndex:anIndex];
+ return YES;
}
return NO;
}
- (BOOL)fileView:(FVFileView *)aFileView replaceURLsAtIndexes:(NSIndexSet
*)aSet withURLs:(NSArray *)newURLs forDrop:(id <NSDraggingInfo>)info
dropOperation:(FVDropOperation)operation {
- BibItem *publication = nil;
- if ([self isDisplayingFileContentSearch] == NO && [self
hasGroupTypeSelected:BDSKExternalGroupType] == NO) {
- NSArray *selPubs = [self selectedPublications];
- if ([selPubs count] == 1)
- publication = [selPubs lastObject];
- }
+ BibItem *publication = [self singleSelectedPublication];
if (publication == nil)
return NO;
@@ -1602,12 +1595,7 @@
}
- (void)fileView:(FVFileView *)aFileView insertURLs:(NSArray *)absoluteURLs
atIndexes:(NSIndexSet *)aSet forDrop:(id <NSDraggingInfo>)info
dropOperation:(FVDropOperation)operation {
- BibItem *publication = nil;
- if ([self isDisplayingFileContentSearch] == NO && [self
hasGroupTypeSelected:BDSKExternalGroupType] == NO) {
- NSArray *selPubs = [self selectedPublications];
- if ([selPubs count] == 1)
- publication = [selPubs lastObject];
- }
+ BibItem *publication = [self singleSelectedPublication];
if (publication == nil)
return;
@@ -1678,12 +1666,7 @@
}
- (BOOL)fileView:(FVFileView *)aFileView deleteURLsAtIndexes:(NSIndexSet
*)indexSet {
- BibItem *publication = nil;
- if ([self isDisplayingFileContentSearch] == NO && [self
hasGroupTypeSelected:BDSKExternalGroupType] == NO) {
- NSArray *selPubs = [self selectedPublications];
- if ([selPubs count] == 1)
- publication = [selPubs lastObject];
- }
+ BibItem *publication = [self singleSelectedPublication];
if (publication == nil)
return NO;
@@ -1693,12 +1676,7 @@
}
- (NSDragOperation)fileView:(FVFileView *)aFileView validateDrop:(id
<NSDraggingInfo>)info proposedIndex:(NSUInteger)anIndex
proposedDropOperation:(FVDropOperation)dropOperation
proposedDragOperation:(NSDragOperation)dragOperation {
- BibItem *publication = nil;
- if ([self isDisplayingFileContentSearch] == NO && [self
hasGroupTypeSelected:BDSKExternalGroupType] == NO) {
- NSArray *selPubs = [self selectedPublications];
- if ([selPubs count] == 1)
- publication = [selPubs lastObject];
- }
+ BibItem *publication = [self singleSelectedPublication];
if (publication == nil)
return NSDragOperationNone;
@@ -1725,9 +1703,11 @@
- (BOOL)fileView:(FVFileView *)aFileView shouldDownloadURL:(NSURL *)aURL
atIndex:(NSUInteger)anIndex replace:(BOOL)replace {
// there should only be a single item selected when we get this
- BibItem *item = [[self selectedPublications] firstObject];
- BDSKLinkedFile *linkedFile = [item objectInFilesAtIndex:anIndex];
- [item downloadLinkedFile:linkedFile replace:replace];
+ BibItem *publication = [self singleSelectedPublication];
+ if (publication) {
+ BDSKLinkedFile *linkedFile = [publication
objectInFilesAtIndex:anIndex];
+ [publication downloadLinkedFile:linkedFile replace:replace];
+ }
return NO;
}
Modified: trunk/bibdesk/BibDocument_UI.m
===================================================================
--- trunk/bibdesk/BibDocument_UI.m 2019-07-14 06:30:11 UTC (rev 24019)
+++ trunk/bibdesk/BibDocument_UI.m 2019-07-14 09:17:07 UTC (rev 24020)
@@ -317,14 +317,6 @@
[bottomFileView reloadIcons];
}
-- (void)updateFileViewProgressIndicators {
- BibItem *item = [[self selectedPublications] firstObject];
- for (BDSKItemDownload *download in [item downloads]) {
- [sideFileView updateProgressIndicator:[download progress]
forURL:[download URL] atIndex:[download index]];
- [bottomFileView updateProgressIndicator:[download progress]
forURL:[download URL] atIndex:[download index]];
- }
-}
-
#pragma mark Status bar
- (void)setStatus:(NSString *)status {
@@ -1200,8 +1192,9 @@
[self updateFileViews];
[self updatePreviews];
[groupOutlineView setNeedsDisplay:YES];
- BOOL fileViewEditable = [self isDisplayingFileContentSearch] == NO &&
[self hasGroupTypeSelected:BDSKExternalGroupType] == NO && [[self
selectedPublications] count] == 1;
- if (fileViewEditable && [[NSUserDefaults standardUserDefaults]
boolForKey:BDSKUseLocalUrlAndUrlKey] && [[[[self selectedPublications]
firstObject] files] count] == 0) {
+ BibItem *singlePub = [self singleSelectedPublication];
+ BOOL fileViewEditable = singlePub != nil;
+ if (fileViewEditable && [[NSUserDefaults standardUserDefaults]
boolForKey:BDSKUseLocalUrlAndUrlKey] && [[singlePub files] count] == 0) {
docFlags.showingURLFields = YES;
fileViewEditable = NO;
} else {
@@ -1213,8 +1206,12 @@
[bottomFileView resetProgressIndicators];
[bottomFileView setEditable:fileViewEditable];
[bottomFileView setAllowsDownloading:fileViewEditable];
- if (fileViewEditable)
- [self updateFileViewProgressIndicators];
+ if (fileViewEditable) {
+ for (BDSKItemDownload *download in [singlePub downloads]) {
+ [sideFileView updateProgressIndicator:[download progress]
forURL:[download URL] atIndex:[download index]];
+ [bottomFileView updateProgressIndicator:[download progress]
forURL:[download URL] atIndex:[download index]];
+ }
+ }
if (docFlags.controllingFVPreviewPanel ||
docFlags.controllingQLPreviewPanel)
[self previewURLs:nil];
}
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