mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-13 08:52:20 +00:00
Added support for tag completion
This commit is contained in:
2
Cartfile
2
Cartfile
@@ -1,3 +1,3 @@
|
||||
github "sparkle-project/Sparkle" ~> 1.18.1
|
||||
github "MacPass/KeePassKit" ~> 1.6
|
||||
github "MacPass/KeePassKit" ~> 1.7
|
||||
github "mstarke/HNHUi" ~> 1.4.1
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
github "MacPass/KeePassKit" "1.6"
|
||||
github "MacPass/KeePassKit" "1.7"
|
||||
github "mstarke/HNHUi" "1.4.1"
|
||||
github "sparkle-project/Sparkle" "1.18.1"
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#import "MPPasswordCreatorViewController.h"
|
||||
#import "MPWindowAssociationsTableViewDelegate.h"
|
||||
#import "MPWindowTitleComboBoxDelegate.h"
|
||||
#import "MPTagsTokenFieldDelegate.h"
|
||||
#import "MPAutotypeBuilderViewController.h"
|
||||
#import "MPReferenceBuilderViewController.h"
|
||||
|
||||
@@ -64,6 +65,7 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
|
||||
MPAttachmentTableDataSource *_attachmentDataSource;
|
||||
MPWindowAssociationsTableViewDelegate *_windowAssociationsTableDelegate;
|
||||
MPWindowTitleComboBoxDelegate *_windowTitleMenuDelegate;
|
||||
MPTagsTokenFieldDelegate *_tagTokenFieldDelegate;
|
||||
}
|
||||
|
||||
@property (nonatomic, assign) BOOL showPassword;
|
||||
@@ -93,6 +95,8 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
|
||||
_attachmentDataSource = [[MPAttachmentTableDataSource alloc] init];
|
||||
_windowAssociationsTableDelegate = [[MPWindowAssociationsTableViewDelegate alloc] init];
|
||||
_windowTitleMenuDelegate = [[MPWindowTitleComboBoxDelegate alloc] init];
|
||||
_tagTokenFieldDelegate = [[MPTagsTokenFieldDelegate alloc] init];
|
||||
_tagTokenFieldDelegate.viewController = self;
|
||||
_attachmentTableDelegate.viewController = self;
|
||||
_customFieldTableDelegate.viewController = self;
|
||||
_activeTab = MPEntryTabGeneral;
|
||||
@@ -159,6 +163,8 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
|
||||
[self.passwordTextField bind:NSStringFromSelector(@selector(showPassword)) toObject:self withKeyPath:NSStringFromSelector(@selector(showPassword)) options:nil];
|
||||
[self.togglePassword bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(showPassword)) options:nil];
|
||||
|
||||
self.tagsTokenField.delegate = _tagTokenFieldDelegate;
|
||||
|
||||
[self _setupViewBindings];
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,10 @@
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "MPEntryInspectorViewController.h"
|
||||
|
||||
@interface MPTagsTokenFieldDelegate : NSObject <NSTokenFieldDelegate>
|
||||
|
||||
@property (weak) MPEntryInspectorViewController *viewController;
|
||||
|
||||
@end
|
||||
|
||||
@@ -22,23 +22,18 @@
|
||||
|
||||
#import "MPTagsTokenFieldDelegate.h"
|
||||
|
||||
#import "MPDocument.h"
|
||||
|
||||
#import "KeePassKit/KeePassKit.h"
|
||||
|
||||
@implementation MPTagsTokenFieldDelegate
|
||||
|
||||
// Each element in the array should be an NSString or an array of NSStrings.
|
||||
// substring is the partial string that is being completed. tokenIndex is the index of the token being completed.
|
||||
// selectedIndex allows you to return by reference an index specifying which of the completions should be selected initially.
|
||||
// The default behavior is not to have any completions.
|
||||
//- (nullable NSArray *)tokenField:(NSTokenField *)tokenField completionsForSubstring:(NSString *)substring indexOfToken:(NSInteger)tokenIndex indexOfSelectedItem:(nullable NSInteger *)selectedIndex;
|
||||
|
||||
// return an array of represented objects you want to add.
|
||||
// If you want to reject the add, return an empty array.
|
||||
// returning nil will cause an error.
|
||||
//- (NSArray *)tokenField:(NSTokenField *)tokenField shouldAddObjects:(NSArray *)tokens atIndex:(NSUInteger)index;
|
||||
|
||||
// If you return nil or don't implement these delegate methods, we will assume
|
||||
// editing string = display string = represented object
|
||||
//- (nullable NSString *)tokenField:(NSTokenField *)tokenField displayStringForRepresentedObject:(id)representedObject;
|
||||
//- (nullable NSString *)tokenField:(NSTokenField *)tokenField editingStringForRepresentedObject:(id)representedObject;
|
||||
//- (id)tokenField:(NSTokenField *)tokenField representedObjectForEditingString: (NSString *)editingString;
|
||||
- (NSArray *)tokenField:(NSTokenField *)tokenField completionsForSubstring:(NSString *)substring indexOfToken:(NSInteger)tokenIndex indexOfSelectedItem:(NSInteger *)selectedIndex {
|
||||
MPDocument *document = self.viewController.windowController.document;
|
||||
|
||||
return [document.tree.availableTags filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id _Nullable evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
|
||||
return [evaluatedObject hasPrefix:substring];
|
||||
}]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user