minor code cleanup on value transformers

This commit is contained in:
michael starke
2017-05-29 16:46:59 +02:00
parent 90599b613a
commit 6ba9c9818d
5 changed files with 22 additions and 24 deletions

View File

@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="12120" systemVersion="16F73" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies> <dependencies>
<deployment identifier="macosx"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12120"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
<capability name="box content view" minToolsVersion="7.0"/> <capability name="box content view" minToolsVersion="7.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
<objects> <objects>
<customObject id="-2" userLabel="File's Owner" customClass="MPPluginSettingsController"> <customObject id="-2" userLabel="File's Owner" customClass="MPPluginSettingsController">
@@ -19,14 +19,12 @@
<customView translatesAutoresizingMaskIntoConstraints="NO" id="Hz6-mo-xeY"> <customView translatesAutoresizingMaskIntoConstraints="NO" id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="520" height="434"/> <rect key="frame" x="0.0" y="0.0" width="520" height="434"/>
<subviews> <subviews>
<box title="Box" borderType="line" titlePosition="noTitle" translatesAutoresizingMaskIntoConstraints="NO" id="vBs-Ga-aq0"> <box borderType="line" title="Box" titlePosition="noTitle" translatesAutoresizingMaskIntoConstraints="NO" id="vBs-Ga-aq0">
<rect key="frame" x="175" y="16" width="328" height="342"/> <rect key="frame" x="175" y="16" width="328" height="342"/>
<view key="contentView" id="tD5-Na-7XI"> <view key="contentView" id="tD5-Na-7XI">
<rect key="frame" x="1" y="1" width="326" height="340"/> <rect key="frame" x="1" y="1" width="326" height="340"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
</view> </view>
<color key="borderColor" white="0.0" alpha="0.41999999999999998" colorSpace="calibratedWhite"/>
<color key="fillColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</box> </box>
<button translatesAutoresizingMaskIntoConstraints="NO" id="CqP-oK-S8k"> <button translatesAutoresizingMaskIntoConstraints="NO" id="CqP-oK-S8k">
<rect key="frame" x="18" y="398" width="159" height="18"/> <rect key="frame" x="18" y="398" width="159" height="18"/>
@@ -35,7 +33,7 @@
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
</buttonCell> </buttonCell>
</button> </button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="aoG-FD-ds8"> <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="aoG-FD-ds8">
<rect key="frame" x="18" y="364" width="484" height="28"/> <rect key="frame" x="18" y="364" width="484" height="28"/>
<textFieldCell key="cell" controlSize="small" sendsActionOnEndEditing="YES" id="2bX-8S-9XM"> <textFieldCell key="cell" controlSize="small" sendsActionOnEndEditing="YES" id="2bX-8S-9XM">
<font key="font" metaFont="smallSystem"/> <font key="font" metaFont="smallSystem"/>
@@ -51,7 +49,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnReordering="NO" columnSelection="YES" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" rowSizeStyle="automatic" viewBased="YES" id="Ocu-C0-03d"> <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnReordering="NO" columnSelection="YES" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" rowSizeStyle="automatic" viewBased="YES" id="Ocu-C0-03d">
<rect key="frame" x="0.0" y="0.0" width="148" height="0.0"/> <rect key="frame" x="0.0" y="0.0" width="148" height="334"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/> <size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/> <color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
@@ -74,8 +72,9 @@
<rect key="frame" x="1" y="1" width="145" height="17"/> <rect key="frame" x="1" y="1" width="145" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="q1P-PD-0LW"> <textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="q1P-PD-0LW">
<rect key="frame" x="0.0" y="0.0" width="100" height="17"/> <rect key="frame" x="0.0" y="0.0" width="100" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="fug-79-n9g"> <textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="fug-79-n9g">
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -92,7 +91,6 @@
</tableColumns> </tableColumns>
</tableView> </tableView>
</subviews> </subviews>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</clipView> </clipView>
<constraints> <constraints>
<constraint firstAttribute="width" constant="150" id="ZpW-Bc-fSx"/> <constraint firstAttribute="width" constant="150" id="ZpW-Bc-fSx"/>
@@ -122,7 +120,7 @@
<constraint firstItem="vBs-Ga-aq0" firstAttribute="leading" secondItem="fCk-fL-jU8" secondAttribute="trailing" constant="8" id="xNu-Sj-xQO"/> <constraint firstItem="vBs-Ga-aq0" firstAttribute="leading" secondItem="fCk-fL-jU8" secondAttribute="trailing" constant="8" id="xNu-Sj-xQO"/>
<constraint firstItem="aoG-FD-ds8" firstAttribute="top" secondItem="CqP-oK-S8k" secondAttribute="bottom" constant="8" symbolic="YES" id="zSW-h3-BrT"/> <constraint firstItem="aoG-FD-ds8" firstAttribute="top" secondItem="CqP-oK-S8k" secondAttribute="bottom" constant="8" symbolic="YES" id="zSW-h3-BrT"/>
</constraints> </constraints>
<point key="canvasLocation" x="-288" y="133"/> <point key="canvasLocation" x="-174" y="134"/>
</customView> </customView>
</objects> </objects>
</document> </document>

View File

@@ -386,7 +386,7 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
[self.expiresCheckButton bind:NSTitleBinding [self.expiresCheckButton bind:NSTitleBinding
toObject:self toObject:self
withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(timeInfo)), NSStringFromSelector(@selector(expirationDate))] withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(timeInfo)), NSStringFromSelector(@selector(expirationDate))]
options:@{ NSValueTransformerNameBindingOption:MPExpiryDateValueTransformer }]; options:@{ NSValueTransformerNameBindingOption:MPExpiryDateValueTransformerName }];
[self.expiresCheckButton bind:NSValueBinding [self.expiresCheckButton bind:NSValueBinding
toObject:self toObject:self
withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(timeInfo)), NSStringFromSelector(@selector(expires))] withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(timeInfo)), NSStringFromSelector(@selector(expires))]

View File

@@ -84,7 +84,7 @@
[self.expiresCheckButton bind:NSTitleBinding [self.expiresCheckButton bind:NSTitleBinding
toObject:self toObject:self
withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(timeInfo)), NSStringFromSelector(@selector(expirationDate))] withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(timeInfo)), NSStringFromSelector(@selector(expirationDate))]
options:@{ NSValueTransformerNameBindingOption:MPExpiryDateValueTransformer }]; options:@{ NSValueTransformerNameBindingOption:MPExpiryDateValueTransformerName }];
[self.autotypePopupButton bind:NSSelectedTagBinding [self.autotypePopupButton bind:NSSelectedTagBinding
toObject:self toObject:self
withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(isAutoTypeEnabled))] withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(isAutoTypeEnabled))]

View File

@@ -9,7 +9,7 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
FOUNDATION_EXPORT NSString *const MPStripLineBreaksTransformerName; FOUNDATION_EXPORT NSString *const MPStripLineBreaksTransformerName;
FOUNDATION_EXPORT NSString *const MPExpiryDateValueTransformer; FOUNDATION_EXPORT NSString *const MPExpiryDateValueTransformerName;
@interface MPValueTransformerHelper : NSObject @interface MPValueTransformerHelper : NSObject

View File

@@ -10,33 +10,33 @@
#import "NSValueTransformer+TransformerKit.h" #import "NSValueTransformer+TransformerKit.h"
NSString *const MPStripLineBreaksTransformerName = @"com.hicknhack.macpass.MPStripLineBreaksTransformerName"; NSString *const MPStripLineBreaksTransformerName = @"com.hicknhack.macpass.MPStripLineBreaksTransformerName";
NSString *const MPExpiryDateValueTransformer = @"com.hicknhack.macpass.kMPExpiryDateValueTransformer"; NSString *const MPExpiryDateValueTransformerName = @"com.hicknhack.macpass.MPExpiryDateValueTransformer";
@implementation MPValueTransformerHelper @implementation MPValueTransformerHelper
+ (void)registerValueTransformer { + (void)registerValueTransformer {
[NSValueTransformer registerValueTransformerWithName:MPStripLineBreaksTransformerName [NSValueTransformer registerValueTransformerWithName:MPStripLineBreaksTransformerName
transformedValueClass:[NSString class] transformedValueClass:NSString.class
returningTransformedValueWithBlock:^id(id value) { returningTransformedValueWithBlock:^id(id value) {
if(![value isKindOfClass:[NSString class]]) { if(![value isKindOfClass:NSString.class]) {
return @""; return @"";
} }
NSArray *elements = [value componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]]; NSArray *elements = [value componentsSeparatedByCharactersInSet:NSCharacterSet.newlineCharacterSet];
return [elements componentsJoinedByString:@" "]; return [elements componentsJoinedByString:@" "];
}]; }];
[NSValueTransformer registerValueTransformerWithName:MPExpiryDateValueTransformer [NSValueTransformer registerValueTransformerWithName:MPExpiryDateValueTransformerName
transformedValueClass:[NSString class] transformedValueClass:NSString.class
returningTransformedValueWithBlock:^id(id value) { returningTransformedValueWithBlock:^id(id value) {
if(![value isKindOfClass:[NSDate class]]) { if(![value isKindOfClass:NSDate.class]) {
return NSLocalizedString(@"NO_EXPIRE_DATE_SET",""); return NSLocalizedString(@"NO_EXPIRE_DATE_SET","");
} }
static NSDateFormatter *formatter; static NSDateFormatter *formatter;
if(!formatter) { if(!formatter) {
formatter = [[NSDateFormatter alloc] init]; formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterFullStyle]; formatter.dateStyle = NSDateFormatterFullStyle;
[formatter setTimeStyle:NSDateFormatterNoStyle]; formatter.timeStyle = NSDateFormatterNoStyle;
} }
NSString *template = NSLocalizedString(@"EXPIRES_AT_DATE_%@", ""); NSString *template = NSLocalizedString(@"EXPIRES_AT_DATE_%@", "");
return [[NSString alloc] initWithFormat:template, [formatter stringFromDate:value]]; return [[NSString alloc] initWithFormat:template, [formatter stringFromDate:value]];