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, MPActionToggleQuicklook,
MPActionShowEntryHistory, // show history MPActionShowEntryHistory, // show history
MPActionHideEntryHistory, // exit history MPActionHideEntryHistory, // exit history
MPActionShowGroupInOutline, // show the group (of the entry) in the outline view
MPActionPerformAutotypeForSelectedEntry, // Perform Autotype for selected Entry MPActionPerformAutotypeForSelectedEntry, // Perform Autotype for selected Entry
MPActionRemoveAttachment // Remove an attachment MPActionRemoveAttachment // Remove an attachment
}; };

View File

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

View File

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

View File

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

View File

@@ -42,6 +42,7 @@ static void MPContextmenuHelperBeginSection(NSMutableArray *items) {
BOOL const insertDuplicate = MPIsFlagSetInOptions(MPContextMenuDuplicate, flags); BOOL const insertDuplicate = MPIsFlagSetInOptions(MPContextMenuDuplicate, flags);
BOOL const insertAutotype = MPIsFlagSetInOptions(MPContextMenuAutotype, flags); BOOL const insertAutotype = MPIsFlagSetInOptions(MPContextMenuAutotype, flags);
BOOL const insertHistory = MPIsFlagSetInOptions(MPContextMenuHistory, flags); BOOL const insertHistory = MPIsFlagSetInOptions(MPContextMenuHistory, flags);
BOOL const insertShowGroupInOutline = MPIsFlagSetInOptions(MPContextMenuShowGroupInOutline, flags);
NSMutableArray *items = [NSMutableArray arrayWithCapacity:10]; NSMutableArray *items = [NSMutableArray arrayWithCapacity:10];
if(insertCreate) { if(insertCreate) {
@@ -113,7 +114,7 @@ static void MPContextmenuHelperBeginSection(NSMutableArray *items) {
[items addObjectsFromArray:@[ copyUsername, copyPassword, urlItem]]; [items addObjectsFromArray:@[ copyUsername, copyPassword, urlItem]];
} }
if(insertAutotype || insertHistory) { if(insertAutotype || insertHistory || insertShowGroupInOutline) {
MPContextmenuHelperBeginSection(items); MPContextmenuHelperBeginSection(items);
if(insertAutotype) { if(insertAutotype) {
NSMenuItem *performAutotype = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"PERFORM_AUTOTYPE_FOR_ENTRY", @"Menu item to perform autotype with the selected entry") 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); showHistory.keyEquivalentModifierMask = (showHistory.keyEquivalentModifierMask | NSCommandKeyMask | NSControlKeyMask);
[items addObject:showHistory]; [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; return items;

View File

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

View File

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

View File

@@ -545,6 +545,14 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
[contentView layoutSubtreeIfNeeded]; [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 -
#pragma mark Actions forwarded to MPEntryViewController #pragma mark Actions forwarded to MPEntryViewController
- (void)copyUsername:(id)sender { - (void)copyUsername:(id)sender {

View File

@@ -23,7 +23,7 @@
#import <Foundation/Foundation.h> #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> @interface MPEntryContextMenuDelegate : NSObject <NSMenuDelegate>

View File

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

View File

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

View File

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