From ff36f6ce873bc7802cfbda44045ca4d84c2ad7a3 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Tue, 24 Jun 2014 22:00:33 -0400 Subject: [PATCH] The search for a background that works on all screens ... --- MasterPassword/ObjC/Mac/MPMacAppDelegate.m | 9 +- .../ObjC/Mac/MPPasswordWindowController.h | 1 + .../ObjC/Mac/MPPasswordWindowController.m | 90 +++++++++---------- .../ObjC/Mac/MPPasswordWindowController.xib | 52 ++++++----- 4 files changed, 78 insertions(+), 74 deletions(-) diff --git a/MasterPassword/ObjC/Mac/MPMacAppDelegate.m b/MasterPassword/ObjC/Mac/MPMacAppDelegate.m index 4b2ed8a3..1da3b96c 100644 --- a/MasterPassword/ObjC/Mac/MPMacAppDelegate.m +++ b/MasterPassword/ObjC/Mac/MPMacAppDelegate.m @@ -10,6 +10,7 @@ #import "MPAppDelegate_Key.h" #import "MPAppDelegate_Store.h" #import "MPPasswordWindowController.h" +#import "PearlProfiler.h" #import #import @@ -70,6 +71,7 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { + PearlProfiler *profiler = [PearlProfiler profilerForTask:@"applicationDidFinishLaunching"]; // Setup delegates and listeners. [MPConfig get].delegate = self; __weak id weakSelf = self; @@ -88,6 +90,7 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven [weakSelf updateMenuItems]; } ); } forKeyPath:@"storeManager.cloudAvailable" options:0 context:nil]; + [profiler finishJob:@"observers"]; // Status item. self.statusView = [[RHStatusItemView alloc] initWithStatusBarItem: @@ -96,6 +99,7 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven self.statusView.menu = self.statusMenu; self.statusView.target = self; self.statusView.action = @selector( showMenu ); + [profiler finishJob:@"statusView"]; [[NSNotificationCenter defaultCenter] addObserverForName:USMStoreDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock: @@ -125,7 +129,9 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven } } }]; + [profiler finishJob:@"notificationCenter"]; [self updateUsers]; + [profiler finishJob:@"updateUsers"]; // Global hotkey. EventHotKeyRef hotKeyRef; @@ -140,14 +146,15 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven status = RegisterEventHotKey( 35 /* p */, controlKey + optionKey + cmdKey, MPLockHotKey, GetApplicationEventTarget(), 0, &hotKeyRef ); if (status != noErr) err( @"Error registering 'lock' hotkey: %i", (int)status ); + [profiler finishJob:@"hotKey"]; // Initial display. - [NSApp activateIgnoringOtherApps:YES]; if ([[MPMacConfig get].firstRun boolValue]) { self.initialWindow = [[NSWindowController alloc] initWithWindowNibName:@"MPInitialWindow" owner:self]; [self.initialWindow.window setLevel:NSFloatingWindowLevel]; [self.initialWindow showWindow:self]; } + [profiler finishJob:@"initial display"]; } - (void)applicationWillResignActive:(NSNotification *)notification { diff --git a/MasterPassword/ObjC/Mac/MPPasswordWindowController.h b/MasterPassword/ObjC/Mac/MPPasswordWindowController.h index b2d6d37a..dc42dd34 100644 --- a/MasterPassword/ObjC/Mac/MPPasswordWindowController.h +++ b/MasterPassword/ObjC/Mac/MPPasswordWindowController.h @@ -31,6 +31,7 @@ @property(nonatomic, weak) IBOutlet NSTableView *siteTable; @property(nonatomic, weak) IBOutlet NSProgressIndicator *progressView; @property(nonatomic, weak) IBOutlet NSButton *typeButton; +@property(nonatomic, weak) IBOutlet NSButton *loginButton; @property(nonatomic, weak) IBOutlet NSView *counterContainer; @property(nonatomic, weak) IBOutlet NSStepper *counterStepper; @property(nonatomic, weak) IBOutlet NSTextField *counterLabel; diff --git a/MasterPassword/ObjC/Mac/MPPasswordWindowController.m b/MasterPassword/ObjC/Mac/MPPasswordWindowController.m index 2a1d9724..8c7da777 100644 --- a/MasterPassword/ObjC/Mac/MPPasswordWindowController.m +++ b/MasterPassword/ObjC/Mac/MPPasswordWindowController.m @@ -69,6 +69,10 @@ withBlock:^(id from, id to, NSKeyValueChange cause, id _self) { [self updateSelection]; }]; + + NSSearchFieldCell *siteFieldCell = self.siteField.cell; + siteFieldCell.searchButtonCell = nil; + siteFieldCell.cancelButtonCell = nil; } #pragma mark - NSResponder @@ -113,10 +117,10 @@ [self.elementsController selectNext:self]; return YES; } -// if ([NSStringFromSelector( commandSelector ) rangeOfString:@"delete"].location == 0) { -// _skipTextChange = YES; -// return NO; -// } + if ([NSStringFromSelector( commandSelector ) rangeOfString:@"delete"].location == 0) { + _skipTextChange = YES; + return NO; + } } return [self handleCommand:commandSelector]; @@ -127,26 +131,6 @@ [self updateElements]; } -- (void)controlTextDidChange:(NSNotification *)note { - -// if (note.object == self.siteField) { -// [self updateElements]; - - // Update the site content as the site name changes. -// if ([[NSApp currentEvent] type] == NSKeyDown && -// [[[NSApp currentEvent] charactersIgnoringModifiers] isEqualToString:@"\r"]) { // Return while completing. -// [self useSite]; -// return; -// } - -// if ([[NSApp currentEvent] type] == NSKeyDown && -// [[[NSApp currentEvent] charactersIgnoringModifiers] characterAtIndex:0] == 0x1b) { // Escape while completing. -// [self trySiteWithAction:NO]; -// return; -// } -// } -} - #pragma mark - NSTextViewDelegate - (BOOL)textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector { @@ -173,7 +157,7 @@ // "Create" button. [[MPMacAppDelegate get] addElementNamed:[self.siteField stringValue] completion:^(MPElementEntity *element) { if (element) - PearlMainQueue( ^{ [self updateElements]; } ); + [self updateElements]; }]; break; } @@ -188,6 +172,11 @@ #pragma mark - State +- (NSString *)query { + + return [self.siteField.stringValue stringByReplacingCharactersInRange:self.siteField.currentEditor.selectedRange withString:@""]; +} + - (void)insertObject:(MPElementModel *)model inElementsAtIndex:(NSUInteger)index { [self.elements insertObject:model atIndex:index]; @@ -222,32 +211,29 @@ - (void)updateUser { [MPMacAppDelegate managedObjectContextForMainThreadPerformBlock:^(NSManagedObjectContext *mainContext) { + self.passwordField.hidden = YES; + self.siteField.hidden = YES; + self.siteTable.hidden = YES; + + self.inputLabel.stringValue = @""; + self.passwordField.stringValue = @""; + self.siteField.stringValue = @""; + MPUserEntity *mainActiveUser = [[MPMacAppDelegate get] activeUserInContext:mainContext]; if (mainActiveUser) { if ([MPMacAppDelegate get].key) { self.inputLabel.stringValue = strf( @"%@'s password for:", mainActiveUser.name ); - [self.passwordField setHidden:YES]; - [self.siteField setHidden:NO]; - [self.siteTable setHidden:NO]; + self.siteField.hidden = NO; + self.siteTable.hidden = NO; [self.siteField becomeFirstResponder]; } else { self.inputLabel.stringValue = strf( @"Enter %@'s master password:", mainActiveUser.name ); - [self.passwordField setHidden:NO]; - [self.siteField setHidden:YES]; - [self.siteTable setHidden:YES]; + self.passwordField.hidden = NO; [self.passwordField becomeFirstResponder]; } } - else { - self.inputLabel.stringValue = @""; - [self.passwordField setHidden:YES]; - [self.siteField setHidden:YES]; - [self.siteTable setHidden:YES]; - } - self.passwordField.stringValue = @""; - self.siteField.stringValue = @""; [self updateElements]; }]; } @@ -259,12 +245,15 @@ return; } - NSString *query = [self.siteField stringValue]; + PearlProfiler *profiler = [PearlProfiler profilerForTask:@"updateElements"]; + NSString *query = [self query]; + [profiler finishJob:@"query"]; [MPMacAppDelegate managedObjectContextPerformBlockAndWait:^(NSManagedObjectContext *context) { NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass( [MPElementEntity class] )]; fetchRequest.sortDescriptors = [NSArray arrayWithObject:[[NSSortDescriptor alloc] initWithKey:@"lastUsed" ascending:NO]]; fetchRequest.predicate = [NSPredicate predicateWithFormat:@"(%@ == '' OR name BEGINSWITH[cd] %@) AND user == %@", query, query, [[MPMacAppDelegate get] activeUserInContext:context]]; + [profiler finishJob:@"setup fetch"]; NSError *error = nil; NSArray *siteResults = [context executeFetchRequest:fetchRequest error:&error]; @@ -272,12 +261,16 @@ err( @"While fetching elements for completion: %@", error ); return; } + [profiler finishJob:@"do fetch"]; NSMutableArray *newElements = [NSMutableArray arrayWithCapacity:[siteResults count]]; for (MPElementEntity *element in siteResults) [newElements addObject:[[MPElementModel alloc] initWithEntity:element]]; + [profiler finishJob:@"make models"]; self.elements = newElements; + [profiler finishJob:@"update elements"]; }]; + [profiler finishJob:@"done"]; } - (void)updateSelection { @@ -287,18 +280,15 @@ return; } - NSString *selectedSiteName = self.selectedElement.siteName; - if (!selectedSiteName) + NSString *siteName = self.selectedElement.siteName; + if (!siteName) return; - NSString *querySiteText = [self.siteField.stringValue stringByReplacingCharactersInRange:self.siteField.currentEditor.selectedRange - withString:@""]; - NSRange selectedSiteNameQueryRange = [selectedSiteName rangeOfString:querySiteText]; - self.siteField.stringValue = selectedSiteName; + NSRange siteNameQueryRange = [siteName rangeOfString:[self query]]; + self.siteField.stringValue = siteName; - if (selectedSiteNameQueryRange.location == 0) - self.siteField.currentEditor.selectedRange = NSMakeRange( - selectedSiteNameQueryRange.length, selectedSiteName.length - selectedSiteNameQueryRange.length ); + if (siteNameQueryRange.location == 0) + self.siteField.currentEditor.selectedRange = NSMakeRange( siteNameQueryRange.length, siteName.length - siteNameQueryRange.length ); } - (void)useSite { @@ -358,7 +348,7 @@ if ([self.window isOnActiveSpace] && self.window.alphaValue) return; - PearlProfiler *profiler = [PearlProfiler new]; + PearlProfiler *profiler = [PearlProfiler profilerForTask:@"fadeIn"]; CGWindowID windowID = (CGWindowID)[self.window windowNumber]; CGImageRef capturedImage = CGWindowListCreateImage( CGRectInfinite, kCGWindowListOptionOnScreenBelowWindow, windowID, kCGWindowImageBoundsIgnoreFraming ); diff --git a/MasterPassword/ObjC/Mac/MPPasswordWindowController.xib b/MasterPassword/ObjC/Mac/MPPasswordWindowController.xib index 5fb88038..f7b68b27 100644 --- a/MasterPassword/ObjC/Mac/MPPasswordWindowController.xib +++ b/MasterPassword/ObjC/Mac/MPPasswordWindowController.xib @@ -13,6 +13,7 @@ + @@ -32,19 +33,20 @@ - + - + - + + @@ -76,7 +78,7 @@ - + @@ -89,7 +91,7 @@ - + @@ -180,7 +182,7 @@ - + @@ -191,23 +193,23 @@