From f9e761649f6fda8f1b7aed573b22ed346522d09d Mon Sep 17 00:00:00 2001 From: Michael Starke Date: Fri, 1 Dec 2017 18:57:38 +0100 Subject: [PATCH] Added pretty pring value transformer --- MacPass.xcodeproj/project.pbxproj | 6 ++++ MacPass/MPAppDelegate.m | 2 ++ MacPass/MPEntryInspectorViewController.m | 30 ++++++++--------- MacPass/MPPrettyPasswordTransformer.h | 17 ++++++++++ MacPass/MPPrettyPasswordTransformer.m | 41 ++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 15 deletions(-) create mode 100644 MacPass/MPPrettyPasswordTransformer.h create mode 100644 MacPass/MPPrettyPasswordTransformer.m diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 4b7a0db4..954d5e2e 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -195,6 +195,7 @@ 4C8F0C731FCF1B7A00BE157F /* MPTestPickcharsParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8F0C721FCF1B7A00BE157F /* MPTestPickcharsParser.m */; }; 4C8F0C791FD05A6A00BE157F /* NSString+MPPrettyPasswordDisplay.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8F0C781FD05A6A00BE157F /* NSString+MPPrettyPasswordDisplay.m */; }; 4C978E0D19AE54AB003067DF /* MPFlagsHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C978E0C19AE54AB003067DF /* MPFlagsHelper.m */; }; + 4C9BFFFB1FD19B5400264B16 /* MPPrettyPasswordTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C9BFFFA1FD19B5400264B16 /* MPPrettyPasswordTransformer.m */; }; 4CA08DA017A831B200A6544B /* MPAddEntryContextMenuDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CA08D9F17A831B200A6544B /* MPAddEntryContextMenuDelegate.m */; }; 4CA0B2ED15BCADAC00654E32 /* SettingsWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CA0B2EC15BCADAC00654E32 /* SettingsWindow.xib */; }; 4CA0B2F915BCAF6700654E32 /* MPGeneralSettingsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CA0B2F815BCAF6700654E32 /* MPGeneralSettingsController.m */; }; @@ -671,6 +672,8 @@ 4C93C5711FBDFEF900F36855 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/AutotypeBuilderView.strings; sourceTree = ""; }; 4C978E0C19AE54AB003067DF /* MPFlagsHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPFlagsHelper.m; sourceTree = ""; }; 4C97CCEF1FA727DC00E58F8C /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; + 4C9BFFF91FD19B5400264B16 /* MPPrettyPasswordTransformer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPPrettyPasswordTransformer.h; sourceTree = ""; }; + 4C9BFFFA1FD19B5400264B16 /* MPPrettyPasswordTransformer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPPrettyPasswordTransformer.m; sourceTree = ""; }; 4CA08D9E17A831B200A6544B /* MPAddEntryContextMenuDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPAddEntryContextMenuDelegate.h; sourceTree = ""; }; 4CA08D9F17A831B200A6544B /* MPAddEntryContextMenuDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPAddEntryContextMenuDelegate.m; sourceTree = ""; }; 4CA0B2EC15BCADAC00654E32 /* SettingsWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SettingsWindow.xib; sourceTree = ""; }; @@ -1020,6 +1023,8 @@ children = ( 4CF6C70F176F4533007A811D /* MPStringLengthValueTransformer.h */, 4CF6C710176F4533007A811D /* MPStringLengthValueTransformer.m */, + 4C9BFFF91FD19B5400264B16 /* MPPrettyPasswordTransformer.h */, + 4C9BFFFA1FD19B5400264B16 /* MPPrettyPasswordTransformer.m */, 4C888C9516EB754B003D34A1 /* MPActionHelper.h */, 4C888C9616EB754B003D34A1 /* MPActionHelper.m */, 4C2E382116D1421B00037A9D /* MPIconHelper.h */, @@ -1912,6 +1917,7 @@ 4C6F228919A4A7F90012310C /* MPAutotypeClear.m in Sources */, 4C0B038C18E36DA400B9F9C9 /* MPFixAutotypeWindowController.m in Sources */, 4C7679BF1D76D6D8001F33D6 /* MPErrorRecoveryAttempter.m in Sources */, + 4C9BFFFB1FD19B5400264B16 /* MPPrettyPasswordTransformer.m in Sources */, 4CA0F3ED1A3074B50067C0E5 /* MPWindowTitleComboBoxDelegate.m in Sources */, 4CF78064176E75AD0032EE71 /* MPIntegrationSettingsController.m in Sources */, 4C25703F1BF11C2300D39416 /* MPPluginSettingsController.m in Sources */, diff --git a/MacPass/MPAppDelegate.m b/MacPass/MPAppDelegate.m index 4248952f..1003cb4b 100644 --- a/MacPass/MPAppDelegate.m +++ b/MacPass/MPAppDelegate.m @@ -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]; } diff --git a/MacPass/MPEntryInspectorViewController.m b/MacPass/MPEntryInspectorViewController.m index a18f4c1f..5bd85619 100644 --- a/MacPass/MPEntryInspectorViewController.m +++ b/MacPass/MPEntryInspectorViewController.m @@ -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; } diff --git a/MacPass/MPPrettyPasswordTransformer.h b/MacPass/MPPrettyPasswordTransformer.h new file mode 100644 index 00000000..4bbc3001 --- /dev/null +++ b/MacPass/MPPrettyPasswordTransformer.h @@ -0,0 +1,17 @@ +// +// MPPrettyPasswordTransformer.h +// MacPass +// +// Created by Michael Starke on 01.12.17. +// Copyright © 2017 HicknHack Software GmbH. All rights reserved. +// + +#import + +APPKIT_EXTERN NSString *const MPPrettyPasswordTransformerName; + +@interface MPPrettyPasswordTransformer : NSValueTransformer + ++ (void)registerTransformer; + +@end diff --git a/MacPass/MPPrettyPasswordTransformer.m b/MacPass/MPPrettyPasswordTransformer.m new file mode 100644 index 00000000..3fb79bcc --- /dev/null +++ b/MacPass/MPPrettyPasswordTransformer.m @@ -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