mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-24 08:49:42 +00:00
Added pretty pring value transformer
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#import "MPSettingsHelper.h"
|
||||
#import "MPSettingsWindowController.h"
|
||||
#import "MPStringLengthValueTransformer.h"
|
||||
#import "MPPrettyPasswordTransformer.h"
|
||||
#import "MPTemporaryFileStorageCenter.h"
|
||||
#import "MPValueTransformerHelper.h"
|
||||
|
||||
@@ -62,6 +63,7 @@ NSString *const MPHelpURLKey = @"MPHelpURL";
|
||||
[MPSettingsHelper setupDefaults];
|
||||
[MPSettingsHelper migrateDefaults];
|
||||
[MPStringLengthValueTransformer registerTransformer];
|
||||
[MPPrettyPasswordTransformer registerTransformer];
|
||||
[MPValueTransformerHelper registerValueTransformer];
|
||||
}
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@
|
||||
#import "MPAutotypeBuilderViewController.h"
|
||||
#import "MPReferenceBuilderViewController.h"
|
||||
|
||||
#import "MPPrettyPasswordTransformer.h"
|
||||
#import "NSString+MPPasswordCreation.h"
|
||||
#import "KPKEntry+MPAdditions.h"
|
||||
|
||||
#import "MPDocument.h"
|
||||
#import "MPIconHelper.h"
|
||||
@@ -137,13 +137,13 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
|
||||
|
||||
NSDictionary *dict = NSDictionaryOfVariableBindings(customFieldTableView, _tagsTokenField, _addCustomFieldButton);
|
||||
[self.generalView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-16-[customFieldTableView]-16-|"
|
||||
options:0
|
||||
metrics:nil
|
||||
views:dict]];
|
||||
options:0
|
||||
metrics:nil
|
||||
views:dict]];
|
||||
[self.generalView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_tagsTokenField]-[customFieldTableView]-[_addCustomFieldButton]"
|
||||
options:0
|
||||
metrics:nil
|
||||
views:dict]];
|
||||
options:0
|
||||
metrics:nil
|
||||
views:dict]];
|
||||
|
||||
|
||||
|
||||
@@ -479,7 +479,7 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
|
||||
toObject:self
|
||||
withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(timeInfo)), NSStringFromSelector(@selector(expires))]
|
||||
options:nil];
|
||||
|
||||
|
||||
[self.tagsTokenField bind:NSValueBinding
|
||||
toObject:self
|
||||
withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(tags))]
|
||||
@@ -546,13 +546,13 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
|
||||
#pragma mark HNHUITextFieldDelegate
|
||||
- (NSMenu *)textField:(NSTextField *)textField textView:(NSTextView *)view menu:(NSMenu *)menu {
|
||||
/*for(NSMenuItem *item in [menu itemArray]) {
|
||||
if(item.action == @selector(showReferenceBuilder:)) {
|
||||
return menu; // item is already contained!
|
||||
}
|
||||
}
|
||||
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"SHOW_REFERENCE_BUILDER", @"Menu item to show the reference builder in a text view's context menu")action:@selector(showReferenceBuilder:) keyEquivalent:@""];
|
||||
item.representedObject = textField;
|
||||
[menu addItem:item];
|
||||
if(item.action == @selector(showReferenceBuilder:)) {
|
||||
return menu; // item is already contained!
|
||||
}
|
||||
}
|
||||
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"SHOW_REFERENCE_BUILDER", @"Menu item to show the reference builder in a text view's context menu")action:@selector(showReferenceBuilder:) keyEquivalent:@""];
|
||||
item.representedObject = textField;
|
||||
[menu addItem:item];
|
||||
*/
|
||||
return menu;
|
||||
}
|
||||
|
||||
17
MacPass/MPPrettyPasswordTransformer.h
Normal file
17
MacPass/MPPrettyPasswordTransformer.h
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// MPPrettyPasswordTransformer.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 01.12.17.
|
||||
// Copyright © 2017 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
APPKIT_EXTERN NSString *const MPPrettyPasswordTransformerName;
|
||||
|
||||
@interface MPPrettyPasswordTransformer : NSValueTransformer
|
||||
|
||||
+ (void)registerTransformer;
|
||||
|
||||
@end
|
||||
41
MacPass/MPPrettyPasswordTransformer.m
Normal file
41
MacPass/MPPrettyPasswordTransformer.m
Normal file
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// MPPrettyPasswordTransformer.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 01.12.17.
|
||||
// Copyright © 2017 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPPrettyPasswordTransformer.h"
|
||||
#import "NSString+MPPrettyPasswordDisplay.h"
|
||||
|
||||
NSString *const MPPrettyPasswordTransformerName = @"com.hicknhack.macpass.MPPrettyPasswordTransformerName";
|
||||
|
||||
@implementation MPPrettyPasswordTransformer
|
||||
|
||||
+ (Class)transformedValueClass {
|
||||
return NSAttributedString.class;
|
||||
}
|
||||
|
||||
+ (BOOL)allowsReverseTransformation {
|
||||
return YES;
|
||||
}
|
||||
|
||||
+ (void)registerTransformer {
|
||||
MPPrettyPasswordTransformer *transformer = [[MPPrettyPasswordTransformer alloc] init];
|
||||
[NSValueTransformer setValueTransformer:transformer
|
||||
forName:MPPrettyPasswordTransformerName];
|
||||
}
|
||||
|
||||
- (id)transformedValue:(id)value {
|
||||
if([value isKindOfClass:NSString.class]) {
|
||||
return ((NSString *)value).passwordPrettified;
|
||||
}
|
||||
if([value isKindOfClass:NSAttributedString.class]) {
|
||||
return ((NSAttributedString *)value).string;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user