Revision: 30059
http://sourceforge.net/p/bibdesk/svn/30059
Author: hofman
Date: 2026-02-25 17:26:48 +0000 (Wed, 25 Feb 2026)
Log Message:
-----------
replace boolean flag by block passing field that was edited
Modified Paths:
--------------
trunk/bibdesk/BDSKEditor.m
Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m 2026-02-25 16:44:59 UTC (rev 30058)
+++ trunk/bibdesk/BDSKEditor.m 2026-02-25 17:26:48 UTC (rev 30059)
@@ -138,7 +138,7 @@
- (void)collectionViewFrameDidChange:(NSNotification *)notification;
- (void)setupTypePopUp;
- (NSArray *)currentFields;
-- (void)reloadTableWithFields:(NSArray *)newFields
ignoreEditing:(BOOL)ignoreEditing;
+- (void)reloadTableWithFields:(NSArray *)newFields
ignoreEditing:(BOOL(^)(NSString *field))ignoreEditing;
- (void)updateTableViewDisplay;
- (void)registerForNotifications;
- (void)updateCiteKeyDuplicateWarning;
@@ -231,7 +231,7 @@
citeKeyConstraint = [[citeKeyTitle widthAnchor]
constraintEqualToConstant:[citeKeyTitle intrinsicContentSize].width];
[citeKeyConstraint setActive:YES];
- [self reloadTableWithFields:[self currentFields] ignoreEditing:NO];
+ [self reloadTableWithFields:[self currentFields] ignoreEditing:nil];
[self setupCollectionView];
if (editorFlags.isEditable)
[tableView registerForDraggedTypes:@[BDSKPasteboardTypePublications,
NSPasteboardTypeString, (__bridge NSString *)kUTTypeURL, (__bridge NSString
*)kUTTypeFileURL, NSURLPboardType, NSFilenamesPboardType]];
@@ -872,7 +872,7 @@
addedFields = [[NSMutableSet alloc] init];
[addedFields addObject:newField];
[tabView selectFirstTabViewItem:nil];
- [self reloadTableWithFields:[self currentFields]
ignoreEditing:NO];
+ [self reloadTableWithFields:[self currentFields]
ignoreEditing:nil];
[self setKeyField:newField];
}
}];
@@ -921,7 +921,7 @@
[addedFields removeObject:oldField];
[tabView selectFirstTabViewItem:nil];
if ([NSString isEmptyAsComplexString:oldValue]) {
- [self reloadTableWithFields:[self currentFields]
ignoreEditing:NO];
+ [self reloadTableWithFields:[self currentFields]
ignoreEditing:nil];
} else {
[publication setField:oldField toValue:nil];
[[self undoManager]
setActionName:NSLocalizedString(@"Remove Field", @"Undo action name")];
@@ -2322,33 +2322,29 @@
else if([changeKey isEqualToString:BDSKPubTypeString]){
NSArray *currentFields = [self currentFields];
if (currentFields)
- [self reloadTableWithFields:currentFields ignoreEditing:NO];
+ [self reloadTableWithFields:currentFields ignoreEditing:nil];
[self updateTypePopup];
[self synchronizeWindowTitleWithDocumentName];
}
else if([changeKey isEqualToString:BDSKCrossrefString]){
// Reset if the crossref changed.
- // We should first set the new value, because resetFields will set the
edited value. This happens when it is set through drag/drop
- BOOL ignoreEditing = NO;
- NSInteger editedRow = [tableView editedTextRow];
- if (editedRow != -1) {
- NSString *editedField = [fields objectAtIndex:editedRow];
- ignoreEditing = ([editedField isEqualToString:BDSKCrossrefString]
|| [NSString isEmptyAsComplexString:[publication valueOfField:editedField
inherit:NO]]);
- }
+ // We should ignore the current editing, because committing will set
the edited value. This happens when it is set through drag/drop
NSArray *currentFields = nil;
if ([NSString isEmptyString:newValue] != [NSString
isEmptyString:oldValue])
// Crossref field was added or removed
currentFields = [self currentFields];
// every field value could change
- [self reloadTableWithFields:currentFields ignoreEditing:ignoreEditing];
+ [self reloadTableWithFields:currentFields ignoreEditing:^(NSString
*editedField){
+ return (BOOL)([editedField isEqualToString:BDSKCrossrefString] ||
[NSString isEmptyAsComplexString:[publication valueOfField:editedField
inherit:NO]]);
+ }];
[authorTableView reloadData];
[self synchronizeWindowTitleWithDocumentName];
}
else if(parentChanged){
// Reset if our parent's cite key changed. Every field value could
change.
- NSInteger editedRow = [tableView editedTextRow];
- BOOL ignoreEditing = (editedRow != -1 && [NSString
isEmptyAsComplexString:[publication valueOfField:[fields
objectAtIndex:editedRow] inherit:NO]]);
- [self reloadTableWithFields:nil ignoreEditing:ignoreEditing];
+ [self reloadTableWithFields:nil ignoreEditing:^(NSString *editedField){
+ return [NSString isEmptyAsComplexString:[publication
valueOfField:editedField inherit:NO]];
+ }];
[authorTableView reloadData];
[self synchronizeWindowTitleWithDocumentName];
[self updateCiteKeyDuplicateWarning];
@@ -2380,7 +2376,7 @@
}
else if (changeKey == nil){
// all fields are set
- [self reloadTableWithFields:[self currentFields] ignoreEditing:YES];
+ [self reloadTableWithFields:[self currentFields]
ignoreEditing:^(NSString *editedField){ return YES; }];
if (inheritedValueChanged == NO)
[self setupCollectionView];
[self synchronizeWindowTitleWithDocumentName];
@@ -2415,9 +2411,9 @@
NSInteger row = [fields indexOfObject:changeKey];
if (row >= minNumberOfFields && ([NSString
isEmptyAsComplexString:newValue] != [NSString
isEmptyAsComplexString:oldValue])) {
// a custom field was added or removed
- NSInteger editedRow = [tableView editedTextRow];
- BOOL ignoreEditing = (editedRow != -1 && [[fields
objectAtIndex:editedRow] isEqualToString:changeKey]);
- [self reloadTableWithFields:[self currentFields]
ignoreEditing:ignoreEditing];
+ [self reloadTableWithFields:[self currentFields]
ignoreEditing:^(NSString *editedField){
+ return [editedField isEqualToString:changeKey];
+ }];
} else if (row != NSNotFound) {
// a field value changed
// don't use newValue, because this can be the parent's value
@@ -2440,9 +2436,9 @@
for (id pub in pubs) {
if ([crossref isCaseInsensitiveEqual:[pub citeKey]]) {
// changes in the parent cannot change the field names, as
custom fields are never inherited
- NSInteger editedRow = [tableView editedTextRow];
- BOOL ignoreEditing = (editedRow != -1 && [NSString
isEmptyAsComplexString:[publication valueOfField:[fields
objectAtIndex:editedRow] inherit:NO]]);
- [self reloadTableWithFields:nil ignoreEditing:ignoreEditing];
+ [self reloadTableWithFields:nil ignoreEditing:^(NSString
*editedField){
+ return [NSString isEmptyAsComplexString:[publication
valueOfField:editedField inherit:NO]];
+ }];
break;
}
}
@@ -2458,7 +2454,7 @@
if ([self commitEditingTableTextField]) {
NSArray *currentFields = [self currentFields];
if (currentFields)
- [self reloadTableWithFields:currentFields ignoreEditing:NO];
+ [self reloadTableWithFields:currentFields ignoreEditing:nil];
}
}
@@ -2471,7 +2467,7 @@
if ((change & (BDSKFieldTypeMaskInteger | BDSKFieldTypeMaskDefault)))
currentFields = [self currentFields];
if (currentFields && [self commitEditingTableTextField]) {
- [self reloadTableWithFields:currentFields ignoreEditing:NO];
+ [self reloadTableWithFields:currentFields ignoreEditing:nil];
} else {
minNumberOfFields = MIN(minNumberOfFields, oldMinNumberOfFields);
if ((change & (BDSKFieldTypeMaskURL | BDSKFieldTypeMaskCitation)))
@@ -3226,16 +3222,16 @@
#pragma mark Private
-- (void)reloadTableWithFields:(NSArray *)newFields
ignoreEditing:(BOOL)ignoreEditing{
+- (void)reloadTableWithFields:(NSArray *)newFields
ignoreEditing:(BOOL(^)(NSString *field))ignoreEditing{
// if we were editing in the tableView, we will restore the selected cell
and the selection
- NSString *editedTitle = nil;
+ NSString *editedField = nil;
NSArray *selection = nil;
NSInteger editedRow = [tableView editedTextRow];
if (editedRow != -1) {
NSTextField *textField = [self textFieldAtRow:editedRow];
- editedTitle = [fields objectAtIndex:editedRow];
+ editedField = [fields objectAtIndex:editedRow];
selection = [(NSTextView *)[textField currentEditor] selectedRanges];
- if (ignoreEditing) {
+ if (ignoreEditing && ignoreEditing(editedField)) {
[textField abortEditing];
[self setEditing:NO];
} else if ([[self window] makeFirstResponder:[self window]] == NO) {
@@ -3277,8 +3273,8 @@
}
// restore the edited cell and its selection
- if (editedTitle)
- [self editTextFieldAtRow:newFields ? NSNotFound : editedRow
forField:editedTitle selection:selection];
+ if (editedField)
+ [self editTextFieldAtRow:newFields ? NSNotFound : editedRow
forField:editedField selection:selection];
}
- (void)updateTableViewDisplay {
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