Revision: 24209
          http://sourceforge.net/p/bibdesk/svn/24209
Author:   hofman
Date:     2019-09-13 15:21:13 +0000 (Fri, 13 Sep 2019)
Log Message:
-----------
Allow Color Label as group field, display color swatch in group icon, pass on 
values to Bdsk-Color field

Modified Paths:
--------------
    trunk/bibdesk/BDSKCategoryGroup.m
    trunk/bibdesk/BDSKGroup.h
    trunk/bibdesk/BDSKGroup.m
    trunk/bibdesk/BDSKGroupCell.h
    trunk/bibdesk/BDSKGroupCell.m
    trunk/bibdesk/BDSKTypeManager.m
    trunk/bibdesk/BibDocument_Groups.m
    trunk/bibdesk/BibDocument_UI.m
    trunk/bibdesk/BibItem.m

Modified: trunk/bibdesk/BDSKCategoryGroup.m
===================================================================
--- trunk/bibdesk/BDSKCategoryGroup.m   2019-09-13 06:30:35 UTC (rev 24208)
+++ trunk/bibdesk/BDSKCategoryGroup.m   2019-09-13 15:21:13 UTC (rev 24209)
@@ -177,7 +177,7 @@
 
 - (BDSKGroupType)groupType { return BDSKCategoryGroupType; }
 
-- (BOOL)isNameEditable { return YES; }
+- (BOOL)isNameEditable { return [key isEqualToString:BDSKColorLabelString] == 
NO && [key isEqualToString:BDSKColorString] == NO; }
 
 - (BOOL)isEditable {
     return [key isPersonField];
@@ -189,6 +189,8 @@
 
 - (BOOL)isEmpty { return NO; }
 
+- (BOOL)displayColor { return [key isEqualToString:BDSKColorLabelString] || 
[key isEqualToString:BDSKColorString]; }
+
 @end
 
 #pragma mark -
@@ -226,4 +228,6 @@
 
 - (BOOL)isEmpty { return YES; }
 
+- (BOOL)displayColor { return NO; }
+
 @end

Modified: trunk/bibdesk/BDSKGroup.h
===================================================================
--- trunk/bibdesk/BDSKGroup.h   2019-09-13 06:30:35 UTC (rev 24208)
+++ trunk/bibdesk/BDSKGroup.h   2019-09-13 15:21:13 UTC (rev 24209)
@@ -98,6 +98,7 @@
 @property (nonatomic, readonly) BOOL allowsRemoval;
 @property (nonatomic, readonly) BOOL failedDownload;
 @property (nonatomic, readonly, getter=isRetrieving) BOOL retrieving;
+@property (nonatomic, readonly, getter=displayColor) BOOL displayColor;
 
 @property (nonatomic, readonly) NSString *stringValue;
 @property (nonatomic, readonly) NSNumber *numberValue;

Modified: trunk/bibdesk/BDSKGroup.m
===================================================================
--- trunk/bibdesk/BDSKGroup.m   2019-09-13 06:30:35 UTC (rev 24208)
+++ trunk/bibdesk/BDSKGroup.m   2019-09-13 15:21:13 UTC (rev 24209)
@@ -57,8 +57,8 @@
 
 + (void)initialize {
     BDSKINITIALIZE;
-    cellValueKeys = [[NSArray alloc] initWithObjects:@"stringValue", 
@"editingStringValue", @"numberValue", @"label", @"icon", @"isRetrieving", 
@"failedDownload", nil];
-    noCountCellValueKeys = [[NSArray alloc] initWithObjects:@"stringValue", 
@"editingStringValue", @"label", @"icon", @"isRetrieving", @"failedDownload", 
nil];
+    cellValueKeys = [[NSArray alloc] initWithObjects:@"stringValue", 
@"editingStringValue", @"numberValue", @"label", @"icon", @"isRetrieving", 
@"failedDownload", @"displayColor", nil];
+    noCountCellValueKeys = [[NSArray alloc] initWithObjects:@"stringValue", 
@"editingStringValue", @"label", @"icon", @"isRetrieving", @"failedDownload", 
@"displayColor", nil];
 }
 
 // super's designated initializer
@@ -147,6 +147,8 @@
 
 - (BOOL)isRetrieving { return NO; }
 
+- (BOOL)displayColor { return NO; }
+
 // custom accessors
 
 - (NSString *)stringValue {

Modified: trunk/bibdesk/BDSKGroupCell.h
===================================================================
--- trunk/bibdesk/BDSKGroupCell.h       2019-09-13 06:30:35 UTC (rev 24208)
+++ trunk/bibdesk/BDSKGroupCell.h       2019-09-13 15:21:13 UTC (rev 24209)
@@ -45,6 +45,7 @@
 extern NSString *BDSKGroupCellCountKey;
 extern NSString *BDSKGroupCellIsRetrievingKey;
 extern NSString *BDSKGroupCellFailedDownloadKey;
+extern NSString *BDSKGroupCellDisplayColorKey;
 
 @class BDSKGroup;
 

Modified: trunk/bibdesk/BDSKGroupCell.m
===================================================================
--- trunk/bibdesk/BDSKGroupCell.m       2019-09-13 06:30:35 UTC (rev 24208)
+++ trunk/bibdesk/BDSKGroupCell.m       2019-09-13 15:21:13 UTC (rev 24209)
@@ -53,6 +53,7 @@
 NSString *BDSKGroupCellCountKey = @"numberValue";
 NSString *BDSKGroupCellIsRetrievingKey = @"isRetrieving";
 NSString *BDSKGroupCellFailedDownloadKey = @"failedDownload";
+NSString *BDSKGroupCellDisplayColorKey = @"displayColor";
 
 #define LABEL_FONTSIZE_OFFSET 2.0
 
@@ -205,6 +206,10 @@
     return [nonNullObjectValueForKey([self objectValue], 
BDSKGroupCellFailedDownloadKey) boolValue];
 }
 
+- (BOOL)displayColor {
+    return [nonNullObjectValueForKey([self objectValue], 
BDSKGroupCellDisplayColorKey) boolValue];
+}
+
 #pragma mark Drawing
 
 #define BORDER_BETWEEN_EDGE_AND_IMAGE (3.0)
@@ -276,6 +281,9 @@
     NSSize cellSize = [super cellSizeForBounds:aRect];
     NSSize countSize = NSZeroSize;
     CGFloat iconHeight = cellSize.height + IMAGE_SIZE_OFFSET;
+    if ([self displayColor]) {
+        cellSize.width = cellSize.height;
+    }
     if ([self label]) {
         cellSize.width = fmax(cellSize.width, [labelCell cellSize].width);
         cellSize.height += [self labelHeight];
@@ -297,18 +305,29 @@
     BOOL isHighlighted = ([self backgroundStyle] == NSBackgroundStyleDark || 
[self backgroundStyle] == NSBackgroundStyleLowered);
     
     // Draw the text
-    NSRect textRect = [self textRectForBounds:aRect]; 
-    NSFont *font = nil;
-    if (isHighlighted && RUNNING_BEFORE(10_10)) {
-        // source list draws selected text bold, but only when the passing an 
NSString to setObjectValue:
-        font = [[self font] retain];
-        [super setFont:[[NSFontManager sharedFontManager] convertWeight:YES 
ofFont:font]];
+    NSRect textRect = [self textRectForBounds:aRect];
+    if ([self displayColor]) {
+        CGFloat height = [super cellSizeForBounds:textRect].height;
+        NSRect swatchRect = BDSKSliceRect(BDSKSliceRect(textRect, height, 
NSMinXEdge), height, [controlView isFlipped] ? NSMinYEdge : NSMaxYEdge);
+        NSColor *color = [NSColor colorWithFourByteString:[self stringValue]];
+        
+        [NSGraphicsContext saveGraphicsState];
+        [[NSBezierPath bezierPathWithOvalInRect:swatchRect] addClip];
+        [color drawSwatchInRect:swatchRect];
+        [NSGraphicsContext restoreGraphicsState];
+    } else {
+        NSFont *font = nil;
+        if (isHighlighted && RUNNING_BEFORE(10_10)) {
+            // source list draws selected text bold, but only when the passing 
an NSString to setObjectValue:
+            font = [[self font] retain];
+            [super setFont:[[NSFontManager sharedFontManager] 
convertWeight:YES ofFont:font]];
+        }
+        [super drawInteriorWithFrame:textRect inView:controlView];
+        if (font) {
+            [super setFont:font];
+            [font release];
+        }
     }
-    [super drawInteriorWithFrame:textRect inView:controlView];
-    if (font) {
-        [super setFont:font];
-        [font release];
-    }
     
     // Draw the count bubble or caution icon, when we're retrieving we don't 
draw to leave space for the spinner
     if ([self isRetrieving] == NO) {

Modified: trunk/bibdesk/BDSKTypeManager.m
===================================================================
--- trunk/bibdesk/BDSKTypeManager.m     2019-09-13 06:30:35 UTC (rev 24208)
+++ trunk/bibdesk/BDSKTypeManager.m     2019-09-13 15:21:13 UTC (rev 24209)
@@ -242,7 +242,7 @@
                BDSKAbstractString, BDSKAnnoteString, BDSKRssDescriptionString, 
nil];
        [invalidFields unionSet:allURLFields];
     
-    NSMutableSet *singleValuedFields = [NSMutableSet 
setWithObjects:BDSKPubTypeString, BDSKTypeString, BDSKCrossrefString, 
BDSKJournalString, BDSKBooktitleString, BDSKVolumetitleString, BDSKYearString, 
BDSKMonthString, BDSKPublisherString, BDSKAddressString, nil];
+    NSMutableSet *singleValuedFields = [NSMutableSet 
setWithObjects:BDSKPubTypeString, BDSKTypeString, BDSKCrossrefString, 
BDSKJournalString, BDSKBooktitleString, BDSKVolumetitleString, BDSKYearString, 
BDSKMonthString, BDSKPublisherString, BDSKAddressString, BDSKColorString, nil];
        [singleValuedFields unionSet:ratingFields];
        [singleValuedFields unionSet:booleanFields];
        [singleValuedFields unionSet:triStateFields];  

Modified: trunk/bibdesk/BibDocument_Groups.m
===================================================================
--- trunk/bibdesk/BibDocument_Groups.m  2019-09-13 06:30:35 UTC (rev 24208)
+++ trunk/bibdesk/BibDocument_Groups.m  2019-09-13 15:21:13 UTC (rev 24209)
@@ -781,7 +781,7 @@
 - (IBAction)addGroupFieldAction:(id)sender{
        BDSKTypeManager *typeMan = [BDSKTypeManager sharedManager];
        NSArray *groupFields = [[NSUserDefaults standardUserDefaults] 
stringArrayForKey:BDSKGroupFieldsKey];
-    NSArray *colNames = [typeMan allFieldNamesIncluding:[NSArray 
arrayWithObjects:BDSKPubTypeString, BDSKCrossrefString, nil]
+    NSArray *colNames = [typeMan allFieldNamesIncluding:[NSArray 
arrayWithObjects:BDSKPubTypeString, BDSKCrossrefString, BDSKColorLabelString, 
nil]
                                               excluding:[[[typeMan 
invalidGroupFieldsSet] allObjects] arrayByAddingObjectsFromArray:groupFields]];
     
     BDSKFieldSheetController *addFieldController = [BDSKFieldSheetController 
fieldSheetControllerWithChoosableFields:colNames
@@ -1335,7 +1335,9 @@
     NSInteger count = 0;
     BDSKFieldAction handleInherited = BDSKFieldActionAsk;
        BDSKFieldAction rv;
-    
+    if ([field isEqualToString:BDSKColorLabelString])
+        field = BDSKColorString;
+
     for (BibItem *pub in pubs) {
         BDSKASSERT([pub isKindOfClass:[BibItem class]]);        
         
@@ -1396,7 +1398,9 @@
         NSString *field = [group key];
                BDSKFieldAction rv;
         NSInteger tmpCount = 0;
-               
+        if ([field isEqualToString:BDSKColorLabelString])
+            field = BDSKColorString;
+        
                for (BibItem *pub in pubs) {
                        BDSKASSERT([pub isKindOfClass:[BibItem class]]);        
                        
@@ -1452,7 +1456,9 @@
     NSMutableArray *newValues = [NSMutableArray arrayWithCapacity:[pubs 
count]];
     NSString *oldValue = nil;
     NSString *field = [group key];
-       
+    if ([field isEqualToString:BDSKColorLabelString])
+        field = BDSKColorString;
+    
        for (BibItem *pub in pubs){
                BDSKASSERT([pub isKindOfClass:[BibItem class]]);        
                

Modified: trunk/bibdesk/BibDocument_UI.m
===================================================================
--- trunk/bibdesk/BibDocument_UI.m      2019-09-13 06:30:35 UTC (rev 24208)
+++ trunk/bibdesk/BibDocument_UI.m      2019-09-13 15:21:13 UTC (rev 24209)
@@ -1032,6 +1032,15 @@
         return [key isEqualToString:searchKey];
 }
 
+static BOOL groupFieldsDependOnKey(NSArray *groupFields, NSString *key) {
+    if ([groupFields containsObject:key])
+        return YES;
+    else if ([key isEqualToString:BDSKColorString])
+        return [groupFields containsObject:BDSKColorLabelString];
+    else
+        return NO;
+}
+
 - (void)handlePrivateBibItemChanged{
     // we can be called from a queue after the document was closed
     if (docFlags.isDocumentClosed)
@@ -1154,7 +1163,7 @@
         }
     }
     
-    if (changedKey == nil || [[self currentGroupFields] 
containsObject:changedKey])
+    if (changedKey == nil || groupFieldsDependOnKey([self currentGroupFields], 
changedKey))
         docFlags.itemChangeMask |= BDSKItemChangedGroupFieldMask;
     if ((tmpSortKey && sortKeyDependsOnKey(tmpSortKey, changedKey)) || 
sortKeyDependsOnKey(sortKey, changedKey) || 
sortKeyDependsOnKey(previousSortKey, changedKey))
         docFlags.itemChangeMask |= BDSKItemChangedSortKeyMask;

Modified: trunk/bibdesk/BibItem.m
===================================================================
--- trunk/bibdesk/BibItem.m     2019-09-13 06:30:35 UTC (rev 24208)
+++ trunk/bibdesk/BibItem.m     2019-09-13 15:21:13 UTC (rev 24209)
@@ -1233,7 +1233,7 @@
                return [NSString stringWithBool:[self boolValueOfField:field]];
     }else if([field isTriStateField]){
                return [NSString stringWithTriStateValue:[self 
triStateValueOfField:field]];
-    }else if([field isNoteField] || [field isCitationField] || [field 
isEqualToString:BDSKCrossrefString]){
+    }else if([field isNoteField] || [field isCitationField] || [field 
isEqualToString:BDSKCrossrefString] || [field 
isEqualToString:BDSKColorLabelString] || [field 
isEqualToString:BDSKColorString]){
                return [self valueOfField:field inherit:NO];
        }else if([field isEqualToString:BDSKPubTypeString]){
                return [self pubType];
@@ -1262,6 +1262,8 @@
        }else if([field isEqualToString:BDSKCiteKeyString]){
                [self setCiteKey:value];
        }else{
+        if ([field isEqualToString:BDSKColorLabelString])
+            field = BDSKColorString;
                [self setField:field toValue:value];
        }
 }
@@ -3202,6 +3204,9 @@
 #pragma mark Groups
 
 - (NSSet *)groupsForField:(NSString *)field{
+    if ([field isEqualToString:BDSKColorLabelString])
+        field = BDSKColorString;
+    
        // first see if we had it cached
        NSSet *groupSet = [groups objectForKey:field];
        if(groupSet)
@@ -3250,6 +3255,8 @@
     // don't add it twice; this is typed as id because it may be a BibAuthor 
or NSString, so be careful
        id groupName = [group name];
        NSString *field = [group key];
+    if ([field isEqualToString:BDSKColorLabelString])
+        field = BDSKColorString;
        BDSKASSERT(field != nil);
     if([[self groupsForField:field] containsObject:groupName])
         return BDSKFieldActionIgnore;
@@ -3305,6 +3312,8 @@
        BDSKASSERT([owner isDocument]);
        id groupName = [group name];
        NSString *field = [group key];
+    if ([field isEqualToString:BDSKColorLabelString])
+        field = BDSKColorString;
        BDSKASSERT(field != nil && [field isEqualToString:BDSKPubTypeString] == 
NO);
        NSSet *groupNames = [groups objectForKey:field];
     if([groupNames containsObject:groupName] == NO)
@@ -3442,6 +3451,8 @@
     id newGroupName = [newGroup name];
        NSString *field = [group key];
        BDSKASSERT(field != nil && [field isEqualToString:[newGroup key]]);
+    if ([field isEqualToString:BDSKColorLabelString])
+        field = BDSKColorString;
        NSSet *groupNames = [groups objectForKey:field];
     if([groupNames containsObject:groupName] == NO)
         return BDSKFieldActionIgnore;

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

Reply via email to