Revamped selection handling to ensure Groupt/Entry display on view switchting

This commit is contained in:
michael starke
2013-06-20 20:56:14 +02:00
parent a1633ad6ba
commit dd14bae24f
21 changed files with 2622 additions and 1441 deletions

View File

@@ -23,6 +23,11 @@
#import "KdbEntry+Undo.h"
#import "HNHGradientView.h"
enum {
MPNotesTab,
MPAttachmentTab
};
@interface MPInspectorViewController () {
BOOL _visible;
}
@@ -30,7 +35,6 @@
@property (assign, nonatomic) KdbEntry *selectedEntry;
@property (assign, nonatomic) KdbGroup *selectedGroup;
@property (assign, nonatomic) BOOL showsEntry;
@property (retain) NSPopover *activePopover;
@property (assign) IBOutlet NSButton *generatePasswordButton;
@property (nonatomic, assign) NSDate *modificationDate;
@@ -50,7 +54,6 @@
if (self) {
_selectedEntry = nil;
_selectedGroup = nil;
_showsEntry = NO;
_attachmentController = [[NSArrayController alloc] init];
}
return self;
@@ -72,6 +75,11 @@
[_attachmentTableView setDelegate:self];
[_attachmentTableView bind:NSContentBinding toObject:_attachmentController withKeyPath:@"arrangedObjects" options:nil];
[_attachmentTableView setHidden:YES];
[_notesOrAttachmentControl setAction:@selector(_toggleInfoTab:)];
[_notesOrAttachmentControl setTarget:self];
[[_notesOrAttachmentControl cell] setTag:MPAttachmentTab forSegment:MPAttachmentTab];
[[_notesOrAttachmentControl cell] setTag:MPNotesTab forSegment:MPNotesTab];
[self _clearContent];
}
@@ -79,21 +87,15 @@
- (void)setupNotifications:(MPDocumentWindowController *)windowController {
/* Register for Entry selection */
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_didChangeSelectedEntry:)
name:MPDidChangeSelectedEntryNotification
object:windowController.entryViewController];
/* Register for Group selection */
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_didChangeSelectedGroup:)
name:MPOutlineViewDidChangeGroupSelection
object:windowController.outlineViewController.outlineDelegate];
selector:@selector(_didChangeCurrentItem:)
name:MPCurrentItemChangedNotification
object:windowController];
}
- (void)_updateInfoString {
NSDate *modificationDate;
NSDate *creationDate;
if(_showsEntry) {
if(self.selectedEntry) {
modificationDate = self.selectedEntry.lastModificationTime;
creationDate = self.selectedEntry.creationTime;
}
@@ -113,10 +115,10 @@
}
- (void)_updateContent {
if(self.showsEntry && self.selectedEntry) {
if(self.selectedEntry) {
[self _showEntry];
}
else if(!self.showsEntry && self.selectedGroup) {
else if(self.selectedGroup) {
[self _showGroup];
}
else {
@@ -137,7 +139,7 @@
[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.notesTextView bind:NSValueBinding toObject:self.selectedEntry withKeyPath:MPEntryNotesUndoableKey options:nil];
[self _setInputEnabled:YES];
}
@@ -160,7 +162,11 @@
[self.passwordTextField setStringValue:@""];
[self.usernameTextField setStringValue:@""];
[self.URLTextField setStringValue:@""];
[self.notesTextField setStringValue:@""];
[self.notesTextView setString:@""];
// Reste toggle
[self.notesOrAttachmentControl setSelected:NO forSegment:MPNotesTab];
[self.notesOrAttachmentControl setSelected:NO forSegment:MPAttachmentTab];
[self _setInputEnabled:YES];
}
@@ -174,7 +180,7 @@
[self.usernameTextField unbind:NSValueBinding];
[self.titleTextField unbind:NSValueBinding];
[self.URLTextField unbind:NSValueBinding];
[self.notesTextField unbind:NSValueBinding];
[self.notesTextView unbind:NSValueBinding];
[self.itemNameTextfield setStringValue:NSLocalizedString(@"INSPECTOR_NO_SELECTION", @"No item selected in inspector")];
[self.itemImageView setImage:[NSImage imageNamed:NSImageNameActionTemplate]];
@@ -184,7 +190,7 @@
[self.usernameTextField setStringValue:@""];
[self.titleTextField setStringValue:@""];
[self.URLTextField setStringValue:@""];
[self.notesTextField setStringValue:@""];
[self.notesTextView setString:@""];
}
@@ -196,17 +202,18 @@
[self.itemNameTextfield setEnabled:enabled];
[self.titleTextField setEnabled:enabled];
enabled &= self.showsEntry;
enabled &= (self.selectedEntry != nil);
[self.passwordTextField setEnabled:enabled];
[self.usernameTextField setEnabled:enabled];
[self.URLTextField setEnabled:enabled];
[self.generatePasswordButton setEnabled:enabled];
[self.notesTextField setEditable:enabled];
[self.notesTextView setEditable:enabled];
[self.notesOrAttachmentControl setEnabled:enabled forSegment:MPNotesTab];
[self.notesOrAttachmentControl setEnabled:enabled forSegment:MPAttachmentTab];
}
- (void)_updateAttachments {
if(self.selectedEntry && self.showsEntry) {
if(self.selectedEntry) {
if([self.selectedEntry isKindOfClass:[Kdb4Entry class]]) {
[self.attachmentController bind:NSContentArrayBinding toObject:self.selectedEntry withKeyPath:@"binaries" options:nil];
}
@@ -220,6 +227,38 @@
#pragma mark Actions
- (void)_toggleInfoTab:(id)sender {
NSUInteger selectedSegment = [sender selectedSegment];
NSUInteger tab = [[sender cell] tagForSegment:selectedSegment];
NSView *infoView = nil;
NSView *oldView = nil;
switch (tab) {
case MPNotesTab:
infoView = _notesScrollView;
oldView = _attachmenScrollView;
break;
case MPAttachmentTab:
oldView = _notesScrollView;
infoView = _attachmenScrollView;
default:
break;
}
if([oldView superview]) {
[oldView removeFromSuperview];
}
[self.scrollContentView addSubview:infoView];
NSDictionary *views = NSDictionaryOfVariableBindings(_notesOrAttachmentControl, infoView);
[self.scrollContentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_notesOrAttachmentControl]-10-[infoView(>=100)]-10-|"
options:0
metrics:nil
views:views]];
[self.scrollContentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[infoView]-10-|"
options:0
metrics:nil
views:views]];
[[self view] layout];
}
- (void)_showImagePopup:(id)sender {
[self _showPopopver:[[[MPIconSelectViewController alloc] init] autorelease] atView:self.itemImageView onEdge:NSMinYEdge];
}
@@ -241,36 +280,40 @@
}
#pragma mark Notificiations
- (void)_didChangeSelectedEntry:(NSNotification *)notification {
MPEntryViewController *entryViewController = [notification object];
if(entryViewController) {
self.selectedEntry = entryViewController.selectedEntry;
- (void)_didChangeCurrentItem:(NSNotification *)notification {
MPDocumentWindowController *sender = [notification object];
id item = sender.currentItem;
if(!item) {
self.selectedGroup = nil;
self.selectedEntry = nil;
}
}
- (void)_didChangeSelectedGroup:(NSNotification *)notification {
MPOutlineViewDelegate *outlineViewDelegae = [notification object];
if(outlineViewDelegae) {
self.selectedGroup = outlineViewDelegae.selectedGroup;
if([item isKindOfClass:[KdbGroup class]]) {
self.selectedEntry = nil;
self.selectedGroup = sender.currentItem;
}
else if([item isKindOfClass:[KdbEntry class]]) {
self.selectedGroup = nil;
self.selectedEntry = sender.currentItem;
}
[self _updateContent];
}
#pragma mark Properties
- (void)setSelectedEntry:(KdbEntry *)selectedEntry {
if(_selectedEntry != selectedEntry) {
_selectedEntry = selectedEntry;
self.showsEntry = YES;
[self _updateContent];
}
}
- (void)setSelectedGroup:(KdbGroup *)selectedGroup {
if(_selectedGroup != selectedGroup) {
_selectedGroup = selectedGroup;
self.showsEntry = NO;
[self _updateContent];
}
}
//- (void)setSelectedEntry:(KdbEntry *)selectedEntry {
// if(_selectedEntry != selectedEntry) {
// _selectedEntry = selectedEntry;
// self.showsEntry = YES;
// [self _updateContent];
// }
//}
//
//- (void)setSelectedGroup:(KdbGroup *)selectedGroup {
// if(_selectedGroup != selectedGroup) {
// _selectedGroup = selectedGroup;
// self.showsEntry = NO;
// [self _updateContent];
// }
//}
#pragma mark NSTableViewDelegate
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {