More drafting on history browsing

This commit is contained in:
michael starke
2014-08-20 01:22:54 +02:00
parent e1d38ad6e2
commit ac3a41e4a0
7 changed files with 70 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13D65" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13E28" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment defaultVersion="1080" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
@@ -52,6 +52,17 @@
<action selector="toggleEdit:" target="-2" id="3144"/>
</connections>
</button>
<button hidden="YES" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="jBD-3D-knW">
<rect key="frame" x="20" y="2" width="59" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="roundTextured" title="History" bezelStyle="texturedRounded" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="w1z-1n-b0m">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="showHistory:" target="-1" id="Ay6-cl-onN"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstAttribute="height" constant="30" id="2949"/>
@@ -74,7 +85,7 @@
</connections>
</imageView>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="249" translatesAutoresizingMaskIntoConstraints="NO" id="3013">
<rect key="frame" x="58" y="628" width="202" height="17"/>
<rect key="frame" x="58" y="627" width="202" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" truncatesLastVisibleLine="YES" allowsUndo="NO" sendsActionOnEndEditing="YES" title="Label" usesSingleLineMode="YES" id="3014">
<font key="font" metaFont="system"/>

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5053" systemVersion="13C64" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13E28" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment defaultVersion="1080" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5053"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="MPContextBarViewController">
@@ -202,6 +202,9 @@
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="smallSystem"/>
</buttonCell>
<connections>
<action selector="exitHistory:" target="-1" id="yy9-6g-Gma"/>
</connections>
</button>
</subviews>
<constraints>

View File

@@ -14,6 +14,7 @@ NSString *const MPDocumentDidExitHistoryNotification = @"MPDocumentDidExitHisto
@implementation MPDocument (HistoryBrowsing)
- (void)showHistory:(id)sender {
NSAssert(self.selectedEntry && self.selectedItem == (id)self.selectedEntry, @"Entry needs to be selected for history browsing!");
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidEnterHistoryNotification object:self];
}

View File

@@ -594,7 +594,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)anItem {
if(self.encrypted || self.isReadOnly) { return NO; }
BOOL valid = YES;
BOOL valid = self.selectedItem ? self.selectedItem.isEditable : YES;
switch([MPActionHelper typeForAction:[anItem action]]) {
case MPActionAddGroup:
valid &= (nil != self.selectedGroup);
@@ -627,8 +627,10 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
case MPActionLock:
valid &= self.compositeKey.hasPasswordOrKeyFile;
break;
case MPActionShowHistory:
valid &= (self.selectedEntry && (self.selectedItem == (id)self.selectedEntry));
default:
valid = YES;
break;
}
return (valid && [super validateUserInterfaceItem:anItem]);
}

View File

@@ -357,6 +357,15 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
}
- (void)_bindEntry {
static NSArray *items;
if(!items) {
items = @[ self.titleTextField,
self.passwordTextField,
self.usernameTextField,
self.URLTextField,
self.expiresCheckButton,
self.tagsTokenField ];
}
if(self.entry) {
[self.titleTextField bind:NSValueBinding toObject:self.entry withKeyPath:NSStringFromSelector(@selector(title)) options:nil];
[self.passwordTextField bind:NSValueBinding toObject:self.entry withKeyPath:NSStringFromSelector(@selector(password)) options:nil];
@@ -368,13 +377,17 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
options:@{ NSValueTransformerNameBindingOption:MPExpiryDateValueTransformer }];
[self.expiresCheckButton bind:NSValueBinding toObject:self.entry.timeInfo withKeyPath:NSStringFromSelector(@selector(expires)) options:nil];
[self.tagsTokenField bind:NSValueBinding toObject:self.entry withKeyPath:NSStringFromSelector(@selector(tags)) options:nil];
/* Setup enable/disable */
for(id item in items) {
[item bind:NSEnabledBinding toObject:self.entry withKeyPath:NSStringFromSelector(@selector(isEditable)) options:nil];
}
}
else {
[self.titleTextField unbind:NSValueBinding];
[self.passwordTextField unbind:NSValueBinding];
[self.usernameTextField unbind:NSValueBinding];
[self.URLTextField unbind:NSValueBinding];
[self.expiresCheckButton unbind:NSValueBinding];
for(id item in items) {
[item unbind:NSValueBinding];
[item unbind:NSEnabledBinding];
}
[self.expiresCheckButton unbind:NSTitleBinding];
}
}

View File

@@ -13,6 +13,7 @@
#import "MPDocument.h"
#import "MPDocument+Search.h"
#import "MPDocument+Autotype.h"
#import "MPDocument+HistoryBrowsing.h"
#import "MPDocumentWindowController.h"
#import "MPPasteBoardController.h"
@@ -235,6 +236,9 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
selector:@selector(_didUnlockDatabase:)
name:MPDocumentDidUnlockDatabaseNotification
object:document];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didEnterHistory:) name:MPDocumentDidEnterHistoryNotification object:document];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didExitHistory:) name:MPDocumentDidExitHistoryNotification object:document];
[self.contextBarViewController registerNotificationsForDocument:document];
}
@@ -413,6 +417,20 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
}
}
- (void)_didEnterHistory:(NSNotification *)notification {
[self _showContextBar];
/* TODO: Show modification date column if not present? */
MPDocument *document = [[self windowController] document];
[self.entryArrayController bind:NSContentArrayBinding toObject:document.selectedEntry withKeyPath:NSStringFromSelector(@selector(history)) options:nil];
}
- (void)_didExitHistory:(NSNotification *)notification {
[self _hideContextBar];
MPDocument *document = [[self windowController] document];
document.selectedItem = document.selectedEntry;
}
#pragma mark ContextBar
- (void)_updateContextBar {
MPDocument *document = [[self windowController] document];

View File

@@ -267,14 +267,24 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
- (void)_updateBindings:(id)item {
if(!item) {
[self.itemNameTextField unbind:NSValueBinding];
[self.itemNameTextField unbind:NSEnabledBinding];
[self.itemNameTextField setHidden:YES];
[self.itemImageView unbind:NSValueBinding];
[self.itemImageView unbind:NSEnabledBinding];
[self.itemImageView setHidden:YES];
[[self.notesTextView enclosingScrollView] setHidden:YES];
[self.notesTextView unbind:NSValueBinding];
[self.notesTextView unbind:NSEditableBinding];
[self.notesTextView setString:@""];
return;
}
/* Disable if item is not editable */
NSLog(@"%@ isEditable: %i", item, [item isEditable]);
[self.itemNameTextField bind:NSEnabledBinding toObject:item withKeyPath:NSStringFromSelector(@selector(isEditable)) options:nil];
[self.itemImageView bind:NSEnabledBinding toObject:item withKeyPath:NSStringFromSelector(@selector(isEditable)) options:nil];
[self.notesTextView bind:NSEditableBinding toObject:item withKeyPath:NSStringFromSelector(@selector(isEditable)) options:nil];
[self.itemImageView bind:NSValueBinding toObject:item withKeyPath:NSStringFromSelector(@selector(iconImage)) options:nil];
[[self.notesTextView enclosingScrollView] setHidden:NO];
[self.notesTextView bind:NSValueBinding toObject:item withKeyPath:NSStringFromSelector(@selector(notes)) options:nil];