mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 17:32:17 +00:00
Added selection observing arraycontroller, moved block based calls into view controllers again
This commit is contained in:
17
MacPass/MPArrayController.h
Normal file
17
MacPass/MPArrayController.h
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// MPArrayController.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 30/08/16.
|
||||
// Copyright © 2016 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class MPDocument;
|
||||
|
||||
@interface MPArrayController : NSArrayController
|
||||
|
||||
@property (weak) MPDocument *document;
|
||||
|
||||
@end
|
||||
26
MacPass/MPArrayController.m
Normal file
26
MacPass/MPArrayController.m
Normal file
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
|
||||
#import "MPViewController.h"
|
||||
|
||||
@class MPDocument;
|
||||
|
||||
@interface MPIconSelectViewController : MPViewController <NSCollectionViewDelegate>
|
||||
|
||||
@property (weak) NSPopover *popover;
|
||||
|
||||
- (IBAction)cancel:(id)sender;
|
||||
- (IBAction)useDefault:(id)sender;
|
||||
@property (weak, nullable) MPDocument *document;
|
||||
@property (weak, nullable) NSPopover *popover;
|
||||
|
||||
@end
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
@@ -11,17 +11,12 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class KPKEntry;
|
||||
@class MPDocument;
|
||||
|
||||
@interface MPPasswordCreatorViewController : MPViewController <NSTextFieldDelegate>
|
||||
|
||||
|
||||
//@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
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user