Revision: 22421
http://sourceforge.net/p/bibdesk/svn/22421
Author: hofman
Date: 2018-07-14 21:39:39 +0000 (Sat, 14 Jul 2018)
Log Message:
-----------
use macros for dictionary keys
Modified Paths:
--------------
trunk/bibdesk/BibPref_Defaults.m
Modified: trunk/bibdesk/BibPref_Defaults.m
===================================================================
--- trunk/bibdesk/BibPref_Defaults.m 2018-07-14 11:34:10 UTC (rev 22420)
+++ trunk/bibdesk/BibPref_Defaults.m 2018-07-14 21:39:39 UTC (rev 22421)
@@ -64,6 +64,9 @@
static NSSet *alwaysDisabledFields = nil;
+#define FIELD_KEY @"field"
+#define TYPE_KEY @"type"
+#define DEFAULT_KEY @"default"
@implementation BibPref_Defaults
@@ -87,7 +90,7 @@
type = [NSNumber numberWithInteger:BDSKLocalFileType];
for (field in [sud arrayForKey:BDSKLocalFileFieldsKey]) {
isDefault = [NSNumber numberWithBool:[defaultFields
containsObject:field]];
- dict = [NSMutableDictionary
dictionaryWithObjectsAndKeys:field, @"field", type, @"type", isDefault,
@"default", nil];
+ dict = [NSMutableDictionary
dictionaryWithObjectsAndKeys:field, FIELD_KEY, type, TYPE_KEY, isDefault,
DEFAULT_KEY, nil];
[customFieldsArray addObject:dict];
[customFieldsSet addObject:field];
}
@@ -96,7 +99,7 @@
type = [NSNumber numberWithInteger:BDSKRemoteURLType];
for (field in [sud arrayForKey:BDSKRemoteURLFieldsKey]) {
isDefault = [NSNumber numberWithBool:[defaultFields
containsObject:field]];
- dict = [NSMutableDictionary
dictionaryWithObjectsAndKeys:field, @"field", type, @"type", isDefault,
@"default", nil];
+ dict = [NSMutableDictionary
dictionaryWithObjectsAndKeys:field, FIELD_KEY, type, TYPE_KEY, isDefault,
DEFAULT_KEY, nil];
[customFieldsArray addObject:dict];
[customFieldsSet addObject:field];
}
@@ -105,7 +108,7 @@
type = [NSNumber numberWithInteger:BDSKBooleanType];
for (field in [sud arrayForKey:BDSKBooleanFieldsKey]) {
isDefault = [NSNumber numberWithBool:[defaultFields
containsObject:field]];
- dict = [NSMutableDictionary
dictionaryWithObjectsAndKeys:field, @"field", type, @"type", isDefault,
@"default", nil];
+ dict = [NSMutableDictionary
dictionaryWithObjectsAndKeys:field, FIELD_KEY, type, TYPE_KEY, isDefault,
DEFAULT_KEY, nil];
[customFieldsArray addObject:dict];
[customFieldsSet addObject:field];
}
@@ -114,7 +117,7 @@
type = [NSNumber numberWithInteger:BDSKTriStateType];
for (field in [sud arrayForKey:BDSKTriStateFieldsKey]) {
isDefault = [NSNumber numberWithBool:[defaultFields
containsObject:field]];
- dict = [NSMutableDictionary
dictionaryWithObjectsAndKeys:field, @"field", type, @"type", isDefault,
@"default", nil];
+ dict = [NSMutableDictionary
dictionaryWithObjectsAndKeys:field, FIELD_KEY, type, TYPE_KEY, isDefault,
DEFAULT_KEY, nil];
[customFieldsArray addObject:dict];
[customFieldsSet addObject:field];
}
@@ -123,7 +126,7 @@
type = [NSNumber numberWithInteger:BDSKRatingType];
for (field in [sud arrayForKey:BDSKRatingFieldsKey]){
isDefault = [NSNumber numberWithBool:[defaultFields
containsObject:field]];
- dict = [NSMutableDictionary
dictionaryWithObjectsAndKeys:field, @"field", type, @"type", isDefault,
@"default", nil];
+ dict = [NSMutableDictionary
dictionaryWithObjectsAndKeys:field, FIELD_KEY, type, TYPE_KEY, isDefault,
DEFAULT_KEY, nil];
[customFieldsArray addObject:dict];
[customFieldsSet addObject:field];
}
@@ -132,7 +135,7 @@
type = [NSNumber numberWithInteger:BDSKCitationType];
for (field in [sud arrayForKey:BDSKCitationFieldsKey]) {
isDefault = [NSNumber numberWithBool:[defaultFields
containsObject:field]];
- dict = [NSMutableDictionary
dictionaryWithObjectsAndKeys:field, @"field", type, @"type", isDefault,
@"default", nil];
+ dict = [NSMutableDictionary
dictionaryWithObjectsAndKeys:field, FIELD_KEY, type, TYPE_KEY, isDefault,
DEFAULT_KEY, nil];
[customFieldsArray addObject:dict];
[customFieldsSet addObject:field];
}
@@ -141,7 +144,7 @@
type = [NSNumber numberWithInteger:BDSKPersonType];
for (field in [sud arrayForKey:BDSKPersonFieldsKey]) {
isDefault = [NSNumber numberWithBool:[defaultFields
containsObject:field]];
- dict = [NSMutableDictionary
dictionaryWithObjectsAndKeys:field, @"field", type, @"type", isDefault,
@"default", nil];
+ dict = [NSMutableDictionary
dictionaryWithObjectsAndKeys:field, FIELD_KEY, type, TYPE_KEY, isDefault,
DEFAULT_KEY, nil];
[customFieldsArray addObject:dict];
[customFieldsSet addObject:field];
}
@@ -152,7 +155,7 @@
for (field in [defaultFields reverseObjectEnumerator]){
if([customFieldsSet containsObject:field])
continue;
- dict = [NSMutableDictionary
dictionaryWithObjectsAndKeys:field, @"field", type, @"type", isDefault,
@"default", nil];
+ dict = [NSMutableDictionary
dictionaryWithObjectsAndKeys:field, FIELD_KEY, type, TYPE_KEY, isDefault,
DEFAULT_KEY, nil];
[customFieldsArray insertObject:dict atIndex:0];
[customFieldsSet addObject:field];
}
@@ -266,9 +269,9 @@
NSInteger type;
for (NSDictionary *dict in customFieldsArray) {
- field = [dict objectForKey:@"field"];
- type = [[dict objectForKey:@"type"] integerValue];
- if([[dict objectForKey:@"default"] boolValue])
+ field = [dict objectForKey:FIELD_KEY];
+ type = [[dict objectForKey:TYPE_KEY] integerValue];
+ if([[dict objectForKey:DEFAULT_KEY] boolValue])
[defaultFields addObject:field];
switch(type){
case BDSKStringType:
@@ -343,16 +346,15 @@
[removeRemoteURLFieldsButton setEnabled:autoConvert];
if (useLocalUrl) {
// make sure Local-Url and Url are defined as Local File and remote
URL fields
- NSArray *customFields = [customFieldsArray valueForKey:@"field"];
- if ([customFields containsObject:BDSKLocalUrlString] == NO ||
[customFields containsObject:BDSKUrlString] == NO) {
+ if ([customFieldsSet containsObject:BDSKLocalUrlString] == NO ||
[customFieldsSet containsObject:BDSKUrlString] == NO) {
NSMutableDictionary *newDict;
- if ([customFields containsObject:BDSKLocalUrlString] == NO) {
- newDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
BDSKLocalUrlString, @"field", [NSNumber numberWithInteger:BDSKLocalFileType],
@"type", [NSNumber numberWithBool:NO], @"default", nil];
+ if ([customFieldsSet containsObject:BDSKLocalUrlString] == NO) {
+ newDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
BDSKLocalUrlString, FIELD_KEY, [NSNumber numberWithInteger:BDSKLocalFileType],
TYPE_KEY, [NSNumber numberWithBool:NO], DEFAULT_KEY, nil];
[customFieldsArray addObject:newDict];
[customFieldsSet addObject:BDSKLocalUrlString];
}
- if ([customFields containsObject:BDSKUrlString] == NO) {
- newDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
BDSKUrlString, @"field", [NSNumber numberWithInteger:BDSKRemoteURLType],
@"type", [NSNumber numberWithBool:NO], @"default", nil];
+ if ([customFieldsSet containsObject:BDSKUrlString] == NO) {
+ newDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
BDSKUrlString, FIELD_KEY, [NSNumber numberWithInteger:BDSKRemoteURLType],
TYPE_KEY, [NSNumber numberWithBool:NO], DEFAULT_KEY, nil];
[customFieldsArray addObject:newDict];
[customFieldsSet addObject:BDSKUrlString];
}
@@ -402,9 +404,9 @@
- (void)tableView:(NSTableView *)tableView setObjectValue:(id)object
forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
if (tableView == defaultFieldsTableView) {
NSString *colID = [tableColumn identifier];
- NSString *field = [[customFieldsArray objectAtIndex:row]
objectForKey:@"field"];
+ NSString *field = [[customFieldsArray objectAtIndex:row]
objectForKey:FIELD_KEY];
- if([colID isEqualToString:@"field"]){
+ if([colID isEqualToString:FIELD_KEY]){
if([customFieldsSet containsObject:object])
return; // don't add duplicate fields
[customFieldsSet removeObject:field];
@@ -494,7 +496,7 @@
- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell
forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
if (tableView == defaultFieldsTableView) {
- NSString *field = [[customFieldsArray objectAtIndex:row]
objectForKey:@"field"];
+ NSString *field = [[customFieldsArray objectAtIndex:row]
objectForKey:FIELD_KEY];
if([alwaysDisabledFields containsObject:field])
[cell setEnabled:NO];
@@ -510,7 +512,7 @@
[addRemoveDefaultFieldButton setEnabled:NO forSegment:1];
return;
}
- NSString *field = [[customFieldsArray objectAtIndex:row]
objectForKey:@"field"];
+ NSString *field = [[customFieldsArray objectAtIndex:row]
objectForKey:FIELD_KEY];
if([alwaysDisabledFields containsObject:field])
[addRemoveDefaultFieldButton setEnabled:NO forSegment:1];
else
@@ -546,11 +548,11 @@
if ([sender selectedSegment] == 0) { // add
NSInteger row = [customFieldsArray count];
- NSMutableDictionary *newDict = [NSMutableDictionary
dictionaryWithObjectsAndKeys: @"Field", @"field", [NSNumber
numberWithInteger:BDSKStringType], @"type", [NSNumber numberWithBool:NO],
@"default", nil]; // do not localize
+ NSMutableDictionary *newDict = [NSMutableDictionary
dictionaryWithObjectsAndKeys: @"Field", FIELD_KEY, [NSNumber
numberWithInteger:BDSKStringType], TYPE_KEY, [NSNumber numberWithBool:NO],
DEFAULT_KEY, nil]; // do not localize
[customFieldsArray addObject:newDict];
[defaultFieldsTableView reloadData];
[defaultFieldsTableView selectRowIndexes:[NSIndexSet
indexSetWithIndex:row] byExtendingSelection:NO];
- [[[defaultFieldsTableView tableColumnWithIdentifier:@"field"]
dataCell] setEnabled:YES]; // hack to make sure we can edit, as the delegate
method is called too late
+ [[[defaultFieldsTableView tableColumnWithIdentifier:FIELD_KEY]
dataCell] setEnabled:YES]; // hack to make sure we can edit, as the delegate
method is called too late
[defaultFieldsTableView editColumn:0 row:row withEvent:nil select:YES];
// don't update the prefs yet, as the user should first set the field
name
@@ -560,7 +562,7 @@
if(row != -1){
if([defaultFieldsTableView editedRow] != -1)
[[defaultFieldsTableView window] makeFirstResponder:nil];
- [customFieldsSet removeObject:[[customFieldsArray
objectAtIndex:row] objectForKey:@"field"]];
+ [customFieldsSet removeObject:[[customFieldsArray
objectAtIndex:row] objectForKey:FIELD_KEY]];
[customFieldsArray removeObjectAtIndex:row];
[self updatePrefs];
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit