mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-21 09:29:24 +00:00
Removed HNHUIBadgedTextField in favour of a composed UI
This commit is contained in:
73
MacPass/MPOutlineTableCellView.m
Normal file
73
MacPass/MPOutlineTableCellView.m
Normal file
@@ -0,0 +1,73 @@
|
||||
//
|
||||
// MPOutlineTableCellView.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 26.09.18.
|
||||
// Copyright © 2018 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPOutlineTableCellView.h"
|
||||
|
||||
@implementation MPOutlineTableCellView
|
||||
|
||||
@synthesize count = _count;
|
||||
|
||||
- (instancetype)initWithFrame:(NSRect)frameRect {
|
||||
self = [super initWithFrame:frameRect];
|
||||
if(self) {
|
||||
[self _setupDefaults];
|
||||
[self _updateCountDisplay];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)decoder {
|
||||
self = [super initWithCoder:decoder];
|
||||
if(self) {
|
||||
[self _setupDefaults];
|
||||
if([decoder containsValueForKey:NSStringFromSelector(@selector(count))]) {
|
||||
_count = [decoder decodeIntegerForKey:NSStringFromSelector(@selector(count))];
|
||||
}
|
||||
if([decoder containsValueForKey:NSStringFromSelector(@selector(hideZeroCount))]) {
|
||||
_hideZeroCount = [decoder decodeBoolForKey:NSStringFromSelector(@selector(hideZeroCount))];
|
||||
}
|
||||
[self _updateCountDisplay];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)aCoder {
|
||||
[super encodeWithCoder:aCoder];
|
||||
[aCoder encodeBool:_hideZeroCount forKey:NSStringFromSelector(@selector(hideZeroCount))];
|
||||
[aCoder encodeInteger:_count forKey:NSStringFromSelector(@selector(count))];
|
||||
}
|
||||
|
||||
- (void)awakeFromNib {
|
||||
[self _updateCountDisplay];
|
||||
}
|
||||
|
||||
- (void)_setupDefaults {
|
||||
_count = 0;
|
||||
_hideZeroCount = YES;
|
||||
}
|
||||
|
||||
- (void)setCount:(NSInteger)count {
|
||||
if(_count != count) {
|
||||
_count = count;
|
||||
[self _updateCountDisplay];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setHideZeroCount:(BOOL)hideZeroCount {
|
||||
if(_hideZeroCount != hideZeroCount) {
|
||||
_hideZeroCount = hideZeroCount;
|
||||
[self _updateCountDisplay];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_updateCountDisplay {
|
||||
self.countButton.title = [NSString stringWithFormat:@"%ld", _count];
|
||||
self.countButton.hidden = (self.hideZeroCount && self.count == 0);
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user