mirror of
https://github.com/MacPass/MacPass.git
synced 2026-01-30 22:48:26 +00:00
Enhanced autotype candidate selection
selection window now uses a table instead of popup menu selection window will not activate MacPass and thus will not block view selection window displays evaluated placeholders (sans password) for better identification
This commit is contained in:
@@ -8,33 +8,69 @@
|
||||
|
||||
#import "MPAutotypeCandidateSelectionViewController.h"
|
||||
#import "MPAutotypeContext.h"
|
||||
#import "MPAutotypeDaemon.h"
|
||||
|
||||
#import "KPKNode+IconImage.h"
|
||||
|
||||
#import <KeePassKit/KeePassKit.h>
|
||||
|
||||
@interface MPAutotypeCandidateSelectionViewController () <NSTableViewDataSource, NSTableViewDelegate>
|
||||
@property (weak) IBOutlet NSButton *selectAutotypeContextButton;
|
||||
@property (weak) IBOutlet NSTableView *contextTableView;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPAutotypeCandidateSelectionViewController
|
||||
|
||||
- (NSNibName)nibName {
|
||||
return @"AutotypeCandidateSelectionViewController";
|
||||
return @"AutotypeCandidateSelectionView";
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
self.selectAutotypeContextButton.enabled = NO;
|
||||
}
|
||||
|
||||
#pragma mark NSTableViewDataSource
|
||||
|
||||
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
|
||||
return self.candidates.count;
|
||||
}
|
||||
|
||||
#pragma mark NSTableViewDelegate
|
||||
|
||||
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
|
||||
NSTableCellView *view = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
|
||||
MPAutotypeContext *context = self.candidates[row];
|
||||
view.textField.stringValue = context.entry.title;
|
||||
view.imageView.image = context.entry.icon.image;
|
||||
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n%@", context.entry.title, context.maskedEvaluatedCommand]];
|
||||
[string setAttributes:@{NSForegroundColorAttributeName: NSColor.disabledControlTextColor} range:NSMakeRange(context.entry.title.length + 1, context.maskedEvaluatedCommand.length)];
|
||||
view.textField.attributedStringValue = string;
|
||||
view.imageView.image = context.entry.iconImage;
|
||||
return view;
|
||||
}
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do view setup here.
|
||||
|
||||
- (void)tableViewSelectionDidChange:(NSNotification *)notification {
|
||||
NSTableView *tableView = notification.object;
|
||||
if(tableView != self.contextTableView) {
|
||||
return;
|
||||
}
|
||||
self.selectAutotypeContextButton.enabled = (self.contextTableView.selectedRow != -1);
|
||||
}
|
||||
|
||||
#pragma mark Actions
|
||||
- (void)selectAutotypeContext:(id)sender {
|
||||
NSInteger selectedRow = self.contextTableView.selectedRow;
|
||||
if(selectedRow >= 0 && selectedRow < self.candidates.count) {
|
||||
[[MPAutotypeDaemon defaultDaemon] selectAutotypeCandiate:self.candidates[selectedRow]];
|
||||
}
|
||||
else {
|
||||
[self cancelSelection:sender]; // cancel since the selection was invalid!
|
||||
}
|
||||
}
|
||||
|
||||
- (void)cancelSelection:(id)sender {
|
||||
[[MPAutotypeDaemon defaultDaemon] cancelAutotypeCandidateSelection];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user