Revision: 29312
http://sourceforge.net/p/bibdesk/svn/29312
Author: hofman
Date: 2025-07-21 16:00:13 +0000 (Mon, 21 Jul 2025)
Log Message:
-----------
notify which custom field types have changed, so we can only reset what is
needed
Modified Paths:
--------------
trunk/bibdesk/BDSKAppController.m
trunk/bibdesk/BDSKEditor.m
trunk/bibdesk/BDSKTypeManager.h
trunk/bibdesk/BDSKTypeManager.m
trunk/bibdesk/BibItem.m
trunk/bibdesk/BibPref_Defaults.m
Modified: trunk/bibdesk/BDSKAppController.m
===================================================================
--- trunk/bibdesk/BDSKAppController.m 2025-07-21 09:10:38 UTC (rev 29311)
+++ trunk/bibdesk/BDSKAppController.m 2025-07-21 16:00:13 UTC (rev 29312)
@@ -268,7 +268,7 @@
}
}
if (didChange)
- [[BDSKTypeManager sharedManager] updateCustomFields];
+ [[BDSKTypeManager sharedManager]
updateCustomFields:BDSKFieldTypeMaskEvery];
}
static BOOL fileIsInTrash(NSURL *fileURL)
Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m 2025-07-21 09:10:38 UTC (rev 29311)
+++ trunk/bibdesk/BDSKEditor.m 2025-07-21 16:00:13 UTC (rev 29312)
@@ -2495,13 +2495,19 @@
[self resetFields:BDSKNoReload];
}
-- (void)customFieldsDidChange:(NSNotification *)aNotification{
- // ensure that the pub updates first, since it observes this notification
also
- [publication customFieldsDidChange:aNotification];
- if (editorFlags.isEditing == NO || [tableView rowForView:(NSText *)[[self
window] firstResponder]] == -1 || [self commitEditing])
- [self resetFields:BDSKUpdateTable];
- [self setupCollectionView];
- [authorTableView reloadData];
+- (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)) ? BDSKReloadTable : BDSKNoReload];
+ }
+ if ((change & BDSKFieldTypeMaskInteger))
+ [self setupCollectionView];
+ if ((change & BDSKFieldTypeMaskPerson)) {
+ // the publication will do this itself, but it needs to be done first
+ [publication resetGroupsAndPeople];
+ [authorTableView reloadData];
+ }
}
- (void)macrosDidChange:(NSNotification *)notification{
Modified: trunk/bibdesk/BDSKTypeManager.h
===================================================================
--- trunk/bibdesk/BDSKTypeManager.h 2025-07-21 09:10:38 UTC (rev 29311)
+++ trunk/bibdesk/BDSKTypeManager.h 2025-07-21 16:00:13 UTC (rev 29312)
@@ -40,6 +40,17 @@
NS_ASSUME_NONNULL_BEGIN
+typedef NS_OPTIONS(NSUInteger, BDSKFieldTypeMask) {
+ BDSKFieldTypeMaskURL = 1 << 0,
+ BDSKFieldTypeMaskInteger = 1 << 1,
+ BDSKFieldTypeMaskCitation = 1 << 2,
+ BDSKFieldTypeMaskPerson = 1 << 3,
+ BDSKFieldTypeMaskDefault = 1 << 4,
+ BDSKFieldTypeMaskEvery = 0x1F
+};
+
+extern NSString *BDSKChangedFieldTypesKey;
+
@interface BDSKTypeManager : NSObject {
NSDictionary *fieldsForTypesDict;
NSArray *types;
@@ -106,7 +117,7 @@
// Updating
- (void)updateUserTypes:(NSArray *)newTypes andFields:(NSDictionary
*)newFieldsForTypes;
-- (void)updateCustomFields;
+- (void)updateCustomFields:(BDSKFieldTypeMask)changedTypes;
// BibTeX
- (NSArray *)requiredFieldsForType:(NSString *)type;
Modified: trunk/bibdesk/BDSKTypeManager.m
===================================================================
--- trunk/bibdesk/BDSKTypeManager.m 2025-07-21 09:10:38 UTC (rev 29311)
+++ trunk/bibdesk/BDSKTypeManager.m 2025-07-21 16:00:13 UTC (rev 29312)
@@ -72,6 +72,7 @@
#define REFER_TYPES_FOR_BIBTEX_TYPES_KEY @"ReferTypesForBibTeXTypes"
#define BIBTEX_TYPES_FOR_HCITE_TYPES_KEY @"BibTeXTypesForHCiteTypes"
+NSString *BDSKChangedFieldTypesKey = @"BDSKChangedFieldTypes";
@interface BDSKTypeManager ()
@@ -302,10 +303,10 @@
}
}
-- (void)updateCustomFields {
+- (void)updateCustomFields:(BDSKFieldTypeMask)changedTypes {
[self reloadFieldSets];
[standardFieldsForTypes removeAllObjects];
- [[NSNotificationCenter defaultCenter]
postNotificationName:BDSKCustomFieldsChangedNotification object:self];
+ [[NSNotificationCenter defaultCenter]
postNotificationName:BDSKCustomFieldsChangedNotification object:self
userInfo:@{BDSKChangedFieldTypesKey: [NSNumber
numberWithUnsignedInteger:changedTypes]}];
}
#pragma mark Getters
Modified: trunk/bibdesk/BibItem.m
===================================================================
--- trunk/bibdesk/BibItem.m 2025-07-21 09:10:38 UTC (rev 29311)
+++ trunk/bibdesk/BibItem.m 2025-07-21 16:00:13 UTC (rev 29312)
@@ -515,8 +515,16 @@
#pragma mark -
-- (void)customFieldsDidChange:(NSNotification *)aNotification{
- [self resetGroupsAndPeople];
+- (void)customFieldsDidChange:(NSNotification *)notification{
+ BDSKFieldTypeMask change = [[[notification userInfo]
objectForKey:BDSKChangedFieldTypesKey] unsignedIntegerValue];
+ // group values for these field types may change, so our cached values
should be discarded
+ if ((change & (BDSKFieldTypeMaskInteger | BDSKFieldTypeMaskCitation |
BDSKFieldTypeMaskPerson)))
+ [groups removeAllObjects];
+ if ((change & (BDSKFieldTypeMaskPerson))) {
+ // these fields may change type, so our cached values should be
discarded
+ [[people allValues] setValue:nil forKey:@"publication"];
+ people = nil;
+ }
}
- (void)resetGroupsAndPeople{
Modified: trunk/bibdesk/BibPref_Defaults.m
===================================================================
--- trunk/bibdesk/BibPref_Defaults.m 2025-07-21 09:10:38 UTC (rev 29311)
+++ trunk/bibdesk/BibPref_Defaults.m 2025-07-21 16:00:13 UTC (rev 29312)
@@ -267,7 +267,7 @@
[globalMacroFiles setArray:[sud
stringArrayForKey:BDSKGlobalMacroFilesKey]];
[self resetDefaultFields];
// the field types may have changed, so notify the type manager
- [[BDSKTypeManager sharedManager] updateCustomFields];
+ [[BDSKTypeManager sharedManager]
updateCustomFields:BDSKFieldTypeMaskEvery];
[sud removeObjectForKey:BDSKDownloadsDirectoryKey];
// reset UI, but only if we loaded the nib
if ([self isViewLoaded]) {
@@ -290,13 +290,20 @@
NSMutableArray *triStateFields = [[NSMutableArray alloc]
initWithCapacity:1];
NSMutableArray *citationFields = [[NSMutableArray alloc]
initWithCapacity:1];
NSMutableArray *personFields = [[NSMutableArray alloc] initWithCapacity:1];
-
- NSString *field;
- NSInteger type;
-
+
+ NSArray *oldDefaultFields = [sud stringArrayForKey:BDSKDefaultFieldsKey];
+ NSArray *oldLocalFileFields = [sud
stringArrayForKey:BDSKLocalFileFieldsKey];
+ NSArray *oldRemoteURLFields = [sud
stringArrayForKey:BDSKRemoteURLFieldsKey];
+ NSArray *oldRatingFields = [sud stringArrayForKey:BDSKRatingFieldsKey];
+ NSArray *oldBooleanFields = [sud stringArrayForKey:BDSKBooleanFieldsKey];
+ NSArray *oldTriStateFields = [sud stringArrayForKey:BDSKTriStateFieldsKey];
+ NSArray *oldCitationFields = [sud stringArrayForKey:BDSKCitationFieldsKey];
+ NSArray *oldPersonFields = [sud stringArrayForKey:BDSKPersonFieldsKey];
+ NSUInteger changedTypes = 0;
+
for (NSDictionary *dict in customFieldsArray) {
- field = [dict objectForKey:FIELD_KEY];
- type = [[dict objectForKey:TYPE_KEY] integerValue];
+ NSString *field = [dict objectForKey:FIELD_KEY];
+ NSInteger type = [[dict objectForKey:TYPE_KEY] integerValue];
if([[dict objectForKey:DEFAULT_KEY] boolValue])
[defaultFields addObject:field];
switch(type){
@@ -327,16 +334,41 @@
[NSException raise:NSInvalidArgumentException format:@"Attempt
to set unrecognized type"];
}
}
- [sud setObject:defaultFields forKey:BDSKDefaultFieldsKey];
- [sud setObject:localFileFields forKey:BDSKLocalFileFieldsKey];
- [sud setObject:remoteURLFields forKey:BDSKRemoteURLFieldsKey];
- [sud setObject:ratingFields forKey:BDSKRatingFieldsKey];
- [sud setObject:booleanFields forKey:BDSKBooleanFieldsKey];
- [sud setObject:triStateFields forKey:BDSKTriStateFieldsKey];
- [sud setObject:citationFields forKey:BDSKCitationFieldsKey];
- [sud setObject:personFields forKey:BDSKPersonFieldsKey];
- [[BDSKTypeManager sharedManager] updateCustomFields];
+ if ([defaultFields isEqualToArray:oldDefaultFields] == NO) {
+ changedTypes |= BDSKFieldTypeMaskDefault;
+ [sud setObject:defaultFields forKey:BDSKDefaultFieldsKey];
+ }
+ if ([localFileFields isEqualToArray:oldLocalFileFields] == NO) {
+ changedTypes |= BDSKFieldTypeMaskURL;
+ [sud setObject:localFileFields forKey:BDSKLocalFileFieldsKey];
+ }
+ if ([remoteURLFields isEqualToArray:oldRemoteURLFields] == NO) {
+ changedTypes |= BDSKFieldTypeMaskURL;
+ [sud setObject:remoteURLFields forKey:BDSKRemoteURLFieldsKey];
+ }
+ if ([ratingFields isEqualToArray:oldRatingFields] == NO) {
+ changedTypes |= BDSKFieldTypeMaskInteger;
+ [sud setObject:ratingFields forKey:BDSKRatingFieldsKey];
+ }
+ if ([booleanFields isEqualToArray:oldBooleanFields] == NO) {
+ changedTypes |= BDSKFieldTypeMaskInteger;
+ [sud setObject:booleanFields forKey:BDSKBooleanFieldsKey];
+ }
+ if ([triStateFields isEqualToArray:oldTriStateFields] == NO) {
+ changedTypes |= BDSKFieldTypeMaskInteger;
+ [sud setObject:triStateFields forKey:BDSKTriStateFieldsKey];
+ }
+ if ([citationFields isEqualToArray:oldCitationFields] == NO) {
+ changedTypes |= BDSKFieldTypeMaskCitation;
+ [sud setObject:citationFields forKey:BDSKCitationFieldsKey];
+ }
+ if ([personFields isEqualToArray:personFields] == NO) {
+ changedTypes |= BDSKFieldTypeMaskPerson;
+ [sud setObject:personFields forKey:BDSKPersonFieldsKey];
+ }
+
+ [[BDSKTypeManager sharedManager] updateCustomFields:changedTypes];
//notification of these changes is posted by the type manager, which
observes the pref keys; this ensures that the type manager gets notified first,
so notification observers don't get stale data; as a consequence, if you add
another custom field type, the type manager needs to observe it in -init
[defaultFieldsTableView reloadData];
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