mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-22 18:49:27 +00:00
Mingling with Editing. Updated KeePassKit
This commit is contained in:
@@ -181,6 +181,7 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
|
||||
}
|
||||
if(!self.passwordCreatorController) {
|
||||
self.passwordCreatorController = [[MPPasswordCreatorViewController alloc] init];
|
||||
self.passwordCreatorController.closeTarget = self.passwordCreatorWindow;
|
||||
NSView *creatorView = [_passwordCreatorController view];
|
||||
[self.passwordCreatorWindow setContentView:creatorView];
|
||||
}
|
||||
|
||||
19
MacPass/MPDocument+EditingSession.h
Normal file
19
MacPass/MPDocument+EditingSession.h
Normal file
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// MPDocument+EditingSession.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 30/05/14.
|
||||
// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPDocument.h"
|
||||
|
||||
@class MPEditSession;
|
||||
|
||||
@interface MPDocument (EditingSession)
|
||||
|
||||
- (BOOL)hasActiveSession;
|
||||
- (void)cancelEditingSession;
|
||||
- (void)commitEditingSession;
|
||||
|
||||
@end
|
||||
48
MacPass/MPDocument+EditingSession.m
Normal file
48
MacPass/MPDocument+EditingSession.m
Normal file
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// MPDocument+EditingSession.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 30/05/14.
|
||||
// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPDocument+EditingSession.h"
|
||||
|
||||
#import "KPKNode.h"
|
||||
#import "MPEditSession.h"
|
||||
|
||||
@implementation MPDocument (EditingSession)
|
||||
|
||||
- (BOOL)hasActiveSession {
|
||||
return (self.editingSession != nil);
|
||||
}
|
||||
|
||||
- (void)commitEditingSession {
|
||||
[self _commitEditingSession:self.editingSession];
|
||||
}
|
||||
|
||||
- (void)cancelEditingSession {
|
||||
[self _cancelEditingSession:self.editingSession];
|
||||
}
|
||||
|
||||
#pragma mark Private
|
||||
- (void)_commitEditingSession:(MPEditSession *)session {
|
||||
if(nil == session) {
|
||||
return; // No session to commit
|
||||
}
|
||||
[[self.undoManager prepareWithInvocationTarget:self] _cancelEditingSession:session];
|
||||
if(session.hasChanges) {
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_cancelEditingSession:(MPEditSession *)session {
|
||||
if(nil == session) {
|
||||
return; // No session to cancel
|
||||
}
|
||||
[[self.undoManager prepareWithInvocationTarget:self] _commitEditingSession:session];
|
||||
if(session.hasChanges) {
|
||||
[session.node updateTo:session.rollbackNode];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -41,6 +41,7 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
|
||||
@class KPKAttribute;
|
||||
@class KPKCompositeKey;
|
||||
@class KPKNode;
|
||||
@class MPEditSession;
|
||||
|
||||
typedef NS_OPTIONS(NSUInteger, MPEntrySearchFlags) {
|
||||
MPEntrySearchNone = 0,
|
||||
@@ -90,6 +91,10 @@ typedef NS_OPTIONS(NSUInteger, MPEntrySearchFlags) {
|
||||
@property (nonatomic, assign) BOOL hasSearch;
|
||||
@property (nonatomic, strong) NSArray *searchResult;
|
||||
|
||||
/*
|
||||
Editing Session
|
||||
*/
|
||||
@property (nonatomic, strong) MPEditSession *editingSession;
|
||||
|
||||
+ (KPKVersion)versionForFileType:(NSString *)fileType;
|
||||
+ (NSString *)fileTypeForVersion:(KPKVersion)version;
|
||||
@@ -177,4 +182,4 @@ typedef NS_OPTIONS(NSUInteger, MPEntrySearchFlags) {
|
||||
|
||||
- (IBAction)cloneEntryWithOptions:(id)sender;
|
||||
|
||||
@end
|
||||
@end
|
||||
|
||||
22
MacPass/MPEditSession.h
Normal file
22
MacPass/MPEditSession.h
Normal file
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// MPEditSession.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 30/05/14.
|
||||
// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class KPKNode;
|
||||
|
||||
@interface MPEditSession : NSObject
|
||||
|
||||
@property (strong, readonly) KPKNode *node;
|
||||
@property (copy, readonly) KPKNode *rollbackNode;
|
||||
|
||||
- (instancetype)initWithNode:(KPKNode *)node;
|
||||
|
||||
- (BOOL)hasChanges;
|
||||
|
||||
@end
|
||||
39
MacPass/MPEditSession.m
Normal file
39
MacPass/MPEditSession.m
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// MPEditSession.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 30/05/14.
|
||||
// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPEditSession.h"
|
||||
#import "KPKNode.h"
|
||||
|
||||
@interface MPEditSession ()
|
||||
|
||||
@property (strong) KPKNode *node;
|
||||
@property (copy) KPKNode *rollbackNode;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPEditSession
|
||||
|
||||
- (instancetype)init {
|
||||
self = [self initWithNode:nil];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithNode:(KPKNode *)node {
|
||||
self = [super init];
|
||||
if(self) {
|
||||
self.node = node;
|
||||
self.rollbackNode = node;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)hasChanges {
|
||||
return [self.node isEqual:self.rollbackNode];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -265,7 +265,11 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
|
||||
_activePopover = [[NSPopover alloc] init];
|
||||
_activePopover.delegate = self;
|
||||
_activePopover.behavior = NSPopoverBehaviorTransient;
|
||||
if([viewController respondsToSelector:@selector(setCloseTarget:)]) {
|
||||
[(id)viewController setCloseTarget:_activePopover];
|
||||
}
|
||||
_activePopover.contentViewController = viewController;
|
||||
|
||||
[_activePopover showRelativeToRect:NSZeroRect ofView:view preferredEdge:edge];
|
||||
}
|
||||
|
||||
|
||||
@@ -35,11 +35,10 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
||||
MPEmptyTab,
|
||||
};
|
||||
|
||||
@interface MPInspectorViewController () {
|
||||
MPEntryInspectorViewController *_entryViewController;
|
||||
MPGroupInspectorViewController *_groupViewController;
|
||||
BOOL _isEditing;
|
||||
}
|
||||
@interface MPInspectorViewController ()
|
||||
|
||||
@property (strong) MPEntryInspectorViewController *entryViewController;
|
||||
@property (strong) MPGroupInspectorViewController *groupViewController;
|
||||
|
||||
@property (strong) MPIconSelectViewController *iconSelectionViewController;
|
||||
@property (strong) NSPopover *popover;
|
||||
@@ -64,10 +63,9 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
||||
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
|
||||
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
||||
if (self) {
|
||||
_activeTab = MPEmptyTab;
|
||||
_entryViewController = [[MPEntryInspectorViewController alloc] init];
|
||||
_groupViewController = [[MPGroupInspectorViewController alloc] init];
|
||||
_isEditing = NO;
|
||||
self.activeTab = MPEmptyTab;
|
||||
self.entryViewController = [[MPEntryInspectorViewController alloc] init];
|
||||
self.groupViewController = [[MPGroupInspectorViewController alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -87,8 +85,8 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
||||
[[self.itemImageView cell] setBackgroundStyle:NSBackgroundStyleRaised];
|
||||
[self.tabView bind:NSSelectedIndexBinding toObject:self withKeyPath:@"activeTab" options:nil];
|
||||
|
||||
NSView *entryView = [_entryViewController view];
|
||||
NSView *groupView = [_groupViewController view];
|
||||
NSView *entryView = [self.entryViewController view];
|
||||
NSView *groupView = [self.groupViewController view];
|
||||
|
||||
|
||||
NSTabViewItem *entryTabItem = [self.tabView tabViewItemAtIndex:MPEntryTab];
|
||||
@@ -115,14 +113,14 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
||||
selector:@selector(_didChangeCurrentItem:)
|
||||
name:MPDocumentCurrentItemChangedNotification
|
||||
object:document];
|
||||
[_entryViewController setupBindings:document];
|
||||
[_groupViewController setupBindings:document];
|
||||
[self.entryViewController setupBindings:document];
|
||||
[self.groupViewController setupBindings:document];
|
||||
}
|
||||
|
||||
- (void)updateResponderChain {
|
||||
[super updateResponderChain];
|
||||
[_groupViewController updateResponderChain];
|
||||
[_entryViewController updateResponderChain];
|
||||
[self.groupViewController updateResponderChain];
|
||||
[self.entryViewController updateResponderChain];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
@@ -167,31 +165,31 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
||||
- (void)toggleEdit:(id)sender {
|
||||
BOOL didCancel = sender == self.cancelEditButton;
|
||||
MPDocument *document = [[self windowController] document];
|
||||
NSUndoManager *undoManager = [document undoManager];
|
||||
|
||||
if(_isEditing) {
|
||||
BOOL didChangeItem = [undoManager canUndo];
|
||||
[undoManager endUndoGrouping];
|
||||
[undoManager setActionName:NSLocalizedString(@"EDIT_GROUP_OR_ENTRY", "")];
|
||||
if(document.selectedItem) {
|
||||
|
||||
/* TODO UndoManager handling */
|
||||
[self.editButton setTitle:NSLocalizedString(@"EDIT_ITEM", "")];
|
||||
[self.cancelEditButton setHidden:YES];
|
||||
[_entryViewController endEditing];
|
||||
[self.entryViewController endEditing];
|
||||
|
||||
/*
|
||||
We need to be carefull to only undo the things we actually changed
|
||||
otherwise we undo older actions
|
||||
*/
|
||||
if(didCancel && didChangeItem) {
|
||||
[undoManager undo];
|
||||
if(didCancel) {
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
[undoManager beginUndoGrouping];
|
||||
//[document.selectedItem beginEditSession];
|
||||
[self.editButton setTitle:NSLocalizedString(@"SAVE_CHANGES", "")];
|
||||
[self.cancelEditButton setHidden:NO];
|
||||
[_entryViewController beginEditing];
|
||||
[self.entryViewController beginEditing];
|
||||
}
|
||||
_isEditing = !_isEditing;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
@@ -309,6 +307,6 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
||||
[self _updateBindings:document.selectedItem];
|
||||
|
||||
/* disable the entry text fields whenever the entry selection changes */
|
||||
//[_entryViewController endEditing];
|
||||
//[self.entryViewController endEditing];
|
||||
}
|
||||
@end
|
||||
@@ -11,6 +11,7 @@
|
||||
@interface MPPasswordCreatorViewController : MPViewController <NSTextFieldDelegate>
|
||||
|
||||
@property (copy, readonly) NSString *generatedPassword;
|
||||
@property (weak) id closeTarget;
|
||||
|
||||
/**
|
||||
* Should be called to reset the generator
|
||||
|
||||
@@ -57,11 +57,6 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) {
|
||||
@property (nonatomic, assign) NSUInteger passwordLength;
|
||||
@property (nonatomic, assign) CGFloat entropy;
|
||||
|
||||
- (IBAction)_generatePassword:(id)sender;
|
||||
- (IBAction)_toggleCharacters:(id)sender;
|
||||
- (IBAction)_usePassword:(id)sender;
|
||||
- (IBAction)_cancel:(id)sender;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPPasswordCreatorViewController
|
||||
@@ -140,15 +135,11 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) {
|
||||
if([self.shouldCopyPasswordToPasteboardButton state] == NSOnState) {
|
||||
[[MPPasteBoardController defaultController] copyObjects:@[_password]];
|
||||
}
|
||||
/* Since we might be displayed inside a NSPopup or a NSWindow, search for the target */
|
||||
id target = [NSApp targetForAction:@selector(performClose:)];
|
||||
[target performClose:nil];
|
||||
[[self _findCloseTarget] performClose:nil];
|
||||
}
|
||||
|
||||
- (IBAction)_cancel:(id)sender {
|
||||
/* Since we might be displayed inside a NSPopup or a NSWindow, search for the target */
|
||||
id target = [NSApp targetForAction:@selector(performClose:)];
|
||||
[target performClose:nil];
|
||||
[[self _findCloseTarget] performClose:nil];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
@@ -213,4 +204,11 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) {
|
||||
[_numbersButton setState:useNumbers ? NSOnState : NSOffState];
|
||||
[_symbolsButton setState:useSymbols ? NSOnState : NSOffState];
|
||||
}
|
||||
|
||||
- (id)_findCloseTarget {
|
||||
if([self.closeTarget respondsToSelector:@selector(performClose:)]) {
|
||||
return self.closeTarget;
|
||||
}
|
||||
return [NSApp targetForAction:@selector(performClose:)];
|
||||
}
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user