mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-24 20:49:35 +00:00
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:
@@ -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"/>
|
||||
|
||||
16
MacPass/MPEntryMenuDelegate.h
Normal file
16
MacPass/MPEntryMenuDelegate.h
Normal 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
|
||||
54
MacPass/MPEntryMenuDelegate.m
Normal file
54
MacPass/MPEntryMenuDelegate.m
Normal 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
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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.
Reference in New Issue
Block a user