From df7a492ec830a684ea223318a7adcfa0a860d978 Mon Sep 17 00:00:00 2001 From: michael starke Date: Tue, 11 Jun 2013 02:50:25 +0200 Subject: [PATCH] Small updates to locking Refactorings --- HNHUi | 2 +- MacPass.xcodeproj/project.pbxproj | 8 ++ MacPass/Base.lproj/InspectorView.xib | 132 ++++++++++++++++++++++- MacPass/Base.lproj/PasswordInputView.xib | 73 ++++++++++++- MacPass/MPDocument.h | 3 +- MacPass/MPDocument.m | 18 ++++ MacPass/MPDocumentWindowController.h | 3 +- MacPass/MPDocumentWindowController.m | 48 ++++++--- MacPass/MPEntryViewController.m | 3 +- MacPass/MPInspectorViewController.h | 8 +- MacPass/MPInspectorViewController.m | 10 +- MacPass/MPOutlineViewController.h | 1 - MacPass/MPOutlineViewController.m | 1 - MacPass/MPResponderQuery.h | 15 +++ MacPass/MacPass-Info.plist | 2 +- MacPass/OutlineView.xib | 2 +- 16 files changed, 293 insertions(+), 36 deletions(-) create mode 100644 MacPass/MPResponderQuery.h diff --git a/HNHUi b/HNHUi index fd3d932c..23b62dd2 160000 --- a/HNHUi +++ b/HNHUi @@ -1 +1 @@ -Subproject commit fd3d932c26af597eac68c8fe38e0f43bd98530a1 +Subproject commit 23b62dd2c53ea407d8c9fb0620bc0984a8a1c2a1 diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 52d73aa2..610d720e 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -92,6 +92,7 @@ 4C77E37315B84A240093A587 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C77E37215B84A240093A587 /* main.m */; }; 4C77E37A15B84A240093A587 /* MPAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C77E37915B84A240093A587 /* MPAppDelegate.m */; }; 4C77E37D15B84A240093A587 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C77E37B15B84A240093A587 /* MainMenu.xib */; }; + 4C79DF2A176685870083708F /* HNHRoundedTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C79DF29176685870083708F /* HNHRoundedTextField.m */; }; 4C7E832A172DE2F2002493D8 /* MPPasswordEditViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C7E8329172DE2F2002493D8 /* MPPasswordEditViewController.m */; }; 4C811C8316ECD06E00C4BAC6 /* MPKeyfilePathControlDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C811C8216ECD06E00C4BAC6 /* MPKeyfilePathControlDelegate.m */; }; 4C83814215BF4677001AE468 /* MPDocumentWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C83814115BF4677001AE468 /* MPDocumentWindowController.m */; }; @@ -306,6 +307,9 @@ 4C77E37415B84A240093A587 /* MacPass-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MacPass-Prefix.pch"; sourceTree = ""; }; 4C77E37815B84A240093A587 /* MPAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPAppDelegate.h; sourceTree = ""; }; 4C77E37915B84A240093A587 /* MPAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPAppDelegate.m; sourceTree = ""; }; + 4C79DF28176685870083708F /* HNHRoundedTextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HNHRoundedTextField.h; sourceTree = ""; }; + 4C79DF29176685870083708F /* HNHRoundedTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HNHRoundedTextField.m; sourceTree = ""; }; + 4C79DF2F1766941D0083708F /* MPResponderQuery.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPResponderQuery.h; sourceTree = ""; }; 4C7E8328172DE2F2002493D8 /* MPPasswordEditViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPPasswordEditViewController.h; sourceTree = ""; }; 4C7E8329172DE2F2002493D8 /* MPPasswordEditViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPPasswordEditViewController.m; sourceTree = ""; }; 4C811C8116ECD06E00C4BAC6 /* MPKeyfilePathControlDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPKeyfilePathControlDelegate.h; sourceTree = ""; }; @@ -730,6 +734,7 @@ isa = PBXGroup; children = ( 4CA0B30D15BCB6FD00654E32 /* MPSettingsTab.h */, + 4C79DF2F1766941D0083708F /* MPResponderQuery.h */, ); name = Protocolls; sourceTree = ""; @@ -792,6 +797,8 @@ children = ( 4CC3AAB8175F4983003EF01B /* HNHRoundedTextFieldCell.h */, 4CC3AAB9175F4983003EF01B /* HNHRoundedTextFieldCell.m */, + 4C79DF28176685870083708F /* HNHRoundedTextField.h */, + 4C79DF29176685870083708F /* HNHRoundedTextField.m */, 4C9D6AA717615199001C660C /* HNHRoundedSecureTextFieldCell.h */, 4C9D6AA817615199001C660C /* HNHRoundedSecureTextFieldCell.m */, 4C58BD4D176370B100B8178C /* HNHBadgedTextField.h */, @@ -1054,6 +1061,7 @@ 4C569D9E17652B0600595B62 /* MPConstants.m in Sources */, 4C569DA117652BFE00595B62 /* MPEntryTableDataSource.m in Sources */, 4C569DA417653F3500595B62 /* KdbEntry+MPTreeTools.m in Sources */, + 4C79DF2A176685870083708F /* HNHRoundedTextField.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/MacPass/Base.lproj/InspectorView.xib b/MacPass/Base.lproj/InspectorView.xib index c7021400..1a1fbeb3 100644 --- a/MacPass/Base.lproj/InspectorView.xib +++ b/MacPass/Base.lproj/InspectorView.xib @@ -16,6 +16,8 @@ NSCustomView NSImageCell NSImageView + NSLevelIndicator + NSLevelIndicatorCell NSTextField NSTextFieldCell NSView @@ -307,7 +309,7 @@ {{80, 243}, {124, 22}} - + _NS:9 YES @@ -334,6 +336,28 @@ _NS:9 HNHGradientView + + + 268 + {{80, 217}, {124, 18}} + + + + _NS:9 + YES + + 0 + 262144 + _NS:9 + + 2 + 2 + 2 + 2 + 2 + + NO + {224, 487} @@ -487,6 +511,54 @@ 29 3 + + + 6 + 0 + + 6 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + 5 + 0 + + 5 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 3 + 0 + + 4 + 1 + + 8 + + 1000 + + 6 + 24 + 3 + 6 @@ -947,6 +1019,7 @@ + @@ -1333,6 +1406,34 @@ + + 684 + + + + + + + + 685 + + + + + 686 + + + + + 687 + + + + + 689 + + + @@ -1372,6 +1473,9 @@ + + + @@ -1387,6 +1491,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + HNHRoundedTextField com.apple.InterfaceBuilder.CocoaPlugin @@ -1459,12 +1564,19 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + HNHLevelIndicatorCell + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin - 683 + 694 @@ -1476,6 +1588,14 @@ ./Classes/HNHGradientView.h + + HNHLevelIndicatorCell + NSLevelIndicatorCell + + IBProjectSource + ./Classes/HNHLevelIndicatorCell.h + + HNHRoundedSecureTextFieldCell HNHRoundedTextFieldCell @@ -1484,6 +1604,14 @@ ./Classes/HNHRoundedSecureTextFieldCell.h + + HNHRoundedTextField + NSTextField + + IBProjectSource + ./Classes/HNHRoundedTextField.h + + HNHRoundedTextFieldCell NSTextFieldCell diff --git a/MacPass/Base.lproj/PasswordInputView.xib b/MacPass/Base.lproj/PasswordInputView.xib index 36a34b1c..ca789932 100644 --- a/MacPass/Base.lproj/PasswordInputView.xib +++ b/MacPass/Base.lproj/PasswordInputView.xib @@ -51,6 +51,7 @@ 268 {{125, 175}, {113, 17}} + _NS:1535 YES @@ -99,6 +100,7 @@ {{157, 200}, {48, 48}} + _NS:9 YES @@ -127,6 +129,7 @@ {{83, 94}, {197, 22}} + _NS:9 YES @@ -151,6 +154,7 @@ 268 {{86, 123}, {191, 22}} + _NS:9 YES @@ -188,6 +192,7 @@ 268 {{17, 126}, {64, 17}} + _NS:1535 YES @@ -208,6 +213,7 @@ 268 {{35, 99}, {46, 17}} + _NS:1535 YES @@ -228,6 +234,8 @@ 268 {{200, 50}, {83, 32}} + + _NS:9 {250, 250} YES @@ -250,6 +258,7 @@ {362, 268} + {751, 750} NSView @@ -1002,7 +1011,69 @@ 296 - + + + + MPPasswordInputController + MPViewController + + _decrypt: + id + + + _decrypt: + + _decrypt: + id + + + + NSImageView + NSTextField + NSPathControl + NSSecureTextField + + + + errorImageView + NSImageView + + + errorInfoTextField + NSTextField + + + keyPathControl + NSPathControl + + + passwordTextField + NSSecureTextField + + + + IBProjectSource + ./Classes/MPPasswordInputController.h + + + + MPViewController + NSViewController + + IBProjectSource + ./Classes/MPViewController.h + + + + NSLayoutConstraint + NSObject + + IBProjectSource + ./Classes/NSLayoutConstraint.h + + + + 0 IBCocoaFramework YES diff --git a/MacPass/MPDocument.h b/MacPass/MPDocument.h index 72c6062f..4ae56713 100644 --- a/MacPass/MPDocument.h +++ b/MacPass/MPDocument.h @@ -23,8 +23,9 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey; @interface MPDocument : NSDocument +@property (assign, readonly) BOOL isProtected; @property (assign, readonly) KdbGroup *root; -@property (retain, readonly) NSURL *file; +@property (nonatomic, retain, readonly) NSURL *file; @property (nonatomic,retain) NSString *password; @property (nonatomic, retain) NSURL *key; @property (assign, readonly) MPDatabaseVersion version; diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index 676b561b..28732be3 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -28,6 +28,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; @interface MPDocument () +@property (assign, nonatomic) BOOL isProtected; @property (retain) KdbTree *tree; @property (retain) NSURL *file; @property (nonatomic, readonly) KdbPassword *passwordHash; @@ -48,6 +49,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; self = [super init]; if(self) { _isDecrypted = YES; + _isProtected = NO; switch(version) { case MPDatabaseVersion3: self.tree = [[[Kdb3Tree alloc] init] autorelease]; @@ -123,6 +125,22 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; return YES; } +- (void)setPassword:(NSString *)password { + if(![_password isEqualToString:password]) { + [_password release]; + _password = [password retain]; + self.isProtected = ([_password length] > 0); + } +} + +- (void)setKey:(NSURL *)key { + if(![[_key absoluteString] isEqualToString:[key absoluteString]]) { + [_key release]; + _key = [key retain]; + self.isProtected = (_key != nil); + } +} + - (KdbPassword *)passwordHash { // TODO: Use defaults to determine Encoding? return [[[KdbPassword alloc] initWithPassword:self.password passwordEncoding:NSUTF8StringEncoding keyFile:[self.key path]] autorelease]; diff --git a/MacPass/MPDocumentWindowController.h b/MacPass/MPDocumentWindowController.h index c61f1f2a..b718b435 100644 --- a/MacPass/MPDocumentWindowController.h +++ b/MacPass/MPDocumentWindowController.h @@ -17,7 +17,7 @@ @class MPCreationViewController; -@interface MPDocumentWindowController : NSWindowController { +@interface MPDocumentWindowController : NSWindowController { @private NSArray *_inspectorContraints; } @@ -37,6 +37,7 @@ - (IBAction)editPassword:(id)sender; - (void)lock:(id)sender; +- (void)createGroup:(id)sender; - (void)toggleInspector:(id)sender; @end diff --git a/MacPass/MPDocumentWindowController.m b/MacPass/MPDocumentWindowController.m index 5f6546ff..1539f481 100644 --- a/MacPass/MPDocumentWindowController.m +++ b/MacPass/MPDocumentWindowController.m @@ -13,13 +13,14 @@ #import "MPPasswordEditViewController.h" #import "MPToolbarDelegate.h" #import "MPOutlineViewController.h" +#import "MPOutlineViewDelegate.h" #import "MPInspectorViewController.h" #import "MPAppDelegate.h" #import "MPActionHelper.h" @interface MPDocumentWindowController () { @private - BOOL _needsDecryption; + id _firstResponder; } @property (retain) IBOutlet NSSplitView *splitView; @@ -34,6 +35,7 @@ @property (retain) MPToolbarDelegate *toolbarDelegate; + @end @implementation MPDocumentWindowController @@ -41,7 +43,7 @@ -(id)init { self = [super initWithWindowNibName:@"DocumentWindow" owner:self]; if( self ) { - _needsDecryption = NO; + _firstResponder = nil; _toolbarDelegate = [[MPToolbarDelegate alloc] init]; _outlineViewController = [[MPOutlineViewController alloc] init]; _inspectorTabViewController = [[MPInspectorViewController alloc] init]; @@ -74,7 +76,7 @@ [self.toolbar setAllowsUserCustomization:YES]; [self.toolbar setDelegate:self.toolbarDelegate]; [self.window setToolbar:self.toolbar]; - + [self.splitView setTranslatesAutoresizingMaskIntoConstraints:NO]; NSView *outlineView = [_outlineViewController view]; @@ -87,7 +89,7 @@ [_splitView setHoldingPriority:NSLayoutPriorityDefaultLow+2 forSubviewAtIndex:0]; [_splitView setHoldingPriority:NSLayoutPriorityDefaultLow+1 forSubviewAtIndex:2]; - [_splitView setDelegate:self]; + [[self window] setDelegate:self]; MPDocument *document = [self document]; if(!document.isDecrypted) { @@ -98,10 +100,6 @@ } } -- (BOOL)splitView:(NSSplitView *)splitView shouldHideDividerAtIndex:(NSInteger)dividerIndex { - return NO; -} - - (void)_setContentViewController:(MPViewController *)viewController { NSView *newContentView = nil; @@ -122,7 +120,7 @@ options:0 metrics:nil views:NSDictionaryOfVariableBindings(newContentView)]]; - + NSNumber *border = @([[self window] contentBorderThicknessForEdge:NSMinYEdge]); [contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[newContentView]-border-|" options:0 @@ -146,10 +144,15 @@ - (BOOL)validateToolbarItem:(NSToolbarItem *)theItem { SEL itemAction = [theItem action]; if( itemAction == [MPActionHelper actionOfType:MPActionLock]) { - return (nil == [[_passwordInputController view] superview]); + MPDocument *document = [self document]; + BOOL showsNoLockScreen = (nil == [[_passwordInputController view] superview]); + return showsNoLockScreen && document.isProtected; } + if(itemAction == [MPActionHelper actionOfType:MPActionAddEntry]) { + return (nil != _entryViewController.activeGroup); + } + return YES; - return [self.toolbarDelegate validateToolbarItem:theItem]; } - (void)showPasswordInput { @@ -175,8 +178,12 @@ [self showPasswordInput]; } -- (void)toggleInspector:(id)sender { +- (void)createGroup:(id)sender { + NSLog(@"WindowControllerCreateGroup"); +} +- (void)toggleInspector:(id)sender { + } - (void)showEntries { @@ -227,6 +234,23 @@ [_outlineViewController showOutline]; } +#pragma mark NSWindowDelegate + +- (void)windowDidUpdate:(NSNotification *)notification { + if(_firstResponder != [[self window] firstResponder]) { + _firstResponder = [[self window] firstResponder]; + if(![_firstResponder isKindOfClass:[NSView class]]) { + return; // wrong responder + } + if( [_firstResponder isDescendantOf:[_entryViewController view]] ) { + //[_inspectorTabViewController showEntry]; + } + else if([_firstResponder isDescendantOf:[_outlineViewController view]]) { + //[_inspectorTabViewController showGroup]; + } + } +} + #pragma mark Helper - (NSSearchField *)locateToolbarSearchField { for(NSToolbarItem *toolbarItem in [[self.window toolbar] items]) { diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index 4b1caf04..5b2e6638 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -229,6 +229,7 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername"; } else { [self.entryArrayController unbind:NSContentArrayBinding]; + [self.entryArrayController setContent:nil]; } } @@ -236,7 +237,7 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername"; #pragma mark Filtering - (void)showFilter:(id)sender { - [self _showFilterBarAnimated:NO]; + //[self _showFilterBarAnimated:NO]; } - (BOOL)hasFilter { diff --git a/MacPass/MPInspectorViewController.h b/MacPass/MPInspectorViewController.h index 25a697fe..ebbcc7d4 100644 --- a/MacPass/MPInspectorViewController.h +++ b/MacPass/MPInspectorViewController.h @@ -8,7 +8,9 @@ #import "MPViewController.h" -@class MPPopupImageView; +@class MPPopupImageView; +@class KdbEntry; +@class KdbGroup; @interface MPInspectorViewController : MPViewController @@ -21,10 +23,6 @@ @property (assign) IBOutlet NSTextField *passwordTextField; @property (assign) IBOutlet NSTextField *titleOrNameLabel; -@property (assign) IBOutlet NSButton *openURLButton; -@property (assign) IBOutlet NSButton *showPasswordCreator; - -- (BOOL)isVisible; - (void)hideImagePopup:(id)sender; @end diff --git a/MacPass/MPInspectorViewController.m b/MacPass/MPInspectorViewController.m index 6e51de9c..0070344e 100644 --- a/MacPass/MPInspectorViewController.m +++ b/MacPass/MPInspectorViewController.m @@ -23,7 +23,8 @@ @property (assign, nonatomic) KdbEntry *selectedEntry; @property (assign, nonatomic) KdbGroup *selectedGroup; -@property (assign) BOOL showsEntry; + +@property (assign, nonatomic) BOOL showsEntry; @property (retain) NSPopover *iconPopup; @property (retain) NSLayoutConstraint *showConstraint; @property (retain) NSLayoutConstraint *hideConstraint; @@ -70,10 +71,6 @@ [self _clearContent]; } -- (BOOL)isVisible { - return [[self view] frame].size.width > 0; -} - - (void)_updateContent { if(self.showsEntry && self.selectedEntry) { [self _showEntry]; @@ -151,8 +148,6 @@ [self.usernameTextField setEnabled:enabled]; [self.URLTextField setEnabled:enabled]; - [self.openURLButton setEnabled:enabled]; - } #pragma mark Actions @@ -202,5 +197,4 @@ [self _updateContent]; } } - @end diff --git a/MacPass/MPOutlineViewController.h b/MacPass/MPOutlineViewController.h index 7ad1a817..8efa5776 100644 --- a/MacPass/MPOutlineViewController.h +++ b/MacPass/MPOutlineViewController.h @@ -15,7 +15,6 @@ @property (retain, readonly) MPOutlineViewDelegate *outlineDelegate; - - (void)clearSelection; - (void)showOutline; diff --git a/MacPass/MPOutlineViewController.m b/MacPass/MPOutlineViewController.m index 7c572490..487aa262 100644 --- a/MacPass/MPOutlineViewController.m +++ b/MacPass/MPOutlineViewController.m @@ -20,7 +20,6 @@ @interface MPOutlineViewController () { BOOL _bindingEstablished; } - @property (assign) IBOutlet NSOutlineView *outlineView; @property (retain) NSTreeController *treeController; diff --git a/MacPass/MPResponderQuery.h b/MacPass/MPResponderQuery.h new file mode 100644 index 00000000..3308e4c3 --- /dev/null +++ b/MacPass/MPResponderQuery.h @@ -0,0 +1,15 @@ +// +// MPResponderQuery.h +// MacPass +// +// Created by Michael Starke on 11.06.13. +// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. +// + +#import + +@protocol MPResponderQuery +@required +- (BOOL)containsFirstResponder; + +@end diff --git a/MacPass/MacPass-Info.plist b/MacPass/MacPass-Info.plist index f13b688d..7b4c0f8f 100644 --- a/MacPass/MacPass-Info.plist +++ b/MacPass/MacPass-Info.plist @@ -48,7 +48,7 @@ CFBundleSignature ???? CFBundleVersion - BD7 + C60 LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} NSHumanReadableCopyright diff --git a/MacPass/OutlineView.xib b/MacPass/OutlineView.xib index 21858876..e7aa7254 100644 --- a/MacPass/OutlineView.xib +++ b/MacPass/OutlineView.xib @@ -204,7 +204,7 @@ MC41AA - 17 + 24 -767557632