Refactored Notification setup to use only the document as object

This commit is contained in:
michael starke
2014-02-25 22:49:41 +01:00
parent 21f299bdff
commit f6dc2193de
10 changed files with 36 additions and 26 deletions

View File

@@ -31,7 +31,6 @@
- (void)showPasswordInput;
#pragma mark Actions
- (IBAction)performFindPanelAction:(id)sender;
- (IBAction)saveDocument:(id)sender;
- (IBAction)editPassword:(id)sender;

View File

@@ -81,9 +81,12 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didRevertDocument:) name:MPDocumentDidRevertNotifiation object:[self document]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showEntries) name:MPDocumentDidUnlockDatabaseNotification object:[self document]];
[_entryViewController setupNotifications:self];
[_inspectorViewController setupNotifications:self];
[_outlineViewController setupNotifications:self];
MPDocument *document = [self document];
[_entryViewController regsiterNotificationsForDocument:document];
[_inspectorViewController regsiterNotificationsForDocument:document];
[_outlineViewController regsiterNotificationsForDocument:document];
[_toolbarDelegate regsiterNotificationsForDocument:document];
@@ -109,8 +112,7 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
if(!showInspector) {
[inspectorView removeFromSuperview];
}
MPDocument *document = [self document];
if(document.encrypted) {
[self showPasswordInput];
}

View File

@@ -26,6 +26,7 @@ typedef NS_ENUM( NSUInteger, MPCopyContentTypeTag) {
@class KPKEntry;
@class MPOutlineViewDelegate;
@class MPDocumentWindowController;
@class MPDocument;
@interface MPEntryViewController : MPViewController <NSTableViewDelegate, MPContextBarDelegate>
@@ -33,7 +34,7 @@ typedef NS_ENUM( NSUInteger, MPCopyContentTypeTag) {
@property (readonly, strong) NSArrayController *entryArrayController;
/* Call this after alle viewcontroller are loaded */
- (void)setupNotifications:(MPDocumentWindowController *)windowController;
- (void)regsiterNotificationsForDocument:(MPDocument *)document;
/* Copy/Paste */
- (void)copyUsername:(id)sender;

View File

@@ -98,11 +98,6 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
_dataSource.viewController = self;
_menuDelegate = [[MPEntryContextMenuDelegate alloc] init];
_contextBarViewController = [[MPContextBarViewController alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_updateSearchResults:)
name:MPDocumentDidChangeSearchNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showFilter:) name:MPDocumentDidEnterSearchNotification object:nil];
}
return self;
}
@@ -196,12 +191,22 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
return self.entryTable;
}
- (void)setupNotifications:(MPDocumentWindowController *)windowController {
MPDocument *document = [windowController document];
- (void)regsiterNotificationsForDocument:(MPDocument *)document {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_didChangeCurrentItem:)
name:MPCurrentItemChangedNotification
object:document];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_updateSearchResults:)
name:MPDocumentDidChangeSearchNotification
object:document];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(showFilter:)
name:MPDocumentDidEnterSearchNotification
object:document];
}
#pragma mark NSTableViewDelgate
@@ -356,10 +361,6 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
}
- (void)showFilter:(NSNotification *)notification {
MPDocument *currentDocument = [[self windowController] document];
if(notification && [notification object] != currentDocument) {
return; // Wrong document
}
[self.contextBarViewController showFilter];
[self _showContextBar];
}

View File

@@ -26,6 +26,6 @@
- (IBAction)toggleEdit:(id)sender;
/* Seperate call to ensure alle registered objects are in place */
- (void)setupNotifications:(NSWindowController *)windowController;
- (void)regsiterNotificationsForDocument:(NSDocument *)document;
@end

View File

@@ -107,8 +107,7 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
[self _updateBindings:nil];
}
- (void)setupNotifications:(NSWindowController *)windowController {
MPDocument *document = [windowController document];
- (void)regsiterNotificationsForDocument:(MPDocument *)document {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_didChangeCurrentItem:)
name:MPCurrentItemChangedNotification

View File

@@ -12,7 +12,7 @@ APPKIT_EXTERN NSString *const MPOutlineViewDidChangeGroupSelection;
@class MPOutlineViewDelegate;
@class HNHGradientView;
@class MPDocumentWindowController;
@class MPDocument;
@interface MPOutlineViewController : MPViewController <NSOutlineViewDelegate, NSMenuDelegate>
@@ -21,7 +21,7 @@ APPKIT_EXTERN NSString *const MPOutlineViewDidChangeGroupSelection;
- (void)clearSelection;
- (void)showOutline;
- (void)setupNotifications:(MPDocumentWindowController *)windowController;
- (void)regsiterNotificationsForDocument:(MPDocument *)document;
- (void)createGroup:(id)sender;
- (void)createEntry:(id)sender;

View File

@@ -136,7 +136,7 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
}
#pragma mark Notifications
- (void)setupNotifications:(MPDocumentWindowController *)windowController {
- (void)regsiterNotificationsForDocument:(MPDocument *)document {
// Nothing to do anymore
}

View File

@@ -22,10 +22,12 @@
#import <Foundation/Foundation.h>
@class MPDocumentWindowController;
@class MPDocument;
@interface MPToolbarDelegate : NSObject <NSToolbarDelegate>
@property (weak, readonly) NSSearchField *searchField;
- (void)regsiterNotificationsForDocument:(MPDocument *)document;
@end

View File

@@ -66,7 +66,6 @@ NSString *const MPToolbarItemSearch = @"TOOLBAR_SEARCH";
_toolbarImages = [self createToolbarImages];
_toolbarItems = [[NSMutableDictionary alloc] initWithCapacity:[self.toolbarIdentifiers count]];
_entryMenuDelegate = [[MPAddEntryContextMenuDelegate alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didExitSearch:) name:MPDocumentDidExitSearchNotification object:self];
}
return self;
}
@@ -187,6 +186,12 @@ NSString *const MPToolbarItemSearch = @"TOOLBAR_SEARCH";
return imageDict;
}
- (void)regsiterNotificationsForDocument:(MPDocument *)document {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didExitSearch:) name:MPDocumentDidExitSearchNotification object:document];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didExitSearch:) name:MPDocumentDidEnterSearchNotification object:document];
}
- (NSString *)_localizedLabelForToolbarItemIdentifier:(NSString *)identifier {
static NSDictionary *labelDict;
static dispatch_once_t onceToken;
@@ -220,6 +225,7 @@ NSString *const MPToolbarItemSearch = @"TOOLBAR_SEARCH";
- (void)_didExitSearch:(NSNotification *)notification {
[self.searchField setStringValue:@""];
[[self.searchField window] makeFirstResponder:nil];
}
@end