mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-13 22:52:26 +00:00
reworking context bar display
This commit is contained in:
@@ -93,7 +93,7 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
|
|||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didAddGroup:) name:MPDocumentDidAddGroupNotification object:document];
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didAddGroup:) name:MPDocumentDidAddGroupNotification object:document];
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didLockDatabase:) name:MPDocumentDidLockDatabaseNotification object:document];
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didLockDatabase:) name:MPDocumentDidLockDatabaseNotification object:document];
|
||||||
|
|
||||||
[self.entryViewController regsiterNotificationsForDocument:document];
|
[self.entryViewController registerNotificationsForDocument:document];
|
||||||
[self.inspectorViewController registerNotificationsForDocument:document];
|
[self.inspectorViewController registerNotificationsForDocument:document];
|
||||||
[self.outlineViewController regsiterNotificationsForDocument:document];
|
[self.outlineViewController regsiterNotificationsForDocument:document];
|
||||||
[self.toolbarDelegate registerNotificationsForDocument:document];
|
[self.toolbarDelegate registerNotificationsForDocument:document];
|
||||||
|
|||||||
@@ -19,13 +19,10 @@ APPKIT_EXTERN NSString *const MPEntryTableNotesColumnIdentifier;
|
|||||||
APPKIT_EXTERN NSString *const MPEntryTableAttachmentColumnIdentifier;
|
APPKIT_EXTERN NSString *const MPEntryTableAttachmentColumnIdentifier;
|
||||||
APPKIT_EXTERN NSString *const MPEntryTableModfiedColumnIdentifier;
|
APPKIT_EXTERN NSString *const MPEntryTableModfiedColumnIdentifier;
|
||||||
|
|
||||||
|
typedef NS_ENUM(NSUInteger, MPDisplayMode) {
|
||||||
/* Tags to determine what to copy */
|
MPDisplayModeEntries,
|
||||||
typedef NS_ENUM( NSUInteger, MPCopyContentTypeTag) {
|
MPDisplayModeSearchResults,
|
||||||
MPCopyUsername,
|
MPDisplayModeHistory
|
||||||
MPCopyPassword,
|
|
||||||
MPCopyURL,
|
|
||||||
MPCopyWholeEntry,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@class KPKEntry;
|
@class KPKEntry;
|
||||||
@@ -36,9 +33,10 @@ typedef NS_ENUM( NSUInteger, MPCopyContentTypeTag) {
|
|||||||
|
|
||||||
@property (weak,readonly) NSTableView *entryTable;
|
@property (weak,readonly) NSTableView *entryTable;
|
||||||
@property (readonly, strong) NSArrayController *entryArrayController;
|
@property (readonly, strong) NSArrayController *entryArrayController;
|
||||||
|
@property (readonly, assign) MPDisplayMode displayMode;
|
||||||
|
|
||||||
/* Call this after all view controllers are loaded */
|
/* Call this after all view controllers are loaded */
|
||||||
- (void)regsiterNotificationsForDocument:(MPDocument *)document;
|
- (void)registerNotificationsForDocument:(MPDocument *)document;
|
||||||
|
|
||||||
/* Copy/Paste */
|
/* Copy/Paste */
|
||||||
- (void)copyUsername:(id)sender;
|
- (void)copyUsername:(id)sender;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
#define STATUS_BAR_ANIMATION_TIME 0.15
|
#define STATUS_BAR_ANIMATION_TIME 0.15
|
||||||
#define EXPIRED_ENTRY_REFRESH_SECONDS 60
|
#define EXPIRED_ENTRY_REFRESH_SECONDS 60
|
||||||
|
|
||||||
typedef NS_ENUM(NSUInteger,MPOVerlayInfoType) {
|
typedef NS_ENUM(NSUInteger, MPOverlayInfoType) {
|
||||||
MPOverlayInfoPassword,
|
MPOverlayInfoPassword,
|
||||||
MPOverlayInfoUsername,
|
MPOverlayInfoUsername,
|
||||||
MPOverlayInfoURL,
|
MPOverlayInfoURL,
|
||||||
@@ -71,6 +71,8 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
|
|||||||
@property (strong) NSArray *filteredEntries;
|
@property (strong) NSArray *filteredEntries;
|
||||||
|
|
||||||
@property (weak) IBOutlet NSTableView *entryTable;
|
@property (weak) IBOutlet NSTableView *entryTable;
|
||||||
|
@property (assign) MPDisplayMode displayMode;
|
||||||
|
|
||||||
|
|
||||||
/* Constraints */
|
/* Constraints */
|
||||||
@property (strong) IBOutlet NSLayoutConstraint *tableToTopConstraint;
|
@property (strong) IBOutlet NSLayoutConstraint *tableToTopConstraint;
|
||||||
@@ -90,6 +92,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
|
|||||||
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
||||||
if(self) {
|
if(self) {
|
||||||
_isDisplayingContextBar = NO;
|
_isDisplayingContextBar = NO;
|
||||||
|
_displayMode = MPDisplayModeEntries;
|
||||||
_entryArrayController = [[NSArrayController alloc] init];
|
_entryArrayController = [[NSArrayController alloc] init];
|
||||||
_dataSource = [[MPEntryTableDataSource alloc] init];
|
_dataSource = [[MPEntryTableDataSource alloc] init];
|
||||||
_dataSource.viewController = self;
|
_dataSource.viewController = self;
|
||||||
@@ -193,7 +196,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
|
|||||||
return self.entryTable;
|
return self.entryTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)regsiterNotificationsForDocument:(MPDocument *)document {
|
- (void)registerNotificationsForDocument:(MPDocument *)document {
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
selector:@selector(_didChangeCurrentItem:)
|
selector:@selector(_didChangeCurrentItem:)
|
||||||
name:MPDocumentCurrentItemChangedNotification
|
name:MPDocumentCurrentItemChangedNotification
|
||||||
@@ -392,25 +395,34 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
|
|||||||
- (void)_didChangeCurrentItem:(NSNotification *)notification {
|
- (void)_didChangeCurrentItem:(NSNotification *)notification {
|
||||||
MPDocument *document = notification.object;
|
MPDocument *document = notification.object;
|
||||||
|
|
||||||
if(document.selectedGroups.count != 1 && !document.hasSearch) {
|
if(document.selectedGroups.count != 1) {
|
||||||
/* no group selection out of search is wrong */
|
if(self.displayMode == MPDisplayModeEntries) {
|
||||||
self.representedObject = nil;
|
/* no group selection out for entry display is wrong */
|
||||||
return;
|
self.representedObject = nil;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
If a group is the current item, see if we already show that group
|
If a group is the current item, see if we already show that group
|
||||||
also test if an element has been selected (issue #257)
|
also test if an element has been selected (issue #257)
|
||||||
*/
|
*/
|
||||||
if(document.selectedNodes.firstObject == document.selectedGroups.firstObject && document.selectedNodes.count > 0) {
|
if(document.selectedNodes.firstObject == document.selectedGroups.firstObject && document.selectedNodes.count > 0) {
|
||||||
if(document.hasSearch) {
|
switch(self.displayMode) {
|
||||||
/* If search was active, stop it and exit */
|
|
||||||
[document exitSearch:self];
|
case MPDisplayModeSearchResults:
|
||||||
}
|
[document exitSearch:nil];
|
||||||
else if([self.entryArrayController.content count] > 0) {
|
break;
|
||||||
KPKEntry *entry = [self.entryArrayController.content lastObject];
|
case MPDisplayModeHistory:
|
||||||
if(entry.parent == document.selectedGroups.lastObject) {
|
[document hideEntryHistory:nil];
|
||||||
return; // we are showing the correct object right now.
|
break;
|
||||||
}
|
case MPDisplayModeEntries:
|
||||||
|
if([self.entryArrayController.content count] > 0) {
|
||||||
|
KPKEntry *entry = [self.entryArrayController.content lastObject];
|
||||||
|
if(entry.parent == document.selectedGroups.lastObject) {
|
||||||
|
return; // we are showing the correct object right now.
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
self.representedObject = document.selectedGroups.count == 1 ? document.selectedGroups.lastObject : nil;
|
self.representedObject = document.selectedGroups.count == 1 ? document.selectedGroups.lastObject : nil;
|
||||||
}
|
}
|
||||||
@@ -444,24 +456,26 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)_didUpdateSearchResults:(NSNotification *)notification {
|
- (void)_didUpdateSearchResults:(NSNotification *)notification {
|
||||||
[self _showContextBar];
|
|
||||||
NSArray *result = notification.userInfo[kMPDocumentSearchResultsKey];
|
NSArray *result = notification.userInfo[kMPDocumentSearchResultsKey];
|
||||||
NSAssert(result != nil, @"Resutls should never be nil");
|
NSAssert(result != nil, @"Resutls should never be nil");
|
||||||
self.filteredEntries = result;
|
self.filteredEntries = result;
|
||||||
[self.entryArrayController unbind:NSContentArrayBinding];
|
[self.entryArrayController unbind:NSContentArrayBinding];
|
||||||
[self.entryArrayController bind:NSContentArrayBinding toObject:self withKeyPath:NSStringFromSelector(@selector(filteredEntries)) options:nil];
|
[self.entryArrayController bind:NSContentArrayBinding toObject:self withKeyPath:NSStringFromSelector(@selector(filteredEntries)) options:nil];
|
||||||
[self.entryTable tableColumnWithIdentifier:MPEntryTableParentColumnIdentifier].hidden = NO;
|
[self.entryTable tableColumnWithIdentifier:MPEntryTableParentColumnIdentifier].hidden = NO;
|
||||||
|
[self _updateContextBar];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void)_didExitSearch:(NSNotification *)notification {
|
- (void)_didExitSearch:(NSNotification *)notification {
|
||||||
[self.entryTable tableColumnWithIdentifier:MPEntryTableParentColumnIdentifier].hidden = YES;
|
[self.entryTable tableColumnWithIdentifier:MPEntryTableParentColumnIdentifier].hidden = YES;
|
||||||
self.filteredEntries = nil;
|
self.filteredEntries = nil;
|
||||||
|
self.displayMode = MPDisplayModeEntries;
|
||||||
[self _updateContextBar];
|
[self _updateContextBar];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_didEnterSearch:(NSNotification *)notification {
|
- (void)_didEnterSearch:(NSNotification *)notification {
|
||||||
[self _showContextBar];
|
self.displayMode = MPDisplayModeSearchResults;
|
||||||
|
[self _updateContextBar];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_didUnlockDatabase:(NSNotification *)notificiation {
|
- (void)_didUnlockDatabase:(NSNotification *)notificiation {
|
||||||
@@ -476,29 +490,32 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)_showEntryHistory:(NSNotification *)notification {
|
- (void)_showEntryHistory:(NSNotification *)notification {
|
||||||
[self _showContextBar];
|
self.displayMode = MPDisplayModeHistory;
|
||||||
KPKEntry *entry = notification.userInfo[MPDocumentEntryKey];
|
KPKEntry *entry = notification.userInfo[MPDocumentEntryKey];
|
||||||
NSAssert(entry != nil, @"Resutls should never be nil");
|
NSAssert(entry != nil, @"Resutls should never be nil");
|
||||||
[self.entryArrayController unbind:NSContentArrayBinding];
|
[self.entryArrayController unbind:NSContentArrayBinding];
|
||||||
[self.entryArrayController bind:NSContentArrayBinding toObject:entry withKeyPath:NSStringFromSelector(@selector(history)) options:nil];
|
[self.entryArrayController bind:NSContentArrayBinding toObject:entry withKeyPath:NSStringFromSelector(@selector(history)) options:nil];
|
||||||
|
[self _updateContextBar];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_hideEntryHistory:(NSNotification *)notification {
|
- (void)_hideEntryHistory:(NSNotification *)notification {
|
||||||
[self _hideContextBar];
|
self.displayMode = MPDisplayModeEntries;
|
||||||
|
[self _updateContextBar];
|
||||||
}
|
}
|
||||||
#pragma mark ContextBar
|
#pragma mark ContextBar
|
||||||
- (void)_updateContextBar {
|
- (void)_updateContextBar {
|
||||||
MPDocument *document = [[self windowController] document];
|
switch(self.displayMode) {
|
||||||
if(!document.hasSearch) {
|
case MPDisplayModeSearchResults:
|
||||||
KPKGroup *group = self.representedObject;
|
case MPDisplayModeHistory:
|
||||||
KPKNode *node = document.selectedNodes.count == 1 ? document.selectedNodes.firstObject : nil;
|
|
||||||
BOOL showTrash = document.tree.metaData.useTrash && (group.isTrash || node.isTrashed);
|
|
||||||
if(showTrash) {
|
|
||||||
[self _showContextBar];
|
[self _showContextBar];
|
||||||
}
|
break;
|
||||||
else {
|
case MPDisplayModeEntries:
|
||||||
[self _hideContextBar];
|
if([[self currentTargetEntries].firstObject isTrashed]) {
|
||||||
}
|
[self _showContextBar];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[self _hideContextBar];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,16 +525,16 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
|
|||||||
}
|
}
|
||||||
_isDisplayingContextBar = YES;
|
_isDisplayingContextBar = YES;
|
||||||
if(!self.contextBarViewController.view.superview) {
|
if(!self.contextBarViewController.view.superview) {
|
||||||
[self.view addSubview:[self.contextBarViewController view]];
|
[self.view addSubview:self.contextBarViewController.view];
|
||||||
[self.contextBarViewController updateResponderChain];
|
[self.contextBarViewController updateResponderChain];
|
||||||
NSView *contextBar = self.contextBarViewController.view;
|
NSView *contextBar = self.contextBarViewController.view;
|
||||||
NSView *scrollView = self.entryTable.enclosingScrollView;
|
NSView *scrollView = self.entryTable.enclosingScrollView;
|
||||||
NSDictionary *views = NSDictionaryOfVariableBindings(scrollView, contextBar);
|
NSDictionary *views = NSDictionaryOfVariableBindings(scrollView, contextBar);
|
||||||
|
|
||||||
/* Pin to the left */
|
/* Pin to the left */
|
||||||
[[self view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[contextBar]|" options:0 metrics:nil views:views]];
|
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[contextBar]|" options:0 metrics:nil views:views]];
|
||||||
/* Pin height and to top of entry table */
|
/* Pin height and to top of entry table */
|
||||||
[[self view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[contextBar(==30)]-0-[scrollView]" options:0 metrics:nil views:views]];
|
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[contextBar(==30)]-0-[scrollView]" options:0 metrics:nil views:views]];
|
||||||
/* Create the top constraint for the filter bar where we can change the constant instead of removing/adding constraints all the time */
|
/* Create the top constraint for the filter bar where we can change the constant instead of removing/adding constraints all the time */
|
||||||
self.contextBarTopConstraint = [NSLayoutConstraint constraintWithItem:contextBar
|
self.contextBarTopConstraint = [NSLayoutConstraint constraintWithItem:contextBar
|
||||||
attribute:NSLayoutAttributeTop
|
attribute:NSLayoutAttributeTop
|
||||||
@@ -557,7 +574,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark Copy/Paste Overlays
|
#pragma mark Copy/Paste Overlays
|
||||||
- (void)_copyToPasteboard:(NSString *)data overlayInfo:(MPOVerlayInfoType)overlayInfoType name:(NSString *)name{
|
- (void)_copyToPasteboard:(NSString *)data overlayInfo:(MPOverlayInfoType)overlayInfoType name:(NSString *)name{
|
||||||
if(data) {
|
if(data) {
|
||||||
[[MPPasteBoardController defaultController] copyObjects:@[ data ]];
|
[[MPPasteBoardController defaultController] copyObjects:@[ data ]];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user