Revision: 24240 http://sourceforge.net/p/bibdesk/svn/24240 Author: hofman Date: 2019-09-27 14:35:54 +0000 (Fri, 27 Sep 2019) Log Message: ----------- Add a few system colors and special labels. Add a custom color well control to choose a default color label or a generic color. Add this control to the action menu and main table context menu.
Modified Paths: -------------- trunk/bibdesk/BibDocument.h trunk/bibdesk/BibDocument.m trunk/bibdesk/BibDocument_Actions.h trunk/bibdesk/BibDocument_Actions.m trunk/bibdesk/BibDocument_UI.m trunk/bibdesk/Bibdesk.xcodeproj/project.pbxproj trunk/bibdesk/English.lproj/BDSKCondition.xib trunk/bibdesk/French.lproj/BDSKCondition.xib trunk/bibdesk/German.lproj/BDSKCondition.xib trunk/bibdesk/NSColor_BDSKExtensions.h trunk/bibdesk/NSColor_BDSKExtensions.m Added Paths: ----------- trunk/bibdesk/BDSKColorLabelWell.h trunk/bibdesk/BDSKColorLabelWell.m Added: trunk/bibdesk/BDSKColorLabelWell.h =================================================================== --- trunk/bibdesk/BDSKColorLabelWell.h (rev 0) +++ trunk/bibdesk/BDSKColorLabelWell.h 2019-09-27 14:35:54 UTC (rev 24240) @@ -0,0 +1,49 @@ +// +// BDSKColorLabelWell.h +// BibDesk +// +// Created by Christiaan Hofman on 27/09/2019. +/* + This software is Copyright (c) 2019 + Christiaan Hofman. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + - Neither the name of Christiaan Hofman nor the names of any + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import <Cocoa/Cocoa.h> + + +@interface BDSKColorLabelWell : NSColorWell { + NSMatrix *matrix; + BOOL suppressColor; +} + +@property (nonatomic) CGFloat margin; + +@end Added: trunk/bibdesk/BDSKColorLabelWell.m =================================================================== --- trunk/bibdesk/BDSKColorLabelWell.m (rev 0) +++ trunk/bibdesk/BDSKColorLabelWell.m 2019-09-27 14:35:54 UTC (rev 24240) @@ -0,0 +1,260 @@ +// +// BDSKColorLabelWell.m +// BibDesk +// +// Created by Christiaan Hofman on 27/09/2019. +/* + This software is Copyright (c) 2019 + Christiaan Hofman. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + - Neither the name of Christiaan Hofman nor the names of any + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import "BDSKColorLabelWell.h" +#import "NSColor_BDSKExtensions.h" + + +@interface BDSKColorLabelCell : NSButtonCell +@end + +#pragma mark - + +@interface BDSKColorLabelWell (Private) +- (void)colorLabelAction:(id)sender; +- (void)updateColorSelection; +@end + + +@implementation BDSKColorLabelWell + +@dynamic margin; + +- (void)makeMatrix { + matrix = [[NSMatrix alloc] initWithFrame:NSMakeRect(0.0, 2.0, 178.0, 22.0)]; + BDSKColorLabelCell *cell = [[[BDSKColorLabelCell alloc] initTextCell:@""] autorelease]; + [cell setButtonType:NSButtonTypeRadio]; + [cell setBordered:NO]; + [matrix setPrototype:cell]; + [matrix setCellSize:NSMakeSize(18.0, 18.0)]; + [matrix setIntercellSpacing:NSMakeSize(2.0, 4.0)]; + [matrix setMode:NSRadioModeMatrix]; + [matrix setSelectionByRect:NO]; + [matrix renewRows:1 columns:9]; + [matrix sizeToCells]; + [matrix deselectAllCells]; + NSArray *colors = [NSColor labelColors]; + NSInteger column; + for (column = 0; column < 9; column++) { + cell = [matrix cellAtRow:0 column:column]; + [cell setTag:column]; + if (column > 0 && column < 8) + [cell setRepresentedObject:[colors objectAtIndex:column - 1]]; + } + [matrix setTarget:self]; + [matrix setAction:@selector(colorLabelAction:)]; + [matrix setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin]; + [self addSubview:matrix]; + [matrix deselectAllCells]; +} + +- (id)initWithFrame:(NSRect)frameRect { + self = [super initWithFrame:frameRect]; + if (self) { + [self makeMatrix]; + [self updateColorSelection]; + } + return self; +} + +- (id)initWithCoder:(NSCoder *)coder { + self = [super initWithCoder:coder]; + if (self) { + if ([coder allowsKeyedCoding]) + matrix = [[coder decodeObjectForKey:@"matrix"] retain]; + else if ([[[self subviews] firstObject] isKindOfClass:[NSMatrix class]]) + matrix = [[[self subviews] firstObject] retain]; + if (matrix == nil) + [self makeMatrix]; + [self updateColorSelection]; + } + return self; +} + +- (void)dealloc { + BDSKDESTROY(matrix); + [super dealloc]; +} + +- (void)encodeWithCoder:(NSCoder *)aCoder { + [super encodeWithCoder:aCoder]; + if ([aCoder allowsKeyedCoding]) + [aCoder encodeConditionalObject:matrix forKey:@"matrix"]; +} + +- (void)sizeToFit { + NSRect frame = [matrix frame]; + [self setFrameSize:NSMakeSize(NSMaxX(frame), NSMaxY(frame) + NSMinY(frame))]; +} + +- (CGFloat)margin { + return NSMinX([matrix frame]); +} + +- (void)setMargin:(CGFloat)margin { + [matrix setFrameOrigin:NSMakePoint(margin, NSMinY([matrix frame]))]; +} + +- (BOOL)becomeFirstResponder { + return [matrix becomeFirstResponder]; +} + +- (BOOL)isOpaque { + return NO; +} + +- (void)updateColorSelection { + NSColor *color = [self color]; + NSUInteger idx = [[NSColor labelColors] indexOfObject:color]; + NSCell *genericCell = [matrix cellWithTag:8]; + if ([[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] alphaComponent] <= 0.0) + idx = 0; + else if (idx != NSNotFound) + idx++; + if (idx != NSNotFound) { + [matrix selectCellWithTag:idx]; + [genericCell setRepresentedObject:nil]; + } else { + [matrix selectCellWithTag:8]; + [genericCell setRepresentedObject:color]; + } +} + +- (NSColor *)color { + return suppressColor ? nil : [super color]; +} + +- (void)setColor:(NSColor *)color { + [super setColor:color]; + [self updateColorSelection]; +} + +- (void)deactivate { + [super deactivate]; + [self updateColorSelection]; +} + +- (void)drawRect:(NSRect)dirtyRect { + if ([self isActive]) { + NSRect rect = [matrix convertRect:[matrix cellFrameAtRow:0 column:8] toView:self]; + [NSGraphicsContext saveGraphicsState]; + [[NSColor colorWithCalibratedWhite:0.66667 alpha:0.75] setFill]; + [[NSBezierPath bezierPathWithOvalInRect:rect] fill]; + [NSGraphicsContext restoreGraphicsState]; + } +} + +- (void)mouseDown:(NSEvent *)event {} + +- (void)changeColor:(id)sender {} + +- (void)colorLabelAction:(id)sender { + NSColor *color = nil; + NSInteger tag = [sender selectedTag]; + if (tag < 0) + return; + else if (tag == 0) + color = [NSColor clearColor]; + else if (tag < 8) + color = [[NSColor labelColors] objectAtIndex:tag - 1]; + if (color) { + if ([self isActive]) + [self deactivate]; + [self setColor:color]; + if ([self action]) + [self sendAction:[self action] to:[self target]]; + } else if ([self isActive]) { + [self deactivate]; + } else { + [self activate:YES]; + if ([self action]) { + suppressColor = YES; + [NSApp sendAction:[self action] to:[self target] from:self]; + suppressColor = NO; + } + } + [[[self enclosingMenuItem] menu] cancelTracking]; +} + +@end + +#pragma mark - + +@implementation BDSKColorLabelCell + +- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { + NSInteger tag = [self tag]; + NSColor *color = [self representedObject]; + NSRect rect = NSInsetRect(cellFrame, 3.0, 3.0); + [NSGraphicsContext saveGraphicsState]; + if ([self state] == NSControlStateValueOn) { + NSRect r = NSInsetRect(cellFrame, 1.0, 1.0); + NSBezierPath *path = [NSBezierPath bezierPathWithOvalInRect:r]; + [path setLineWidth:1.5]; + [[NSColor lightGrayColor] setStroke]; + [path stroke]; + } + if (tag == 0) { + rect = NSInsetRect(rect, 0.5, 0.5); + NSBezierPath *path = [NSBezierPath bezierPathWithOvalInRect:rect]; + NSPoint c = NSMakePoint(NSMidX(rect), NSMidY(rect)); + CGFloat r = 0.5 * M_SQRT1_2 * NSWidth(rect); + [path moveToPoint:NSMakePoint(c.x + r, c.x + r)]; + [path lineToPoint:NSMakePoint(c.x - r, c.x - r)]; + [path moveToPoint:NSMakePoint(c.x - r, c.x + r)]; + [path lineToPoint:NSMakePoint(c.x + r, c.x - r)]; + [[NSColor controlTextColor] setStroke]; + [path setLineWidth:1.0]; + [path stroke]; + } else if (tag < 8) { + [color setFill]; + [[NSBezierPath bezierPathWithOvalInRect:rect] fill]; + [[NSColor colorWithCalibratedWhite:1.0 alpha:0.2] setFill]; + [[NSBezierPath bezierPathWithOvalInRect:NSInsetRect(rect, 1.0, 1.0)] fill]; + } else if (color) { + [[NSBezierPath bezierPathWithOvalInRect:rect] addClip]; + [color drawSwatchInRect:rect]; + } else { + NSImage *image = [NSImage imageNamed:NSImageNameColorPanel]; + [[NSBezierPath bezierPathWithOvalInRect:rect] addClip]; + [image drawInRect:NSInsetRect(cellFrame, 1.0, 1.0)]; + } + [NSGraphicsContext restoreGraphicsState]; +} + +@end Modified: trunk/bibdesk/BibDocument.h =================================================================== --- trunk/bibdesk/BibDocument.h 2019-09-27 06:30:57 UTC (rev 24239) +++ trunk/bibdesk/BibDocument.h 2019-09-27 14:35:54 UTC (rev 24240) @@ -46,7 +46,7 @@ @class BibItem, BibAuthor, BDSKGroup, BDSKStaticGroup, BDSKSmartGroup, BDSKTemplate, BDSKPublicationsArray, BDSKGroupsArray; @class AGRegex, BDSKMacroResolver; @class BDSKEditor, BDSKMacroWindowController, BDSKDocumentInfoWindowController, BDSKPreviewer, BDSKFileContentSearchController, BDSKCustomCiteDrawerController, BDSKSearchGroupViewController, BDSKSaveAccessoryViewController; -@class BDSKStatusBar, BDSKButtonBar, BDSKMainTableView, BDSKGroupOutlineView, BDSKGradientView, BDSKCollapsibleView, BDSKEdgeView, BDSKImagePopUpButton, BDSKColoredView, BDSKEncodingPopUpButton, BDSKZoomablePDFView, FVFileView, BDSKSplitView; +@class BDSKStatusBar, BDSKButtonBar, BDSKMainTableView, BDSKGroupOutlineView, BDSKGradientView, BDSKCollapsibleView, BDSKEdgeView, BDSKImagePopUpButton, BDSKColoredView, BDSKEncodingPopUpButton, BDSKZoomablePDFView, FVFileView, BDSKSplitView, BDSKColorLabelWell; @class BDSKWebGroupViewController; @class BDSKItemSearchIndexes, BDSKNotesSearchIndex, BDSKFileMigrationController, BDSKDocumentSearch; @class BDSKItemPasteboardHelper; @@ -184,6 +184,7 @@ NSMenu *groupMenu; NSMenu *actionMenu; NSMenu *alternateCopyMenu; + BDSKColorLabelWell *colorLabelWell; #pragma mark Accessory view variables Modified: trunk/bibdesk/BibDocument.m =================================================================== --- trunk/bibdesk/BibDocument.m 2019-09-27 06:30:57 UTC (rev 24239) +++ trunk/bibdesk/BibDocument.m 2019-09-27 14:35:54 UTC (rev 24240) @@ -79,6 +79,7 @@ #import "BDSKZoomablePDFView.h" #import "BDSKZoomableTextView.h" #import "BDSKGradientView.h" +#import "BDSKColorLabelWell.h" #import "BDSKItemPasteboardHelper.h" #import "BDSKMacroResolver.h" @@ -319,6 +320,7 @@ BDSKDESTROY(groupSpinners); BDSKDESTROY(previewURLs); BDSKDESTROY(touchBar); + BDSKDESTROY(colorLabelWell); [super dealloc]; } @@ -542,6 +544,23 @@ [(BDSKZoomableTextView *)sidePreviewTextView setScaleFactor:[xattrDefaults doubleForKey:BDSKSidePreviewScaleFactorKey defaultValue:1.0]]; [(BDSKZoomableTextView *)bottomPreviewTextView setScaleFactor:[xattrDefaults doubleForKey:BDSKBottomPreviewScaleFactorKey defaultValue:1.0]]; + colorLabelWell = [[BDSKColorLabelWell alloc] initWithFrame:NSMakeRect(0.0, 0.0, 198, 22.0)]; + [colorLabelWell setMargin:20.0]; + [colorLabelWell sizeToFit]; + [colorLabelWell setColor:[NSColor clearColor]]; + [colorLabelWell setAction:@selector(changeColorLabel:)]; + [colorLabelWell setTarget:self]; + + NSInteger idx = [actionMenu indexOfItemWithTarget:self andAction:@selector(changeMainTableFont:)]; + if (idx == -1) + idx = [actionMenu numberOfItems]; + NSMenuItem *item = [[[NSMenuItem alloc] init] autorelease]; + [item setView:colorLabelWell]; + [actionMenu insertItem:[NSMenuItem separatorItem] atIndex:idx]; + [actionMenu insertItem:item atIndex:idx]; + + [actionMenu setDelegate:self]; + // ImagePopUpButtons setup [[actionMenuButton cell] setAltersStateOfSelectedItem:NO]; [actionMenuButton setMenu:actionMenu]; Modified: trunk/bibdesk/BibDocument_Actions.h =================================================================== --- trunk/bibdesk/BibDocument_Actions.h 2019-09-27 06:30:57 UTC (rev 24239) +++ trunk/bibdesk/BibDocument_Actions.h 2019-09-27 14:35:54 UTC (rev 24240) @@ -120,6 +120,8 @@ - (void)printPublications:(NSArray *)pubs; - (IBAction)printSelection:(id)sender; +- (void)changeColorLabel:(id)sender; + #pragma mark URL actions - (IBAction)chooseLinkedFile:(id)sender; Modified: trunk/bibdesk/BibDocument_Actions.m =================================================================== --- trunk/bibdesk/BibDocument_Actions.m 2019-09-27 06:30:57 UTC (rev 24239) +++ trunk/bibdesk/BibDocument_Actions.m 2019-09-27 14:35:54 UTC (rev 24240) @@ -649,6 +649,19 @@ } } +- (void)changeColorLabel:(id)sender { + if ([self hasGroupTypeSelected:BDSKExternalGroupType] == NO && [self isDisplayingFileContentSearch] == NO) { + NSColor *color = [sender color]; + if (color == nil) { + [self selectPublications:[self clickedOrSelectedPublications]]; + } else if ([[self clickedOrSelectedPublications] count] > 0 && changingColors == NO) { + changingColors = YES; + [[self clickedOrSelectedPublications] setValue:[sender color] forKey:@"color"]; + changingColors = NO; + } + } +} + - (void)printPublications:(NSArray *)pubs { NSString *string = [self bibTeXStringForPublications:pubs]; NSAttributedString *attrString = [[[NSAttributedString alloc] initWithString:string attributeName:NSFontAttributeName attributeValue:[NSFont userFontOfSize:0.0]] autorelease]; Modified: trunk/bibdesk/BibDocument_UI.m =================================================================== --- trunk/bibdesk/BibDocument_UI.m 2019-09-27 06:30:57 UTC (rev 24239) +++ trunk/bibdesk/BibDocument_UI.m 2019-09-27 14:35:54 UTC (rev 24240) @@ -80,6 +80,7 @@ #import "NSObject_BDSKExtensions.h" #import "BDSKSmartGroup.h" #import "NSAttributedString_BDSKExtensions.h" +#import "BDSKColorLabelWell.h" #define BDSKDisableMigrationWarningKey @"BDSKDisableMigrationWarning" @@ -595,6 +596,14 @@ NSURL *theURL; BOOL isSingle; + NSColor *color = nil; + if ([self hasGroupTypeSelected:BDSKExternalGroupType] == NO && [self isDisplayingFileContentSearch] == NO && [[self clickedOrSelectedPublications] count]) { + NSSet *set = [NSSet setWithArray:[[self clickedOrSelectedPublications] valueForKey:@"color"]]; + if ([set count] == 1 && [set containsObject:[NSNull null]] == NO) + color = [set anyObject]; + } + [colorLabelWell setColor:color ?: [NSColor clearColor]]; + if([tcId isGeneralURLField] || [tcId isCitationField]){ if([tcId isEqualToString:BDSKLocalFileString]) linkedURLs = [self clickedOrSelectedFileURLs]; @@ -727,6 +736,16 @@ } } +- (void)updateActionMenu:(NSMenu *)menu { + NSColor *color = nil; + if ([self hasGroupTypeSelected:BDSKExternalGroupType] == NO && [self isDisplayingFileContentSearch] == NO && [[self clickedOrSelectedPublications] count]) { + NSSet *set = [NSSet setWithArray:[[self clickedOrSelectedPublications] valueForKey:@"color"]]; + if ([set count] == 1 && [set containsObject:[NSNull null]] == NO) + color = [set anyObject]; + } + [colorLabelWell setColor:color ?: [NSColor clearColor]]; +} + - (void)menuNeedsUpdate:(NSMenu *)menu { if (menu == bottomTemplatePreviewMenu || menu == sideTemplatePreviewMenu) [self updateTemplatePreviewMenu:menu]; @@ -736,6 +755,8 @@ [self updateMainTableMenu:menu]; else if (menu == [groupOutlineView menu]) [self updateGroupTableMenu:menu]; + else if (menu == actionMenu) + [self updateActionMenu:menu]; } #pragma mark SplitView delegate Modified: trunk/bibdesk/Bibdesk.xcodeproj/project.pbxproj =================================================================== --- trunk/bibdesk/Bibdesk.xcodeproj/project.pbxproj 2019-09-27 06:30:57 UTC (rev 24239) +++ trunk/bibdesk/Bibdesk.xcodeproj/project.pbxproj 2019-09-27 14:35:54 UTC (rev 24240) @@ -107,6 +107,8 @@ CE21D10B09208B9D0075E607 /* BDSKGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = CE21D10909208B9D0075E607 /* BDSKGroup.m */; }; CE22E1CE0A8CCF9D002CEFB8 /* BDSKOrphanedFilesFinder.m in Sources */ = {isa = PBXBuildFile; fileRef = CE22E1CC0A8CCF9C002CEFB8 /* BDSKOrphanedFilesFinder.m */; }; CE2391620A334890009F3A5B /* BDSKDocumentInfoWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = CE2391600A334890009F3A5B /* BDSKDocumentInfoWindowController.m */; }; + CE23B2CC233E0B96006390D9 /* BDSKColorLabelWell.h in Headers */ = {isa = PBXBuildFile; fileRef = CE23B2CA233E0B96006390D9 /* BDSKColorLabelWell.h */; }; + CE23B2CD233E0B96006390D9 /* BDSKColorLabelWell.m in Sources */ = {isa = PBXBuildFile; fileRef = CE23B2CB233E0B96006390D9 /* BDSKColorLabelWell.m */; }; CE23F8CD21E0EC3300276091 /* BDSKFontManager.m in Sources */ = {isa = PBXBuildFile; fileRef = CE23F8CB21E0EC3300276091 /* BDSKFontManager.m */; }; CE248773112C974D006B4FA5 /* NSFont_BDSKExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = CE248771112C974D006B4FA5 /* NSFont_BDSKExtensions.m */; }; CE24B33510C3E13900818EDF /* BDSKLibraryGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = CE24B33310C3E13900818EDF /* BDSKLibraryGroup.m */; }; @@ -1286,6 +1288,8 @@ CE22E1CC0A8CCF9C002CEFB8 /* BDSKOrphanedFilesFinder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BDSKOrphanedFilesFinder.m; sourceTree = "<group>"; }; CE23915F0A334890009F3A5B /* BDSKDocumentInfoWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BDSKDocumentInfoWindowController.h; sourceTree = "<group>"; }; CE2391600A334890009F3A5B /* BDSKDocumentInfoWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BDSKDocumentInfoWindowController.m; sourceTree = "<group>"; }; + CE23B2CA233E0B96006390D9 /* BDSKColorLabelWell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BDSKColorLabelWell.h; sourceTree = "<group>"; }; + CE23B2CB233E0B96006390D9 /* BDSKColorLabelWell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BDSKColorLabelWell.m; sourceTree = "<group>"; }; CE23F8CA21E0EC3300276091 /* BDSKFontManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BDSKFontManager.h; sourceTree = "<group>"; }; CE23F8CB21E0EC3300276091 /* BDSKFontManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BDSKFontManager.m; sourceTree = "<group>"; }; CE248770112C974D006B4FA5 /* NSFont_BDSKExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSFont_BDSKExtensions.h; sourceTree = "<group>"; }; @@ -2496,6 +2500,7 @@ CE96DB7010C7288800F085F3 /* BDSKButtonBar.m */, CEEC6C53093A411E00A64F54 /* BDSKCollapsibleView.m */, CE6003270AF3E465000B5680 /* BDSKColoredView.m */, + CE23B2CB233E0B96006390D9 /* BDSKColorLabelWell.m */, CE34E9780A03C16B00222942 /* BDSKConditionsView.m */, CE7595FE0ADDB0E0009C1329 /* BDSKContainerView.m */, CEEC70E0093B6EC200A64F54 /* BDSKDragImageView.m */, @@ -2981,6 +2986,7 @@ 6CAEE4CA0F98EC63009EA5FE /* BDSKCOinSParser.h */, CEEC6C52093A411D00A64F54 /* BDSKCollapsibleView.h */, CE6003260AF3E465000B5680 /* BDSKColoredView.h */, + CE23B2CA233E0B96006390D9 /* BDSKColorLabelWell.h */, CE09CEA40DDEF65E00F3F2FE /* BDSKCompletionManager.h */, CEFEF0EA11C23F1F0050350D /* BDSKCompletionServer.h */, CE3A0BD50B1634D500233208 /* BDSKCompletionServerProtocol.h */, @@ -3365,6 +3371,7 @@ buildActionMask = 2147483647; files = ( CE2A0A19224599EF00A8F31C /* BDSKImagePopUpButtonCell.h in Headers */, + CE23B2CC233E0B96006390D9 /* BDSKColorLabelWell.h in Headers */, CE2A0A5B22459A0A00A8F31C /* BDSKScriptGroup.h in Headers */, CE2A09FF224599E100A8F31C /* BDSKFilerErrorController.h in Headers */, CE2A0A47224599F600A8F31C /* BDSKPreviewer.h in Headers */, @@ -4352,6 +4359,7 @@ F9025DCA0969AD2C008A551C /* NSCharacterSet_BDSKExtensions.m in Sources */, F9025F310969D66F008A551C /* CFString_BDSKExtensions.m in Sources */, CEAE613F097FF60A000B618C /* BDSKJSTORParser.m in Sources */, + CE23B2CD233E0B96006390D9 /* BDSKColorLabelWell.m in Sources */, F9E069B70981A03B00AEFBE7 /* BDSKWebOfScienceParser.m in Sources */, F941135509B549BF00EE8463 /* BDSKEditorTextView.m in Sources */, F94DE74C09CB46FF00B5FD51 /* BDSKPersistentSearch.m in Sources */, Modified: trunk/bibdesk/English.lproj/BDSKCondition.xib =================================================================== --- trunk/bibdesk/English.lproj/BDSKCondition.xib 2019-09-27 06:30:57 UTC (rev 24239) +++ trunk/bibdesk/English.lproj/BDSKCondition.xib 2019-09-27 14:35:54 UTC (rev 24240) @@ -114,8 +114,8 @@ <rect key="frame" x="212" y="20" width="228" height="32"/> <autoresizingMask key="autoresizingMask"/> <subviews> - <colorWell id="bjW-G5-P4U"> - <rect key="frame" x="4" y="5" width="44" height="22"/> + <colorWell id="bjW-G5-P4U" customClass="BDSKColorLabelWell"> + <rect key="frame" x="4" y="5" width="178" height="22"/> <autoresizingMask key="autoresizingMask"/> <color key="color" red="0.05813049898" green="0.055541899059999997" blue="1" alpha="1" colorSpace="calibratedRGB"/> <connections> Modified: trunk/bibdesk/French.lproj/BDSKCondition.xib =================================================================== --- trunk/bibdesk/French.lproj/BDSKCondition.xib 2019-09-27 06:30:57 UTC (rev 24239) +++ trunk/bibdesk/French.lproj/BDSKCondition.xib 2019-09-27 14:35:54 UTC (rev 24240) @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none"> <dependencies> + <deployment identifier="macosx"/> <development version="8000" identifier="xcode"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> @@ -113,8 +114,8 @@ <rect key="frame" x="212" y="20" width="228" height="32"/> <autoresizingMask key="autoresizingMask"/> <subviews> - <colorWell id="bjW-G5-P4U"> - <rect key="frame" x="4" y="5" width="44" height="22"/> + <colorWell id="bjW-G5-P4U" customClass="BDSKColorLabelWell"> + <rect key="frame" x="4" y="5" width="178" height="22"/> <autoresizingMask key="autoresizingMask"/> <color key="color" red="0.05813049898" green="0.055541899059999997" blue="1" alpha="1" colorSpace="calibratedRGB"/> <connections> Modified: trunk/bibdesk/German.lproj/BDSKCondition.xib =================================================================== --- trunk/bibdesk/German.lproj/BDSKCondition.xib 2019-09-27 06:30:57 UTC (rev 24239) +++ trunk/bibdesk/German.lproj/BDSKCondition.xib 2019-09-27 14:35:54 UTC (rev 24240) @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none"> <dependencies> + <deployment identifier="macosx"/> <development version="8000" identifier="xcode"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> @@ -113,8 +114,8 @@ <rect key="frame" x="212" y="20" width="228" height="32"/> <autoresizingMask key="autoresizingMask"/> <subviews> - <colorWell id="bjW-G5-P4U"> - <rect key="frame" x="4" y="5" width="44" height="22"/> + <colorWell id="bjW-G5-P4U" customClass="BDSKColorLabelWell"> + <rect key="frame" x="4" y="5" width="178" height="22"/> <autoresizingMask key="autoresizingMask"/> <color key="color" red="0.05813049898" green="0.055541899059999997" blue="1" alpha="1" colorSpace="calibratedRGB"/> <connections> Modified: trunk/bibdesk/NSColor_BDSKExtensions.h =================================================================== --- trunk/bibdesk/NSColor_BDSKExtensions.h 2019-09-27 06:30:57 UTC (rev 24239) +++ trunk/bibdesk/NSColor_BDSKExtensions.h 2019-09-27 14:35:54 UTC (rev 24240) @@ -61,6 +61,8 @@ + (NSColor *)searchHighlightColor; ++ (NSArray *)labelColors; + + (NSColor *)colorWithFourByteString:(NSString *)string; - (id)fourByteStringValue; @@ -75,12 +77,14 @@ #if SDK_BEFORE(10_10) @interface NSColor (BDSKYosemiteDeclarations) +- (NSColor *)systemRedColor; +- (NSColor *)systemOrangeColor; +- (NSColor *)systemYellowColor; +- (NSColor *)systemGreenColor; - (NSColor *)systemBlueColor; -- (NSColor *)systemRedColor; - (NSColor *)systemPurpleColor; +- (NSColor *)systemGrayColor; - (NSColor *)systemBrownColor; -- (NSColor *)systemGrayColor; -- (NSColor *)systemOrangeColor; - (NSColor *)linkColor; @end #endif Modified: trunk/bibdesk/NSColor_BDSKExtensions.m =================================================================== --- trunk/bibdesk/NSColor_BDSKExtensions.m 2019-09-27 06:30:57 UTC (rev 24239) +++ trunk/bibdesk/NSColor_BDSKExtensions.m 2019-09-27 14:35:54 UTC (rev 24240) @@ -135,9 +135,11 @@ BDSKAddClassMethodImplementationFromSelector(self, @selector(systemBlueColor), @selector(blueColor)); BDSKAddClassMethodImplementationFromSelector(self, @selector(systemBrownColor), @selector(brownColor)); BDSKAddClassMethodImplementationFromSelector(self, @selector(systemGrayColor), @selector(grayColor)); + BDSKAddClassMethodImplementationFromSelector(self, @selector(systemGreenColor), @selector(greenColor)); BDSKAddClassMethodImplementationFromSelector(self, @selector(systemOrangeColor), @selector(orangeColor)); BDSKAddClassMethodImplementationFromSelector(self, @selector(systemPurpleColor), @selector(purpleColor)); BDSKAddClassMethodImplementationFromSelector(self, @selector(systemRedColor), @selector(redColor)); + BDSKAddClassMethodImplementationFromSelector(self, @selector(systemYellowColor), @selector(yellowColor)); BDSKAddClassMethodImplementationFromSelector(self, @selector(linkColor), @selector(blueColor)); } @@ -262,6 +264,13 @@ return color; } ++ (NSArray *)labelColors { + static NSArray *labelColors = nil; + if (labelColors == nil) + labelColors = [[NSArray alloc] initWithObjects:[NSColor systemRedColor], [NSColor systemOrangeColor], [NSColor systemYellowColor], [NSColor systemGreenColor], [NSColor systemBlueColor], [NSColor systemPurpleColor], [NSColor systemGrayColor], nil]; + return labelColors; +} + typedef union _BDSKRGBAInt { struct { uint8_t r; @@ -275,9 +284,14 @@ + (NSColor *)colorWithFourByteString:(NSString *)string { NSColor *color = nil; if ([NSString isEmptyString:string] == NO) { - BDSKRGBAInt u; - u.uintValue = CFSwapInt32BigToHost(strtoul([string UTF8String], NULL, 10)); - color = [NSColor colorWithCalibratedRed:u.rgba.r / 255.0 green:u.rgba.g / 255.0 blue:u.rgba.b / 255.0 alpha:u.rgba.a / 255.0]; + uint32_t label = strtoul([string UTF8String], NULL, 10); + if (label > 0 && label <= [[self labelColors] count]) { + color = [[NSColor labelColors] objectAtIndex:label - 1]; + } else { + BDSKRGBAInt u; + u.uintValue = CFSwapInt32BigToHost(label); + color = [NSColor colorWithCalibratedRed:u.rgba.r / 255.0 green:u.rgba.g / 255.0 blue:u.rgba.b / 255.0 alpha:u.rgba.a / 255.0]; + } } return color; } @@ -284,28 +298,37 @@ - (id)fourByteStringValue { NSString *string = nil; - NSColor *rgbColor = [self colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; - if (rgbColor) { - CGFloat r = 0.0, g = 0.0, b = 0.0, a = 0.0; - [rgbColor getRed:&r green:&g blue:&b alpha:&a]; - // store a 32 bit color instead of the floating point values - BDSKRGBAInt u; - u.rgba.r = (uint32_t)(r * 255); - u.rgba.g = (uint32_t)(g * 255); - u.rgba.b = (uint32_t)(b * 255); - u.rgba.a = (uint32_t)(a * 255); - string = [NSString stringWithFormat:@"%u", CFSwapInt32HostToBig(u.uintValue)]; + NSUInteger label = [[NSColor labelColors] indexOfObject:self]; + if (label != NSNotFound) { + string = [NSString stringWithFormat:@"%lu", (unsigned long)(label + 1)]; + } else { + NSColor *rgbColor = [self colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; + if (rgbColor) { + CGFloat r = 0.0, g = 0.0, b = 0.0, a = 0.0; + [rgbColor getRed:&r green:&g blue:&b alpha:&a]; + // store a 32 bit color instead of the floating point values + BDSKRGBAInt u; + u.rgba.r = (uint32_t)(r * 255); + u.rgba.g = (uint32_t)(g * 255); + u.rgba.b = (uint32_t)(b * 255); + u.rgba.a = (uint32_t)(a * 255); + if (u.rgba.a > 0) + string = [NSString stringWithFormat:@"%u", CFSwapInt32HostToBig(u.uintValue)]; + } } return string; } - (BOOL)isBlackOrWhiteOrTransparentForMargin:(CGFloat)margin { - CGFloat b = 0.0, a = 0.0; - [[self colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getHue:NULL saturation:NULL brightness:&b alpha:&a]; - return (b > 1.0-margin || b < margin || a < margin); + CGFloat r = 0.0, g = 0.0, b = 0.0, a = 0.0; + [[self colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a]; + return (a < margin || (r > 1.0-margin && g > 1.0-margin && b > 1.0-margin) || (r < margin && g < margin && b < margin)); } - (uint32_t)fourByteHSBAValue { + NSUInteger label = [[NSColor labelColors] indexOfObject:self]; + if (label != NSNotFound) + return label + 1; CGFloat hue = 0.0, saturation = 0.0, brightness = 0.0, alpha = 0.0; union _ { struct { @@ -321,7 +344,7 @@ u.hsba.s = (uint8_t)(saturation * 255); u.hsba.b = (uint8_t)(brightness * 255); u.hsba.a = (uint8_t)(alpha * 255); - return CFSwapInt32HostToBig(u.uintValue); + return u.hsba.a == 0 ? 0 : CFSwapInt32HostToBig(u.uintValue); } - (NSComparisonResult)colorCompare:(id)other { 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