From 90f844f87ee241dd4f89e0927f391103dee3570f Mon Sep 17 00:00:00 2001 From: michael starke Date: Fri, 5 Dec 2014 02:57:10 +0100 Subject: [PATCH] moving more code to @properties, ReferenceBuilder WIP --- MacPass.xcodeproj/project.pbxproj | 8 ++- MacPass/Base.lproj/EntryInspectorView.xib | 2 +- MacPass/DDHotKey+MacPassAdditions.m | 1 - MacPass/MPEntryViewController.m | 2 +- MacPass/MPOutlineViewController.m | 2 +- MacPass/MPPasteBoardController.m | 28 +++++---- MacPass/MPReferenceBuilderViewController.h | 16 ++++++ MacPass/MPReferenceBuilderViewController.m | 49 ++++++++++++++++ MacPass/MPViewController.h | 4 +- MacPass/MPViewController.m | 4 +- MacPass/ReferenceBuilderView.xib | 66 ++++++++++++++-------- 11 files changed, 137 insertions(+), 45 deletions(-) create mode 100644 MacPass/MPReferenceBuilderViewController.h create mode 100644 MacPass/MPReferenceBuilderViewController.m diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index ca657d56..6bca9df7 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -284,6 +284,7 @@ 4CE2961518429AA5005F01CE /* MPAutotypeKeyPress.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE2961418429AA5005F01CE /* MPAutotypeKeyPress.m */; }; 4CE296191842A166005F01CE /* MPAutotypePaste.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE296181842A166005F01CE /* MPAutotypePaste.m */; }; 4CE298EB1795FC2A00DF7BDB /* MPEntryContextMenuDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE298EA1795FC2A00DF7BDB /* MPEntryContextMenuDelegate.m */; }; + 4CE30ACC1A312B7F0063FCC6 /* MPReferenceBuilderViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE30ACB1A312B7F0063FCC6 /* MPReferenceBuilderViewController.m */; }; 4CE39ABF16ECE34A000FE29D /* MPIconSelectViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE39ABE16ECE34A000FE29D /* MPIconSelectViewController.m */; }; 4CE39AC416ECE4F7000FE29D /* MPPopupImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE39AC316ECE4F7000FE29D /* MPPopupImageView.m */; }; 4CE3E62617AB0D2D00D9E4B4 /* MPAttachmentTableDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE3E62517AB0D2D00D9E4B4 /* MPAttachmentTableDataSource.m */; }; @@ -893,6 +894,8 @@ 4CE296181842A166005F01CE /* MPAutotypePaste.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPAutotypePaste.m; sourceTree = ""; }; 4CE298E91795FC2A00DF7BDB /* MPEntryContextMenuDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPEntryContextMenuDelegate.h; sourceTree = ""; }; 4CE298EA1795FC2A00DF7BDB /* MPEntryContextMenuDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPEntryContextMenuDelegate.m; sourceTree = ""; }; + 4CE30ACA1A312B7F0063FCC6 /* MPReferenceBuilderViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPReferenceBuilderViewController.h; sourceTree = ""; }; + 4CE30ACB1A312B7F0063FCC6 /* MPReferenceBuilderViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPReferenceBuilderViewController.m; sourceTree = ""; }; 4CE39ABD16ECE34A000FE29D /* MPIconSelectViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPIconSelectViewController.h; sourceTree = ""; }; 4CE39ABE16ECE34A000FE29D /* MPIconSelectViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPIconSelectViewController.m; sourceTree = ""; }; 4CE39AC216ECE4F7000FE29D /* MPPopupImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPPopupImageView.h; sourceTree = ""; }; @@ -1090,6 +1093,7 @@ 4C2C8B331787500E009649F3 /* UnprotectedWarningView.xib */, 6021FE7918E15FF300C3BC51 /* DatePickingView.xib */, 4C26C34A18D8D5A300CF1A1C /* PreviewView.xib */, + 4C99E6A41A30FDFD00E2BA8D /* ReferenceBuilderView.xib */, 4C74DD05177BD1640034A9DB /* MPCustomFieldView.h */, 4C74DD06177BD1640034A9DB /* MPCustomFieldView.m */, 4CE8247316E2F2B900573141 /* MPOverlayView.h */, @@ -1106,7 +1110,6 @@ 4C5FE9AD17843CE20001D5A8 /* MPSelectedAttachmentTableCellView.m */, 4CCEDE28179F203B008402BE /* MPOutlineView.h */, 4CCEDE29179F203B008402BE /* MPOutlineView.m */, - 4C99E6A41A30FDFD00E2BA8D /* ReferenceBuilderView.xib */, ); name = Views; sourceTree = ""; @@ -1711,6 +1714,8 @@ 4C1E9884185F71A800943563 /* MPContextBarViewController.m */, 4C26C34818D8D5A300CF1A1C /* MPPreviewViewController.h */, 4C26C34918D8D5A300CF1A1C /* MPPreviewViewController.m */, + 4CE30ACA1A312B7F0063FCC6 /* MPReferenceBuilderViewController.h */, + 4CE30ACB1A312B7F0063FCC6 /* MPReferenceBuilderViewController.m */, ); name = "View Controller"; sourceTree = ""; @@ -2405,6 +2410,7 @@ 4C88C66918D9F8D600F43852 /* MPTemporaryFileStorageCenter.m in Sources */, 4C245B79176E1E3D0086100E /* HTTPAuthenticationRequest.m in Sources */, 4C245B7A176E1E3D0086100E /* HTTPConnection.m in Sources */, + 4CE30ACC1A312B7F0063FCC6 /* MPReferenceBuilderViewController.m in Sources */, 4C6F228C19A4AA700012310C /* MPAutotypeDelay.m in Sources */, 4C245B7B176E1E3D0086100E /* HTTPMessage.m in Sources */, 4C3C4EA718D6FEA100153127 /* TTTStringTransformers.m in Sources */, diff --git a/MacPass/Base.lproj/EntryInspectorView.xib b/MacPass/Base.lproj/EntryInspectorView.xib index bffe9c39..3e19806a 100644 --- a/MacPass/Base.lproj/EntryInspectorView.xib +++ b/MacPass/Base.lproj/EntryInspectorView.xib @@ -620,7 +620,7 @@ - + diff --git a/MacPass/DDHotKey+MacPassAdditions.m b/MacPass/DDHotKey+MacPassAdditions.m index f083aa10..db1fc74d 100644 --- a/MacPass/DDHotKey+MacPassAdditions.m +++ b/MacPass/DDHotKey+MacPassAdditions.m @@ -87,7 +87,6 @@ BOOL missingModifier = self.modifierFlags == 0; BOOL onlyModifiers = MPIsFlagSetInOptions(flags, self.modifierFlags) || (self.modifierFlags != 0 && flags != 0); BOOL isInvalid = onlyModifiers || missingModifier; - NSLog(@"%@ valid:%d", self, !isInvalid); return !isInvalid; } diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index f1c46357..50d1cb44 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -705,7 +705,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell"; MPDoubleClickTitleAction action = [[NSUserDefaults standardUserDefaults] integerForKey:kMPSettingsKeyDoubleClickTitleAction]; switch(action) { case MPDoubleClickTitleActionInspect: - [[self windowController] showInspector:nil]; + [(MPDocumentWindowController *)self.windowController showInspector:nil]; break; case MPDoubleClickTitleActionIgnore: break; diff --git a/MacPass/MPOutlineViewController.m b/MacPass/MPOutlineViewController.m index 944215ce..20cbd7b5 100644 --- a/MacPass/MPOutlineViewController.m +++ b/MacPass/MPOutlineViewController.m @@ -203,7 +203,7 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; #pragma mark Actions - (void)_doubleClickedGroup:(id)sender { - [[self windowController] showInspector:sender]; + [(MPDocumentWindowController *)self.windowController showInspector:sender]; } #pragma mark NSOutlineViewDelegate diff --git a/MacPass/MPPasteBoardController.m b/MacPass/MPPasteBoardController.m index abb77a20..bf8dfb35 100644 --- a/MacPass/MPPasteBoardController.m +++ b/MacPass/MPPasteBoardController.m @@ -41,8 +41,7 @@ NSString *const MPPasteBoardControllerDidClearClipboard = @"com.hicknhack.macpas return self; } -- (void)dealloc -{ +- (void)dealloc { if(_clearPasteboardOnShutdown) { [[NSNotificationCenter defaultCenter] removeObserver:self]; } @@ -64,8 +63,7 @@ NSString *const MPPasteBoardControllerDidClearClipboard = @"com.hicknhack.macpas } } -- (void)stashObjects -{ +- (void)stashObjects { self.stashedObjects = [NSMutableArray array]; for (NSPasteboardItem *item in [[NSPasteboard generalPasteboard] pasteboardItems]) { NSPasteboardItem *newItem = [[NSPasteboardItem alloc] init]; @@ -79,10 +77,8 @@ NSString *const MPPasteBoardControllerDidClearClipboard = @"com.hicknhack.macpas } } -- (void)restoreObjects -{ - if (self.stashedObjects) - { +- (void)restoreObjects { + if (self.stashedObjects) { [[NSPasteboard generalPasteboard] clearContents]; [[NSPasteboard generalPasteboard] writeObjects:self.stashedObjects]; self.stashedObjects = nil; @@ -116,10 +112,18 @@ NSString *const MPPasteBoardControllerDidClearClipboard = @"com.hicknhack.macpas - (void)_setupBindings { NSUserDefaultsController *userDefaultsController = [NSUserDefaultsController sharedUserDefaultsController]; - NSString *clearOnShutdownKeyPath = [NSString stringWithFormat:@"values.%@", kMPSettingsKeyClearPasteboardOnQuit]; - [self bind:NSStringFromSelector(@selector(clearPasteboardOnShutdown)) toObject:userDefaultsController withKeyPath:clearOnShutdownKeyPath options:nil]; - NSString *clearTimoutKeyPath = [NSString stringWithFormat:@"values.%@", kMPSettingsKeyPasteboardClearTimeout]; - [self bind:NSStringFromSelector(@selector(clearTimeout)) toObject:userDefaultsController withKeyPath:clearTimoutKeyPath options:nil]; + NSString *clearOnShutdownKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyClearPasteboardOnQuit]; + NSString *clearTimoutKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyPasteboardClearTimeout]; + + [self bind:NSStringFromSelector(@selector(clearPasteboardOnShutdown)) + toObject:userDefaultsController + withKeyPath:clearOnShutdownKeyPath + options:nil]; + + [self bind:NSStringFromSelector(@selector(clearTimeout)) + toObject:userDefaultsController + withKeyPath:clearTimoutKeyPath + options:nil]; } @end diff --git a/MacPass/MPReferenceBuilderViewController.h b/MacPass/MPReferenceBuilderViewController.h new file mode 100644 index 00000000..2b6f7656 --- /dev/null +++ b/MacPass/MPReferenceBuilderViewController.h @@ -0,0 +1,16 @@ +// +// MPReferenceBuilderViewController.h +// MacPass +// +// Created by Michael Starke on 05/12/14. +// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved. +// + +#import "MPViewController.h" + +@interface MPReferenceBuilderViewController : MPViewController +@property (weak) IBOutlet NSPopUpButton *valuePopUpButton; +@property (weak) IBOutlet NSPopUpButton *searchKeyPopUpButton; +@property (weak) IBOutlet NSTextField *searchStringTextField; + +@end diff --git a/MacPass/MPReferenceBuilderViewController.m b/MacPass/MPReferenceBuilderViewController.m new file mode 100644 index 00000000..81014f81 --- /dev/null +++ b/MacPass/MPReferenceBuilderViewController.m @@ -0,0 +1,49 @@ +// +// MPReferenceBuilderViewController.m +// MacPass +// +// Created by Michael Starke on 05/12/14. +// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved. +// + +#import "MPReferenceBuilderViewController.h" + +@interface MPReferenceBuilderViewController () + +@end + +@implementation MPReferenceBuilderViewController + +- (NSString *)nibName { + return @"ReferenceBuilderView"; +} + +//- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { +// self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; +// if(self) { +// } +// return self; +//} + +- (void)didLoadView { + [self.searchKeyPopUpButton setMenu:[self _allocateAttributeItemMenu:YES withTitle:NSLocalizedString(@"SEARCH_VALUE", "")]]; + [self.valuePopUpButton setMenu:[self _allocateAttributeItemMenu:NO withTitle:NSLocalizedString(@"OUTPUT_VALUE", "")]]; +} + +- (NSMenu *)_allocateAttributeItemMenu:(BOOL)allowCustomAttributes withTitle:(NSString *)title { + NSMenu *menu = [[NSMenu alloc] init]; + /* first item is button label */ + [menu addItemWithTitle:title action:NULL keyEquivalent:@""]; + [menu addItemWithTitle:NSLocalizedString(@"UUID","") action:NULL keyEquivalent:@""]; + [menu addItemWithTitle:NSLocalizedString(@"TITLE","") action:NULL keyEquivalent:@""]; + [menu addItemWithTitle:NSLocalizedString(@"USERNAME","") action:NULL keyEquivalent:@""]; + [menu addItemWithTitle:NSLocalizedString(@"PASSWORD","") action:NULL keyEquivalent:@""]; + [menu addItemWithTitle:NSLocalizedString(@"URL","") action:NULL keyEquivalent:@""]; + [menu addItemWithTitle:NSLocalizedString(@"NOTES","") action:NULL keyEquivalent:@""]; + if(allowCustomAttributes) { + [menu addItemWithTitle:NSLocalizedString(@"CUSTOM_ATTRIBUTE","") action:NULL keyEquivalent:@""]; + } + return menu; +} + +@end diff --git a/MacPass/MPViewController.h b/MacPass/MPViewController.h index 67c7aee4..292f5e6b 100644 --- a/MacPass/MPViewController.h +++ b/MacPass/MPViewController.h @@ -10,10 +10,12 @@ @interface MPViewController : NSViewController +@property (nonatomic, readonly) NSWindowController *windowController; + - (void)didLoadView; - (NSResponder *)reconmendedFirstResponder; /* Returns the associated window controller */ -- (id)windowController; + - (void)updateResponderChain; diff --git a/MacPass/MPViewController.m b/MacPass/MPViewController.m index dce049d0..ba907119 100644 --- a/MacPass/MPViewController.m +++ b/MacPass/MPViewController.m @@ -20,8 +20,8 @@ // override } -- (id)windowController { - return [[[self view] window] windowController]; +- (NSWindowController *)windowController { + return [self.view.window windowController]; } #pragma mark Responder Chain diff --git a/MacPass/ReferenceBuilderView.xib b/MacPass/ReferenceBuilderView.xib index fb873699..4a074836 100644 --- a/MacPass/ReferenceBuilderView.xib +++ b/MacPass/ReferenceBuilderView.xib @@ -5,63 +5,79 @@ - + + + + + + + + - + - - - + + + - - - - + + + - + - - - - + + + + + + - - - + + + + + + + + + + + + + +