Started support for file attachments

This commit is contained in:
michael starke
2013-06-16 00:57:44 +02:00
parent 091bb384fe
commit cbbf55e0c5
7 changed files with 978 additions and 87 deletions

View File

@@ -18,6 +18,7 @@
#import "MPOutlineViewController.h"
#import "MPOutlineViewDelegate.h"
#import "KdbLib.h"
#import "Kdb4Node.h"
#import "KdbGroup+Undo.h"
#import "KdbEntry+Undo.h"
#import "HNHGradientView.h"
@@ -32,6 +33,9 @@
@property (assign, nonatomic) BOOL showsEntry;
@property (retain) NSPopover *activePopover;
@property (assign) IBOutlet NSButton *generatePasswordButton;
@property (nonatomic, assign) NSDate *modificationDate;
@property (nonatomic, assign) NSDate *creationDate;
@property (retain, nonatomic) NSArrayController *attachmentController;
@end
@@ -47,21 +51,27 @@
_selectedEntry = nil;
_selectedGroup = nil;
_showsEntry = NO;
_attachmentController = [[NSArrayController alloc] init];
}
return self;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[_attachmentController release];
[_activePopover release];
[super dealloc];
}
- (void)didLoadView {
[[self.itemImageView cell] setBackgroundStyle:NSBackgroundStyleRaised];
[self.itemImageView setTarget:self];
[_bottomBar setBorderType:HNHBorderTop];
[[_infoTextField cell] setBackgroundStyle:NSBackgroundStyleRaised];
[_attachmentTableView setDelegate:self];
[_attachmentTableView bind:NSContentBinding toObject:_attachmentController withKeyPath:@"arrangedObjects" options:nil];
[_attachmentTableView setHidden:YES];
[self _clearContent];
}
@@ -79,6 +89,28 @@
object:windowController.outlineViewController.outlineDelegate];
}
- (void)_updateInfoString {
NSDate *modificationDate;
NSDate *creationDate;
if(_showsEntry) {
modificationDate = self.selectedEntry.lastModificationTime;
creationDate = self.selectedEntry.creationTime;
}
else {
modificationDate = self.selectedGroup.lastModificationTime;
creationDate = self.selectedGroup.creationTime;
}
[self.infoTextField setStringValue:[NSString stringWithFormat:@"created: %@ modified: %@", creationDate, modificationDate]];
}
- (void)setModificationDate:(NSDate *)modificationDate {
[self _updateInfoString];
}
- (void)setCreationDate:(NSDate *)creationDate {
[self _updateInfoString];
}
- (void)_updateContent {
if(self.showsEntry && self.selectedEntry) {
[self _showEntry];
@@ -89,9 +121,14 @@
else {
[self _clearContent];
}
[self _updateAttachments];
}
- (void)_showEntry {
[self bind:@"modificationDate" toObject:self.selectedEntry withKeyPath:@"lastModificationTime" options:nil];
[self bind:@"creationDate" toObject:self.selectedEntry withKeyPath:@"creationTime" options:nil];
[self.itemNameTextfield bind:NSValueBinding toObject:self.selectedEntry withKeyPath:MPEntryTitleUndoableKey options:nil];
[self.itemImageView setImage:[MPIconHelper icon:(MPIconType)self.selectedEntry.image ]];
[self.passwordTextField bind:NSValueBinding toObject:self.selectedEntry withKeyPath:MPEntryPasswordUndoableKey options:nil];
@@ -99,11 +136,15 @@
[self.titleOrNameLabel setStringValue:NSLocalizedString(@"TITLE",@"")];
[self.titleTextField bind:NSValueBinding toObject:self.selectedEntry withKeyPath:MPEntryTitleUndoableKey options:nil];
[self.URLTextField bind:NSValueBinding toObject:self.selectedEntry withKeyPath:MPEntryUrlUndoableKey options:nil];
[self.notesTextField bind:NSValueBinding toObject:self.selectedEntry withKeyPath:MPEntryNotesUndoableKey options:nil];
[self _setInputEnabled:YES];
}
- (void)_showGroup {
[self bind:@"modificationDate" toObject:self.selectedGroup withKeyPath:@"lastModificationTime" options:nil];
[self bind:@"creationDate" toObject:self.selectedGroup withKeyPath:@"creationTime" options:nil];
[self.itemNameTextfield bind:NSValueBinding toObject:self.selectedGroup withKeyPath:MPGroupNameUndoableKey options:nil];
[self.itemImageView setImage:[MPIconHelper icon:(MPIconType)self.selectedGroup.image ]];
[self.titleOrNameLabel setStringValue:NSLocalizedString(@"NAME",@"")];
@@ -118,6 +159,7 @@
[self.passwordTextField setStringValue:@""];
[self.usernameTextField setStringValue:@""];
[self.URLTextField setStringValue:@""];
[self.notesTextField setStringValue:@""];
[self _setInputEnabled:YES];
}
@@ -131,6 +173,7 @@
[self.usernameTextField unbind:NSValueBinding];
[self.titleTextField unbind:NSValueBinding];
[self.URLTextField unbind:NSValueBinding];
[self.notesTextField unbind:NSValueBinding];
[self.itemNameTextfield setStringValue:NSLocalizedString(@"INSPECTOR_NO_SELECTION", @"No item selected in inspector")];
[self.itemImageView setImage:[NSImage imageNamed:NSImageNameActionTemplate]];
@@ -140,6 +183,7 @@
[self.usernameTextField setStringValue:@""];
[self.titleTextField setStringValue:@""];
[self.URLTextField setStringValue:@""];
[self.notesTextField setStringValue:@""];
}
@@ -156,9 +200,23 @@
[self.usernameTextField setEnabled:enabled];
[self.URLTextField setEnabled:enabled];
[self.generatePasswordButton setEnabled:enabled];
[self.notesTextField setEditable:enabled];
}
- (void)_updateAttachments {
if(self.selectedEntry && self.showsEntry) {
if([self.selectedEntry isKindOfClass:[Kdb4Entry class]]) {
[self.attachmentController bind:NSContentArrayBinding toObject:self.selectedEntry withKeyPath:@"binaries" options:nil];
}
}
else {
[self.attachmentController unbind:NSContentArrayBinding];
[self.attachmentController setContent:nil];
}
[self.attachmentTableView setHidden:(0 == [[self.attachmentController arrangedObjects] count])];
}
#pragma mark Actions
- (void)_showImagePopup:(id)sender {
@@ -212,4 +270,15 @@
[self _updateContent];
}
}
#pragma mark NSTableViewDelegate
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
NSTableCellView *tableCellView = [tableView makeViewWithIdentifier:[tableColumn identifier] owner:tableView];
BinaryRef *binaryRef = [self.attachmentController arrangedObjects][row];
[tableCellView.textField bind:NSValueBinding toObject:binaryRef withKeyPath:@"key" options:nil];
[[tableCellView.textField cell] setBackgroundStyle:NSBackgroundStyleRaised];
[[tableCellView.imageView cell] setBackgroundStyle:NSBackgroundStyleLight];
return tableCellView;
}
@end