Added show group in outline to context menus

This commit is contained in:
Michael Starke
2019-08-14 13:26:33 +02:00
parent 6b13ab37b8
commit 9c177afdb0
12 changed files with 41 additions and 23 deletions

View File

@@ -47,6 +47,7 @@ typedef NS_ENUM(NSUInteger, MPActionType) {
MPActionToggleQuicklook,
MPActionShowEntryHistory, // show history
MPActionHideEntryHistory, // exit history
MPActionShowGroupInOutline, // show the group (of the entry) in the outline view
MPActionPerformAutotypeForSelectedEntry, // Perform Autotype for selected Entry
MPActionRemoveAttachment // Remove an attachment
};

View File

@@ -57,6 +57,7 @@
@(MPActionToggleQuicklook): NSStringFromSelector(@selector(toggleQuicklookPreview:)),
@(MPActionShowEntryHistory): NSStringFromSelector(@selector(showEntryHistory:)),
@(MPActionHideEntryHistory): NSStringFromSelector(@selector(hideEntryHistory:)),
@(MPActionShowGroupInOutline): NSStringFromSelector(@selector(showGroupInOutline:)),
@(MPActionPerformAutotypeForSelectedEntry): NSStringFromSelector(@selector(performAutotypeForEntry:)),
@(MPActionRemoveAttachment): NSStringFromSelector(@selector(removeAttachment:))
};

View File

@@ -158,7 +158,7 @@ typedef NS_OPTIONS(NSInteger, MPAppStartupState) {
[fileMenu insertItem:item atIndex:insertIndex];
}
[self.itemMenu removeAllItems];
for(NSMenuItem *item in [MPContextMenuHelper contextMenuItemsWithItems:MPContextMenuFull]) {
for(NSMenuItem *item in [MPContextMenuHelper contextMenuItemsWithItems:MPContextMenuFull|MPContextMenuShowGroupInOutline]) {
[self.itemMenu addItem:item];
}
self.itemMenu.delegate = self.itemActionMenuDelegate;

View File

@@ -23,16 +23,17 @@
#import <Cocoa/Cocoa.h>
typedef NS_OPTIONS(NSUInteger, MPContextMenuItemsFlags) {
MPContextMenuCreate = 1 << 0,
MPContextMenuDelete = 1 << 1,
MPContextMenuCopy = 1 << 2,
MPContextMenuTrash = 1 << 3,
MPContextMenuDuplicate = 1 << 4,
MPContextMenuAutotype = 1 << 5,
MPContextMenuHistory = 1 << 6,
MPContextMenuMinimal = MPContextMenuCreate | MPContextMenuDelete,
MPContextMenuFull = MPContextMenuMinimal | MPContextMenuCopy | MPContextMenuDuplicate | MPContextMenuAutotype | MPContextMenuHistory,
MPContextMenuExtended = MPContextMenuFull | MPContextMenuTrash
MPContextMenuCreate = 1 << 0,
MPContextMenuDelete = 1 << 1,
MPContextMenuCopy = 1 << 2,
MPContextMenuTrash = 1 << 3,
MPContextMenuDuplicate = 1 << 4,
MPContextMenuAutotype = 1 << 5,
MPContextMenuHistory = 1 << 6,
MPContextMenuShowGroupInOutline = 1 << 7,
MPContextMenuMinimal = MPContextMenuCreate | MPContextMenuDelete,
MPContextMenuFull = MPContextMenuMinimal | MPContextMenuCopy | MPContextMenuDuplicate | MPContextMenuAutotype | MPContextMenuHistory,
MPContextMenuExtended = MPContextMenuFull | MPContextMenuTrash
};
@interface MPContextMenuHelper : NSTableCellView

View File

@@ -42,6 +42,7 @@ static void MPContextmenuHelperBeginSection(NSMutableArray *items) {
BOOL const insertDuplicate = MPIsFlagSetInOptions(MPContextMenuDuplicate, flags);
BOOL const insertAutotype = MPIsFlagSetInOptions(MPContextMenuAutotype, flags);
BOOL const insertHistory = MPIsFlagSetInOptions(MPContextMenuHistory, flags);
BOOL const insertShowGroupInOutline = MPIsFlagSetInOptions(MPContextMenuShowGroupInOutline, flags);
NSMutableArray *items = [NSMutableArray arrayWithCapacity:10];
if(insertCreate) {
@@ -113,7 +114,7 @@ static void MPContextmenuHelperBeginSection(NSMutableArray *items) {
[items addObjectsFromArray:@[ copyUsername, copyPassword, urlItem]];
}
if(insertAutotype || insertHistory) {
if(insertAutotype || insertHistory || insertShowGroupInOutline) {
MPContextmenuHelperBeginSection(items);
if(insertAutotype) {
NSMenuItem *performAutotype = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"PERFORM_AUTOTYPE_FOR_ENTRY", @"Menu item to perform autotype with the selected entry")
@@ -128,6 +129,12 @@ static void MPContextmenuHelperBeginSection(NSMutableArray *items) {
showHistory.keyEquivalentModifierMask = (showHistory.keyEquivalentModifierMask | NSCommandKeyMask | NSControlKeyMask);
[items addObject:showHistory];
}
if(insertShowGroupInOutline) {
NSMenuItem *showGroupInOutline = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"SHOW_GROUP_IN_OUTLINE", @"Menu item to show the entries group in the outline view")
action:[MPActionHelper actionOfType:MPActionShowGroupInOutline]
keyEquivalent:@""];
[items addObject:showGroupInOutline];
}
}
return items;

View File

@@ -914,6 +914,9 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
case MPActionCopyCustomAttribute:
case MPActionCopyAsReference:
valid &= (nil != targetEntry);
case MPActionShowGroupInOutline:
valid &= (nil != targetEntry);
valid &= self.hasSearch;
break;
default:
break;

View File

@@ -66,11 +66,11 @@
- (IBAction)delete:(id)sender;
- (IBAction)duplicateEntryWithOptions:(id)sender;
- (IBAction)pickExpiryDate:(id)sender;
- (IBAction)performAutotypeForEntry:(id)sender;
- (IBAction)showGroupInOutline:(id)sender;
/* actions relayed to MPEntryViewController */
- (IBAction)copyUsername:(id)sender;
- (IBAction)copyPassword:(id)sender;

View File

@@ -545,6 +545,14 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
[contentView layoutSubtreeIfNeeded];
}
- (void)showGroupInOutline:(id)sender {
NSArray<KPKEntry *> *targetEntries = self.entryViewController.currentTargetEntries;
if(targetEntries.count != 1) {
return;
}
[self.outlineViewController selectGroup:targetEntries.lastObject.parent];
}
#pragma mark -
#pragma mark Actions forwarded to MPEntryViewController
- (void)copyUsername:(id)sender {

View File

@@ -23,7 +23,7 @@
#import <Foundation/Foundation.h>
/**
Delegate is used for context menus that are show in the entries table
Delegate is used for context menus that are show in the entries table as well as the items menu in the main menu
*/
@interface MPEntryContextMenuDelegate : NSObject <NSMenuDelegate>

View File

@@ -602,7 +602,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
- (void)_setupEntryMenu {
NSMenu *menu = [[NSMenu alloc] init];
NSArray *items = [MPContextMenuHelper contextMenuItemsWithItems:MPContextMenuFull];
NSArray *items = [MPContextMenuHelper contextMenuItemsWithItems:MPContextMenuFull|MPContextMenuShowGroupInOutline];
for(NSMenuItem *item in items) {
[menu addItem:item];
}
@@ -777,12 +777,8 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
}
- (void)_executeGroupColumnDoubleClick {
NSUInteger clickedRow = self.entryTable.clickedRow;
if(clickedRow < 0 || clickedRow > [self.entryArrayController.arrangedObjects count]) {
return;
}
KPKEntry *entry = self.entryArrayController.arrangedObjects[clickedRow];
[((MPDocumentWindowController *)self.windowController).outlineViewController selectGroup:entry.parent];
id target = [NSApp targetForAction:@selector(showGroupInOutline:)];
[target showGroupInOutline:self];
}
- (void)_executeTitleColumnDoubleClick {

View File

@@ -157,6 +157,7 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
}
NSUInteger rowToSelect = [self _rowForUUID:groupUUID node:node];
[self.outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:rowToSelect] byExtendingSelection:NO];
[self.outlineView scrollRowToVisible:rowToSelect];
}
- (void)_expandItems:(NSTreeNode *)node {

View File

@@ -128,7 +128,7 @@ NSString *const MPToolbarItemAutotype = @"TOOLBAR_AUTOTYPE";
NSMenuItem *actionImageItem = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""];
actionImageItem.image = self.toolbarImages[MPToolbarItemAction];
[menu addItem:actionImageItem];
NSArray *menuItems = [MPContextMenuHelper contextMenuItemsWithItems:MPContextMenuExtended];
NSArray *menuItems = [MPContextMenuHelper contextMenuItemsWithItems:MPContextMenuExtended|MPContextMenuShowGroupInOutline];
for(NSMenuItem *item in menuItems) {
[menu addItem:item];
}