Revision: 27471
http://sourceforge.net/p/bibdesk/svn/27471
Author: hofman
Date: 2022-05-24 09:00:33 +0000 (Tue, 24 May 2022)
Log Message:
-----------
make sure formatter and textfield button are set properly in editor when custom
fields change
Modified Paths:
--------------
trunk/bibdesk/BDSKEditor.m
Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m 2022-05-24 06:30:13 UTC (rev 27470)
+++ trunk/bibdesk/BDSKEditor.m 2022-05-24 09:00:33 UTC (rev 27471)
@@ -116,8 +116,9 @@
- (void)setupCollectionView;
- (void)collectionViewFrameDidChange:(NSNotification *)notification;
- (void)setupTypePopUp;
-- (void)resetFields:(BOOL)alwaysReload;
+- (void)resetFields:(NSInteger)reloadTable;
- (void)reloadTableWithFields:(NSArray *)newFields;
+- (void)updateTableViewDisplay;
- (void)registerForNotifications;
- (void)breakTextStorageConnections;
- (void)updateCiteKeyDuplicateWarning;
@@ -217,7 +218,7 @@
citeKeyConstraint = [[NSLayoutConstraint constraintWithWidth:[citeKeyTitle
intrinsicContentSize].width forItem:citeKeyTitle] retain];
[citeKeyTitle addConstraint:citeKeyConstraint];
- [self resetFields:YES];
+ [self resetFields:1];
[self setupCollectionView];
if (editorFlags.isEditable)
[tableView registerForDraggedTypes:[NSArray
arrayWithObjects:BDSKPasteboardTypePublications, NSPasteboardTypeString,
(NSString *)kUTTypeURL, (NSString *)kUTTypeFileURL, NSURLPboardType,
NSFilenamesPboardType, nil]];
@@ -791,7 +792,7 @@
addedFields = [[NSMutableSet alloc] init];
[addedFields addObject:newField];
[tabView selectFirstTabViewItem:nil];
- [self resetFields:YES];
+ [self resetFields:1];
[self setKeyField:newField];
}
}];
@@ -839,7 +840,7 @@
[addedFields removeObject:oldField];
[tabView selectFirstTabViewItem:nil];
if ([NSString isEmptyString:oldValue]) {
- [self resetFields:YES];
+ [self resetFields:1];
} else {
[publication setField:oldField toValue:nil];
[[self undoManager]
setActionName:NSLocalizedString(@"Remove Field", @"Undo action name")];
@@ -2426,7 +2427,7 @@
[self updatePreviewing];
}
else if([changeKey isEqualToString:BDSKPubTypeString]){
- [self resetFields:NO];
+ [self resetFields:0];
[self updateTypePopup];
[self synchronizeWindowTitleWithDocumentName];
}
@@ -2438,7 +2439,7 @@
[[[self textFieldAtRow:editedRow] currentEditor]
setString:newValue ?: @""];
if ([changeKey isEqualToString:BDSKCrossrefString] && [NSString
isEmptyString:newValue] != [NSString isEmptyString:oldValue]) {
// Crossref field was added or removed
- [self resetFields:YES];
+ [self resetFields:0];
} else {
// every field value could change, but not the displayed field
names
[self reloadTableWithFields:nil];
@@ -2492,7 +2493,7 @@
NSTextField *textField = [self textFieldAtRow:editedRow];
[[textField currentEditor] setString:[textField formatter] ?
[[textField formatter] editingStringForObjectValue:tmpValue] : tmpValue];
}
- [self resetFields:YES];
+ [self resetFields:1];
[self setupCollectionView];
[self synchronizeWindowTitleWithDocumentName];
[authorTableView reloadData];
@@ -2531,7 +2532,7 @@
BDSKEditorTextField *textField = [self
textFieldAtRow:editedRow];
[[textField currentEditor] setString:[textField formatter] ?
[[textField formatter] editingStringForObjectValue:tmpValue] : tmpValue];
}
- [self resetFields:YES];
+ [self resetFields:1];
} else {
// a field value changed
NSUInteger row = [fields indexOfObject:changeKey];
@@ -2572,7 +2573,7 @@
- (void)typeInfoDidChange:(NSNotification *)aNotification{
if ([self commitEditing]) {
[self setupTypePopUp];
- [self resetFields:NO];
+ [self resetFields:0];
}
}
@@ -2580,7 +2581,7 @@
// ensure that the pub updates first, since it observes this notification
also
[publication customFieldsDidChange:aNotification];
if ([self commitEditing]) {
- [self resetFields:NO];
+ [self resetFields:-1];
[self setupCollectionView];
[authorTableView reloadData];
}
@@ -3401,7 +3402,26 @@
}
}
-- (void)resetFields:(BOOL)alwaysReload{
+- (void)updateTableViewDisplay {
+ [fields enumerateObjectsUsingBlock:^(NSString *field, NSUInteger row, BOOL
*stop){
+ BDSKEditorTextField *textField = [self textFieldAtRow:row];
+ NSString *value = [publication valueOfField:field] ?: @"";
+ id object = nil;
+ if ([value isInherited] || ([field isEqualToString:BDSKCrossrefString]
&& [NSString isEmptyString:value] == NO))
+ object = [[[BDSKField alloc] initWithName:field bibItem:nil]
autorelease];
+ else if ([field isURLField])
+ object = [publication URLForField:field];
+ [textField setRepresentedObject:object];
+ NSFormatter *formatter = [field isEqualToString:BDSKCrossrefString] ?
crossrefFormatter : [field isCitationField] ? citationFormatter :
tableCellFormatter;
+ if (formatter != [textField formatter]) {
+ [textField setFormatter:formatter];
+ if ([textField currentEditor])
+ [[textField currentEditor] setString:[formatter
editingStringForObjectValue:value]];
+ }
+ }];
+}
+
+- (void)resetFields:(NSInteger)reloadTable {
// build the new set of fields
NSMutableArray *currentFields = [NSMutableArray array];
NSMutableArray *allFields = [[NSMutableArray alloc] init];
@@ -3441,8 +3461,10 @@
if ([fields isEqualToArray:currentFields])
currentFields = nil;
- if (alwaysReload || currentFields)
+ if (reloadTable == 1 || currentFields)
[self reloadTableWithFields:currentFields];
+ else if (reloadTable == -1)
+ [self updateTableViewDisplay];
}
- (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
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit