Make selected textfield end editing when a save will occur (issue #203)

This commit is contained in:
James Hurst
2014-08-16 15:14:46 -04:00
parent be03656ce9
commit 7daf8ed879
3 changed files with 17 additions and 1 deletions

View File

@@ -40,6 +40,8 @@ APPKIT_EXTERN NSString *const MPDocumentDidUnlockDatabaseNotification;
APPKIT_EXTERN NSString *const MPDocumentCurrentItemChangedNotification; APPKIT_EXTERN NSString *const MPDocumentCurrentItemChangedNotification;
APPKIT_EXTERN NSString *const MPDocumentWillSaveNotification;
/* Keys used in userInfo NSDictionaries on notifications */ /* Keys used in userInfo NSDictionaries on notifications */
APPKIT_EXTERN NSString *const MPDocumentEntryKey; APPKIT_EXTERN NSString *const MPDocumentEntryKey;
APPKIT_EXTERN NSString *const MPDocumentGroupKey; APPKIT_EXTERN NSString *const MPDocumentGroupKey;

View File

@@ -56,6 +56,8 @@ NSString *const MPDocumentDidUnlockDatabaseNotification = @"com.hicknhack.macp
NSString *const MPDocumentCurrentItemChangedNotification = @"com.hicknhack.macpass.MPDocumentCurrentItemChangedNotification"; NSString *const MPDocumentCurrentItemChangedNotification = @"com.hicknhack.macpass.MPDocumentCurrentItemChangedNotification";
NSString *const MPDocumentWillSaveNotification = @"com.hicknhack.macpass.MPDocumentWillSaveNotification";
NSString *const MPDocumentEntryKey = @"MPDocumentEntryKey"; NSString *const MPDocumentEntryKey = @"MPDocumentEntryKey";
NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
@@ -140,10 +142,12 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
} }
- (void)saveDocumentAs:(id)sender { - (void)saveDocumentAs:(id)sender {
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentWillSaveNotification object:self];
[super saveDocumentAs:sender]; [super saveDocumentAs:sender];
} }
- (void)saveDocument:(id)sender { - (void)saveDocument:(id)sender {
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentWillSaveNotification object:self];
[super saveDocument:sender]; [super saveDocument:sender];
} }

View File

@@ -125,7 +125,12 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_didAddEntry:) selector:@selector(_didAddEntry:)
name:MPDocumentDidAddEntryNotification name:MPDocumentDidAddEntryNotification
object:document]; object:document];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_willSave:)
name:MPDocumentWillSaveNotification
object:document];
} }
- (void)dealloc { - (void)dealloc {
@@ -439,4 +444,9 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
[self.titleTextField becomeFirstResponder]; [self.titleTextField becomeFirstResponder];
} }
- (void)_willSave:(NSNotification *)notification {
// Force selected textfield to end editing
[[[self view] window] makeFirstResponder:nil];
}
@end @end