mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-13 21:42:32 +00:00
Changes on entries now get pushed to the history
This commit is contained in:
@@ -167,14 +167,6 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
|
||||
|
||||
- (IBAction)duplicateEntryWithOptions:(id)sender;
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Editing
|
||||
|
||||
- (void)willChangeEntry:(KPKEntry *)entry;
|
||||
- (void)commitChangesToEntry:(KPKEntry *)entry;
|
||||
- (void)discardChangesToEntry:(KPKEntry *)entry;
|
||||
|
||||
@end
|
||||
|
||||
@interface MPDocument (Attachments)
|
||||
|
||||
@@ -39,18 +39,18 @@
|
||||
#import "NSString+MPPasswordCreation.h"
|
||||
#import "NSString+MPHash.h"
|
||||
|
||||
NSString *const MPDocumentDidAddGroupNotification = @"com.hicknhack.macpass.MPDocumentDidAddGroupNotification";
|
||||
NSString *const MPDocumentDidAddEntryNotification = @"com.hicknhack.macpass.MPDocumentDidAddEntryNotification";
|
||||
NSString *const MPDocumentDidAddGroupNotification = @"com.hicknhack.macpass.MPDocumentDidAddGroupNotification";
|
||||
NSString *const MPDocumentDidAddEntryNotification = @"com.hicknhack.macpass.MPDocumentDidAddEntryNotification";
|
||||
|
||||
NSString *const MPDocumentDidRevertNotifiation = @"com.hicknhack.macpass.MPDocumentDidRevertNotifiation";
|
||||
NSString *const MPDocumentDidRevertNotifiation = @"com.hicknhack.macpass.MPDocumentDidRevertNotifiation";
|
||||
|
||||
NSString *const MPDocumentDidLockDatabaseNotification = @"com.hicknhack.macpass.MPDocumentDidLockDatabaseNotification";
|
||||
NSString *const MPDocumentDidUnlockDatabaseNotification = @"com.hicknhack.macpass.MPDocumentDidUnlockDatabaseNotification";
|
||||
NSString *const MPDocumentDidLockDatabaseNotification = @"com.hicknhack.macpass.MPDocumentDidLockDatabaseNotification";
|
||||
NSString *const MPDocumentDidUnlockDatabaseNotification = @"com.hicknhack.macpass.MPDocumentDidUnlockDatabaseNotification";
|
||||
|
||||
NSString *const MPDocumentCurrentItemChangedNotification = @"com.hicknhack.macpass.MPDocumentCurrentItemChangedNotification";
|
||||
NSString *const MPDocumentCurrentItemChangedNotification = @"com.hicknhack.macpass.MPDocumentCurrentItemChangedNotification";
|
||||
|
||||
NSString *const MPDocumentEntryKey = @"MPDocumentEntryKey";
|
||||
NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
|
||||
NSString *const MPDocumentEntryKey = @"MPDocumentEntryKey";
|
||||
NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
|
||||
|
||||
@interface MPDocument () {
|
||||
@private
|
||||
@@ -77,8 +77,6 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
|
||||
|
||||
@property (assign) BOOL fileChangeDialogOpen;
|
||||
|
||||
@property (strong) NSMutableDictionary *modifiedEntries;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPDocument
|
||||
@@ -771,22 +769,6 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
|
||||
[self.trash clear];
|
||||
}
|
||||
|
||||
- (void)willChangeEntry:(KPKEntry *)entry {
|
||||
/* we store a copy of the entry */
|
||||
NSAssert(nil == self.modifiedEntries[entry.uuid], @"Inconsistent state, pending changes present for entry!");
|
||||
self.modifiedEntries[entry.uuid] = [entry copy];
|
||||
}
|
||||
|
||||
- (void)discardChangesToEntry:(KPKEntry *)entry {
|
||||
self.modifiedEntries[entry.uuid] = nil;
|
||||
/* TODO KeePassKit copy entry with info from old entry */
|
||||
}
|
||||
|
||||
- (void)commitChangesToEntry:(KPKEntry *)entry {
|
||||
/* TODO KeePassKit entry pushHistory:self.modifiedEntries[entry.uuid] */
|
||||
[self discardChangesToEntry:entry];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark MPTargetNodeResolving
|
||||
|
||||
|
||||
@@ -24,9 +24,6 @@
|
||||
|
||||
- (IBAction)pickIcon:(id)sender;
|
||||
- (IBAction)pickExpiryDate:(id)sender;
|
||||
- (IBAction)saveChanges:(id)sender;
|
||||
- (IBAction)discardChanges:(id)sender;
|
||||
|
||||
|
||||
/* Separate call to ensure all registered objects are in place */
|
||||
- (void)registerNotificationsForDocument:(NSDocument *)document;
|
||||
|
||||
@@ -46,6 +46,8 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
||||
@property (weak) IBOutlet NSSplitView *splitView;
|
||||
@property (unsafe_unretained) IBOutlet NSTextView *notesTextView;
|
||||
|
||||
@property BOOL didPushHistory;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPInspectorViewController
|
||||
@@ -60,6 +62,16 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
||||
self.activeTab = MPEmptyTab;
|
||||
self.entryViewController = [[MPEntryInspectorViewController alloc] init];
|
||||
self.groupViewController = [[MPGroupInspectorViewController alloc] init];
|
||||
self.didPushHistory = NO;
|
||||
/* subviewcontrollers will notify us about a change so we can handle the history pushing */
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(_willChangeValueForRepresentedObjectNotification:)
|
||||
name:MPViewControllerWillChangeValueForRepresentedObjectKeyPathNotification
|
||||
object:self.entryViewController];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(_willChangeValueForRepresentedObjectNotification:)
|
||||
name:MPViewControllerWillChangeValueForRepresentedObjectKeyPathNotification
|
||||
object:self.groupViewController];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -185,18 +197,6 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
||||
}
|
||||
|
||||
|
||||
- (void)saveChanges:(id)sender {
|
||||
MPDocument *document = self.windowController.document;
|
||||
KPKEntry *entry = self.representedObject;
|
||||
[document commitChangesToEntry:entry];
|
||||
}
|
||||
|
||||
- (void)discardChanges:(id)sender {
|
||||
MPDocument *document = self.windowController.document;
|
||||
KPKEntry *entry = self.representedObject;
|
||||
[document discardChangesToEntry:entry];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark NSPopover Delegate
|
||||
|
||||
@@ -207,31 +207,28 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Bindings
|
||||
- (void)_establishBindings {
|
||||
|
||||
// [self.itemImageView bind:NSValueBinding
|
||||
// toObject:self
|
||||
// withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(iconImage))]
|
||||
// options:nil];
|
||||
// [self.notesTextView bind:NSValueBinding
|
||||
// toObject:self
|
||||
// withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(notes))]
|
||||
// options:@{ NSNullPlaceholderBindingOption: NSLocalizedString(@"NONE", "")}];
|
||||
// [self.itemNameTextField bind:NSValueBinding
|
||||
// toObject:self
|
||||
// withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(title))]
|
||||
// options:@{NSNullPlaceholderBindingOption: NSLocalizedString(@"NONE", "")}];
|
||||
}
|
||||
|
||||
- (void)willChangeValueForRepresentedObjectKeyPath:(NSString *)keyPath {
|
||||
MPDocument *document = self.windowController.document;
|
||||
KPKEntry *entry = [self.representedObject asEntry];
|
||||
if(entry) {
|
||||
[document willChangeEntry:entry];
|
||||
}
|
||||
[self _recordChangesForCurrentNode];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark MPViewController Notifications
|
||||
- (void)_willChangeValueForRepresentedObjectNotification:(NSNotification *)notification {
|
||||
[self _recordChangesForCurrentNode];
|
||||
}
|
||||
|
||||
- (void)_recordChangesForCurrentNode {
|
||||
/* TODO use uuids for pushed item? */
|
||||
if(self.didPushHistory) {
|
||||
return;
|
||||
}
|
||||
KPKEntry *entry = [self.representedObject asEntry];
|
||||
if( entry ) {
|
||||
[entry pushHistory];
|
||||
self.didPushHistory = YES;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark MPDocument Notifications
|
||||
@@ -248,9 +245,12 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
||||
else {
|
||||
self.activeTab = MPEmptyTab;
|
||||
}
|
||||
self.didPushHistory = NO;
|
||||
|
||||
self.representedObject = node;
|
||||
self.entryViewController.representedObject = node.asEntry;
|
||||
self.groupViewController.representedObject = node.asGroup;
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
|
||||
@interface MPViewController : NSViewController
|
||||
|
||||
APPKIT_EXTERN NSString *const MPViewControllerWillChangeValueForRepresentedObjectKeyPathNotification;
|
||||
APPKIT_EXTERN NSString *const MPViewControllerDidChangeValueForRepresentedObjectKeyPathNotification;
|
||||
|
||||
@property (nonatomic, readonly) NSWindowController *windowController;
|
||||
|
||||
- (void)didLoadView;
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
//
|
||||
|
||||
#import "MPViewController.h"
|
||||
#import "MPDocument.h"
|
||||
|
||||
NSString *const MPViewControllerWillChangeValueForRepresentedObjectKeyPathNotification = @"com.hicknhack.macpass.MPViewControllerWillChangeValueForRepresentedObjectKeyPathNotification";
|
||||
NSString *const MPViewControllerDidChangeValueForRepresentedObjectKeyPathNotification = @"comt.hicknhack.macpass.MPViewControllerDidChangeValueForRepresentedObjectKeyPathNotification";
|
||||
|
||||
@implementation MPViewController
|
||||
|
||||
@@ -41,8 +43,10 @@
|
||||
#pragma mark Binding observation
|
||||
- (void)setValue:(id)value forKeyPath:(NSString *)keyPath {
|
||||
if([keyPath hasPrefix:@"representedObject."]) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPViewControllerWillChangeValueForRepresentedObjectKeyPathNotification object:self];
|
||||
[self willChangeValueForRepresentedObjectKeyPath:keyPath];
|
||||
[super setValue:value forKeyPath:keyPath];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPViewControllerDidChangeValueForRepresentedObjectKeyPathNotification object:self];
|
||||
[self didChangeValueForRepresentedObjectKeyPath:keyPath];
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user