mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-23 22:09:25 +00:00
Context bar display now works again. Search is still broken
This commit is contained in:
@@ -12,6 +12,8 @@ typedef NS_ENUM(NSUInteger, MPActionType) {
|
||||
MPUnkownAction, // Neutral element to be used for returns
|
||||
MPActionAddEntry, // Add an new entry
|
||||
MPActionAddGroup, // Add a new group
|
||||
MPActionCloneEntry, // Simply clone an entry (inlcuding history)
|
||||
MPActionCloneEntryWithOptions, // Request user inptu what clone
|
||||
MPActionDelete, // Delete entry or group
|
||||
MPActionCopyUsername, // copy username to pasteboard
|
||||
MPActionCopyPassword, // copy password to pasteboard
|
||||
|
||||
@@ -15,21 +15,22 @@
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
actionDict = @{
|
||||
@(MPActionAddEntry) : @"createEntry:",
|
||||
@(MPActionAddGroup) : @"createGroup:",
|
||||
@(MPActionCopyPassword) : @"copyPassword:",
|
||||
@(MPActionCopyURL) : @"copyURL:",
|
||||
@(MPActionCopyUsername) : @"copyUsername:",
|
||||
@(MPActionDelete) : @"delete:",
|
||||
@(MPActionEditPassword) : @"editPassword:",
|
||||
@(MPActionOpenURL) : @"openURL:",
|
||||
@(MPActionToggleInspector) : @"toggleInspector:",
|
||||
@(MPActionLock) : @"lock:",
|
||||
@(MPActionEmptyTrash) : @"emptyTrash:",
|
||||
@(MPActionDatabaseSettings) : @"showDatabaseSettings:",
|
||||
@(MPActionEditTemplateGroup) : @"editTemplateGroup:",
|
||||
@(MPActionExportXML) : @"exportAsXML",
|
||||
@(MPActionImportXML) : @"importFromXMl",
|
||||
@(MPActionAddEntry): @"createEntry:",
|
||||
@(MPActionAddGroup): @"createGroup:",
|
||||
@(MPActionCloneEntry): @"cloneEntry:",
|
||||
@(MPActionCopyPassword): @"copyPassword:",
|
||||
@(MPActionCopyURL): @"copyURL:",
|
||||
@(MPActionCopyUsername): @"copyUsername:",
|
||||
@(MPActionDelete): @"delete:",
|
||||
@(MPActionEditPassword): @"editPassword:",
|
||||
@(MPActionOpenURL): @"openURL:",
|
||||
@(MPActionToggleInspector): @"toggleInspector:",
|
||||
@(MPActionLock): @"lock:",
|
||||
@(MPActionEmptyTrash): @"emptyTrash:",
|
||||
@(MPActionDatabaseSettings): @"showDatabaseSettings:",
|
||||
@(MPActionEditTemplateGroup): @"editTemplateGroup:",
|
||||
@(MPActionExportXML): @"exportAsXML",
|
||||
@(MPActionImportXML): @"importFromXMl",
|
||||
};
|
||||
});
|
||||
return actionDict;
|
||||
|
||||
@@ -44,6 +44,7 @@ typedef NS_ENUM(NSUInteger, MPContextTab) {
|
||||
|
||||
@implementation MPContextBarViewController
|
||||
|
||||
#pragma mark Livecycle
|
||||
- (instancetype)init {
|
||||
self = [self initWithNibName:@"ContextBar" bundle:nil];
|
||||
return self;
|
||||
@@ -76,7 +77,13 @@ typedef NS_ENUM(NSUInteger, MPContextTab) {
|
||||
[self _updateFilterButtons];
|
||||
}
|
||||
|
||||
#pragma mark Properties
|
||||
#pragma mark MPDocument Notifications
|
||||
- (void)registerNotificationsForDocument:(MPDocument *)document {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_updateFilterButtons) name:MPDocumentDidChangeSearchFlags object:document];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didEnterSearch:) name:MPDocumentDidEnterSearchNotification object:document];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didEnterHistory:) name:MPDocumentDidEnterHistoryNotification object:document];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didChangeCurrentItem:) name:MPDocumentCurrentItemChangedNotification object:document];
|
||||
}
|
||||
|
||||
- (void)_didEnterSearch:(NSNotification *)notification {
|
||||
/* Select text if already visible */
|
||||
@@ -89,15 +96,13 @@ typedef NS_ENUM(NSUInteger, MPContextTab) {
|
||||
[self _updateBindings];
|
||||
}
|
||||
|
||||
- (void)_showTrash {
|
||||
self.activeTab = MPContextTabTrash;
|
||||
[self _updateBindings];
|
||||
}
|
||||
|
||||
- (void)registerNotificationsForDocument:(MPDocument *)document {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_updateFilterButtons) name:MPDocumentDidChangeSearchFlags object:document];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didEnterSearch:) name:MPDocumentDidEnterSearchNotification object:document];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didEnterHistory:) name:MPDocumentDidEnterHistoryNotification object:document];
|
||||
- (void)_didChangeCurrentItem:(NSNotification *)notification {
|
||||
MPDocument *document = [notification object];
|
||||
BOOL showTrash = document.useTrash && (document.selectedGroup == document.trash || [document isItemTrashed:document.selectedItem]);
|
||||
if(showTrash) {
|
||||
self.activeTab = MPContextTabTrash;
|
||||
[self _updateBindings];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -109,6 +114,7 @@ typedef NS_ENUM(NSUInteger, MPContextTab) {
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
#pragma mark UI Helper
|
||||
- (void)_updateBindings {
|
||||
// only the entry view has to be bound, the rest not
|
||||
|
||||
@@ -9,13 +9,22 @@
|
||||
#import "MPContextMenuHelper.h"
|
||||
#import "MPActionHelper.h"
|
||||
|
||||
#import "MPFlagsHelper.h"
|
||||
|
||||
static void MPContextmenuHelperBeginSection(NSMutableArray *items) {
|
||||
if([items count] > 0) {
|
||||
[items addObject:[NSMenuItem separatorItem]];
|
||||
}
|
||||
}
|
||||
|
||||
@implementation MPContextMenuHelper
|
||||
|
||||
+ (NSArray *)contextMenuItemsWithItems:(MPContextMenuItemsFlags)flags {
|
||||
BOOL insertCreate = (0 != (flags & MPContextMenuCreate));
|
||||
BOOL insertDelete = (0 != (flags & MPContextMenuDelete));
|
||||
BOOL insertCopy = (0 != (flags & MPContextMenuCopy));
|
||||
BOOL insertTrash = (0 != (flags & MPContextMenuTrash));
|
||||
|
||||
BOOL const insertCreate = MPTestFlagInOptions(MPContextMenuCreate, flags);
|
||||
BOOL const insertDelete = MPTestFlagInOptions(MPContextMenuDelete, flags);
|
||||
BOOL const insertCopy = MPTestFlagInOptions(MPContextMenuCopy, flags);
|
||||
BOOL const insertTrash = MPTestFlagInOptions(MPContextMenuTrash, flags);
|
||||
|
||||
NSMutableArray *items = [NSMutableArray arrayWithCapacity:10];
|
||||
if(insertCreate) {
|
||||
@@ -30,27 +39,27 @@
|
||||
[items addObjectsFromArray:@[ newGroup, newEntry ]];
|
||||
}
|
||||
if(insertDelete || insertTrash) {
|
||||
[self _beginSection:items];
|
||||
MPContextmenuHelperBeginSection(items);
|
||||
if(insertDelete) {
|
||||
NSMenuItem *delete = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"DELETE", @"")
|
||||
action:[MPActionHelper actionOfType:MPActionDelete]
|
||||
keyEquivalent:@""];
|
||||
[items addObject:delete];
|
||||
|
||||
|
||||
}
|
||||
if(insertTrash) {
|
||||
NSMenuItem *emptyTrash = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"EMPTY_TRASH", @"")
|
||||
action:[MPActionHelper actionOfType:MPActionEmptyTrash]
|
||||
keyEquivalent:@""];
|
||||
action:[MPActionHelper actionOfType:MPActionEmptyTrash]
|
||||
keyEquivalent:@""];
|
||||
[emptyTrash setKeyEquivalentModifierMask:(NSShiftKeyMask | NSCommandKeyMask)];
|
||||
unichar backSpace = NSBackspaceCharacter;
|
||||
[emptyTrash setKeyEquivalent:[NSString stringWithCharacters:&backSpace length:1]];
|
||||
[items addObject:emptyTrash];
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
if(insertCopy) {
|
||||
[self _beginSection:items];
|
||||
MPContextmenuHelperBeginSection(items);
|
||||
NSMenuItem *copyUsername = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"COPY_USERNAME", @"")
|
||||
action:[MPActionHelper actionOfType:MPActionCopyUsername]
|
||||
keyEquivalent:@"C"];
|
||||
@@ -79,10 +88,4 @@
|
||||
return items;
|
||||
}
|
||||
|
||||
+ (void)_beginSection:(NSMutableArray *)items {
|
||||
if([items count] > 0) {
|
||||
[items addObject:[NSMenuItem separatorItem]];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -206,7 +206,7 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
|
||||
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(_updateContextBar)
|
||||
selector:@selector(_didExitSearch:)
|
||||
name:MPDocumentDidExitSearchNotification
|
||||
object:document];
|
||||
|
||||
@@ -355,8 +355,8 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
|
||||
});
|
||||
}
|
||||
|
||||
#pragma mark MPContextBarDelegate
|
||||
- (void)contextBarDidExitFilter {
|
||||
#pragma mark NSDocument+Search Notifications
|
||||
- (void)_didExitSearch:(NSNotification *)notification {
|
||||
[[self.entryTable tableColumnWithIdentifier:MPEntryTableParentColumnIdentifier] setHidden:YES];
|
||||
MPDocument *document = [[self windowController] document];
|
||||
document.selectedItem = document.selectedGroup;
|
||||
@@ -368,16 +368,12 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
|
||||
}
|
||||
|
||||
#pragma mark ContextBar
|
||||
- (void)_showTrashBar {
|
||||
[self _showContextBar];
|
||||
}
|
||||
|
||||
- (void)_updateContextBar {
|
||||
MPDocument *document = [[self windowController] document];
|
||||
if(!document.hasSearch) {
|
||||
BOOL showTrash = document.useTrash && (document.selectedGroup == document.trash || [document isItemTrashed:document.selectedItem]);
|
||||
if(showTrash) {
|
||||
[self _showTrashBar];
|
||||
[self _showContextBar];
|
||||
}
|
||||
else {
|
||||
[self _hideContextBar];
|
||||
|
||||
Reference in New Issue
Block a user