Revision: 28714
http://sourceforge.net/p/bibdesk/svn/28714
Author: hofman
Date: 2024-02-09 15:41:27 +0000 (Fri, 09 Feb 2024)
Log Message:
-----------
use radio buttons instead of matrix for finder label control
Modified Paths:
--------------
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVColorMenuView.h
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVColorMenuView.m
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVColorMenuView.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVColorMenuView.h 2024-02-09
00:05:12 UTC (rev 28713)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVColorMenuView.h 2024-02-09
15:41:27 UTC (rev 28714)
@@ -60,7 +60,7 @@
*/
@interface FVColorMenuView : NSControl
{
- FVColorMenuMatrix *_matrix;
+ NSArray *_buttons;
NSTextFieldCell *_labelCell;
NSTextFieldCell *_labelNameCell;
SEL _action;
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVColorMenuView.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVColorMenuView.m 2024-02-09
00:05:12 UTC (rev 28713)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVColorMenuView.m 2024-02-09
15:41:27 UTC (rev 28714)
@@ -46,18 +46,17 @@
- (NSColor *)systemGrayColor;
@end
+@interface FVColorMenuButton : NSButton
+@property (nonatomic, readonly) NSString *hoveredLabelName;
+@end
+
@interface FVColorMenuCell : NSButtonCell
{
- BOOL hovered;
+ BOOL _hovered;
}
-- (BOOL)isHovered;
-- (void)setHovered:(BOOL)flag;
+@property (nonatomic, getter=isHovered) BOOL hovered;
@end
-@interface FVColorMenuMatrix : NSMatrix
-- (NSString *)hoveredLabelName;
-@end
-
@interface FVColorMenuView (FVPrivate)
- (void)_handleColorNameUpdate:(NSNotification *)note;
- (void)fvLabelColorAction:(id)sender;
@@ -65,26 +64,39 @@
@implementation FVColorMenuView
-@dynamic target;
-@dynamic action;
+@synthesize target=_target;
+@synthesize action=_action;
#define DEFAULT_FRAME ((NSRect) { 0.0, 0.0, 188.0, 68.0 })
#define DEFAULT_SIZE ((NSSize) { 188.0, 68.0 })
#define DEFAULT_HEIGHT ((CGFloat) 68.0)
-#define DEFAULT_MATRIX_FRAME ((NSRect) { 20.0, 28.0, 158.0, 18.0 })
+#define DEFAULT_BUTTON_FRAME ((NSRect) { 20.0, 28.0, 18.0, 18.0 })
+#define DEFAULT_BUTTON_SEP ((CGFloat) 20.0)
#define LABEL_MARGIN ((CGFloat) 20.0)
+#define FINDER_LABELS { 0, 6, 7, 5, 2, 4, 3, 1 }
+
+ (FVColorMenuView *)menuView;
{
return [[self alloc] initWithFrame:DEFAULT_FRAME];
}
-- (void)_createMatrix
+- (void)_createButtons
{
- _matrix = [[FVColorMenuMatrix alloc] initWithFrame:DEFAULT_MATRIX_FRAME];
- [_matrix setTarget:self];
- [_matrix setAction:@selector(fvLabelColorAction:)];
- [self addSubview:_matrix];
+ NSMutableArray *buttons = [NSMutableArray array];
+ NSRect rect = DEFAULT_BUTTON_FRAME;
+ NSInteger tags[8] = FINDER_LABELS;
+ for (NSUInteger i = 0; i < 8; i++) {
+ NSButton *button = [[FVColorMenuButton alloc] initWithFrame:rect];
+ [button setTag:tags[i]];
+ [[button cell] setTag:tags[i]];
+ [button setTarget:self];
+ [button setAction:@selector(fvLabelColorAction:)];
+ [self addSubview:button];
+ [buttons addObject:button];
+ rect.origin.x += DEFAULT_BUTTON_SEP;
+ }
+ _buttons = [buttons copy];
}
- (id)initWithFrame:(NSRect)aRect
@@ -109,13 +121,16 @@
#endif
// @@ Dark mode
[_labelNameCell setTextColor:[NSColor systemGrayColor]];
- [self _createMatrix];
+ [self _createButtons];
+
_target = nil;
_action = nil;
- if (_matrix)
- [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_handleColorNameUpdate:) name:FVColorNameUpdateNotification
object:_matrix];
+ if ([_buttons count])
+ [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_handleColorNameUpdate:) name:FVColorNameUpdateNotification
object:nil];
+
+ [self setAutoresizesSubviews:NO];
}
return self;
}
@@ -123,29 +138,40 @@
- (void)encodeWithCoder:(NSCoder *)coder
{
[super encodeWithCoder:coder];
- [coder encodeConditionalObject:_matrix forKey:@"_matrix"];
[coder encodeObject:_labelCell forKey:@"_labelCell"];
[coder encodeObject:_labelNameCell forKey:@"_labelNameCell"];
[coder encodeConditionalObject:_target forKey:@"_target"];
[coder encodeObject:NSStringFromSelector(_action) forKey:@"_action"];
+ [_buttons enumerateObjectsUsingBlock:^(NSButton *button, NSUInteger i,
BOOL *stop){
+ [coder encodeConditionalObject:button forKey:[NSString
stringWithFormat:@"_button%lu", (unsigned long)i]];
+ }];
}
- (id)initWithCoder:(NSCoder *)coder
{
- if (self = [super initWithCoder:coder]) {
- // the following should be unarchived as a subview, so no need to
retain them
- _matrix = [coder decodeObjectForKey:@"_matrix"];
+ self = [super initWithCoder:coder];
+ if (self) {
_labelCell = [coder decodeObjectForKey:@"_labelCell"];
_labelNameCell = [coder decodeObjectForKey:@"_labelNameCell"];
_target = [coder decodeObjectForKey:@"_target"];
_action = NSSelectorFromString([coder decodeObjectForKey:@"_action"]);
+ NSMutableArray *buttons = [NSMutableArray array];
+ for (NSUInteger i = 0; i < 8; i++) {
+ NSButton *button = [coder decodeObjectForKey:[NSString
stringWithFormat:@"_button%lu", (unsigned long)i]];
+ if (button)
+ [buttons addObject:button];
+ }
+ _buttons = [buttons copy];
+
[_labelNameCell setStringValue:@""];
- if (_matrix == nil)
- [self _createMatrix];
- if (_matrix)
- [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_handleColorNameUpdate:) name:FVColorNameUpdateNotification
object:_matrix];
+ if ([_buttons count] == 0)
+ [self _createButtons];
+ if ([_buttons count])
+ [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_handleColorNameUpdate:) name:FVColorNameUpdateNotification
object:nil];
+
+ [self setAutoresizesSubviews:NO];
}
return self;
}
@@ -157,24 +183,20 @@
[self setFrameSize:DEFAULT_SIZE];
}
-- (void)setTarget:(id)target { _target = target; }
-
-- (id)target { return _target; }
-
-- (SEL)action { return _action; }
-
-- (void)setAction:(SEL)action { _action = action; }
-
- (void)selectLabel:(NSUInteger)label;
{
- NSParameterAssert(nil != _matrix);
- [_matrix selectCellWithTag:label];
+ NSParameterAssert(0 != [_buttons count]);
+ for (NSButton *button in _buttons)
+ [button setState:[button tag] == (NSInteger)label ? NSOnState :
NSOffState];
}
- (NSInteger)selectedTag;
{
- NSParameterAssert(nil != [_matrix selectedCell]);
- return [[_matrix selectedCell] tag];
+ for (NSButton *button in _buttons) {
+ if ([button state] == NSOnState)
+ return [button tag];
+ }
+ return 0;
}
// called by the action receiver
@@ -204,14 +226,26 @@
// notification posted in response to a mouseover so we can update the label
name
- (void)_handleColorNameUpdate:(NSNotification *)note
{
- [_labelNameCell setStringValue:[_matrix hoveredLabelName]];
- [self setNeedsDisplay:YES];
+ FVColorMenuButton *button = [note object];
+ if ([_buttons containsObject:button]) {
+ [_labelNameCell setStringValue:[button hoveredLabelName]];
+ [self setNeedsDisplay:YES];
+ }
}
- (void)fvLabelColorAction:(id)sender
{
- [NSApp sendAction:[self action] to:[self target] from:self];
+#if !defined(MAC_OS_X_VERSION_10_8) || MAC_OS_X_VERSION_MIN_REQUIRED <
MAC_OS_X_VERSION_10_8
+ if (floor(NSAppKitVersionNumber) < NSAppKitVersionNumber10_8) {
+ for (NSButton *button in _buttons) {
+ if (button != sender)
+ [button setState:NSOffState];
+ }
+ }
+#endif
+ [self sendAction:[self action] to:[self target]];
+
// we have to close the menu manually
[[[self enclosingMenuItem] menu] cancelTracking];
}
@@ -218,34 +252,80 @@
@end
-@implementation FVColorMenuCell
+@implementation FVColorMenuButton
-#define CELL_SIZE ((NSSize) { 18.0, 18.0 })
+@dynamic hoveredLabelName;
-- (id)initTextCell:(NSString *)aString
++ (Class)cellClass
{
- if (self = [super initTextCell:aString]) {
+ return [FVColorMenuCell class];
+}
+
+- (void)_createTrackingArea
+{
+ NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited |
NSTrackingActiveInKeyWindow | NSTrackingInVisibleRect;
+ NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:[self bounds]
options:options owner:self userInfo:nil];
+ [self addTrackingArea:area];
+}
+
+- (id)initWithFrame:(NSRect)frameRect
+{
+ self = [super initWithFrame:frameRect];
+ if (self) {
[self setButtonType:NSRadioButton];
[self setBordered:NO];
+ [self _createTrackingArea];
}
return self;
}
-- (NSSize)cellSize
+- (id)initWithCoder:(NSCoder *)coder
{
- return CELL_SIZE;
+ self = [super initWithCoder:coder];
+ if (self) {
+ [self _createTrackingArea];
+ }
+ return self;
}
-- (BOOL)isHovered
+- (void)mouseEntered:(NSEvent *)event
{
- return hovered;
+ [(FVColorMenuCell *)[self cell] setHovered:YES];
+ [self setNeedsDisplay:YES];
+ [[NSNotificationCenter defaultCenter]
postNotificationName:FVColorNameUpdateNotification object:self];
+ [super mouseEntered:event];
}
-- (void)setHovered:(BOOL)flag
+- (void)mouseExited:(NSEvent *)event
{
- hovered = flag;
+ [(FVColorMenuCell *)[self cell] setHovered:NO];
+ [self setNeedsDisplay:YES];
+ [[NSNotificationCenter defaultCenter]
postNotificationName:FVColorNameUpdateNotification object:self];
+ [super mouseExited:event];
}
+- (NSString *)hoveredLabelName
+{
+ FVColorMenuCell *cell = [self cell];
+ if ([cell isHovered] == NO)
+ return @"";
+ // Finder uses curly quotes around the name, and displays nothing for the
X item
+ return 0 == [cell tag] ? @"" : [NSString stringWithFormat:@"%C%@%C",
(unichar)0x201C, [FVFinderLabel localizedNameForLabel:[cell tag]],
(unichar)0x201D];
+}
+
+@end
+
+@implementation FVColorMenuCell
+
+@synthesize hovered=_hovered;
+
+#define CELL_SIZE ((NSSize) { 18.0, 18.0 })
+
+- (NSSize)cellSize
+{
+ return CELL_SIZE;
+}
+
static NSRect __FVSquareRectCenteredInRect(const NSRect iconRect)
{
// determine aspect ratio (copy paste from FVIcon)
@@ -324,113 +404,3 @@
}
@end
-
-@implementation FVColorMenuMatrix
-
-#define FINDER_LABELS { 0, 6, 7, 5, 2, 4, 3, 1 }
-
-- (id)initWithFrame:(NSRect)frameRect
-{
- if (self = [super initWithFrame:frameRect]) {
- [self setPrototype:[[FVColorMenuCell alloc] initTextCell:@""]];
- [self setCellSize:CELL_SIZE];
- [self setIntercellSpacing:NSMakeSize(2.0, 4.0)];
- [self setMode:NSRadioModeMatrix];
- [self renewRows:1 columns:8];
- [self sizeToCells];
- NSInteger column, tags[8] = FINDER_LABELS;
- for (column = 0; column < 8; column++)
- [[self cellAtRow:0 column:column] setTag:tags[column]];
- }
- return self;
-}
-
-- (void)removeTrackingAreas
-{
- for (NSTrackingArea *area in [[self trackingAreas] copy])
- [self removeTrackingArea:area];
-}
-
-- (void)rebuildTrackingAreas
-{
- [self removeTrackingAreas];
- NSUInteger r, nr = [self numberOfRows];
- NSUInteger c, nc = [self numberOfColumns];
-
- for (r = 0; r < nr; r++) {
-
- for (c = 0; c < nc; c++) {
-
- NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited |
NSTrackingActiveInKeyWindow;
- NSRect cellFrame = [self cellFrameAtRow:r column:c];
- NSTrackingArea *area = [[NSTrackingArea alloc]
initWithRect:cellFrame options:options owner:self userInfo:nil];
- [self addTrackingArea:area];
- }
- }
-}
-
-- (void)viewWillMoveToWindow:(NSWindow *)window
-{
- [[self cells] setValue:[NSNumber numberWithBool:NO] forKey:@"hovered"];
-
- if (window)
- [self rebuildTrackingAreas];
- else
- [self removeTrackingAreas];
-}
-
-- (void)mouseEntered:(NSEvent *)event
-{
- NSInteger r = -1, c = -1;
-
- [self getRow:&r column:&c forPoint:[self convertPoint:[event
locationInWindow] fromView:nil]];
- [[self cells] setValue:[NSNumber numberWithBool:NO] forKey:@"hovered"];
- if (r != -1 && c != -1)
- [[self cellAtRow:r column:c] setHovered:YES];
- [self setNeedsDisplay:YES];
- [[NSNotificationCenter defaultCenter]
postNotificationName:FVColorNameUpdateNotification object:self];
- [super mouseEntered:event];
-}
-
-- (void)mouseExited:(NSEvent *)event
-{
- [[self cells] setValue:[NSNumber numberWithBool:NO] forKey:@"hovered"];
- [self setNeedsDisplay:YES];
- [[NSNotificationCenter defaultCenter]
postNotificationName:FVColorNameUpdateNotification object:self];
- [super mouseExited:event];
-}
-
-- (NSString *)hoveredLabelName;
-{
- FVColorMenuCell *cell = nil;
- for (cell in [self cells]) {
- if ([cell isHovered])
- break;
- }
-
- // Finder uses curly quotes around the name, and displays nothing for the
X item
- return 0 == [cell tag] ? @"" : [NSString stringWithFormat:@"%C%@%C",
(unichar)0x201C, [FVFinderLabel localizedNameForLabel:[cell tag]],
(unichar)0x201D];
-}
-
-- (NSArray *)accessibilityAttributeNames {
- static NSArray *attributes = nil;
- if (attributes == nil)
- attributes = [[super accessibilityAttributeNames]
arrayByAddingObject:NSAccessibilityTitleAttribute];
- return attributes;
-}
-
-- (id)accessibilityAttributeValue:(NSString *)attribute {
- if ([attribute isEqualToString:NSAccessibilityTitleAttribute]) {
- NSBundle *bundle = [NSBundle bundleForClass:[FVColorMenuView self]];
- return NSLocalizedStringFromTableInBundle(@"Label:", @"FileView",
bundle, @"Finder label menu item title");
- } else {
- return [super accessibilityAttributeValue:attribute];
- }
-}
-
-- (NSString *)accessibilityLabel {
- NSBundle *bundle = [NSBundle bundleForClass:[FVColorMenuView self]];
- return NSLocalizedStringFromTableInBundle(@"Label:", @"FileView", bundle,
@"Finder label menu item title");
-}
-
-@end
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