Centralized actions inside MPDocumetnWindowController

This commit is contained in:
michael starke
2014-10-24 16:18:53 +02:00
parent 675c5f92c8
commit 3a2dff5e07
13 changed files with 112 additions and 87 deletions

View File

@@ -340,7 +340,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
}
#pragma mark MPTargetItemResolving
- (KPKNode *)targetItemForAction {
- (KPKEntry *)currentTargetEntry {
NSInteger activeRow = [self.entryTable clickedRow];
/* Fallback to selection e.g. for toolbar actions */
if(activeRow < 0 ) {
@@ -352,6 +352,15 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
return nil;
}
- (KPKNode *)currentTargetNode {
KPKEntry *entry = [self currentTargetEntry];
if(entry) {
return entry;
}
MPDocument *document = [[self windowController] document];
return document.selectedItem;
}
#pragma mark MPDocument Notifications
- (void)_didChangeCurrentItem:(NSNotification *)notification {
MPDocument *document = [notification object];
@@ -597,21 +606,21 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
#pragma mark Actions
- (void)copyPassword:(id)sender {
KPKEntry *selectedEntry = [[self targetItemForAction] asEntry];
KPKEntry *selectedEntry = [[self currentTargetNode] asEntry];
if(selectedEntry) {
[self _copyToPasteboard:[selectedEntry.password finalValueForEntry:selectedEntry] overlayInfo:MPOverlayInfoPassword name:nil];
}
}
- (void)copyUsername:(id)sender {
KPKEntry *selectedEntry = [[self targetItemForAction] asEntry];
KPKEntry *selectedEntry = [[self currentTargetNode] asEntry];
if(selectedEntry) {
[self _copyToPasteboard:[selectedEntry.username finalValueForEntry:selectedEntry] overlayInfo:MPOverlayInfoUsername name:nil];
}
}
- (void)copyCustomAttribute:(id)sender {
KPKEntry *selectedEntry = [[self targetItemForAction] asEntry];
KPKEntry *selectedEntry = [[self currentTargetNode] asEntry];
if(selectedEntry && [selectedEntry isKindOfClass:[KPKEntry class]]) {
NSUInteger index = [sender tag];
NSAssert((index >= 0) && (index < [selectedEntry.customAttributes count]), @"Index for custom field needs to be valid");
@@ -621,14 +630,14 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
}
- (void)copyURL:(id)sender {
KPKEntry *selectedEntry = [[self targetItemForAction] asEntry];
KPKEntry *selectedEntry = [[self currentTargetNode] asEntry];
if(selectedEntry) {
[self _copyToPasteboard:[selectedEntry.url finalValueForEntry:selectedEntry] overlayInfo:MPOverlayInfoURL name:nil];
}
}
- (void)openURL:(id)sender {
KPKEntry *selectedEntry = [[self targetItemForAction] asEntry];
KPKEntry *selectedEntry = [[self currentTargetNode] asEntry];
if(selectedEntry && [selectedEntry.url length] > 0) {
NSURL *webURL = [NSURL URLWithString:[selectedEntry.url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *scheme = [webURL scheme];
@@ -650,7 +659,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
}
- (void)delete:(id)sender {
KPKEntry *entry = [[self targetItemForAction] asEntry];
KPKEntry *entry = [[self currentTargetNode] asEntry];
if(!entry) {
return;
}