diff --git a/MasterPassword/MPAppDelegate_Key.h b/MasterPassword/MPAppDelegate_Key.h index 97e754ce..f29a6895 100644 --- a/MasterPassword/MPAppDelegate_Key.h +++ b/MasterPassword/MPAppDelegate_Key.h @@ -37,7 +37,7 @@ - (void)printStore; - (void)loadStoredKey; -- (void)signOut; +- (IBAction)signOut:(id)sender; - (BOOL)tryMasterPassword:(NSString *)tryPassword; - (void)updateKey:(NSData *)key; diff --git a/MasterPassword/MPAppDelegate_Key.m b/MasterPassword/MPAppDelegate_Key.m index 89b462a1..d1b1d31b 100644 --- a/MasterPassword/MPAppDelegate_Key.m +++ b/MasterPassword/MPAppDelegate_Key.m @@ -222,7 +222,7 @@ static NSDictionary *keyHashQuery() { #endif } -- (void)signOut { +- (IBAction)signOut:(id)sender { [self updateKey:nil]; } diff --git a/MasterPassword/Mac/MPAppDelegate.h b/MasterPassword/Mac/MPAppDelegate.h index 21cb2bc7..555433b4 100644 --- a/MasterPassword/Mac/MPAppDelegate.h +++ b/MasterPassword/Mac/MPAppDelegate.h @@ -11,11 +11,13 @@ @interface MPAppDelegate : NSObject -@property (assign) IBOutlet NSWindow *window; @property (strong) NSStatusItem *statusItem; +@property (weak) IBOutlet NSMenuItem *unlockItem; +@property (weak) IBOutlet NSMenuItem *lockItem; +@property (weak) IBOutlet NSMenuItem *showItem; +@property (strong) IBOutlet NSMenu *statusMenu; -- (IBAction)saveAction:(id)sender; - -- (void)loadKey; +- (IBAction)activate:(id)sender; +- (IBAction)unlock:(id)sender; @end diff --git a/MasterPassword/Mac/MPAppDelegate.m b/MasterPassword/Mac/MPAppDelegate.m index 26c66d5c..0a943988 100644 --- a/MasterPassword/Mac/MPAppDelegate.m +++ b/MasterPassword/Mac/MPAppDelegate.m @@ -16,13 +16,14 @@ @property (readwrite, strong, nonatomic) MPPasswordWindowController *passwordWindow; -- (void)activate; - @end @implementation MPAppDelegate -@synthesize window; @synthesize statusItem; +@synthesize unlockItem; +@synthesize lockItem; +@synthesize showItem; +@synthesize statusMenu; @synthesize passwordWindow; @dynamic persistentStoreCoordinator, managedObjectModel, managedObjectContext; @@ -50,26 +51,34 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven // Check which hotkey this was. if (hotKeyID.signature == MPShowHotKey.signature && hotKeyID.id == MPShowHotKey.id) { - [((__bridge MPAppDelegate *)userData) activate]; + [((__bridge MPAppDelegate *)userData) activate:nil]; return noErr; } return eventNotHandledErr; } -- (void)activate { +- (void)showMenu { + + [self.showItem setEnabled:![self.passwordWindow.window isVisible]]; + [self.statusItem popUpStatusItemMenu:self.statusMenu]; +} + +- (IBAction)activate:(id)sender { [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; } - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { + [self addObserver:self forKeyPath:@"key" options:0 context:nil]; + // Status item. self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength]; self.statusItem.title = @"•••"; self.statusItem.highlightMode = YES; self.statusItem.target = self; - self.statusItem.action = @selector(activate); + self.statusItem.action = @selector(showMenu); // Global hotkey. EventHotKeyRef hotKeyRef; @@ -84,15 +93,27 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven } - (void)applicationDidBecomeActive:(NSNotification *)notification { - + if (!self.passwordWindow) self.passwordWindow = [[MPPasswordWindowController alloc] initWithWindowNibName:@"MPPasswordWindowController"]; [self.passwordWindow showWindow:self]; - [self loadKey]; + [self unlock:self]; } -- (void)loadKey { +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { + + if ([keyPath isEqualToString:@"key"]) { + if (self.key) + [self.lockItem setEnabled:YES]; + else { + [self.lockItem setEnabled:NO]; + [self.passwordWindow close]; + } + } +} + +- (IBAction)unlock:(id)sender { if (!self.key) // Try and load the key from the keychain. @@ -143,20 +164,6 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven return [[self managedObjectContext] undoManager]; } -// Performs the save action for the application, which is to send the save: message to the application's managed object context. Any encountered errors are presented to the user. -- (IBAction)saveAction:(id)sender -{ - NSError *error = nil; - - if (![[self managedObjectContext] commitEditing]) { - NSLog(@"%@:%@ unable to commit editing before saving", [self class], NSStringFromSelector(_cmd)); - } - - if (![[self managedObjectContext] save:&error]) { - [[NSApplication sharedApplication] presentError:error]; - } -} - - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { // Save changes in the application's managed object context before the application terminates. diff --git a/MasterPassword/Mac/en.lproj/MainMenu.xib b/MasterPassword/Mac/en.lproj/MainMenu.xib index 31f6322f..1bbb2c0d 100644 --- a/MasterPassword/Mac/en.lproj/MainMenu.xib +++ b/MasterPassword/Mac/en.lproj/MainMenu.xib @@ -3,18 +3,18 @@ 1070 11D50 - 2177 + 2182 1138.32 568.00 com.apple.InterfaceBuilder.CocoaPlugin - 2177 + 2182 - NSUserDefaultsController - NSMenu NSMenuItem + NSMenu NSCustomObject + NSUserDefaultsController com.apple.InterfaceBuilder.CocoaPlugin @@ -35,231 +35,62 @@ AMainMenu - - - - Master Password - - 1048576 - 2147483647 - - NSImage - NSMenuCheckmark - - - NSImage - NSMenuMixedState - - submenuAction: - - Master Password - - - - About Master Password - - 2147483647 - - - - - - YES - YES - - - 1048576 - 2147483647 - - - - - - Preferences… - , - 1048576 - 2147483647 - - - - - - YES - YES - - - 1048576 - 2147483647 - - - - - - Services - - 1048576 - 2147483647 - - - submenuAction: - - Services - - _NSServicesMenu - - - - - YES - YES - - - 1048576 - 2147483647 - - - - - - Hide Master Password - h - 1048576 - 2147483647 - - - - - - Hide Others - h - 1572864 - 2147483647 - - - - - - Show All - - 1048576 - 2147483647 - - - - - - YES - YES - - - 1048576 - 2147483647 - - - - - - Quit Master Password - q - 1048576 - 2147483647 - - - - - _NSAppleMenu - - - - - Window - - 1048576 - 2147483647 - - - submenuAction: - - Window - - - - Minimize - m - 1048576 - 2147483647 - - - - - - Zoom - - 1048576 - 2147483647 - - - - - - YES - YES - - - 1048576 - 2147483647 - - - - - - Bring All to Front - - 1048576 - 2147483647 - - - - - _NSWindowsMenu - - - - - Help - - 2147483647 - - - submenuAction: - - Help - - - - Master Password Help - ? - 1048576 - 2147483647 - - - - - _NSHelpMenu - - - + _NSMainMenu MPAppDelegate - - NSFontManager - YES + + + + + + Show + + 2147483647 + + NSImage + NSMenuCheckmark + + + NSImage + NSMenuMixedState + + + + + YES + YES + + + 2147483647 + + + + + + YES + Lock + + 2147483647 + + + + + + Quit + + 2147483647 + + + + + YES + @@ -267,17 +98,9 @@ terminate: - + - 449 - - - - orderFrontStandardAboutPanel: - - - - 142 + 734 @@ -288,60 +111,44 @@ 495 - - performMiniaturize: - - + + lockItem + + - 37 + 726 - arrangeInFront: - - + signOut: + + - 39 + 727 + + + + showItem + + + + 730 + + + + statusMenu + + + + 731 - performZoom: - - + activate: + + - 240 - - - - hide: - - - - 367 - - - - hideOtherApplications: - - - - 368 - - - - unhideAllApplications: - - - - 370 - - - - showHelp: - - - - 493 + 736 @@ -373,167 +180,9 @@ 29 - - - - - + - - 19 - - - - - - - - 56 - - - - - - - - 57 - - - - - - - - - - - - - - - - - - 58 - - - - - 134 - - - - - 150 - - - - - 136 - - - - - 144 - - - - - 129 - - - - - 143 - - - - - 236 - - - - - 131 - - - - - - - - 149 - - - - - 145 - - - - - 130 - - - - - 24 - - - - - - - - - - - 92 - - - - - 5 - - - - - 239 - - - - - 23 - - - - - 420 - - - - - 490 - - - - - - - - 491 - - - - - - - - 492 - - - 494 @@ -544,80 +193,59 @@ + + 716 + + + + + + + + + + + 717 + + + + + 718 + + + + + 719 + + + + + 720 + + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin - 715 - - - - - MPAppDelegate - NSObject - - saveAction: - id - - - saveAction: - - saveAction: - id - - - - window - NSWindow - - - window - - window - NSWindow - - - - IBProjectSource - ./Classes/MPAppDelegate.h - - - + 736 + 0 IBCocoaFramework