Revision: 29405 http://sourceforge.net/p/bibdesk/svn/29405 Author: hofman Date: 2025-07-30 22:27:31 +0000 (Wed, 30 Jul 2025) Log Message: ----------- separate building fields array and reloading the table
Modified Paths: -------------- trunk/bibdesk/BDSKEditor.m Modified: trunk/bibdesk/BDSKEditor.m =================================================================== --- trunk/bibdesk/BDSKEditor.m 2025-07-30 17:01:41 UTC (rev 29404) +++ trunk/bibdesk/BDSKEditor.m 2025-07-30 22:27:31 UTC (rev 29405) @@ -110,7 +110,6 @@ #define FIELD_COLUMNID @"field" enum { BDSKMoveToTrashAsk = -1, BDSKMoveToTrashNo = 0, BDSKMoveToTrashYes = 1 }; -enum { BDSKUpdateTable = -1, BDSKNoReload = 0, BDSKReloadTable = 1 }; @interface BDSKEditor () @@ -138,7 +137,7 @@ - (void)setupCollectionView; - (void)collectionViewFrameDidChange:(NSNotification *)notification; - (void)setupTypePopUp; -- (void)resetFields:(NSInteger)reloadTable; +- (NSArray *)currentFields; - (void)reloadTableWithFields:(NSArray *)newFields; - (void)updateTableViewDisplay; - (void)registerForNotifications; @@ -233,7 +232,7 @@ citeKeyConstraint = [[citeKeyTitle widthAnchor] constraintEqualToConstant:[citeKeyTitle intrinsicContentSize].width]; [citeKeyConstraint setActive:YES]; - [self resetFields:BDSKReloadTable]; + [self reloadTableWithFields:[self currentFields]]; [self setupCollectionView]; if (editorFlags.isEditable) [tableView registerForDraggedTypes:@[BDSKPasteboardTypePublications, NSPasteboardTypeString, (__bridge NSString *)kUTTypeURL, (__bridge NSString *)kUTTypeFileURL, NSURLPboardType, NSFilenamesPboardType]]; @@ -886,7 +885,7 @@ addedFields = [[NSMutableSet alloc] init]; [addedFields addObject:newField]; [tabView selectFirstTabViewItem:nil]; - [self resetFields:BDSKNoReload]; + [self reloadTableWithFields:[self currentFields]]; [self setKeyField:newField]; } }]; @@ -935,7 +934,7 @@ [addedFields removeObject:oldField]; [tabView selectFirstTabViewItem:nil]; if ([NSString isEmptyAsComplexString:oldValue]) { - [self resetFields:BDSKNoReload]; + [self reloadTableWithFields:[self currentFields]]; } else { [publication setField:oldField toValue:nil]; [[self undoManager] setActionName:NSLocalizedString(@"Remove Field", @"Undo action name")]; @@ -2362,7 +2361,9 @@ [self updatePreviewing]; } else if([changeKey isEqualToString:BDSKPubTypeString]){ - [self resetFields:BDSKNoReload]; + NSArray *currentFields = [self currentFields]; + if (currentFields) + [self reloadTableWithFields:currentFields]; [self updateTypePopup]; [self synchronizeWindowTitleWithDocumentName]; } @@ -2372,13 +2373,12 @@ NSInteger editedRow = [tableView editedTextRow]; if (editedRow != -1 && [[fields objectAtIndex:editedRow] isEqualToString:changeKey]) [[[self textFieldAtRow:editedRow] currentEditor] setString:newValue ?: @""]; - if ([changeKey isEqualToString:BDSKCrossrefString] && [NSString isEmptyString:newValue] != [NSString isEmptyString:oldValue]) { + NSArray *currentFields = nil; + if ([changeKey isEqualToString:BDSKCrossrefString] && [NSString isEmptyString:newValue] != [NSString isEmptyString:oldValue]) // Crossref field was added or removed - [self resetFields:BDSKReloadTable]; - } else { - // every field value could change, but not the displayed field names - [self reloadTableWithFields:nil]; - } + currentFields = [self currentFields]; + // every field value could change + [self reloadTableWithFields:currentFields]; [authorTableView reloadData]; [self synchronizeWindowTitleWithDocumentName]; } @@ -2416,7 +2416,7 @@ NSTextField *textField = [self textFieldAtRow:editedRow]; [[textField currentEditor] setString:[textField formatter] ? [[textField formatter] editingStringForObjectValue:tmpValue] : tmpValue]; } - [self resetFields:BDSKReloadTable]; + [self reloadTableWithFields:[self currentFields]]; [self setupCollectionView]; [self synchronizeWindowTitleWithDocumentName]; [authorTableView reloadData]; @@ -2455,7 +2455,7 @@ BDSKEditorTextField *textField = [self textFieldAtRow:editedRow]; [[textField currentEditor] setString:[textField formatter] ? [[textField formatter] editingStringForObjectValue:tmpValue] : tmpValue]; } - [self resetFields:BDSKReloadTable]; + [self reloadTableWithFields:[self currentFields]]; } else { // a field value changed NSUInteger row = [fields indexOfObject:changeKey]; @@ -2490,8 +2490,11 @@ - (void)typeInfoDidChange:(NSNotification *)aNotification{ [self setupTypePopUp]; - if (editorFlags.isEditing == NO || [tableView rowForView:(NSText *)[[self window] firstResponder]] == -1 || [self commitEditing]) - [self resetFields:BDSKNoReload]; + if (editorFlags.isEditing == NO || [tableView rowForView:(NSText *)[[self window] firstResponder]] == -1 || [self commitEditing]) { + NSArray *currentFields = [self currentFields]; + if (currentFields) + [self reloadTableWithFields:currentFields]; + } } // this is forwarded by the document rather than observed by ourselves, @@ -2498,9 +2501,16 @@ // so we can be sure it is performed after the publication - (void)customFieldsDidChange:(NSNotification *)notification{ BDSKFieldTypeMask change = [[[notification userInfo] objectForKey:BDSKChangedFieldTypesKey] unsignedIntegerValue]; - if ((change & (BDSKFieldTypeMaskURL | BDSKFieldTypeMaskInteger | BDSKFieldTypeMaskCitation | BDSKFieldTypeMaskDefault))) { - if (editorFlags.isEditing == NO || [tableView rowForView:(NSText *)[[self window] firstResponder]] == -1 || [self commitEditing]) - [self resetFields:(change & (BDSKFieldTypeMaskURL | BDSKFieldTypeMaskCitation)) ? BDSKUpdateTable : BDSKNoReload]; + NSArray *currentFields = nil; + if ((change & (BDSKFieldTypeMaskInteger | BDSKFieldTypeMaskDefault))) + currentFields = [self currentFields]; + if (currentFields || (change & (BDSKFieldTypeMaskURL | BDSKFieldTypeMaskCitation))) { + if (editorFlags.isEditing == NO || [tableView rowForView:(NSText *)[[self window] firstResponder]] == -1 || [self commitEditing]) { + if (currentFields) + [self reloadTableWithFields:currentFields]; + else + [self updateTableViewDisplay]; + } } if ((change & BDSKFieldTypeMaskInteger)) [self setupCollectionView]; @@ -3320,7 +3330,7 @@ }]; } -- (void)resetFields:(NSInteger)reloadTable { +- (NSArray *)currentFields { // build the new set of fields NSMutableArray *currentFields = [NSMutableArray array]; NSMutableArray *allFields = [[NSMutableArray alloc] init]; @@ -3355,10 +3365,7 @@ if ([fields isEqualToArray:currentFields]) currentFields = nil; - if (reloadTable == BDSKReloadTable || currentFields) - [self reloadTableWithFields:currentFields]; - else if (reloadTable == BDSKUpdateTable) - [self updateTableViewDisplay]; + return currentFields; } - (CGFloat)addButtonToCollectionviewItem:(BDSKEditorCollectionViewItem *)item { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Bibdesk-commit mailing list Bibdesk-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-commit