mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-25 04:09:24 +00:00
Reference builder now works rudimentarily
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
|
||||
@interface MPReferenceBuilderViewController ()
|
||||
|
||||
@property (nonatomic, copy) NSString *searchString;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPReferenceBuilderViewController
|
||||
@@ -28,22 +30,51 @@
|
||||
- (void)didLoadView {
|
||||
[self.searchKeyPopUpButton setMenu:[self _allocateAttributeItemMenu:YES withTitle:NSLocalizedString(@"SEARCH_VALUE", "")]];
|
||||
[self.valuePopUpButton setMenu:[self _allocateAttributeItemMenu:NO withTitle:NSLocalizedString(@"OUTPUT_VALUE", "")]];
|
||||
[self.searchStringTextField bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(searchString)) options:nil];
|
||||
[self _updateReferenceString];
|
||||
}
|
||||
|
||||
- (NSMenu *)_allocateAttributeItemMenu:(BOOL)allowCustomAttributes withTitle:(NSString *)title {
|
||||
NSMenu *menu = [[NSMenu alloc] init];
|
||||
/* first item is button label */
|
||||
[menu addItemWithTitle:title action:NULL keyEquivalent:@""];
|
||||
//[menu addItemWithTitle:title action:NULL keyEquivalent:@""];
|
||||
[menu addItemWithTitle:NSLocalizedString(@"UUID","") action:NULL keyEquivalent:@""];
|
||||
[menu addItemWithTitle:NSLocalizedString(@"TITLE","") action:NULL keyEquivalent:@""];
|
||||
[menu addItemWithTitle:NSLocalizedString(@"USERNAME","") action:NULL keyEquivalent:@""];
|
||||
[menu addItemWithTitle:NSLocalizedString(@"PASSWORD","") action:NULL keyEquivalent:@""];
|
||||
[menu addItemWithTitle:NSLocalizedString(@"URL","") action:NULL keyEquivalent:@""];
|
||||
[menu addItemWithTitle:NSLocalizedString(@"NOTES","") action:NULL keyEquivalent:@""];
|
||||
[menu addItemWithTitle:NSLocalizedString(@"NOTES","") action:NULL keyEquivalent:@""];
|
||||
if(allowCustomAttributes) {
|
||||
[menu addItemWithTitle:NSLocalizedString(@"CUSTOM_ATTRIBUTE","") action:NULL keyEquivalent:@""];
|
||||
}
|
||||
NSArray *keys = @[ @"I", @"T", @"U", @"P", @"A", @"N", @"S" ];
|
||||
[menu.itemArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||
NSMenuItem *item = (NSMenuItem *)obj;
|
||||
NSAssert(keys.count > idx, @"");
|
||||
item.representedObject = keys[idx];
|
||||
}];
|
||||
return menu;
|
||||
}
|
||||
|
||||
- (void)setSearchString:(NSString *)searchString {
|
||||
if(![searchString isEqualToString:_searchString]) {
|
||||
_searchString = [searchString copy];
|
||||
[self _updateReferenceString];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)updateReference:(id)sender {
|
||||
[self _updateReferenceString];
|
||||
}
|
||||
|
||||
- (IBAction)updateKey:(id)sender {
|
||||
[self _updateReferenceString];
|
||||
}
|
||||
|
||||
- (void)_updateReferenceString {
|
||||
NSString *key = self.searchKeyPopUpButton.selectedItem.representedObject;
|
||||
NSString *value = self.valuePopUpButton.selectedItem.representedObject;
|
||||
NSString *newValue = [[NSString alloc] initWithFormat:@"{REF:%@@%@:%@}", value, key, self.searchStringTextField.stringValue];
|
||||
self.referenceStringTextField.stringValue = newValue;
|
||||
}
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user