mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 08:12:28 +00:00
72 lines
2.8 KiB
Objective-C
72 lines
2.8 KiB
Objective-C
//
|
|
// MPEntryContextMenuDelegate.m
|
|
// MacPass
|
|
//
|
|
// Created by Michael Starke on 17.07.13.
|
|
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
//
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
//
|
|
|
|
#import "MPEntryContextMenuDelegate.h"
|
|
#import "MPEntryViewController.h"
|
|
|
|
#import "KeePassKit/KeePassKit.h"
|
|
|
|
static NSUInteger const kMPCustomFieldMenuItem = 1000;
|
|
static NSUInteger const kMPAttachmentsMenuItem = 2000;
|
|
|
|
@implementation MPEntryContextMenuDelegate
|
|
|
|
- (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];
|
|
}
|
|
/* since we can get opened on the non-selected entry, we have to resolve the target node */
|
|
id<MPTargetNodeResolving> entryResolver = [NSApp targetForAction:@selector(currentTargetEntries)];
|
|
NSArray *entries = [entryResolver currentTargetEntries];
|
|
if(entries.count != 1) {
|
|
return;
|
|
}
|
|
KPKEntry *entry = entries.lastObject;
|
|
if(entry.customAttributes.count > 0) {
|
|
[menu addItem:[NSMenuItem separatorItem]];
|
|
NSMenuItem *attributeItem = [[NSMenuItem alloc] init];
|
|
NSMenu *submenu = [[NSMenu alloc] initWithTitle:NSLocalizedString(@"COPY_CUSTOM_FIELDS_MENU", @"Context menu sub-menu to copy custom fields to clipboard")];
|
|
attributeItem.title = NSLocalizedString(@"COPY_CUSTOM_FIELDS", "Submenu to Copy custom fields");
|
|
attributeItem.tag = kMPCustomFieldMenuItem;
|
|
for (KPKAttribute *attribute in entry.customAttributes) {
|
|
NSString *title = [NSString stringWithFormat:NSLocalizedString(@"COPY_FIELD_%@", "Mask for title to copy field value"), attribute.key];
|
|
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:title action:@selector(copyCustomAttribute:) keyEquivalent:@""];
|
|
item.tag = [entry.customAttributes indexOfObject:attribute];
|
|
[submenu addItem:item];
|
|
}
|
|
attributeItem.submenu = submenu;
|
|
[menu addItem:attributeItem];
|
|
}
|
|
}
|
|
|
|
@end
|