restore history entries added

This commit is contained in:
michael starke
2017-06-07 18:19:19 +02:00
parent 379d430035
commit 68ed110c4c
11 changed files with 65 additions and 43 deletions

View File

@@ -1,3 +1,3 @@
github "sparkle-project/Sparkle" ~> 1.17.0 github "sparkle-project/Sparkle" ~> 1.17.0
github "mstarke/KeePassKit" "ab95d3a85b2bcb86d9e3e5e74d2168c209756b8b" github "mstarke/KeePassKit" "b25eab0892f6101ee4929bef3f57788dbc5fa607"
github "mstarke/HNHUi" ~> 1.1 github "mstarke/HNHUi" ~> 1.1

View File

@@ -1,3 +1,3 @@
github "mstarke/HNHUi" "1.1" github "mstarke/HNHUi" "1.1"
github "mstarke/KeePassKit" "ab95d3a85b2bcb86d9e3e5e74d2168c209756b8b" github "mstarke/KeePassKit" "b25eab0892f6101ee4929bef3f57788dbc5fa607"
github "sparkle-project/Sparkle" "1.17.0" github "sparkle-project/Sparkle" "1.17.0"

View File

@@ -1,14 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies> <dependencies>
<deployment identifier="macosx"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12121"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12120"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
<objects> <objects>
<customObject id="-2" userLabel="File's Owner" customClass="MPEntryInspectorViewController"> <customObject id="-2" userLabel="File's Owner" customClass="MPEntryInspectorViewController">
<connections> <connections>
<outlet property="URLTextField" destination="56" id="262"/> <outlet property="URLTextField" destination="56" id="262"/>
<outlet property="addAttachmentButton" destination="177" id="w3F-U0-Rpk"/>
<outlet property="addCustomFieldButton" destination="179" id="I3F-Sp-dbI"/>
<outlet property="addWindowAssociationButton" destination="Iy9-9L-Aev" id="kDA-Mm-lah"/>
<outlet property="associationSequenceTextField" destination="NjR-ea-Y7k" id="kTb-Y5-XrZ"/> <outlet property="associationSequenceTextField" destination="NjR-ea-Y7k" id="kTb-Y5-XrZ"/>
<outlet property="attachmentTableView" destination="137" id="265"/> <outlet property="attachmentTableView" destination="137" id="265"/>
<outlet property="autotypView" destination="zv7-wE-Bmg" id="m1g-dk-hFv"/> <outlet property="autotypView" destination="zv7-wE-Bmg" id="m1g-dk-hFv"/>
@@ -21,6 +23,7 @@
<outlet property="infoTabControl" destination="82" id="264"/> <outlet property="infoTabControl" destination="82" id="264"/>
<outlet property="obfuscateAutotypeCheckButton" destination="I7L-Am-Qpa" id="hwa-zl-24W"/> <outlet property="obfuscateAutotypeCheckButton" destination="I7L-Am-Qpa" id="hwa-zl-24W"/>
<outlet property="passwordTextField" destination="60" id="263"/> <outlet property="passwordTextField" destination="60" id="263"/>
<outlet property="pickExpireDateButton" destination="8" id="cJg-5V-AL6"/>
<outlet property="showCustomAssociationSequenceAutotypeBuilderButton" destination="m1C-m8-BKR" id="B3I-AG-TCJ"/> <outlet property="showCustomAssociationSequenceAutotypeBuilderButton" destination="m1C-m8-BKR" id="B3I-AG-TCJ"/>
<outlet property="showCustomEntrySequenceAutotypeBuilderButton" destination="HDS-Bz-jrr" id="7u1-17-oMK"/> <outlet property="showCustomEntrySequenceAutotypeBuilderButton" destination="HDS-Bz-jrr" id="7u1-17-oMK"/>
<outlet property="tabView" destination="83" id="269"/> <outlet property="tabView" destination="83" id="269"/>
@@ -94,7 +97,7 @@
<rect key="frame" x="20" y="26" width="253" height="396"/> <rect key="frame" x="20" y="26" width="253" height="396"/>
<clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="F3N-QI-Di5"> <clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="F3N-QI-Di5">
<rect key="frame" x="1" y="1" width="251" height="394"/> <rect key="frame" x="1" y="1" width="251" height="394"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnSelection="YES" multipleSelection="NO" autosaveColumns="NO" rowHeight="36" rowSizeStyle="automatic" viewBased="YES" id="137"> <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnSelection="YES" multipleSelection="NO" autosaveColumns="NO" rowHeight="36" rowSizeStyle="automatic" viewBased="YES" id="137">
<rect key="frame" x="0.0" y="0.0" width="251" height="394"/> <rect key="frame" x="0.0" y="0.0" width="251" height="394"/>
@@ -271,7 +274,7 @@
<rect key="frame" x="16" y="50" width="261" height="372"/> <rect key="frame" x="16" y="50" width="261" height="372"/>
<clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="k8G-zp-BXZ"> <clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="k8G-zp-BXZ">
<rect key="frame" x="1" y="1" width="259" height="370"/> <rect key="frame" x="1" y="1" width="259" height="370"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" selectionHighlightStyle="none" columnSelection="YES" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" rowHeight="54" rowSizeStyle="automatic" viewBased="YES" id="193"> <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" selectionHighlightStyle="none" columnSelection="YES" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" rowHeight="54" rowSizeStyle="automatic" viewBased="YES" id="193">
<rect key="frame" x="0.0" y="0.0" width="259" height="370"/> <rect key="frame" x="0.0" y="0.0" width="259" height="370"/>

View File

@@ -31,7 +31,8 @@ typedef NS_ENUM(NSUInteger, MPActionType) {
MPActionToggleQuicklook, MPActionToggleQuicklook,
MPActionShowEntryHistory, // show history MPActionShowEntryHistory, // show history
MPActionHideEntryHistory, // exit history MPActionHideEntryHistory, // exit history
MPActionPerformAutotypeForSelectedEntry // Perform Autotype for selected Entry MPActionPerformAutotypeForSelectedEntry, // Perform Autotype for selected Entry
MPActionRemoveAttachment // Remove an attachment
}; };
/** /**
* Helper to retrieve commonly used actions * Helper to retrieve commonly used actions

View File

@@ -40,7 +40,8 @@
@(MPActionToggleQuicklook): NSStringFromSelector(@selector(toggleQuicklookPreview:)), @(MPActionToggleQuicklook): NSStringFromSelector(@selector(toggleQuicklookPreview:)),
@(MPActionShowEntryHistory): NSStringFromSelector(@selector(showEntryHistory:)), @(MPActionShowEntryHistory): NSStringFromSelector(@selector(showEntryHistory:)),
@(MPActionHideEntryHistory): NSStringFromSelector(@selector(hideEntryHistory:)), @(MPActionHideEntryHistory): NSStringFromSelector(@selector(hideEntryHistory:)),
@(MPActionPerformAutotypeForSelectedEntry): NSStringFromSelector(@selector(performAutotypeForEntry:)) @(MPActionPerformAutotypeForSelectedEntry): NSStringFromSelector(@selector(performAutotypeForEntry:)),
@(MPActionRemoveAttachment): NSStringFromSelector(@selector(removeAttachment:))
}; };
}); });
return actionDict; return actionDict;

View File

@@ -39,6 +39,14 @@
toObject:view toObject:view
withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(objectValue)), NSStringFromSelector(@selector(value))] withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(objectValue)), NSStringFromSelector(@selector(value))]
options:nil]; options:nil];
// TODO: Move to public KeePassKit API!
for(NSControl *control in @[view.labelTextField, view.valueTextField, view.removeButton ]) {
[control bind:NSEnabledBinding
toObject:view
withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(objectValue)), NSStringFromSelector(@selector(entry)), NSStringFromSelector(@selector(isHistory))]
options:@{NSConditionallySetsEditableBindingOption: @NO, NSValueTransformerNameBindingOption: NSNegateBooleanTransformerName}];
}
view.removeButton.target = self.viewController; view.removeButton.target = self.viewController;
view.removeButton.action = @selector(removeCustomField:); view.removeButton.action = @selector(removeCustomField:);
view.removeButton.tag = row; view.removeButton.tag = row;

View File

@@ -22,17 +22,22 @@ NSString *const MPDocumentHideEntryHistoryNotification = @"MPDocumentHideEntryH
if(self.hasSearch) { if(self.hasSearch) {
[self exitSearch:sender]; [self exitSearch:sender];
} }
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentShowEntryHistoryNotification self.historyEntry = entries.firstObject;
object:self if(self.historyEntry) {
userInfo:@{ MPDocumentEntryKey: entries.firstObject }]; [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentShowEntryHistoryNotification
object:self
userInfo:@{ MPDocumentEntryKey: self.historyEntry }];
}
} }
- (void)hideEntryHistory:(id)sender { - (void)hideEntryHistory:(id)sender {
self.historyEntry = nil;
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentHideEntryHistoryNotification [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentHideEntryHistoryNotification
object:self]; object:self];
} }
- (void)revertEntry:(KPKEntry *)entry toEntry:(KPKEntry *)historyEntry { - (void)revertEntry:(KPKEntry *)entry toEntry:(KPKEntry *)historyEntry {
[entry pushHistory];
[entry revertToEntry:historyEntry]; [entry revertToEntry:historyEntry];
[self.undoManager setActionName:NSLocalizedString(@"RESTORE_HISTORY_ENTRY", "Action to restore and Entry to a previous state of it's history")]; [self.undoManager setActionName:NSLocalizedString(@"RESTORE_HISTORY_ENTRY", "Action to restore and Entry to a previous state of it's history")];
} }

View File

@@ -95,6 +95,7 @@ FOUNDATION_EXPORT NSString *const MPDocumentGroupKey;
@property (nonatomic, readonly) BOOL hasSearch; @property (nonatomic, readonly) BOOL hasSearch;
@property (nonatomic, copy) MPEntrySearchContext *searchContext; @property (nonatomic, copy) MPEntrySearchContext *searchContext;
@property (nonatomic, strong, readonly) NSArray *searchResult; @property (nonatomic, strong, readonly) NSArray *searchResult;
@property (nonatomic, weak) KPKEntry *historyEntry;
+ (KPKDatabaseFormat)formatForFileType:(NSString *)fileType; + (KPKDatabaseFormat)formatForFileType:(NSString *)fileType;
+ (NSString *)fileTypeForVersion:(KPKDatabaseFormat)format; + (NSString *)fileTypeForVersion:(KPKDatabaseFormat)format;

View File

@@ -27,14 +27,18 @@
@property (weak) IBOutlet HNHUIRoundedSecureTextField *passwordTextField; @property (weak) IBOutlet HNHUIRoundedSecureTextField *passwordTextField;
@property (weak) IBOutlet NSButton *generatePasswordButton; @property (weak) IBOutlet NSButton *generatePasswordButton;
@property (weak) IBOutlet NSButton *togglePassword; @property (weak) IBOutlet NSButton *togglePassword;
@property (weak) IBOutlet NSButton *pickExpireDateButton;
@property (weak) IBOutlet NSButton *expiresCheckButton; @property (weak) IBOutlet NSButton *expiresCheckButton;
@property (weak) IBOutlet NSTokenField *tagsTokenField; @property (weak) IBOutlet NSTokenField *tagsTokenField;
@property (weak) IBOutlet NSTextField *uuidTextField; @property (weak) IBOutlet NSTextField *uuidTextField;
@property (weak) IBOutlet NSTextField *createdTextField; @property (weak) IBOutlet NSTextField *createdTextField;
@property (weak) IBOutlet NSTextField *modifiedTextField; @property (weak) IBOutlet NSTextField *modifiedTextField;
@property (weak) IBOutlet NSButton *addCustomFieldButton;
/* Attachments */ /* Attachments */
@property (weak) IBOutlet NSButtonCell *addAttachmentButton;
@property (weak) IBOutlet NSTableView *attachmentTableView; @property (weak) IBOutlet NSTableView *attachmentTableView;
@property (weak) IBOutlet NSTableView *customFieldsTableView; @property (weak) IBOutlet NSTableView *customFieldsTableView;
@@ -50,6 +54,7 @@
@property (weak) IBOutlet NSButton *showCustomAssociationSequenceAutotypeBuilderButton; @property (weak) IBOutlet NSButton *showCustomAssociationSequenceAutotypeBuilderButton;
@property (weak) IBOutlet NSTextField *associationSequenceTextField; @property (weak) IBOutlet NSTextField *associationSequenceTextField;
@property (weak) IBOutlet NSButton *addWindowAssociationButton;
- (void)registerNotificationsForDocument:(MPDocument *)document; - (void)registerNotificationsForDocument:(MPDocument *)document;

View File

@@ -240,6 +240,8 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
case MPActionToggleQuicklook: { case MPActionToggleQuicklook: {
BOOL enabled = [[NSUserDefaults standardUserDefaults] boolForKey:kMPSettingsKeyEnableQuicklookPreview]; BOOL enabled = [[NSUserDefaults standardUserDefaults] boolForKey:kMPSettingsKeyEnableQuicklookPreview];
return enabled ? [self acceptsPreviewPanelControl:nil] : NO; return enabled ? [self acceptsPreviewPanelControl:nil] : NO;
case MPActionRemoveAttachment:
return !self.representedEntry.isHistory;
} }
default: default:
return YES; return YES;
@@ -360,13 +362,7 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
#pragma mark - #pragma mark -
#pragma mark Entry Selection #pragma mark Entry Selection
- (void)_setupViewBindings { - (void)_setupViewBindings {
[self _bindEntry]; /* general */
[self _bindAttachments];
[self _bindCustomFields];
[self _bindAutotype];
}
- (void)_bindEntry {
[self.titleTextField bind:NSValueBinding [self.titleTextField bind:NSValueBinding
toObject:self toObject:self
withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(title))] withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(title))]
@@ -396,21 +392,6 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(tags))] withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(tags))]
options:nil]; options:nil];
NSArray *inputs = @[self.titleTextField,
self.passwordTextField,
self.usernameTextField,
self.URLTextField,
self.expiresCheckButton,
self.tagsTokenField,
self.generatePasswordButton];
for(NSControl *control in inputs) {
NSString *keyPath = [NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(isHistory))];
[control bind:NSEnabledBinding
toObject:self
withKeyPath:keyPath
options:@{NSConditionallySetsEditableBindingOption: @NO, NSValueTransformerNameBindingOption: NSNegateBooleanTransformerName}];
}
[self.uuidTextField bind:NSValueBinding [self.uuidTextField bind:NSValueBinding
toObject:self toObject:self
@@ -418,23 +399,19 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
options:@{ NSConditionallySetsEditableBindingOption: @NO }]; options:@{ NSConditionallySetsEditableBindingOption: @NO }];
self.uuidTextField.editable = NO; self.uuidTextField.editable = NO;
} /* Attachments */
- (void)_bindAttachments {
[_attachmentsController bind:NSContentArrayBinding [_attachmentsController bind:NSContentArrayBinding
toObject:self toObject:self
withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(binaries))] withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(binaries))]
options:nil]; options:nil];
}
- (void)_bindCustomFields { /* CustomField */
[_customFieldsController bind:NSContentArrayBinding [_customFieldsController bind:NSContentArrayBinding
toObject:self toObject:self
withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(customAttributes))] withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(customAttributes))]
options:nil]; options:nil];
}
- (void)_bindAutotype {
/* Autotype */
[self.enableAutotypeCheckButton bind:NSValueBinding [self.enableAutotypeCheckButton bind:NSValueBinding
toObject:self toObject:self
withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(autotype)), NSStringFromSelector(@selector(enabled))] options:nil]; withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(autotype)), NSStringFromSelector(@selector(enabled))] options:nil];
@@ -464,6 +441,27 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
toObject:_windowAssociationsController toObject:_windowAssociationsController
withKeyPath:[NSString stringWithFormat:@"selection.%@", NSStringFromSelector(@selector(keystrokeSequence))] withKeyPath:[NSString stringWithFormat:@"selection.%@", NSStringFromSelector(@selector(keystrokeSequence))]
options:nil]; options:nil];
NSArray *inputs = @[self.titleTextField,
self.passwordTextField,
self.usernameTextField,
self.URLTextField,
self.expiresCheckButton,
self.tagsTokenField,
self.generatePasswordButton,
self.addAttachmentButton,
self.addCustomFieldButton,
self.addWindowAssociationButton];
for(NSControl *control in inputs) {
NSString *keyPath = [NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(isHistory))];
[control bind:NSEnabledBinding
toObject:self
withKeyPath:keyPath
options:@{NSConditionallySetsEditableBindingOption: @NO, NSValueTransformerNameBindingOption: NSNegateBooleanTransformerName}];
}
} }

View File

@@ -735,7 +735,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
if(historyEntries.count != 1) { if(historyEntries.count != 1) {
return; return;
} }
//[document restoreEntry:entry toEntry:historyEntries.firstObject]; [document revertEntry:document.historyEntry toEntry:historyEntries.firstObject];
} }
- (void)_columnDoubleClick:(id)sender { - (void)_columnDoubleClick:(id)sender {