Added custom-field copy to the context menu on entries. It's not fully functional as it's not correctly using the click but always the selected entry!

This commit is contained in:
michael starke
2013-07-17 01:02:02 +02:00
parent 442d16e297
commit 0a42e55f0e
9 changed files with 112 additions and 8 deletions

View File

@@ -207,6 +207,7 @@
4CD884B715BD47080042BBF8 /* DocumentWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CD884B615BD47080042BBF8 /* DocumentWindow.xib */; };
4CDB5C421794AA4F0017667E /* KPKTree+Serializing.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CDB5C411794AA4F0017667E /* KPKTree+Serializing.m */; };
4CDF01A316D1B76700D0AC08 /* MPEntryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CDF01A216D1B76700D0AC08 /* MPEntryViewController.m */; };
4CE298EB1795FC2A00DF7BDB /* MPEntryMenuDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE298EA1795FC2A00DF7BDB /* MPEntryMenuDelegate.m */; };
4CE39ABF16ECE34A000FE29D /* MPIconSelectViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE39ABE16ECE34A000FE29D /* MPIconSelectViewController.m */; };
4CE39AC116ECE359000FE29D /* IconSelection.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CE39AC016ECE359000FE29D /* IconSelection.xib */; };
4CE39AC416ECE4F7000FE29D /* MPPopupImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE39AC316ECE4F7000FE29D /* MPPopupImageView.m */; };
@@ -603,6 +604,8 @@
4CDB5C411794AA4F0017667E /* KPKTree+Serializing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "KPKTree+Serializing.m"; path = "../Core/KPKTree+Serializing.m"; sourceTree = "<group>"; };
4CDF01A116D1B76700D0AC08 /* MPEntryViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPEntryViewController.h; sourceTree = "<group>"; };
4CDF01A216D1B76700D0AC08 /* MPEntryViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPEntryViewController.m; sourceTree = "<group>"; };
4CE298E91795FC2A00DF7BDB /* MPEntryMenuDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPEntryMenuDelegate.h; sourceTree = "<group>"; };
4CE298EA1795FC2A00DF7BDB /* MPEntryMenuDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPEntryMenuDelegate.m; sourceTree = "<group>"; };
4CE39ABD16ECE34A000FE29D /* MPIconSelectViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPIconSelectViewController.h; sourceTree = "<group>"; };
4CE39ABE16ECE34A000FE29D /* MPIconSelectViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPIconSelectViewController.m; sourceTree = "<group>"; };
4CE39AC016ECE359000FE29D /* IconSelection.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = IconSelection.xib; sourceTree = "<group>"; };
@@ -950,6 +953,8 @@
4C3BD51416D276F800389F1F /* MPToolbarDelegate.m */,
4C811C8116ECD06E00C4BAC6 /* MPKeyfilePathControlDelegate.h */,
4C811C8216ECD06E00C4BAC6 /* MPKeyfilePathControlDelegate.m */,
4CE298E91795FC2A00DF7BDB /* MPEntryMenuDelegate.h */,
4CE298EA1795FC2A00DF7BDB /* MPEntryMenuDelegate.m */,
);
name = Delegates;
sourceTree = "<group>";
@@ -1784,6 +1789,7 @@
4CF62B86179385D700B660B6 /* KPKAttribute.m in Sources */,
4CDB5C421794AA4F0017667E /* KPKTree+Serializing.m in Sources */,
4C5AA591179549A1008ECAD7 /* KPKXmlTreeWriter.m in Sources */,
4CE298EB1795FC2A00DF7BDB /* MPEntryMenuDelegate.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -136,7 +136,7 @@
<array class="NSMutableArray" key="NSSubviews">
<object class="NSButton" id="277685969">
<reference key="NSNextResponder" ref="816254670"/>
<int key="NSvFlags">268</int>
<int key="NSvFlags">-2147483380</int>
<string key="NSFrame">{{184, 5}, {45, 19}}</string>
<reference key="NSSuperview" ref="816254670"/>
<reference key="NSWindow"/>
@@ -165,7 +165,7 @@
</object>
<object class="NSButton" id="442762067">
<reference key="NSNextResponder" ref="816254670"/>
<int key="NSvFlags">268</int>
<int key="NSvFlags">-2147483380</int>
<string key="NSFrame">{{237, 5}, {36, 19}}</string>
<reference key="NSSuperview" ref="816254670"/>
<reference key="NSWindow"/>

View File

@@ -0,0 +1,16 @@
//
// MPEntryMenuDelegate.h
// MacPass
//
// Created by Michael Starke on 17.07.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import <Foundation/Foundation.h>
@class MPEntryViewController;
@interface MPEntryMenuDelegate : NSObject <NSMenuDelegate>
@property (weak) MPEntryViewController *viewController;
@end

View File

@@ -0,0 +1,54 @@
//
// MPEntryMenuDelegate.m
// MacPass
//
// Created by Michael Starke on 17.07.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "MPEntryMenuDelegate.h"
#import "MPEntryViewController.h"
#import "Kdb4Node.h"
static NSUInteger const kMPCustomFieldMenuItem = 1000;
static NSUInteger const kMPAttachmentsMenuItem = 2000;
@implementation MPEntryMenuDelegate
- (void)menuNeedsUpdate:(NSMenu *)menu {
NSMenuItem *fieldsMenu = [menu itemWithTag:kMPCustomFieldMenuItem];
NSMenuItem *attachmentsMenu = [menu itemWithTag:kMPAttachmentsMenuItem];
if(fieldsMenu) {
[menu removeItem:fieldsMenu];
}
if(attachmentsMenu) {
[menu removeItem:attachmentsMenu];
}
NSMenuItem *lastItem = [[menu itemArray] lastObject];
if([lastItem isSeparatorItem]) {
[menu removeItem:lastItem];
}
if([self.viewController.selectedEntry isKindOfClass:[Kdb4Entry class]]) {
Kdb4Entry *entry = (Kdb4Entry *)self.viewController.selectedEntry;
if([entry.stringFields count] > 0) {
[menu addItem:[NSMenuItem separatorItem]];
NSMenuItem *customFieldsItem = [[NSMenuItem alloc] init];
NSMenu *submenu = [[NSMenu alloc] initWithTitle:@"Fields"];
[customFieldsItem setTitle:NSLocalizedString(@"COPY_CUSTOM_FIELDS", "Submenu to Copy custom fields")];
[customFieldsItem setTag:kMPCustomFieldMenuItem];
for (StringField *field in entry.stringFields) {
NSString *title = [NSString stringWithFormat:NSLocalizedString(@"COPY_FIELD_%@", "Mask for title to copy field value"), field.key];
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:title action:@selector(copyCustomField:) keyEquivalent:@""];
[item setTag:[entry.stringFields indexOfObject:field]];
[submenu addItem:item];
}
[customFieldsItem setSubmenu:submenu];
[menu addItem:customFieldsItem];
}
}
}
@end

View File

@@ -48,9 +48,11 @@ typedef NS_ENUM( NSUInteger, MPCopyContentTypeTag) {
/* Copy/Paste */
- (void)copyUsername:(id)sender;
- (void)copyPassword:(id)sender;
- (void)copyCustomField:(id)sender;
- (void)copyURL:(id)sender;
- (void)openURL:(id)sender;
/* Entry Handling*/
- (void)deleteNode:(id)sender;

View File

@@ -20,10 +20,12 @@
#import "MPConstants.h"
#import "MPEntryTableDataSource.h"
#import "MPStringLengthValueTransformer.h"
#import "MPEntryMenuDelegate.h"
#import "HNHTableHeaderCell.h"
#import "HNHGradientView.h"
#import "Kdb4Node.h"
#import "KdbGroup+MPTreeTools.h"
#import "KdbGroup+Undo.h"
#import "KdbEntry+Undo.h"
@@ -43,6 +45,7 @@ typedef NS_ENUM(NSUInteger,MPOVerlayInfoType) {
MPOverlayInfoPassword,
MPOverlayInfoUsername,
MPOverlayInfoURL,
MPOverlayInfoCustom
};
NSString *const MPEntryTableUserNameColumnIdentifier = @"MPUserNameColumnIdentifier";
@@ -59,7 +62,9 @@ NSString *const _toggleFilterURLButton = @"SearchURL";
NSString *const _toggleFilterTitleButton = @"SearchTitle";
NSString *const _toggleFilterUsernameButton = @"SearchUsername";
@interface MPEntryViewController ()
@interface MPEntryViewController () {
MPEntryMenuDelegate *_menuDelegate;
}
@property (strong) NSArrayController *entryArrayController;
@property (strong) NSArray *filteredEntries;
@@ -103,6 +108,9 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername";
_entryArrayController = [[NSArrayController alloc] init];
_dataSource = [[MPEntryTableDataSource alloc] init];
_dataSource.viewController = self;
_menuDelegate = [[MPEntryMenuDelegate alloc] init];
_menuDelegate.viewController = self;
_selectedEntry = nil;
}
return self;
@@ -396,7 +404,7 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername";
}
}
- (void)_copyToPasteboard:(NSString *)data overlayInfo:(MPOVerlayInfoType)overlayInfoType {
- (void)_copyToPasteboard:(NSString *)data overlayInfo:(MPOVerlayInfoType)overlayInfoType name:(NSString *)name{
if(data) {
[[MPPasteBoardController defaultController] copyObjects:@[ data ]];
}
@@ -417,6 +425,11 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername";
infoImage = [[NSBundle mainBundle] imageForResource:@"09_IdentityTemplate"];
infoText = NSLocalizedString(@"COPIED_USERNAME", @"Username was copied to the pasteboard");
break;
case MPOverlayInfoCustom:
infoImage = [[NSBundle mainBundle] imageForResource:@"00_PasswordTemplate"];
infoText = [NSString stringWithFormat:NSLocalizedString(@"COPIED_FIELD_%@", "Field nam that was copied to the pasteboard"), name];
break;
}
[[MPOverlayWindowController sharedController] displayOverlayImage:infoImage label:infoText atView:self.view];
}
@@ -430,7 +443,9 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername";
for(NSMenuItem *item in items) {
[menu addItem:item];
}
[menu setDelegate:_menuDelegate];
[self.entryTable setMenu:menu];
}
#pragma makr Action Helper
@@ -452,21 +467,32 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername";
- (void)copyPassword:(id)sender {
KdbEntry *selectedEntry = [self _clickedOrSelectedEntry];
if(selectedEntry) {
[self _copyToPasteboard:selectedEntry.password overlayInfo:MPOverlayInfoPassword];
[self _copyToPasteboard:selectedEntry.password overlayInfo:MPOverlayInfoPassword name:nil];
}
}
- (void)copyUsername:(id)sender {
KdbEntry *selectedEntry = [self _clickedOrSelectedEntry];
if(selectedEntry) {
[self _copyToPasteboard:selectedEntry.username overlayInfo:MPOverlayInfoUsername];
[self _copyToPasteboard:selectedEntry.username overlayInfo:MPOverlayInfoUsername name:nil];
}
}
- (void)copyCustomField:(id)sender {
KdbEntry *selectedEntry = [self _clickedOrSelectedEntry];
if(selectedEntry && [selectedEntry isKindOfClass:[Kdb4Entry class]]) {
Kdb4Entry *entry = (Kdb4Entry *)selectedEntry;
NSUInteger index = [sender tag];
NSAssert((index >= 0) && (index < [entry.stringFields count]), @"Index for custom field needs to be valid");
StringField *field = entry.stringFields[index];
[self _copyToPasteboard:field.value overlayInfo:MPOverlayInfoCustom name:field.key];
}
}
- (void)copyURL:(id)sender {
KdbEntry *selectedEntry = [self _clickedOrSelectedEntry];
if(selectedEntry) {
[self _copyToPasteboard:selectedEntry.url overlayInfo:MPOverlayInfoURL];
[self _copyToPasteboard:selectedEntry.url overlayInfo:MPOverlayInfoURL name:nil];
}
}

Binary file not shown.

Binary file not shown.