2012-03-05 09:53:32 +01:00
|
|
|
//
|
|
|
|
// MPPasswordWindowController.m
|
|
|
|
// MasterPassword-Mac
|
|
|
|
//
|
|
|
|
// Created by Maarten Billemont on 04/03/12.
|
|
|
|
// Copyright (c) 2012 Lyndir. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "MPPasswordWindowController.h"
|
2012-03-05 22:19:05 +01:00
|
|
|
#import "MPAppDelegate.h"
|
2012-03-05 09:53:32 +01:00
|
|
|
|
|
|
|
@interface MPPasswordWindowController ()
|
|
|
|
|
2012-03-05 22:19:05 +01:00
|
|
|
@property (nonatomic, assign) BOOL completingSiteName;
|
|
|
|
|
2012-03-05 09:53:32 +01:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation MPPasswordWindowController
|
2012-03-05 22:19:05 +01:00
|
|
|
@synthesize completingSiteName;
|
2012-03-05 09:53:32 +01:00
|
|
|
@synthesize siteField;
|
|
|
|
@synthesize contentField;
|
|
|
|
|
|
|
|
- (void)windowDidLoad {
|
|
|
|
|
2012-03-05 22:19:05 +01:00
|
|
|
[self.contentField setStringValue:@""];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserverForName:NSWindowWillCloseNotification object:self.window queue:nil
|
|
|
|
usingBlock:^(NSNotification *note) {
|
|
|
|
[[NSApplication sharedApplication] hide:self];
|
|
|
|
}];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserverForName:NSControlTextDidChangeNotification object:self.siteField queue:nil
|
|
|
|
usingBlock:^(NSNotification *note) {
|
|
|
|
if (!self.completingSiteName) {
|
|
|
|
self.completingSiteName = YES;
|
|
|
|
[[[note userInfo] objectForKey:@"NSFieldEditor"] complete:nil];
|
|
|
|
self.completingSiteName = NO;
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
|
2012-03-05 09:53:32 +01:00
|
|
|
[super windowDidLoad];
|
2012-03-05 22:19:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *)control:(NSControl *)control textView:(NSTextView *)textView completions:(NSArray *)words forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(NSInteger *)index {
|
2012-03-05 09:53:32 +01:00
|
|
|
|
2012-03-05 22:19:05 +01:00
|
|
|
NSString *query = [[control stringValue] substringWithRange:charRange];
|
|
|
|
NSFetchRequest *fetchRequest = [MPAppDelegate.managedObjectModel
|
|
|
|
fetchRequestFromTemplateWithName:@"MPElements"
|
|
|
|
substitutionVariables:[NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
query, @"query",
|
|
|
|
[MPAppDelegate get].keyPhraseHashHex, @"mpHashHex",
|
|
|
|
nil]];
|
|
|
|
|
|
|
|
return [NSArray arrayWithObjects:@"cow", @"milk", @"hippopotamus", nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)controlTextDidEndEditing:(NSNotification *)obj {
|
|
|
|
|
|
|
|
if (obj.object == self.siteField) {
|
|
|
|
// NSString *siteName = [self.siteField stringValue];
|
|
|
|
|
|
|
|
// [self.contentField setStringValue:];
|
|
|
|
}
|
2012-03-05 09:53:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|