diff --git a/MacPass/MPDocument.h b/MacPass/MPDocument.h index c95bc1e5..be0f2d3b 100644 --- a/MacPass/MPDocument.h +++ b/MacPass/MPDocument.h @@ -40,6 +40,8 @@ APPKIT_EXTERN NSString *const MPDocumentDidUnlockDatabaseNotification; APPKIT_EXTERN NSString *const MPDocumentCurrentItemChangedNotification; +APPKIT_EXTERN NSString *const MPDocumentWillSaveNotification; + /* Keys used in userInfo NSDictionaries on notifications */ APPKIT_EXTERN NSString *const MPDocumentEntryKey; APPKIT_EXTERN NSString *const MPDocumentGroupKey; diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index 6ed90806..5ab30290 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -56,6 +56,8 @@ NSString *const MPDocumentDidUnlockDatabaseNotification = @"com.hicknhack.macp NSString *const MPDocumentCurrentItemChangedNotification = @"com.hicknhack.macpass.MPDocumentCurrentItemChangedNotification"; +NSString *const MPDocumentWillSaveNotification = @"com.hicknhack.macpass.MPDocumentWillSaveNotification"; + NSString *const MPDocumentEntryKey = @"MPDocumentEntryKey"; NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; @@ -140,10 +142,12 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey } - (void)saveDocumentAs:(id)sender { + [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentWillSaveNotification object:self]; [super saveDocumentAs:sender]; } - (void)saveDocument:(id)sender { + [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentWillSaveNotification object:self]; [super saveDocument:sender]; } diff --git a/MacPass/MPEntryInspectorViewController.m b/MacPass/MPEntryInspectorViewController.m index d36cf951..682b2e82 100644 --- a/MacPass/MPEntryInspectorViewController.m +++ b/MacPass/MPEntryInspectorViewController.m @@ -125,7 +125,12 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didAddEntry:) name:MPDocumentDidAddEntryNotification - object:document]; + object:document]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(_willSave:) + name:MPDocumentWillSaveNotification + object:document]; } - (void)dealloc { @@ -439,4 +444,9 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { [self.titleTextField becomeFirstResponder]; } +- (void)_willSave:(NSNotification *)notification { + // Force selected textfield to end editing + [[[self view] window] makeFirstResponder:nil]; +} + @end