Revision: 11874
http://bibdesk.svn.sourceforge.net/bibdesk/?rev=11874&view=rev
Author: amaxwell
Date: 2007-12-11 22:19:45 -0800 (Tue, 11 Dec 2007)
Log Message:
-----------
Eliminate -[BibItem makeType] as per comment. The editor now adds empty fields
and rearranges as necessary to handle type changes, rather than the document
creating a bunch of empty fields. This significantly improves file opening
performance.
Check for nil in editor setup, since they may not be set to the empty string
now. Unregister document for type changes.
Modified Paths:
--------------
trunk/bibdesk/BDSKEditor.m
trunk/bibdesk/BibDocument.h
trunk/bibdesk/BibDocument.m
trunk/bibdesk/BibItem.h
trunk/bibdesk/BibItem.m
Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m 2007-12-12 05:56:34 UTC (rev 11873)
+++ trunk/bibdesk/BDSKEditor.m 2007-12-12 06:19:45 UTC (rev 11874)
@@ -250,11 +250,17 @@
[authorTableView setDoubleAction:@selector(showPersonDetailCmd:)];
// Setup the textviews
- [notesView setString:[publication valueOfField:BDSKAnnoteString
inherit:NO]];
+ NSString *currentValue = [publication valueOfField:BDSKAnnoteString
inherit:NO];
+ if (currentValue)
+ [notesView setString:currentValue];
[notesView setEditable:isEditable];
- [abstractView setString:[publication valueOfField:BDSKAbstractString
inherit:NO]];
+ currentValue = [publication valueOfField:BDSKAbstractString inherit:NO];
+ if (currentValue)
+ [abstractView setString:currentValue];
[abstractView setEditable:isEditable];
- [rssDescriptionView setString:[publication
valueOfField:BDSKRssDescriptionString inherit:NO]];
+ currentValue = [publication valueOfField:BDSKRssDescriptionString
inherit:NO];
+ if (currentValue)
+ [rssDescriptionView setString:currentValue];
[rssDescriptionView setEditable:isEditable];
currentEditedView = nil;
@@ -1988,8 +1994,6 @@
}
- (void)typeInfoDidChange:(NSNotification *)aNotification{
- // ensure that the pub updates first, since it observes this notification
also
- [publication typeInfoDidChange:aNotification];
[self setupTypePopUp];
[self setupFields];
}
Modified: trunk/bibdesk/BibDocument.h
===================================================================
--- trunk/bibdesk/BibDocument.h 2007-12-12 05:56:34 UTC (rev 11873)
+++ trunk/bibdesk/BibDocument.h 2007-12-12 06:19:45 UTC (rev 11874)
@@ -431,7 +431,6 @@
- (void)handleTableSelectionChangedNotification:(NSNotification *)notification;
// notifications observed on behalf of owned BibItems for efficiency
-- (void)handleTypeInfoDidChangeNotification:(NSNotification *)notification;
- (void)handleCustomFieldsDidChangeNotification:(NSNotification *)notification;
/*!
Modified: trunk/bibdesk/BibDocument.m
===================================================================
--- trunk/bibdesk/BibDocument.m 2007-12-12 05:56:34 UTC (rev 11873)
+++ trunk/bibdesk/BibDocument.m 2007-12-12 06:19:45 UTC (rev 11874)
@@ -2464,12 +2464,8 @@
selector:@selector(handleApplicationWillTerminateNotification:)
name:NSApplicationWillTerminateNotification
object:nil];
- // observe these two on behalf of our BibItems, or else all BibItems
register for these notifications and -[BibItem dealloc] gets expensive when
unregistering; this means that (shared) items without a document won't get
these notifications
+ // observe this on behalf of our BibItems, or else all BibItems
register for these notifications and -[BibItem dealloc] gets expensive when
unregistering; this means that (shared) items without a document won't get
these notifications
[nc addObserver:self
- selector:@selector(handleTypeInfoDidChangeNotification:)
- name:BDSKBibTypeInfoChangedNotification
- object:[BDSKTypeManager sharedManager]];
- [nc addObserver:self
selector:@selector(handleCustomFieldsDidChangeNotification:)
name:BDSKCustomFieldsChangedNotification
object:nil];
@@ -2684,10 +2680,6 @@
[self saveSortOrder];
}
-- (void)handleTypeInfoDidChangeNotification:(NSNotification *)notification{
- [publications makeObjectsPerformSelector:@selector(typeInfoDidChange:)
withObject:notification];
-}
-
- (void)handleCustomFieldsDidChangeNotification:(NSNotification *)notification{
[publications makeObjectsPerformSelector:@selector(customFieldsDidChange:)
withObject:notification];
[tableView setupTableColumnsWithIdentifiers:[tableView
tableColumnIdentifiers]];
Modified: trunk/bibdesk/BibItem.h
===================================================================
--- trunk/bibdesk/BibItem.h 2007-12-12 05:56:34 UTC (rev 11873)
+++ trunk/bibdesk/BibItem.h 2007-12-12 06:19:45 UTC (rev 11874)
@@ -828,7 +828,6 @@
- (NSString *)documentInfoForKey:(NSString *)key;
-- (void)typeInfoDidChange:(NSNotification *)aNotification;
- (void)customFieldsDidChange:(NSNotification *)aNotification;
- (void)duplicateTitleToBooktitleOverwriting:(BOOL)overwrite;
Modified: trunk/bibdesk/BibItem.m
===================================================================
--- trunk/bibdesk/BibItem.m 2007-12-12 05:56:34 UTC (rev 11873)
+++ trunk/bibdesk/BibItem.m 2007-12-12 06:19:45 UTC (rev 11874)
@@ -118,9 +118,6 @@
// updates derived info from the dictionary
- (void)updateMetadataForKey:(NSString *)key;
-// rearranges the field dictionary, keeping old keys if they have a value
-- (void)makeType;
-
- (void)createFilesArray;
@end
@@ -319,7 +316,6 @@
- (id)initWithCoder:(NSCoder *)coder{
if([coder allowsKeyedCoding]){
if(self = [super init]){
- // we need to set the pubFields first because makeType might have
to change it
pubFields = [[coder decodeObjectForKey:@"pubFields"] retain];
[self setFileType:[coder decodeObjectForKey:@"fileType"]];
[self setCiteKeyString:[coder decodeObjectForKey:@"citeKey"]];
@@ -510,12 +506,7 @@
#pragma mark -
-- (void)typeInfoDidChange:(NSNotification *)aNotification{
- [self makeType];
-}
-
- (void)customFieldsDidChange:(NSNotification *)aNotification{
- [self makeType];
[groups removeAllObjects];
// these fields may change type, so our cached values should be discarded
[people release];
@@ -3382,8 +3373,6 @@
if(![[self pubType] isEqualToString:newType]){
[pubType release];
pubType = [newType copy];
-
- [self makeType];
}
}
@@ -3410,9 +3399,6 @@
// invalidate the cached groups; they are rebuilt when needed
if(allFieldsChanged){
[groups removeAllObjects];
- // re-call make type to make sure we still have all the appropriate
bibtex defined fields...
- // but only if we have set the full pubFields array, as we should not
be able to remove necessary fields.
- [self makeType];
// the URL cache is certainly invalid now
[cachedURLs removeAllObjects];
@@ -3486,88 +3472,8 @@
}
}
-#pragma mark Type info
+#pragma mark File conversion
-typedef struct _EmptyFieldApplierContext {
- NSMutableDictionary *dict;
- NSMutableSet *removalSet;
-} EmptyFieldApplierContext;
-
-// used to be a #define; changed to function for clarity in debugging
-static inline void setEmptyStringIfObjectIsNilAndExcludeFromRemoval(const void
*value, void *ctxt)
-{
- NSString *key = (NSString *)value;
- EmptyFieldApplierContext *context = (EmptyFieldApplierContext *)ctxt;
- if([context->dict objectForKey:key] == nil)
- [context->dict setObject:@"" forKey:key];
- [context->removalSet removeObject:key];
-}
-
-// CFSetApplierFunction callback
-static void removeItemsInSetFromDictionary(const void *value, void *context)
-{
- CFDictionaryRemoveValue((CFMutableDictionaryRef)context, value);
-}
-
-// CFSet string equality callback
-static Boolean stringIsEqualToString(const void *value1, const void *value2) {
return [(id)value1 isEqualToString:(id)value2]; }
-
-- (void)makeType{
- NSString *theType = [self pubType];
-
- BDSKTypeManager *typeManager = [BDSKTypeManager sharedManager];
-
- // enumerating small arrays by index is generally faster than
NSEnumerator, and -makeType is called many times at load
- CFArrayRef requiredFields = (CFArrayRef)[typeManager
requiredFieldsForType:theType];
- CFArrayRef optionalFields = (CFArrayRef)[typeManager
optionalFieldsForType:theType];
- CFArrayRef userFields = (CFArrayRef)[typeManager
userDefaultFieldsForType:theType];
-
- // current state of this item's pubFields
- CFArrayRef allFields = (CFArrayRef)[self allFieldNames];
-
- CFIndex allFieldsCount = CFArrayGetCount(allFields);
-
- // have to retain keys removed from the dictionary, but we know they're
strings
- CFSetCallBacks callBacks = { 0, OFCFTypeRetain, OFCFTypeRelease,
CFCopyDescription, stringIsEqualToString, CFHash };
-
- // fixed-size mutable set; this needn't be larger than allFieldsCount
- NSMutableSet *emptyFieldsToRemove = (NSMutableSet
*)CFSetCreateMutable(CFAllocatorGetDefault(), allFieldsCount, &callBacks);
- NSString *key;
-
- CFIndex idx;
-
- // for each field currently in this publication, check if it's value is an
empty string; if so, add to the set of fields to be removed
- for (idx = 0; idx < allFieldsCount; idx++) {
- key = (id)CFArrayGetValueAtIndex(allFields, idx);
- if ([[pubFields objectForKey:key] isEqualAsComplexString:@""])
- [emptyFieldsToRemove addObject:key];
- }
-
- EmptyFieldApplierContext context;
- context.dict = pubFields;
- context.removalSet = emptyFieldsToRemove;
-
- // @@ BDSKEditor handles empty fields specially; fields set to @"" are
shown, but nil fields are not. This code also handles type conversions without
loss of information. It would be nice to move more of this functionality into
the controller layer, instead of the model. We could have a convertToType:
method that handles the conversion, and the editor could handle the
optional/required/user fields by displaying the appropriate UI.
-
- // see if we have a nil value for any required field; if so, give it an
empty value and don't remove it at the end
- CFArrayApplyFunction(requiredFields, CFRangeMake(0,
CFArrayGetCount(requiredFields)),
setEmptyStringIfObjectIsNilAndExcludeFromRemoval, &context);
-
- // now check the BibTeX-defined optional fields
- CFArrayApplyFunction(optionalFields, CFRangeMake(0,
CFArrayGetCount(optionalFields)),
setEmptyStringIfObjectIsNilAndExcludeFromRemoval, &context);
-
- // now check all user-defined default fields
- CFArrayApplyFunction(userFields, CFRangeMake(0,
CFArrayGetCount(userFields)), setEmptyStringIfObjectIsNilAndExcludeFromRemoval,
&context);
-
- // I don't enforce Keywords, but since there's GUI depending on them, I
will enforce these others as being non-nil:
- setEmptyStringIfObjectIsNilAndExcludeFromRemoval(BDSKAnnoteString,
&context);
- setEmptyStringIfObjectIsNilAndExcludeFromRemoval(BDSKAbstractString,
&context);
- setEmptyStringIfObjectIsNilAndExcludeFromRemoval(BDSKRssDescriptionString,
&context);
-
- // now remove everything that's left in removeKeys from pubFields, since
it's non-standard for this type
- CFSetApplyFunction((CFMutableSetRef)emptyFieldsToRemove,
removeItemsInSetFromDictionary, pubFields);
- CFRelease(emptyFieldsToRemove);
-}
-
static void addURLForFieldToArrayIfNotNil(const void *key, void *context)
{
BibItem *self = [(id)context valueForKey:@"publication"];
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit