Revision: 29469
http://sourceforge.net/p/bibdesk/svn/29469
Author: hofman
Date: 2025-08-25 15:33:18 +0000 (Mon, 25 Aug 2025)
Log Message:
-----------
allow dragging URL to item table to add a URL
Modified Paths:
--------------
trunk/bibdesk/BDSKTextImportController.m
Modified: trunk/bibdesk/BDSKTextImportController.m
===================================================================
--- trunk/bibdesk/BDSKTextImportController.m 2025-08-25 15:00:18 UTC (rev
29468)
+++ trunk/bibdesk/BDSKTextImportController.m 2025-08-25 15:33:18 UTC (rev
29469)
@@ -203,7 +203,7 @@
if (@available(macOS 10.14, *))
[sourceTextView setDrawsBackground:NO];
- [itemTableView registerForDraggedTypes:@[NSPasteboardTypeString]];
+ [itemTableView registerForDraggedTypes:@[NSPasteboardTypeString,
NSPasteboardTypeURL]];
[itemTableView setDoubleAction:@selector(addTextToCurrentFieldAction:)];
BDSKTypeSelectHelper *aTypeSelectHelper = [[BDSKTypeSelectHelper alloc]
init];
@@ -1415,9 +1415,14 @@
// This method is used by NSTableView to determine a valid drop target. Based
on the mouse position, the table view will suggest a proposed drop location.
This method must return a value that indicates which dragging operation the
data source will perform. The data source may "re-target" a drop if desired by
calling setDropRow:dropOperation: and returning something other than
NSDragOperationNone. One may choose to re-target for various reasons (eg. for
better visual feedback when inserting into a sorted position).
- (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id
<NSDraggingInfo>)info proposedRow:(NSInteger)row
proposedDropOperation:(NSTableViewDropOperation)op{
NSPasteboard *pboard = [info draggingPasteboard];
- if ([pboard canReadObjectForClasses:@[[NSString class]] options:@{}] &&
- op == NSTableViewDropOn)
- return NSDragOperationCopy;
+ if ([pboard canReadObjectForClasses:@[[NSURL class]] options:@{}] &&
+ op == NSTableViewDropOn) {
+ [tv setDropRow:-1 dropOperation:NSTableViewDropOn];
+ return NSDragOperationGeneric;
+ } else if ([pboard canReadObjectForClasses:@[[NSString class]]
options:@{}] &&
+ op == NSTableViewDropOn) {
+ return NSDragOperationGeneric;
+ }
return NSDragOperationNone;
}
@@ -1424,28 +1429,41 @@
// This method is called when the mouse is released over a table view that
previously decided to allow a drop via the validateDrop method. The data
source should incorporate the data from the dragging pasteboard at this time.
- (BOOL)tableView:(NSTableView*)tv acceptDrop:(id <NSDraggingInfo>)info
row:(NSInteger)row dropOperation:(NSTableViewDropOperation)op{
NSPasteboard *pboard = [info draggingPasteboard];
- NSArray *strings = [pboard readObjectsForClasses:@[[NSString class]]
options:@{}];
- if ([strings count] > 0) {
+ NSURL *url = [[pboard readObjectsForClasses:@[[NSURL class]] options:@{}]
firstObject];
+ if (url) {
+ if ([[NSUserDefaults standardUserDefaults]
boolForKey:BDSKUseLocalUrlAndUrlKey])
+ [[self publication] setField:[url isFileURL] ? BDSKLocalUrlString
: BDSKUrlString toURLValue:url];
+ else
+ [[self publication] addFileForURL:url autoFile:YES
runScriptHook:NO];
+ [[self undoManager] setActionName:NSLocalizedString(@"Edit
Publication", @"Undo action name")];
+
+ return YES;
+ } else if (row != -1) {
+ NSString *value = [[pboard readObjectsForClasses:@[[NSString class]]
options:@{}] firstObject];
+
+ if (value) {
- NSString *value = [strings objectAtIndex:0];
- NSString *key = [fields objectAtIndex:row];
- NSString *oldValue = [[self publication] valueOfField:key];
-
- if(([NSEvent standardModifierFlags] & NSEventModifierFlagControl) != 0
&&
- [NSString isEmptyString:oldValue] == NO &&
- [key isSingleValuedField] == NO){
+ NSString *key = [fields objectAtIndex:row];
+ NSString *oldValue = [[self publication] valueOfField:key];
- NSString *separator;
- if([key isPersonField])
- separator = @" and ";
- else
- separator = [[NSUserDefaults standardUserDefaults]
stringForKey:BDSKDefaultGroupFieldSeparatorKey];
- value = [NSString stringWithFormat:@"%@%@%@", oldValue, separator,
value];
+ if(([NSEvent standardModifierFlags] & NSEventModifierFlagControl)
!= 0 &&
+ [NSString isEmptyString:oldValue] == NO &&
+ [key isSingleValuedField] == NO){
+
+ NSString *separator;
+ if([key isPersonField])
+ separator = @" and ";
+ else
+ separator = [[NSUserDefaults standardUserDefaults]
stringForKey:BDSKDefaultGroupFieldSeparatorKey];
+ value = [NSString stringWithFormat:@"%@%@%@", oldValue,
separator, value];
+ }
+
+ [self recordChangingField:key toValue:value];
+
+ return YES;
}
-
- [self recordChangingField:key toValue:value];
}
- return YES;
+ return NO;
}
- (void)tableView:(NSTableView *)tv pasteFromPasteboard:(NSPasteboard *)pboard{
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