2017-04-05 20:56:22 +00:00
|
|
|
|
//==============================================================================
|
|
|
|
|
// This file is part of Master Password.
|
|
|
|
|
// Copyright (c) 2011-2017, Maarten Billemont.
|
2012-03-05 08:53:32 +00:00
|
|
|
|
//
|
2017-04-05 20:56:22 +00:00
|
|
|
|
// Master Password is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
2012-03-05 08:53:32 +00:00
|
|
|
|
//
|
2017-04-05 20:56:22 +00:00
|
|
|
|
// Master Password is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
2012-03-05 08:53:32 +00:00
|
|
|
|
//
|
2017-04-05 20:56:22 +00:00
|
|
|
|
// You can find a copy of the GNU General Public License in the
|
|
|
|
|
// LICENSE file. Alternatively, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
//==============================================================================
|
2012-03-05 08:53:32 +00:00
|
|
|
|
|
2014-06-24 04:55:08 +00:00
|
|
|
|
#import <QuartzCore/QuartzCore.h>
|
2017-05-07 22:36:01 +00:00
|
|
|
|
#import "MPSitesWindowController.h"
|
2013-04-25 01:23:53 +00:00
|
|
|
|
#import "MPMacAppDelegate.h"
|
2012-05-13 08:24:19 +00:00
|
|
|
|
#import "MPAppDelegate_Store.h"
|
2014-06-24 04:55:08 +00:00
|
|
|
|
#import "MPAppDelegate_Key.h"
|
|
|
|
|
|
2017-05-07 22:36:01 +00:00
|
|
|
|
@interface MPSitesWindowController()
|
2014-06-24 14:47:04 +00:00
|
|
|
|
|
2014-06-30 03:18:25 +00:00
|
|
|
|
@property(nonatomic, strong) CAGradientLayer *siteGradient;
|
2014-10-26 14:39:59 +00:00
|
|
|
|
|
2014-06-24 14:47:04 +00:00
|
|
|
|
@end
|
|
|
|
|
|
2017-05-07 22:36:01 +00:00
|
|
|
|
@implementation MPSitesWindowController
|
2012-03-05 08:53:32 +00:00
|
|
|
|
|
2014-02-20 12:29:05 +00:00
|
|
|
|
#pragma mark - Life
|
|
|
|
|
|
2012-03-05 08:53:32 +00:00
|
|
|
|
- (void)windowDidLoad {
|
2012-06-08 21:46:13 +00:00
|
|
|
|
|
2015-11-05 04:53:46 +00:00
|
|
|
|
prof_new( @"windowDidLoad" );
|
2014-06-22 01:56:28 +00:00
|
|
|
|
[super windowDidLoad];
|
2015-11-01 04:19:47 +00:00
|
|
|
|
prof_rewind( @"super" );
|
2013-05-07 04:45:06 +00:00
|
|
|
|
|
2014-12-29 21:35:23 +00:00
|
|
|
|
[self replaceFonts:self.window.contentView];
|
2015-11-01 04:19:47 +00:00
|
|
|
|
prof_rewind( @"replaceFonts" );
|
2014-12-29 21:35:23 +00:00
|
|
|
|
|
2017-04-18 01:57:08 +00:00
|
|
|
|
PearlAddNotificationObserver( NSWindowDidBecomeKeyNotification, self.window, [NSOperationQueue mainQueue],
|
|
|
|
|
^(id host, NSNotification *note) {
|
2015-11-05 04:53:46 +00:00
|
|
|
|
prof_new( @"didBecomeKey" );
|
2016-04-17 23:30:06 +00:00
|
|
|
|
[self.window makeKeyAndOrderFront:nil];
|
2015-11-05 04:53:46 +00:00
|
|
|
|
prof_rewind( @"fadeIn" );
|
2014-10-30 01:24:35 +00:00
|
|
|
|
[self updateUser];
|
2015-11-05 04:53:46 +00:00
|
|
|
|
prof_finish( @"updateUser" );
|
2017-04-18 01:57:08 +00:00
|
|
|
|
} );
|
|
|
|
|
PearlAddNotificationObserver( NSWindowWillCloseNotification, self.window, [NSOperationQueue mainQueue],
|
|
|
|
|
^(id host, NSNotification *note) {
|
2014-10-30 01:24:35 +00:00
|
|
|
|
NSWindow *sheet = [self.window attachedSheet];
|
|
|
|
|
if (sheet)
|
2015-11-01 04:19:47 +00:00
|
|
|
|
[self.window endSheet:sheet];
|
2017-04-18 01:57:08 +00:00
|
|
|
|
} );
|
|
|
|
|
PearlAddNotificationObserver( NSApplicationWillResignActiveNotification, nil, [NSOperationQueue mainQueue],
|
|
|
|
|
^(id host, NSNotification *note) {
|
2016-04-30 22:09:27 +00:00
|
|
|
|
[self.window close];
|
2017-04-18 01:57:08 +00:00
|
|
|
|
} );
|
|
|
|
|
PearlAddNotificationObserver( MPSignedInNotification, nil, [NSOperationQueue mainQueue], ^(id host, NSNotification *note) {
|
|
|
|
|
[self updateUser];
|
|
|
|
|
} );
|
|
|
|
|
PearlAddNotificationObserver( MPSignedOutNotification, nil, [NSOperationQueue mainQueue], ^(id host, NSNotification *note) {
|
|
|
|
|
[self updateUser];
|
|
|
|
|
} );
|
2017-05-07 22:36:01 +00:00
|
|
|
|
[self observeKeyPath:@"sitesController.selection" withBlock:^(id from, id to, NSKeyValueChange cause, id self) {
|
2020-04-08 23:36:19 +00:00
|
|
|
|
[self updateTable];
|
2017-04-13 04:06:46 +00:00
|
|
|
|
}];
|
2015-11-01 04:19:47 +00:00
|
|
|
|
prof_rewind( @"observers" );
|
2014-06-25 02:00:33 +00:00
|
|
|
|
|
2017-04-18 01:57:08 +00:00
|
|
|
|
NSSearchFieldCell *siteFieldCell = self.siteField.cell;
|
2014-06-25 02:00:33 +00:00
|
|
|
|
siteFieldCell.searchButtonCell = nil;
|
|
|
|
|
siteFieldCell.cancelButtonCell = nil;
|
2014-06-26 05:19:42 +00:00
|
|
|
|
|
2014-06-30 03:18:25 +00:00
|
|
|
|
self.siteGradient = [CAGradientLayer layer];
|
|
|
|
|
self.siteGradient.colors = @[ (__bridge id)[NSColor whiteColor].CGColor, (__bridge id)[NSColor clearColor].CGColor ];
|
|
|
|
|
self.siteGradient.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
|
|
|
|
|
self.siteGradient.frame = self.siteTable.bounds;
|
|
|
|
|
self.siteTable.superview.superview.layer.mask = self.siteGradient;
|
2014-07-01 01:00:25 +00:00
|
|
|
|
|
|
|
|
|
self.siteTable.controller = self;
|
2015-11-01 04:19:47 +00:00
|
|
|
|
prof_finish( @"ui" );
|
2013-04-30 05:49:53 +00:00
|
|
|
|
}
|
2013-04-27 04:34:28 +00:00
|
|
|
|
|
2020-04-04 20:30:14 +00:00
|
|
|
|
- (void)dealloc {
|
|
|
|
|
PearlRemoveNotificationObservers();
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-29 21:35:23 +00:00
|
|
|
|
- (void)replaceFonts:(NSView *)view {
|
|
|
|
|
|
|
|
|
|
if (view.window.backingScaleFactor == 1)
|
|
|
|
|
[view enumerateViews:^(NSView *subview, BOOL *stop, BOOL *recurse) {
|
|
|
|
|
if ([subview respondsToSelector:@selector( setFont: )]) {
|
|
|
|
|
NSFont *font = [(id)subview font];
|
|
|
|
|
if ([font.fontName isEqualToString:@"HelveticaNeue-Thin"])
|
|
|
|
|
[(id)subview setFont:[NSFont fontWithName:@"HelveticaNeue" matrix:font.matrix]];
|
|
|
|
|
if ([font.fontName isEqualToString:@"HelveticaNeue-Light"])
|
|
|
|
|
[(id)subview setFont:[NSFont fontWithName:@"HelveticaNeue" matrix:font.matrix]];
|
|
|
|
|
}
|
|
|
|
|
} recurse:YES];
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-27 03:13:21 +00:00
|
|
|
|
- (void)flagsChanged:(NSEvent *)theEvent {
|
|
|
|
|
|
2016-02-21 02:56:04 +00:00
|
|
|
|
BOOL shiftPressed = (theEvent.modifierFlags & NSShiftKeyMask) != 0;
|
2020-04-08 23:36:19 +00:00
|
|
|
|
if (shiftPressed != self.shiftPressed) {
|
2016-02-21 02:56:04 +00:00
|
|
|
|
self.shiftPressed = shiftPressed;
|
2020-04-08 23:36:19 +00:00
|
|
|
|
[self.selectedSite updateContent];
|
|
|
|
|
[self updateSelection];
|
|
|
|
|
}
|
2016-02-21 02:56:04 +00:00
|
|
|
|
|
2014-06-27 03:13:21 +00:00
|
|
|
|
BOOL alternatePressed = (theEvent.modifierFlags & NSAlternateKeyMask) != 0;
|
|
|
|
|
if (alternatePressed != self.alternatePressed) {
|
|
|
|
|
self.alternatePressed = alternatePressed;
|
2015-09-23 04:31:33 +00:00
|
|
|
|
self.showVersionContainer = self.alternatePressed || self.selectedSite.outdated;
|
2014-09-21 15:47:53 +00:00
|
|
|
|
[self.selectedSite updateContent];
|
2020-04-08 23:36:19 +00:00
|
|
|
|
[self updateSelection];
|
2014-06-30 03:18:25 +00:00
|
|
|
|
|
|
|
|
|
if (self.locked) {
|
|
|
|
|
NSTextField *passwordField = self.securePasswordField;
|
|
|
|
|
if (self.securePasswordField.isHidden)
|
|
|
|
|
passwordField = self.revealPasswordField;
|
2020-03-25 17:12:06 +00:00
|
|
|
|
[passwordField.window makeFirstResponder:passwordField];
|
2014-06-30 03:18:25 +00:00
|
|
|
|
[[passwordField currentEditor] moveToEndOfLine:nil];
|
|
|
|
|
}
|
2014-06-27 03:13:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[super flagsChanged:theEvent];
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-24 04:55:08 +00:00
|
|
|
|
#pragma mark - NSResponder
|
|
|
|
|
|
2015-11-01 04:19:47 +00:00
|
|
|
|
// Handle any unhandled editor command.
|
2014-06-24 04:55:08 +00:00
|
|
|
|
- (void)doCommandBySelector:(SEL)commandSelector {
|
|
|
|
|
|
|
|
|
|
[self handleCommand:commandSelector];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - NSTextFieldDelegate
|
|
|
|
|
|
2015-11-01 04:19:47 +00:00
|
|
|
|
// Editor command in a text field.
|
2014-06-24 04:55:08 +00:00
|
|
|
|
- (BOOL)control:(NSControl *)control textView:(NSTextView *)fieldEditor doCommandBySelector:(SEL)commandSelector {
|
|
|
|
|
|
2014-06-30 03:18:25 +00:00
|
|
|
|
if (control == self.siteField) {
|
2014-10-30 01:24:35 +00:00
|
|
|
|
if ([NSStringFromSelector( commandSelector ) rangeOfString:@"delete"].location == 0)
|
|
|
|
|
return NO;
|
2014-06-24 04:55:08 +00:00
|
|
|
|
}
|
2014-07-01 01:00:25 +00:00
|
|
|
|
if (control == self.securePasswordField || control == self.revealPasswordField) {
|
|
|
|
|
if (commandSelector == @selector( insertNewline: ))
|
2014-10-30 01:24:35 +00:00
|
|
|
|
return NO;
|
2014-07-01 01:00:25 +00:00
|
|
|
|
}
|
2014-06-24 04:55:08 +00:00
|
|
|
|
|
2014-10-30 01:24:35 +00:00
|
|
|
|
return [self handleCommand:commandSelector];
|
2014-06-24 04:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-27 03:13:21 +00:00
|
|
|
|
- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor {
|
|
|
|
|
|
|
|
|
|
if (control == self.siteField)
|
|
|
|
|
[fieldEditor replaceCharactersInRange:fieldEditor.selectedRange withString:@""];
|
|
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-30 03:18:25 +00:00
|
|
|
|
- (IBAction)doUnlockUser:(id)sender {
|
|
|
|
|
|
|
|
|
|
[self.progressView startAnimation:self];
|
2017-04-30 03:52:57 +00:00
|
|
|
|
[MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *context) {
|
|
|
|
|
MPUserEntity *activeUser = [[MPMacAppDelegate get] activeUserInContext:context];
|
2014-06-30 03:18:25 +00:00
|
|
|
|
NSString *userName = activeUser.name;
|
2017-04-30 03:52:57 +00:00
|
|
|
|
BOOL success = [[MPMacAppDelegate get] signInAsUser:activeUser saveInContext:context usingMasterPassword:self.masterPassword];
|
2014-06-30 03:18:25 +00:00
|
|
|
|
|
|
|
|
|
PearlMainQueue( ^{
|
|
|
|
|
self.masterPassword = nil;
|
|
|
|
|
[self.progressView stopAnimation:self];
|
|
|
|
|
if (!success)
|
|
|
|
|
[[NSAlert alertWithError:[NSError errorWithDomain:MPErrorDomain code:0 userInfo:@{
|
2017-04-01 04:30:25 +00:00
|
|
|
|
NSLocalizedDescriptionKey: strf( @"Incorrect master password for user %@", userName )
|
2016-04-23 16:22:15 +00:00
|
|
|
|
}]] beginSheetModalForWindow:self.window completionHandler:nil];
|
2014-06-30 03:18:25 +00:00
|
|
|
|
} );
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-21 15:47:53 +00:00
|
|
|
|
- (IBAction)doSearchSites:(id)sender {
|
2014-06-24 14:47:04 +00:00
|
|
|
|
|
2014-09-21 15:47:53 +00:00
|
|
|
|
[self updateSites];
|
2014-06-24 14:47:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-24 04:55:08 +00:00
|
|
|
|
#pragma mark - NSTextViewDelegate
|
|
|
|
|
|
|
|
|
|
- (BOOL)textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector {
|
|
|
|
|
|
|
|
|
|
return [self handleCommand:commandSelector];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - NSTableViewDataSource
|
|
|
|
|
|
|
|
|
|
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
|
|
|
|
|
|
2014-09-21 15:47:53 +00:00
|
|
|
|
return (NSInteger)[self.sites count];
|
2014-06-24 04:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-01 01:00:25 +00:00
|
|
|
|
#pragma mark - NSTableViewDelegate
|
|
|
|
|
|
2014-12-29 21:35:23 +00:00
|
|
|
|
- (void)tableView:(NSTableView *)tableView didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger)row {
|
|
|
|
|
|
|
|
|
|
[self replaceFonts:rowView];
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-24 04:55:08 +00:00
|
|
|
|
#pragma mark - State
|
|
|
|
|
|
2014-09-21 15:47:53 +00:00
|
|
|
|
- (void)insertObject:(MPSiteModel *)model inSitesAtIndex:(NSUInteger)index {
|
2014-06-24 04:55:08 +00:00
|
|
|
|
|
2014-09-21 15:47:53 +00:00
|
|
|
|
[self.sites insertObject:model atIndex:index];
|
2014-06-24 04:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-21 15:47:53 +00:00
|
|
|
|
- (void)removeObjectFromSitesAtIndex:(NSUInteger)index {
|
2014-06-24 04:55:08 +00:00
|
|
|
|
|
2014-09-21 15:47:53 +00:00
|
|
|
|
[self.sites removeObjectAtIndex:index];
|
2014-06-24 04:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-21 15:47:53 +00:00
|
|
|
|
- (MPSiteModel *)selectedSite {
|
2014-06-24 04:55:08 +00:00
|
|
|
|
|
2014-09-21 15:47:53 +00:00
|
|
|
|
return [self.sitesController.selectedObjects firstObject];
|
2014-06-24 04:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-26 05:19:42 +00:00
|
|
|
|
#pragma mark - Actions
|
|
|
|
|
|
2014-06-27 03:13:21 +00:00
|
|
|
|
- (IBAction)settings:(id)sender {
|
|
|
|
|
|
2016-04-17 23:30:06 +00:00
|
|
|
|
[self.window close];
|
2014-06-27 03:13:21 +00:00
|
|
|
|
[[MPMacAppDelegate get] showPopup:sender];
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-21 15:47:53 +00:00
|
|
|
|
- (IBAction)deleteSite:(id)sender {
|
2014-06-26 05:19:42 +00:00
|
|
|
|
|
|
|
|
|
NSAlert *alert = [NSAlert new];
|
|
|
|
|
[alert addButtonWithTitle:@"Delete"];
|
|
|
|
|
[alert addButtonWithTitle:@"Cancel"];
|
|
|
|
|
[alert setMessageText:@"Delete Site?"];
|
2014-10-30 01:24:35 +00:00
|
|
|
|
[alert setInformativeText:strf( @"Do you want to delete the site named:\n\n%@", self.selectedSite.name )];
|
2016-04-23 16:22:15 +00:00
|
|
|
|
[alert beginSheetModalForWindow:self.window completionHandler:^(NSModalResponse returnCode) {
|
|
|
|
|
switch (returnCode) {
|
|
|
|
|
case NSAlertFirstButtonReturn: {
|
|
|
|
|
// "Delete" button.
|
|
|
|
|
[MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *context) {
|
|
|
|
|
[context deleteObject:[self.selectedSite entityInContext:context]];
|
|
|
|
|
[context saveToStore];
|
|
|
|
|
}];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}];
|
2014-06-26 05:19:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (IBAction)changeLogin:(id)sender {
|
|
|
|
|
|
|
|
|
|
NSAlert *alert = [NSAlert new];
|
|
|
|
|
[alert addButtonWithTitle:@"Save"];
|
|
|
|
|
[alert addButtonWithTitle:@"Cancel"];
|
|
|
|
|
[alert setMessageText:@"Change Login Name"];
|
2016-05-16 04:50:17 +00:00
|
|
|
|
[alert setInformativeText:strf( @"Your login name for: %@", self.selectedSite.name )];
|
|
|
|
|
NSTextField *loginField = [NSTextField new];
|
|
|
|
|
[loginField bind:@"value" toObject:self.selectedSite withKeyPath:@"loginName" options:nil];
|
|
|
|
|
NSButton *generatedField = [NSButton new];
|
|
|
|
|
[generatedField setButtonType:NSSwitchButton];
|
|
|
|
|
[generatedField bind:@"value" toObject:self.selectedSite withKeyPath:@"loginGenerated" options:nil];
|
|
|
|
|
generatedField.title = @"Generated";
|
|
|
|
|
NSStackView *stackView = [NSStackView stackViewWithViews:@[ loginField, generatedField ]];
|
|
|
|
|
stackView.orientation = NSUserInterfaceLayoutOrientationVertical;
|
|
|
|
|
stackView.frame = NSMakeRect( 0, 0, 200, 44 );
|
|
|
|
|
[stackView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[loginField(200)]"
|
|
|
|
|
options:0 metrics:nil
|
|
|
|
|
views:NSDictionaryOfVariableBindings( loginField, stackView )]];
|
|
|
|
|
[stackView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[generatedField(200)]"
|
|
|
|
|
options:0 metrics:nil
|
|
|
|
|
views:NSDictionaryOfVariableBindings( generatedField, stackView )]];
|
|
|
|
|
[alert setAccessoryView:stackView];
|
2014-06-26 05:19:42 +00:00
|
|
|
|
[alert layout];
|
2016-05-16 04:50:17 +00:00
|
|
|
|
[loginField selectText:self];
|
|
|
|
|
|
2016-04-23 16:22:15 +00:00
|
|
|
|
[alert beginSheetModalForWindow:self.window completionHandler:^(NSModalResponse returnCode) {
|
|
|
|
|
switch (returnCode) {
|
|
|
|
|
case NSAlertFirstButtonReturn: {
|
|
|
|
|
// "Save" button.
|
2016-05-16 04:50:17 +00:00
|
|
|
|
NSString *loginName = [loginField stringValue];
|
2016-04-23 16:22:15 +00:00
|
|
|
|
[MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *context) {
|
|
|
|
|
MPSiteEntity *entity = [self.selectedSite entityInContext:context];
|
2016-05-16 04:50:17 +00:00
|
|
|
|
entity.loginName = !self.selectedSite.loginGenerated && [loginName length]? loginName: nil;
|
2016-04-23 16:22:15 +00:00
|
|
|
|
[context saveToStore];
|
2016-05-16 04:50:17 +00:00
|
|
|
|
[self.selectedSite updateContent];
|
2016-04-23 16:22:15 +00:00
|
|
|
|
}];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}];
|
2014-06-26 05:19:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-30 03:18:25 +00:00
|
|
|
|
- (IBAction)resetMasterPassword:(id)sender {
|
|
|
|
|
|
|
|
|
|
NSAlert *alert = [NSAlert new];
|
|
|
|
|
[alert addButtonWithTitle:@"Reset"];
|
|
|
|
|
[alert addButtonWithTitle:@"Cancel"];
|
|
|
|
|
[alert setMessageText:@"Reset My Master Password"];
|
|
|
|
|
[alert setInformativeText:strf( @"This will allow you to change %@'s master password.\n\n"
|
2016-04-23 16:22:15 +00:00
|
|
|
|
@"WARNING: All your site passwords will change. Do this only if you've forgotten your "
|
|
|
|
|
@"master password and are fully prepared to change all your sites' passwords to the new ones.",
|
|
|
|
|
[MPMacAppDelegate get].activeUserForMainThread.name )];
|
|
|
|
|
|
|
|
|
|
[alert beginSheetModalForWindow:self.window completionHandler:^(NSModalResponse returnCode) {
|
|
|
|
|
switch (returnCode) {
|
|
|
|
|
case NSAlertFirstButtonReturn: {
|
|
|
|
|
// "Reset" button.
|
|
|
|
|
[MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *context) {
|
|
|
|
|
MPUserEntity *activeUser = [[MPMacAppDelegate get] activeUserInContext:context];
|
|
|
|
|
NSString *activeUserName = activeUser.name;
|
|
|
|
|
activeUser.keyID = nil;
|
|
|
|
|
[[MPMacAppDelegate get] forgetSavedKeyFor:activeUser];
|
|
|
|
|
[context saveToStore];
|
|
|
|
|
|
|
|
|
|
PearlMainQueue( ^{
|
|
|
|
|
NSAlert *alert_ = [NSAlert new];
|
|
|
|
|
alert_.messageText = @"Master Password Reset";
|
|
|
|
|
alert_.informativeText = strf( @"%@'s master password has been reset.\n\nYou can now set a new one by logging in.",
|
|
|
|
|
activeUserName );
|
2016-05-16 04:50:17 +00:00
|
|
|
|
[alert_ beginSheetModalForWindow:self.window completionHandler:nil];
|
2016-04-23 16:22:15 +00:00
|
|
|
|
|
|
|
|
|
if ([MPMacAppDelegate get].key)
|
2020-04-04 20:30:14 +00:00
|
|
|
|
[[MPMacAppDelegate get] signOut];
|
2016-04-23 16:22:15 +00:00
|
|
|
|
} );
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}];
|
2014-06-30 03:18:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-26 05:19:42 +00:00
|
|
|
|
- (IBAction)changePassword:(id)sender {
|
|
|
|
|
|
2014-09-21 15:47:53 +00:00
|
|
|
|
if (!self.selectedSite.stored)
|
2014-06-26 05:19:42 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
NSAlert *alert = [NSAlert new];
|
|
|
|
|
[alert addButtonWithTitle:@"Save"];
|
|
|
|
|
[alert addButtonWithTitle:@"Cancel"];
|
|
|
|
|
[alert setMessageText:@"Change Password"];
|
2014-10-30 01:24:35 +00:00
|
|
|
|
[alert setInformativeText:strf( @"Enter the new password for: %@", self.selectedSite.name )];
|
2016-05-16 04:50:17 +00:00
|
|
|
|
NSSecureTextField *passwordField = [[NSSecureTextField alloc] initWithFrame:NSMakeRect( 0, 0, 200, 22 )];
|
|
|
|
|
[alert setAccessoryView:passwordField];
|
2014-06-26 05:19:42 +00:00
|
|
|
|
[alert layout];
|
2016-04-23 16:22:15 +00:00
|
|
|
|
[alert beginSheetModalForWindow:self.window completionHandler:^(NSModalResponse returnCode) {
|
|
|
|
|
switch (returnCode) {
|
|
|
|
|
case NSAlertFirstButtonReturn: {
|
|
|
|
|
// "Save" button.
|
2016-05-16 04:50:17 +00:00
|
|
|
|
NSString *password = [passwordField stringValue];
|
2016-04-23 16:22:15 +00:00
|
|
|
|
[MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *context) {
|
|
|
|
|
MPSiteEntity *entity = [self.selectedSite entityInContext:context];
|
|
|
|
|
[entity.algorithm savePassword:password toSite:entity usingKey:[MPMacAppDelegate get].key];
|
|
|
|
|
[context saveToStore];
|
2016-05-16 04:50:17 +00:00
|
|
|
|
[self.selectedSite updateContent];
|
2016-04-23 16:22:15 +00:00
|
|
|
|
}];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}];
|
2014-06-26 05:19:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (IBAction)changeType:(id)sender {
|
|
|
|
|
|
2014-09-21 15:47:53 +00:00
|
|
|
|
MPSiteModel *site = self.selectedSite;
|
2016-04-23 15:54:07 +00:00
|
|
|
|
NSArray *types = [site.algorithm allTypes];
|
2014-06-26 05:19:42 +00:00
|
|
|
|
[self.passwordTypesMatrix renewRows:(NSInteger)[types count] columns:1];
|
|
|
|
|
for (NSUInteger t = 0; t < [types count]; ++t) {
|
2017-08-13 02:26:48 +00:00
|
|
|
|
MPResultType type = (MPResultType)[types[t] unsignedIntegerValue];
|
2014-09-21 15:47:53 +00:00
|
|
|
|
NSString *title = [site.algorithm nameOfType:type];
|
2017-08-13 02:26:48 +00:00
|
|
|
|
if (type & MPResultTypeClassTemplate)
|
2017-08-13 01:57:47 +00:00
|
|
|
|
title = strf( @"%@ – %@", [site.algorithm mpwTemplateForSiteNamed:site.name ofType:type withCounter:site.counter
|
|
|
|
|
usingKey:[MPMacAppDelegate get].key], title );
|
2014-06-26 05:19:42 +00:00
|
|
|
|
|
|
|
|
|
NSButtonCell *cell = [self.passwordTypesMatrix cellAtRow:(NSInteger)t column:0];
|
|
|
|
|
cell.tag = type;
|
2014-09-21 15:47:53 +00:00
|
|
|
|
cell.state = type == site.type? NSOnState: NSOffState;
|
2014-06-26 05:19:42 +00:00
|
|
|
|
cell.title = title;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-23 15:54:07 +00:00
|
|
|
|
self.passwordTypesBox.title = strf( @"Choose a password type for %@:", site.name );
|
|
|
|
|
|
2014-06-26 05:19:42 +00:00
|
|
|
|
NSAlert *alert = [NSAlert new];
|
|
|
|
|
[alert addButtonWithTitle:@"Save"];
|
|
|
|
|
[alert addButtonWithTitle:@"Cancel"];
|
|
|
|
|
[alert setMessageText:@"Change Password Type"];
|
|
|
|
|
[alert setAccessoryView:self.passwordTypesBox];
|
|
|
|
|
[alert layout];
|
2016-04-23 16:22:15 +00:00
|
|
|
|
[alert beginSheetModalForWindow:self.window completionHandler:^(NSModalResponse returnCode) {
|
|
|
|
|
switch (returnCode) {
|
|
|
|
|
case NSAlertFirstButtonReturn: {
|
|
|
|
|
// "Save" button.
|
2017-08-13 02:26:48 +00:00
|
|
|
|
MPResultType type = (MPResultType)[self.passwordTypesMatrix.selectedCell tag];
|
2016-04-23 16:22:15 +00:00
|
|
|
|
[MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *context) {
|
|
|
|
|
MPSiteEntity *entity = [[MPMacAppDelegate get] changeSite:[self.selectedSite entityInContext:context]
|
|
|
|
|
saveInContext:context toType:type];
|
|
|
|
|
if ([entity isKindOfClass:[MPStoredSiteEntity class]] && ![(MPStoredSiteEntity *)entity contentObject].length)
|
|
|
|
|
PearlMainQueue( ^{
|
|
|
|
|
[self changePassword:nil];
|
|
|
|
|
} );
|
|
|
|
|
}];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}];
|
2014-06-26 05:19:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-23 18:07:08 +00:00
|
|
|
|
- (IBAction)securityQuestions:(id)sender {
|
|
|
|
|
|
|
|
|
|
MPSiteModel *site = self.selectedSite;
|
|
|
|
|
self.securityQuestionsBox.title = strf( @"Answer to security questions for %@:", site.name );
|
|
|
|
|
|
|
|
|
|
NSAlert *alert = [NSAlert new];
|
|
|
|
|
[alert addButtonWithTitle:@"Copy Answer"];
|
|
|
|
|
[alert addButtonWithTitle:@"Close"];
|
|
|
|
|
[alert setMessageText:@"Security Questions"];
|
|
|
|
|
[alert setAccessoryView:self.securityQuestionsBox];
|
|
|
|
|
[alert layout];
|
|
|
|
|
[alert beginSheetModalForWindow:self.window completionHandler:^(NSModalResponse returnCode) {
|
|
|
|
|
switch (returnCode) {
|
|
|
|
|
case NSAlertFirstButtonReturn: {
|
|
|
|
|
// "Copy Answer" button.
|
|
|
|
|
[self copyContent:self.securityAnswerField.stringValue];
|
2016-04-30 22:06:23 +00:00
|
|
|
|
[self.window close];
|
2016-04-23 18:07:08 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-24 04:55:08 +00:00
|
|
|
|
#pragma mark - Private
|
|
|
|
|
|
|
|
|
|
- (BOOL)handleCommand:(SEL)commandSelector {
|
|
|
|
|
|
2014-07-01 01:00:25 +00:00
|
|
|
|
if (commandSelector == @selector( moveUp: )) {
|
2014-09-21 15:47:53 +00:00
|
|
|
|
[self.sitesController selectPrevious:self];
|
2014-07-01 01:00:25 +00:00
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
if (commandSelector == @selector( moveDown: )) {
|
2014-09-21 15:47:53 +00:00
|
|
|
|
[self.sitesController selectNext:self];
|
2014-07-01 01:00:25 +00:00
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
if (commandSelector == @selector( insertNewline: )) {
|
|
|
|
|
[self useSite];
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
2014-06-24 04:55:08 +00:00
|
|
|
|
if (commandSelector == @selector( cancel: ) || commandSelector == @selector( cancelOperation: )) {
|
2016-04-17 23:30:06 +00:00
|
|
|
|
[self.window close];
|
2014-06-24 04:55:08 +00:00
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-30 03:18:25 +00:00
|
|
|
|
- (void)useSite {
|
|
|
|
|
|
2014-09-21 15:47:53 +00:00
|
|
|
|
MPSiteModel *selectedSite = [self selectedSite];
|
2015-03-05 22:28:04 +00:00
|
|
|
|
if (!selectedSite)
|
|
|
|
|
return;
|
2014-06-30 03:18:25 +00:00
|
|
|
|
|
2015-03-05 22:28:04 +00:00
|
|
|
|
if (selectedSite.transient) {
|
|
|
|
|
[self createNewSite:selectedSite.name];
|
|
|
|
|
return;
|
2014-06-30 03:18:25 +00:00
|
|
|
|
}
|
2015-03-05 22:28:04 +00:00
|
|
|
|
|
|
|
|
|
// Performing action while content is available. Copy it.
|
2020-04-08 23:36:19 +00:00
|
|
|
|
[self copyContent:self.shiftPressed? selectedSite.loginName: selectedSite.content];
|
2017-04-13 15:32:38 +00:00
|
|
|
|
[NSApp hide:nil];
|
2015-03-05 22:28:04 +00:00
|
|
|
|
|
|
|
|
|
NSUserNotification *notification = [NSUserNotification new];
|
|
|
|
|
notification.title = @"Password Copied";
|
|
|
|
|
if (selectedSite.loginName.length)
|
|
|
|
|
notification.subtitle = strf( @"%@ at %@", selectedSite.loginName, selectedSite.name );
|
|
|
|
|
else
|
|
|
|
|
notification.subtitle = selectedSite.name;
|
|
|
|
|
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
|
2014-06-30 03:18:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-22 01:56:28 +00:00
|
|
|
|
- (void)updateUser {
|
2014-02-20 12:29:05 +00:00
|
|
|
|
|
2014-06-22 01:56:28 +00:00
|
|
|
|
[MPMacAppDelegate managedObjectContextForMainThreadPerformBlock:^(NSManagedObjectContext *mainContext) {
|
2014-06-30 03:18:25 +00:00
|
|
|
|
self.locked = YES;
|
2014-07-19 02:04:10 +00:00
|
|
|
|
self.newUser = YES;
|
2014-06-25 02:00:33 +00:00
|
|
|
|
|
|
|
|
|
self.inputLabel.stringValue = @"";
|
|
|
|
|
self.siteField.stringValue = @"";
|
|
|
|
|
|
2014-06-22 01:56:28 +00:00
|
|
|
|
MPUserEntity *mainActiveUser = [[MPMacAppDelegate get] activeUserInContext:mainContext];
|
2014-06-24 04:55:08 +00:00
|
|
|
|
if (mainActiveUser) {
|
2014-07-19 02:04:10 +00:00
|
|
|
|
self.newUser = mainActiveUser.keyID == nil;
|
|
|
|
|
|
2014-06-24 04:55:08 +00:00
|
|
|
|
if ([MPMacAppDelegate get].key) {
|
|
|
|
|
self.inputLabel.stringValue = strf( @"%@'s password for:", mainActiveUser.name );
|
2014-06-30 03:18:25 +00:00
|
|
|
|
self.locked = NO;
|
2020-03-25 17:12:06 +00:00
|
|
|
|
[self.siteField.window makeFirstResponder:self.siteField];
|
2014-06-24 04:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
self.inputLabel.stringValue = strf( @"Enter %@'s master password:", mainActiveUser.name );
|
2014-06-30 03:18:25 +00:00
|
|
|
|
NSTextField *passwordField = self.securePasswordField;
|
|
|
|
|
if (self.securePasswordField.isHidden)
|
|
|
|
|
passwordField = self.revealPasswordField;
|
2020-03-25 17:12:06 +00:00
|
|
|
|
[passwordField.window makeFirstResponder:passwordField];
|
2014-06-24 04:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-21 15:47:53 +00:00
|
|
|
|
[self updateSites];
|
2013-05-16 02:42:21 +00:00
|
|
|
|
}];
|
2013-05-07 04:45:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-21 15:47:53 +00:00
|
|
|
|
- (void)updateSites {
|
2012-05-04 22:15:51 +00:00
|
|
|
|
|
2015-03-11 21:30:34 +00:00
|
|
|
|
NSAssert( [NSOperationQueue currentQueue] == [NSOperationQueue mainQueue], @"updateSites should be called on the main queue." );
|
2014-06-24 04:55:08 +00:00
|
|
|
|
if (![MPMacAppDelegate get].key) {
|
2014-09-21 15:47:53 +00:00
|
|
|
|
self.sites = nil;
|
2014-06-24 04:55:08 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-30 01:24:35 +00:00
|
|
|
|
static NSRegularExpression *fuzzyRE;
|
|
|
|
|
static dispatch_once_t once = 0;
|
|
|
|
|
dispatch_once( &once, ^{
|
|
|
|
|
fuzzyRE = [NSRegularExpression regularExpressionWithPattern:@"(.)" options:0 error:nil];
|
|
|
|
|
} );
|
|
|
|
|
|
2017-04-13 03:41:17 +00:00
|
|
|
|
prof_new( @"updateSites" );
|
2014-10-30 01:24:35 +00:00
|
|
|
|
NSString *queryString = self.siteField.stringValue;
|
2017-04-13 03:41:17 +00:00
|
|
|
|
NSString *queryPattern = [[queryString stringByReplacingMatchesOfExpression:fuzzyRE withTemplate:@"*$1"] stringByAppendingString:@"*"];
|
|
|
|
|
prof_rewind( @"queryPattern" );
|
2014-10-30 01:24:35 +00:00
|
|
|
|
NSMutableArray *fuzzyGroups = [NSMutableArray new];
|
|
|
|
|
[fuzzyRE enumerateMatchesInString:queryString options:0 range:NSMakeRange( 0, queryString.length )
|
|
|
|
|
usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
|
2014-12-29 21:35:23 +00:00
|
|
|
|
[fuzzyGroups addObject:[queryString substringWithRange:result.range]];
|
2014-10-30 01:24:35 +00:00
|
|
|
|
}];
|
2017-04-13 03:41:17 +00:00
|
|
|
|
prof_rewind( @"fuzzyRE" );
|
2015-03-11 21:30:34 +00:00
|
|
|
|
[MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *context) {
|
2017-04-13 03:41:17 +00:00
|
|
|
|
prof_rewind( @"moc" );
|
|
|
|
|
|
2014-09-21 14:39:09 +00:00
|
|
|
|
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass( [MPSiteEntity class] )];
|
2014-10-26 14:39:59 +00:00
|
|
|
|
fetchRequest.sortDescriptors = @[ [[NSSortDescriptor alloc] initWithKey:@"lastUsed" ascending:NO] ];
|
2017-04-27 06:20:49 +00:00
|
|
|
|
fetchRequest.predicate =
|
|
|
|
|
[NSPredicate predicateWithFormat:@"name LIKE[cd] %@ AND user == %@", queryPattern, [MPMacAppDelegate get].activeUserOID];
|
2017-04-13 03:41:17 +00:00
|
|
|
|
prof_rewind( @"fetchRequest" );
|
2014-06-24 04:55:08 +00:00
|
|
|
|
|
|
|
|
|
NSError *error = nil;
|
|
|
|
|
NSArray *siteResults = [context executeFetchRequest:fetchRequest error:&error];
|
|
|
|
|
if (!siteResults) {
|
2017-04-13 03:41:17 +00:00
|
|
|
|
prof_finish( @"executeFetchRequest: %@ // %@", fetchRequest.predicate, [error fullDescription] );
|
2017-04-30 03:03:50 +00:00
|
|
|
|
MPError( error, @"While fetching sites for completion." );
|
2014-06-24 04:55:08 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-04-13 03:41:17 +00:00
|
|
|
|
prof_rewind( @"executeFetchRequest: %@", fetchRequest.predicate );
|
2014-06-24 04:55:08 +00:00
|
|
|
|
|
2015-03-05 22:28:04 +00:00
|
|
|
|
BOOL exact = NO;
|
2014-09-21 15:47:53 +00:00
|
|
|
|
NSMutableArray *newSites = [NSMutableArray arrayWithCapacity:[siteResults count]];
|
2015-03-05 22:28:04 +00:00
|
|
|
|
for (MPSiteEntity *site in siteResults) {
|
2014-10-30 01:24:35 +00:00
|
|
|
|
[newSites addObject:[[MPSiteModel alloc] initWithEntity:site fuzzyGroups:fuzzyGroups]];
|
2015-03-05 22:28:04 +00:00
|
|
|
|
exact |= [site.name isEqualToString:queryString];
|
|
|
|
|
}
|
2017-04-13 03:41:17 +00:00
|
|
|
|
prof_rewind( @"newSites: %u, exact: %d", (uint)[siteResults count], exact );
|
2015-03-11 21:30:34 +00:00
|
|
|
|
if (!exact && [queryString length]) {
|
|
|
|
|
MPUserEntity *activeUser = [[MPAppDelegate_Shared get] activeUserInContext:context];
|
|
|
|
|
[newSites addObject:[[MPSiteModel alloc] initWithName:queryString forUser:activeUser]];
|
|
|
|
|
}
|
2017-04-13 03:41:17 +00:00
|
|
|
|
prof_finish( @"newSites: %@", newSites );
|
2015-03-11 21:30:34 +00:00
|
|
|
|
|
|
|
|
|
if (![newSites isEqualToArray:self.sites])
|
|
|
|
|
PearlMainQueue( ^{
|
|
|
|
|
self.sites = newSites;
|
|
|
|
|
} );
|
2014-06-24 04:55:08 +00:00
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-08 23:36:19 +00:00
|
|
|
|
- (void)updateTable {
|
2014-06-24 14:47:04 +00:00
|
|
|
|
|
2014-09-21 15:47:53 +00:00
|
|
|
|
[self.siteTable scrollRowToVisible:(NSInteger)self.sitesController.selectionIndex];
|
2014-06-24 04:55:08 +00:00
|
|
|
|
|
2014-06-30 03:18:25 +00:00
|
|
|
|
NSView *siteScrollView = self.siteTable.superview.superview;
|
2014-09-21 15:47:53 +00:00
|
|
|
|
NSRect selectedCellFrame = [self.siteTable frameOfCellAtColumn:0 row:((NSInteger)self.sitesController.selectionIndex)];
|
2014-06-30 03:18:25 +00:00
|
|
|
|
CGFloat selectedOffset = [siteScrollView convertPoint:selectedCellFrame.origin fromView:self.siteTable].y;
|
|
|
|
|
CGFloat gradientOpacity = selectedOffset / siteScrollView.bounds.size.height;
|
|
|
|
|
self.siteGradient.colors = @[
|
|
|
|
|
(__bridge id)[NSColor whiteColor].CGColor,
|
2016-04-17 23:30:06 +00:00
|
|
|
|
(__bridge id)[NSColor colorWithDeviceWhite:1 alpha:1 - (1 - gradientOpacity) * 4 / 5].CGColor,
|
2014-06-30 03:18:25 +00:00
|
|
|
|
(__bridge id)[NSColor colorWithDeviceWhite:1 alpha:gradientOpacity].CGColor
|
|
|
|
|
];
|
2015-09-23 04:31:33 +00:00
|
|
|
|
|
2020-04-08 23:36:19 +00:00
|
|
|
|
[self updateSelection];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)updateSelection {
|
2015-09-23 04:31:33 +00:00
|
|
|
|
self.showVersionContainer = self.alternatePressed || self.selectedSite.outdated;
|
2020-04-08 23:36:19 +00:00
|
|
|
|
[self.sitePasswordTipField setAttributedStringValue:
|
|
|
|
|
straf( @"Your %@ for %@:", self.shiftPressed? @"login": @"password", self.selectedSite.displayedName )];
|
2014-06-24 04:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)createNewSite:(NSString *)siteName {
|
|
|
|
|
|
|
|
|
|
PearlMainQueue( ^{
|
|
|
|
|
NSAlert *alert = [NSAlert new];
|
|
|
|
|
[alert addButtonWithTitle:@"Create"];
|
|
|
|
|
[alert addButtonWithTitle:@"Cancel"];
|
|
|
|
|
[alert setMessageText:@"Create site?"];
|
2014-07-01 01:00:25 +00:00
|
|
|
|
[alert setInformativeText:strf( @"Do you want to create a new site named:\n\n%@", siteName )];
|
2016-04-23 16:22:15 +00:00
|
|
|
|
[alert beginSheetModalForWindow:self.window completionHandler:^(NSModalResponse returnCode) {
|
|
|
|
|
switch (returnCode) {
|
|
|
|
|
case NSAlertFirstButtonReturn: {
|
|
|
|
|
// "Create" button.
|
|
|
|
|
[[MPMacAppDelegate get] addSiteNamed:[self.siteField stringValue] completion:
|
|
|
|
|
^(MPSiteEntity *site, NSManagedObjectContext *context) {
|
|
|
|
|
if (site)
|
|
|
|
|
PearlMainQueue( ^{ [self updateSites]; } );
|
|
|
|
|
}];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}];
|
2014-06-24 04:55:08 +00:00
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)copyContent:(NSString *)content {
|
|
|
|
|
|
2014-10-26 14:39:59 +00:00
|
|
|
|
[[NSPasteboard generalPasteboard] declareTypes:@[ NSStringPboardType ] owner:nil];
|
2014-06-24 04:55:08 +00:00
|
|
|
|
if (![[NSPasteboard generalPasteboard] setString:content forType:NSPasteboardTypeString]) {
|
|
|
|
|
wrn( @"Couldn't copy password to pasteboard." );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-30 03:52:57 +00:00
|
|
|
|
[MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *context) {
|
|
|
|
|
[[self.selectedSite entityInContext:context] use];
|
|
|
|
|
[context saveToStore];
|
2014-06-24 04:55:08 +00:00
|
|
|
|
}];
|
|
|
|
|
}
|
2014-02-19 05:59:01 +00:00
|
|
|
|
|
2012-03-05 08:53:32 +00:00
|
|
|
|
@end
|