diff --git a/Cartfile.resolved b/Cartfile.resolved index 43d0fd65..aa9a310c 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,3 +1,3 @@ github "mstarke/HNHUi" "1.0.1" -github "mstarke/KeePassKit" "722652647b9f1ff0967429ac02da046e3534178f" +github "mstarke/KeePassKit" "bf47781a618fc514288315995a966b5f630f6918" github "sparkle-project/Sparkle" "1.14.0" diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index cf6a437f..b5655ffb 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -202,6 +202,7 @@ 4CC6DB7A17D23719002C6091 /* KPKNode+IconImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC6DB7917D23719002C6091 /* KPKNode+IconImage.m */; }; 4CCA8E9B18D91ED9001A6754 /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CCA8E9A18D91ED9001A6754 /* Quartz.framework */; }; 4CCCD83E1C8DFF20002B77B6 /* MPEntryProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CCCD83D1C8DFF20002B77B6 /* MPEntryProxy.m */; }; + 4CCCE8011D75CA48006AA951 /* MPArrayController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CCCE8001D75CA48006AA951 /* MPArrayController.m */; }; 4CCEDE2A179F203B008402BE /* MPOutlineView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CCEDE29179F203B008402BE /* MPOutlineView.m */; }; 4CCEDE2E179F213B008402BE /* MPNotifications.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CCEDE2D179F213B008402BE /* MPNotifications.m */; }; 4CCFA13D1BF0CC7A0078E0A1 /* Test_Password_1234.kdb in Resources */ = {isa = PBXBuildFile; fileRef = 4CCFA1321BF0CC7A0078E0A1 /* Test_Password_1234.kdb */; }; @@ -601,6 +602,8 @@ 4CCA8E9A18D91ED9001A6754 /* Quartz.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quartz.framework; path = System/Library/Frameworks/Quartz.framework; sourceTree = SDKROOT; }; 4CCCD83C1C8DFF20002B77B6 /* MPEntryProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPEntryProxy.h; sourceTree = ""; }; 4CCCD83D1C8DFF20002B77B6 /* MPEntryProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPEntryProxy.m; sourceTree = ""; }; + 4CCCE7FF1D75CA48006AA951 /* MPArrayController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPArrayController.h; sourceTree = ""; }; + 4CCCE8001D75CA48006AA951 /* MPArrayController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPArrayController.m; sourceTree = ""; }; 4CCEDE28179F203B008402BE /* MPOutlineView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPOutlineView.h; sourceTree = ""; }; 4CCEDE29179F203B008402BE /* MPOutlineView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPOutlineView.m; sourceTree = ""; }; 4CCEDE2C179F2122008402BE /* MPNotifications.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPNotifications.h; sourceTree = ""; }; @@ -1357,6 +1360,8 @@ 4C431BCC16E2A82700700A81 /* MPPasteBoardController.m */, 4C6AEEF71A043E2B00CA2420 /* MPDocumentController.h */, 4C6AEEF81A043E2B00CA2420 /* MPDocumentController.m */, + 4CCCE7FF1D75CA48006AA951 /* MPArrayController.h */, + 4CCCE8001D75CA48006AA951 /* MPArrayController.m */, ); name = "Data Controller"; sourceTree = ""; @@ -1748,6 +1753,7 @@ 4CEE46DD181C301D006BF1E5 /* MPAutotypeDaemon.m in Sources */, 4CA3530B18A53CB800839B0F /* MPKeyMapper.m in Sources */, 4CE298EB1795FC2A00DF7BDB /* MPEntryContextMenuDelegate.m in Sources */, + 4CCCE8011D75CA48006AA951 /* MPArrayController.m in Sources */, 4CC0D2CE17974A47000B4BDA /* MPCustomFieldTableViewDelegate.m in Sources */, 4CC0D2D117974A5A000B4BDA /* MPAttachmentTableViewDelegate.m in Sources */, 4C26C33F18D8C92100CF1A1C /* MPTemporaryFileStorage.m in Sources */, diff --git a/MacPass/MPArrayController.h b/MacPass/MPArrayController.h new file mode 100644 index 00000000..2c4c44d1 --- /dev/null +++ b/MacPass/MPArrayController.h @@ -0,0 +1,17 @@ +// +// MPArrayController.h +// MacPass +// +// Created by Michael Starke on 30/08/16. +// Copyright © 2016 HicknHack Software GmbH. All rights reserved. +// + +#import + +@class MPDocument; + +@interface MPArrayController : NSArrayController + +@property (weak) MPDocument *document; + +@end diff --git a/MacPass/MPArrayController.m b/MacPass/MPArrayController.m new file mode 100644 index 00000000..410bc854 --- /dev/null +++ b/MacPass/MPArrayController.m @@ -0,0 +1,26 @@ +// +// MPArrayController.m +// MacPass +// +// Created by Michael Starke on 30/08/16. +// Copyright © 2016 HicknHack Software GmbH. All rights reserved. +// + +#import "MPArrayController.h" +#import "MPDocument.h" + +@implementation MPArrayController + + +- (void)setValue:(id)value forKeyPath:(NSString *)keyPath { + if([keyPath hasPrefix:@"selection."]) { + [self.document willChangeModelProperty]; + [super setValue:value forKeyPath:keyPath]; + [self.document didChangeModelProperty]; + } + else { + [super setValue:value forKeyPath:keyPath]; + } +} + +@end diff --git a/MacPass/MPDatePickingViewController.h b/MacPass/MPDatePickingViewController.h index fbe60895..7f7f607b 100644 --- a/MacPass/MPDatePickingViewController.h +++ b/MacPass/MPDatePickingViewController.h @@ -6,15 +6,17 @@ // Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. // + #import "MPViewController.h" +NS_ASSUME_NONNULL_BEGIN + +@class MPDocument; + @interface MPDatePickingViewController : MPViewController -@property (weak) IBOutlet NSDatePicker *datePicker; -@property (weak) IBOutlet NSPopUpButton *presetPopupButton; - -- (IBAction)useDate:(id)sender; -- (IBAction)cancel:(id)sender; -- (IBAction)setDatePreset:(id)sender; +@property (nullable, weak) MPDocument *document; @end + +NS_ASSUME_NONNULL_END \ No newline at end of file diff --git a/MacPass/MPDatePickingViewController.m b/MacPass/MPDatePickingViewController.m index b80ea71c..cfe6adb1 100644 --- a/MacPass/MPDatePickingViewController.m +++ b/MacPass/MPDatePickingViewController.m @@ -23,6 +23,9 @@ typedef NS_ENUM(NSUInteger, MPDatePreset) { @interface MPDatePickingViewController () +@property (nullable, weak) IBOutlet NSDatePicker *datePicker; +@property (nullable, weak) IBOutlet NSPopUpButton *presetPopupButton; + @end @implementation MPDatePickingViewController @@ -59,10 +62,9 @@ typedef NS_ENUM(NSUInteger, MPDatePreset) { } - (IBAction)useDate:(id)sender { - KPKTimeInfo *timeInfo = [self.representedObject timeInfo]; - [self.windowController.document willChangeModelProperty]; - timeInfo.expirationDate = self.datePicker.dateValue; - [self.windowController.document didChangeModelProperty]; + [self.document willChangeModelProperty]; + [self.representedObject timeInfo].expirationDate = self.datePicker.dateValue; + [self.document didChangeModelProperty]; [self.view.window performClose:sender]; } @@ -95,8 +97,7 @@ typedef NS_ENUM(NSUInteger, MPDatePreset) { default: return; // Nothing to do; } - NSDate *newDate = [gregorian dateByAddingComponents:offsetComponents toDate:[NSDate date] options:0]; - self.datePicker.dateValue = newDate; + self.datePicker.dateValue = [gregorian dateByAddingComponents:offsetComponents toDate:[NSDate date] options:0]; } @end diff --git a/MacPass/MPEntryInspectorViewController.m b/MacPass/MPEntryInspectorViewController.m index e3eb063a..bfe80d2b 100644 --- a/MacPass/MPEntryInspectorViewController.m +++ b/MacPass/MPEntryInspectorViewController.m @@ -24,6 +24,8 @@ #import "MPActionHelper.h" #import "MPSettingsHelper.h" +#import "MPArrayController.h" + #import "KeePassKit/KeePassKit.h" #import "HNHUi/HNHUi.h" @@ -39,7 +41,7 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { @private NSArrayController *_attachmentsController; NSArrayController *_customFieldsController; - NSArrayController *_windowAssociationsController; + MPArrayController *_windowAssociationsController; MPAttachmentTableViewDelegate *_attachmentTableDelegate; MPCustomFieldTableViewDelegate *_customFieldTableDelegate; MPAttachmentTableDataSource *_attachmentDataSource; @@ -70,7 +72,7 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { _showPassword = NO; _attachmentsController = [[NSArrayController alloc] init]; _customFieldsController = [[NSArrayController alloc] init]; - _windowAssociationsController = [[NSArrayController alloc] init]; + _windowAssociationsController = [[MPArrayController alloc] init]; _attachmentTableDelegate = [[MPAttachmentTableViewDelegate alloc] init]; _customFieldTableDelegate = [[MPCustomFieldTableViewDelegate alloc] init]; _attachmentDataSource = [[MPAttachmentTableDataSource alloc] init]; @@ -265,15 +267,7 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { MPPasswordCreatorViewController *viewController = [[MPPasswordCreatorViewController alloc] init]; viewController.allowsEntryDefaults = YES; viewController.representedObject = self.representedObject; - viewController.completionHandler = ^void (NSModalResponse response, NSString *password) { - /* TODO mark for modification! */ - self.generatePasswordButton.enabled = YES; - /* We should only use the password if there is actually one */ - if(password.length > 0) { - self.representedEntry.password = password; - } - }; - + viewController.document = self.windowController.document; [self _showPopopver:viewController atView:self.passwordTextField onEdge:NSMinYEdge]; } @@ -291,6 +285,7 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { } - (void)popoverDidClose:(NSNotification *)notification { + self.generatePasswordButton.enabled = YES; self.activePopover = nil; } diff --git a/MacPass/MPIconSelectViewController.h b/MacPass/MPIconSelectViewController.h index 76497c87..356085b7 100644 --- a/MacPass/MPIconSelectViewController.h +++ b/MacPass/MPIconSelectViewController.h @@ -8,11 +8,11 @@ #import "MPViewController.h" +@class MPDocument; + @interface MPIconSelectViewController : MPViewController -@property (weak) NSPopover *popover; - -- (IBAction)cancel:(id)sender; -- (IBAction)useDefault:(id)sender; +@property (weak, nullable) MPDocument *document; +@property (weak, nullable) NSPopover *popover; @end diff --git a/MacPass/MPIconSelectViewController.m b/MacPass/MPIconSelectViewController.m index c7631366..96dc2230 100644 --- a/MacPass/MPIconSelectViewController.m +++ b/MacPass/MPIconSelectViewController.m @@ -34,9 +34,9 @@ - (IBAction)useDefault:(id)sender { KPKNode *node = self.representedObject; - [self.windowController.document willChangeModelProperty]; + [self.document willChangeModelProperty]; node.iconId = [[node class] defaultIcon]; - [self.windowController.document didChangeModelProperty]; + [self.document didChangeModelProperty]; [self.view.window performClose:sender]; } @@ -50,9 +50,9 @@ NSUInteger buttonIndex = [self.iconCollectionView.content indexOfObject:image]; NSInteger newIconId = ((NSNumber *)[MPIconHelper databaseIconTypes][buttonIndex]).integerValue; KPKNode *node = self.representedObject; - [self.windowController.document willChangeModelProperty]; + [self.document willChangeModelProperty]; node.iconId = newIconId; - [self.windowController.document didChangeModelProperty]; + [self.document didChangeModelProperty]; [self.view.window performClose:sender]; } diff --git a/MacPass/MPInspectorViewController.m b/MacPass/MPInspectorViewController.m index 95880310..12661e0c 100644 --- a/MacPass/MPInspectorViewController.m +++ b/MacPass/MPInspectorViewController.m @@ -115,7 +115,7 @@ typedef NS_ENUM(NSUInteger, MPContentTab) { object:document]; [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(_willChangeValueForRepresentedObjectNotification:) + selector:@selector(_willChangeModelProperty:) name:MPDocumentWillChangeModelPropertyNotification object:document]; @@ -160,8 +160,8 @@ typedef NS_ENUM(NSUInteger, MPContentTab) { NSString *modifedAtTemplate = NSLocalizedString(@"MODIFED_AT_%@", @"Modifed at template string. %@ is replaced by locaized date and time"); NSString *createdAtTemplate = NSLocalizedString(@"CREATED_AT_%@", @"Created at template string. %@ is replaced by locaized date and time"); - [self.modifiedTextField setStringValue:[NSString stringWithFormat:modifedAtTemplate, modificationString]]; - [self.createdTextField setStringValue:[NSString stringWithFormat:createdAtTemplate, creationString]]; + self.modifiedTextField.stringValue = [NSString stringWithFormat:modifedAtTemplate, modificationString]; + self.createdTextField.stringValue = [NSString stringWithFormat:createdAtTemplate, creationString]; } #pragma mark - @@ -176,6 +176,7 @@ typedef NS_ENUM(NSUInteger, MPContentTab) { MPIconSelectViewController *vc = [[MPIconSelectViewController alloc] init]; vc.representedObject = self.representedObject; vc.popover = self.popover; + vc.document = self.windowController.document; self.popover.contentViewController = vc; [self.popover showRelativeToRect:NSZeroRect ofView:sender preferredEdge:NSMinYEdge]; } @@ -190,6 +191,7 @@ typedef NS_ENUM(NSUInteger, MPContentTab) { self.popover.behavior = NSPopoverBehaviorTransient; MPDatePickingViewController *vc = [[MPDatePickingViewController alloc] init]; vc.representedObject = self.representedObject; + vc.document = self.windowController.document; self.popover.contentViewController = vc; [self.popover showRelativeToRect:NSZeroRect ofView:sender preferredEdge:NSMinYEdge]; } diff --git a/MacPass/MPPasswordCreatorViewController.h b/MacPass/MPPasswordCreatorViewController.h index 9a761d36..966163a5 100644 --- a/MacPass/MPPasswordCreatorViewController.h +++ b/MacPass/MPPasswordCreatorViewController.h @@ -11,17 +11,12 @@ NS_ASSUME_NONNULL_BEGIN -@class KPKEntry; +@class MPDocument; @interface MPPasswordCreatorViewController : MPViewController - -//@property (weak) id closeTarget; +@property (weak, nullable) MPDocument *document; @property (assign) BOOL allowsEntryDefaults; -/** - * Block gets called whenever the user opts to store the password or cancel - */ -@property (nonatomic, copy, nullable) void (^completionHandler)(NSModalResponse response, NSString *password); /** * Should be called to reset the generator diff --git a/MacPass/MPPasswordCreatorViewController.m b/MacPass/MPPasswordCreatorViewController.m index 4e97b7a6..74bf9854 100644 --- a/MacPass/MPPasswordCreatorViewController.m +++ b/MacPass/MPPasswordCreatorViewController.m @@ -11,6 +11,7 @@ #import "NSString+MPPasswordCreation.h" #import "MPUniqueCharactersFormatter.h" #import "MPSettingsHelper.h" +#import "MPDocument.h" #import "MPFlagsHelper.h" @@ -174,16 +175,16 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) { if(self.shouldCopyPasswordToPasteboardButton.state == NSOnState) { [[MPPasteBoardController defaultController] copyObjects:@[self.password]]; } - if(self.completionHandler) { - self.completionHandler(NSModalResponseOK, self.password); + KPKEntry *entry = self.representedObject; + if(entry && self.password.length > 0) { + [self.document willChangeModelProperty]; + entry.password = self.password; + [self.document didChangeModelProperty]; } [self.view.window performClose:sender]; } - (IBAction)_cancel:(id)sender { - if(self.completionHandler) { - self.completionHandler(NSModalResponseCancel, self.password); - } [self.view.window performClose:sender]; }