Moving editing session to KeePassKit

Signed-off-by: michael starke <michael.starke@hicknhack-software.com>
This commit is contained in:
michael starke
2015-10-14 15:34:53 +02:00
parent 59c50a06c2
commit 7ae9f5b9a1
8 changed files with 17 additions and 90 deletions

View File

@@ -7,7 +7,7 @@
//
#import "MPDocument.h"
#import "MPEditingSession.h"
#import "KPKEditingSession.h"
#import "KPKNode.h"
@@ -33,14 +33,13 @@ NSString *const MPDocumentDidCommitChangesToSelectedItem = @"com.hicknhack.mac
[((NSWindowController *)self.windowControllers.firstObject).window makeFirstResponder:nil];
/* update the data */
[self.editingSession.source updateToNode:self.editingSession.node];
if(self.editingSession.node.asEntry) {
[self.editingSession.source commitEditing];
if(self.editingSession.source.asEntry) {
[self.undoManager setActionName:NSLocalizedString(@"UPDATE_ENTRY", "")];
}
else if(self.editingSession.node.asGroup) {
else if(self.editingSession.source.asGroup) {
[self.undoManager setActionName:NSLocalizedString(@"UPDATE_GROUP", "")];
}
self.editingSession = nil;
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidCommitChangesToSelectedItem object:self];
}
@@ -48,7 +47,7 @@ NSString *const MPDocumentDidCommitChangesToSelectedItem = @"com.hicknhack.mac
if(nil == self.editingSession) {
return; // No session to cancel
}
self.editingSession = nil;
[self.selectedItem cancelEditing];
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidCancelChangesToSelectedItem object:self];
}
@@ -56,7 +55,7 @@ NSString *const MPDocumentDidCommitChangesToSelectedItem = @"com.hicknhack.mac
if(nil == self.selectedItem) {
return;
}
self.editingSession = [MPEditingSession editingSessionWithSource:self.selectedItem];
[self.selectedItem beginEditing];
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidBeginEditingSelectedItem object:self];
}

View File

@@ -58,7 +58,7 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
@class KPKAttribute;
@class KPKCompositeKey;
@class KPKNode;
@class MPEditingSession;
@class KPKEditingSession;
@interface MPDocument : NSDocument <MPTargetNodeResolving>
@@ -88,11 +88,6 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
@property (nonatomic, copy) MPEntrySearchContext *searchContext;
@property (nonatomic, strong) NSArray *searchResult;
/*
Editing Session
*/
@property (nonatomic, strong) MPEditingSession *editingSession;
+ (KPKVersion)versionForFileType:(NSString *)fileType;
+ (NSString *)fileTypeForVersion:(KPKVersion)version;

View File

@@ -78,7 +78,6 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
@property (nonatomic, strong) NSData *encryptedData;
@property (nonatomic, strong) MPTreeDelegate *treeDelgate;
@property (assign) BOOL readOnly;
@property (strong) NSURL *lockFileURL;

View File

@@ -1,30 +0,0 @@
//
// MPEditSession.h
// MacPass
//
// Created by Michael Starke on 30/05/14.
// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class KPKNode;
@interface MPEditingSession : NSObject
@property (copy, readonly) KPKNode *node;
@property (nullable, weak, readonly) KPKNode *source;
+ (instancetype)editingSessionWithSource:(KPKNode *)node;
- (instancetype)initWithSource:(KPKNode *)node;
- (instancetype)init NS_UNAVAILABLE;
- (BOOL)hasChanges;
@end
NS_ASSUME_NONNULL_END

View File

@@ -1,38 +0,0 @@
//
// MPEditSession.m
// MacPass
//
// Created by Michael Starke on 30/05/14.
// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved.
//
#import "MPEditingSession.h"
#import "KPKNode.h"
@interface MPEditingSession ()
@property (copy) KPKNode *node;
@property (weak) KPKNode *source;
@end
@implementation MPEditingSession
+ (instancetype)editingSessionWithSource:(KPKNode *)node {
return [[MPEditingSession alloc] initWithSource:node];
}
- (instancetype)initWithSource:(KPKNode *)node {
self = [super init];
if(self) {
self.node = node;
self.source = node;
}
return self;
}
- (BOOL)hasChanges {
return ![self.node isEqual:self.source];
}
@end

View File

@@ -9,7 +9,7 @@
#import "MPInspectorViewController.h"
#import "MPDatePickingViewController.h"
#import "MPDocument.h"
#import "MPEditingSession.h"
#import "KPKEditingSession.h"
#import "MPEntryInspectorViewController.h"
#import "MPGroupInspectorViewController.h"
#import "MPIconHelper.h"