mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 22:42:18 +00:00
Refactored Notification setup to use only the document as object
This commit is contained in:
@@ -31,7 +31,6 @@
|
|||||||
- (void)showPasswordInput;
|
- (void)showPasswordInput;
|
||||||
|
|
||||||
#pragma mark Actions
|
#pragma mark Actions
|
||||||
- (IBAction)performFindPanelAction:(id)sender;
|
|
||||||
- (IBAction)saveDocument:(id)sender;
|
- (IBAction)saveDocument:(id)sender;
|
||||||
|
|
||||||
- (IBAction)editPassword:(id)sender;
|
- (IBAction)editPassword:(id)sender;
|
||||||
|
|||||||
@@ -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(_didRevertDocument:) name:MPDocumentDidRevertNotifiation object:[self document]];
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showEntries) name:MPDocumentDidUnlockDatabaseNotification object:[self document]];
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showEntries) name:MPDocumentDidUnlockDatabaseNotification object:[self document]];
|
||||||
|
|
||||||
[_entryViewController setupNotifications:self];
|
MPDocument *document = [self document];
|
||||||
[_inspectorViewController setupNotifications:self];
|
|
||||||
[_outlineViewController setupNotifications:self];
|
[_entryViewController regsiterNotificationsForDocument:document];
|
||||||
|
[_inspectorViewController regsiterNotificationsForDocument:document];
|
||||||
|
[_outlineViewController regsiterNotificationsForDocument:document];
|
||||||
|
[_toolbarDelegate regsiterNotificationsForDocument:document];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -110,7 +113,6 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
|
|||||||
[inspectorView removeFromSuperview];
|
[inspectorView removeFromSuperview];
|
||||||
}
|
}
|
||||||
|
|
||||||
MPDocument *document = [self document];
|
|
||||||
if(document.encrypted) {
|
if(document.encrypted) {
|
||||||
[self showPasswordInput];
|
[self showPasswordInput];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ typedef NS_ENUM( NSUInteger, MPCopyContentTypeTag) {
|
|||||||
@class KPKEntry;
|
@class KPKEntry;
|
||||||
@class MPOutlineViewDelegate;
|
@class MPOutlineViewDelegate;
|
||||||
@class MPDocumentWindowController;
|
@class MPDocumentWindowController;
|
||||||
|
@class MPDocument;
|
||||||
|
|
||||||
@interface MPEntryViewController : MPViewController <NSTableViewDelegate, MPContextBarDelegate>
|
@interface MPEntryViewController : MPViewController <NSTableViewDelegate, MPContextBarDelegate>
|
||||||
|
|
||||||
@@ -33,7 +34,7 @@ typedef NS_ENUM( NSUInteger, MPCopyContentTypeTag) {
|
|||||||
@property (readonly, strong) NSArrayController *entryArrayController;
|
@property (readonly, strong) NSArrayController *entryArrayController;
|
||||||
|
|
||||||
/* Call this after alle viewcontroller are loaded */
|
/* Call this after alle viewcontroller are loaded */
|
||||||
- (void)setupNotifications:(MPDocumentWindowController *)windowController;
|
- (void)regsiterNotificationsForDocument:(MPDocument *)document;
|
||||||
|
|
||||||
/* Copy/Paste */
|
/* Copy/Paste */
|
||||||
- (void)copyUsername:(id)sender;
|
- (void)copyUsername:(id)sender;
|
||||||
|
|||||||
@@ -98,11 +98,6 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
|
|||||||
_dataSource.viewController = self;
|
_dataSource.viewController = self;
|
||||||
_menuDelegate = [[MPEntryContextMenuDelegate alloc] init];
|
_menuDelegate = [[MPEntryContextMenuDelegate alloc] init];
|
||||||
_contextBarViewController = [[MPContextBarViewController 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;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -196,12 +191,22 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
|
|||||||
return self.entryTable;
|
return self.entryTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setupNotifications:(MPDocumentWindowController *)windowController {
|
- (void)regsiterNotificationsForDocument:(MPDocument *)document {
|
||||||
MPDocument *document = [windowController document];
|
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
selector:@selector(_didChangeCurrentItem:)
|
selector:@selector(_didChangeCurrentItem:)
|
||||||
name:MPCurrentItemChangedNotification
|
name:MPCurrentItemChangedNotification
|
||||||
object:document];
|
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
|
#pragma mark NSTableViewDelgate
|
||||||
@@ -356,10 +361,6 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)showFilter:(NSNotification *)notification {
|
- (void)showFilter:(NSNotification *)notification {
|
||||||
MPDocument *currentDocument = [[self windowController] document];
|
|
||||||
if(notification && [notification object] != currentDocument) {
|
|
||||||
return; // Wrong document
|
|
||||||
}
|
|
||||||
[self.contextBarViewController showFilter];
|
[self.contextBarViewController showFilter];
|
||||||
[self _showContextBar];
|
[self _showContextBar];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,6 @@
|
|||||||
- (IBAction)toggleEdit:(id)sender;
|
- (IBAction)toggleEdit:(id)sender;
|
||||||
|
|
||||||
/* Seperate call to ensure alle registered objects are in place */
|
/* Seperate call to ensure alle registered objects are in place */
|
||||||
- (void)setupNotifications:(NSWindowController *)windowController;
|
- (void)regsiterNotificationsForDocument:(NSDocument *)document;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -107,8 +107,7 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
|||||||
[self _updateBindings:nil];
|
[self _updateBindings:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setupNotifications:(NSWindowController *)windowController {
|
- (void)regsiterNotificationsForDocument:(MPDocument *)document {
|
||||||
MPDocument *document = [windowController document];
|
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
selector:@selector(_didChangeCurrentItem:)
|
selector:@selector(_didChangeCurrentItem:)
|
||||||
name:MPCurrentItemChangedNotification
|
name:MPCurrentItemChangedNotification
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ APPKIT_EXTERN NSString *const MPOutlineViewDidChangeGroupSelection;
|
|||||||
|
|
||||||
@class MPOutlineViewDelegate;
|
@class MPOutlineViewDelegate;
|
||||||
@class HNHGradientView;
|
@class HNHGradientView;
|
||||||
@class MPDocumentWindowController;
|
@class MPDocument;
|
||||||
|
|
||||||
@interface MPOutlineViewController : MPViewController <NSOutlineViewDelegate, NSMenuDelegate>
|
@interface MPOutlineViewController : MPViewController <NSOutlineViewDelegate, NSMenuDelegate>
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ APPKIT_EXTERN NSString *const MPOutlineViewDidChangeGroupSelection;
|
|||||||
|
|
||||||
- (void)clearSelection;
|
- (void)clearSelection;
|
||||||
- (void)showOutline;
|
- (void)showOutline;
|
||||||
- (void)setupNotifications:(MPDocumentWindowController *)windowController;
|
- (void)regsiterNotificationsForDocument:(MPDocument *)document;
|
||||||
|
|
||||||
- (void)createGroup:(id)sender;
|
- (void)createGroup:(id)sender;
|
||||||
- (void)createEntry:(id)sender;
|
- (void)createEntry:(id)sender;
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark Notifications
|
#pragma mark Notifications
|
||||||
- (void)setupNotifications:(MPDocumentWindowController *)windowController {
|
- (void)regsiterNotificationsForDocument:(MPDocument *)document {
|
||||||
// Nothing to do anymore
|
// Nothing to do anymore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,10 +22,12 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
@class MPDocumentWindowController;
|
@class MPDocument;
|
||||||
|
|
||||||
@interface MPToolbarDelegate : NSObject <NSToolbarDelegate>
|
@interface MPToolbarDelegate : NSObject <NSToolbarDelegate>
|
||||||
|
|
||||||
@property (weak, readonly) NSSearchField *searchField;
|
@property (weak, readonly) NSSearchField *searchField;
|
||||||
|
|
||||||
|
- (void)regsiterNotificationsForDocument:(MPDocument *)document;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ NSString *const MPToolbarItemSearch = @"TOOLBAR_SEARCH";
|
|||||||
_toolbarImages = [self createToolbarImages];
|
_toolbarImages = [self createToolbarImages];
|
||||||
_toolbarItems = [[NSMutableDictionary alloc] initWithCapacity:[self.toolbarIdentifiers count]];
|
_toolbarItems = [[NSMutableDictionary alloc] initWithCapacity:[self.toolbarIdentifiers count]];
|
||||||
_entryMenuDelegate = [[MPAddEntryContextMenuDelegate alloc] init];
|
_entryMenuDelegate = [[MPAddEntryContextMenuDelegate alloc] init];
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didExitSearch:) name:MPDocumentDidExitSearchNotification object:self];
|
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -187,6 +186,12 @@ NSString *const MPToolbarItemSearch = @"TOOLBAR_SEARCH";
|
|||||||
return imageDict;
|
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 {
|
- (NSString *)_localizedLabelForToolbarItemIdentifier:(NSString *)identifier {
|
||||||
static NSDictionary *labelDict;
|
static NSDictionary *labelDict;
|
||||||
static dispatch_once_t onceToken;
|
static dispatch_once_t onceToken;
|
||||||
@@ -220,6 +225,7 @@ NSString *const MPToolbarItemSearch = @"TOOLBAR_SEARCH";
|
|||||||
|
|
||||||
- (void)_didExitSearch:(NSNotification *)notification {
|
- (void)_didExitSearch:(NSNotification *)notification {
|
||||||
[self.searchField setStringValue:@""];
|
[self.searchField setStringValue:@""];
|
||||||
|
[[self.searchField window] makeFirstResponder:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
Reference in New Issue
Block a user