Moving more stuff about context bar into the document away from the EntryViewController.

Some refactorings considering notification registration.
This commit is contained in:
michael starke
2014-02-26 21:17:35 +01:00
parent ff6b29d23c
commit 51bb22a9b7
16 changed files with 78 additions and 51 deletions

View File

@@ -159,6 +159,7 @@
4C68456D17BC227B00FCDBFC /* KPKWindowAssociation.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C68456C17BC227B00FCDBFC /* KPKWindowAssociation.m */; };
4C68456F17BC2A0700FCDBFC /* WelcomeWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C68456E17BC2A0700FCDBFC /* WelcomeWindow.xib */; };
4C69A73A16D589DF00EC1B1A /* HNHGradientView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C69A73916D589DF00EC1B1A /* HNHGradientView.m */; };
4C6B7C7D18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6B7C7C18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.m */; };
4C6BEA3117A88E6C00CF69A8 /* MPStripLineBreaksTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6BEA3017A88E6C00CF69A8 /* MPStripLineBreaksTransformer.m */; };
4C6C72C417C01E4200768849 /* NSMutableData+KeePassKit.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6C72C317C01E4200768849 /* NSMutableData+KeePassKit.m */; };
4C6D1D25178579570014C5A5 /* 48_FolderTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4C6D1D24178579570014C5A5 /* 48_FolderTemplate.pdf */; };
@@ -624,6 +625,8 @@
4C68456E17BC2A0700FCDBFC /* WelcomeWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = WelcomeWindow.xib; sourceTree = "<group>"; };
4C69A73816D589DF00EC1B1A /* HNHGradientView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HNHGradientView.h; sourceTree = "<group>"; };
4C69A73916D589DF00EC1B1A /* HNHGradientView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HNHGradientView.m; sourceTree = "<group>"; };
4C6B7C7B18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MPDocument+HistoryBrowsing.h"; sourceTree = "<group>"; };
4C6B7C7C18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MPDocument+HistoryBrowsing.m"; sourceTree = "<group>"; };
4C6BEA2F17A88E6C00CF69A8 /* MPStripLineBreaksTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPStripLineBreaksTransformer.h; sourceTree = "<group>"; };
4C6BEA3017A88E6C00CF69A8 /* MPStripLineBreaksTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPStripLineBreaksTransformer.m; sourceTree = "<group>"; };
4C6C72C217C01E4200768849 /* NSMutableData+KeePassKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSMutableData+KeePassKit.h"; sourceTree = "<group>"; };
@@ -1225,6 +1228,8 @@
4C1FA07A18231900003A3F8C /* MPDocument+Autotype.m */,
4C15B74418BCA3B1003F8008 /* MPDocument+Search.h */,
4C15B74518BCA3B1003F8008 /* MPDocument+Search.m */,
4C6B7C7B18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.h */,
4C6B7C7C18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.m */,
);
name = Model;
sourceTree = "<group>";
@@ -2093,6 +2098,7 @@
4CAD747F15B887FD00104512 /* DDXMLNode.m in Sources */,
4C37A84015B8B474005EF8EE /* MPOutlineDataSource.m in Sources */,
4CA0B2F915BCAF6700654E32 /* MPGeneralSettingsController.m in Sources */,
4C6B7C7D18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.m in Sources */,
4CA0B2FC15BCAF8600654E32 /* MPSettingsWindowController.m in Sources */,
4C83814215BF4677001AE468 /* MPDocumentWindowController.m in Sources */,
4C2E382316D1421B00037A9D /* MPIconHelper.m in Sources */,

View File

@@ -9,25 +9,16 @@
#import "MPViewController.h"
#import "MPDocument+Search.h"
@protocol MPContextBarDelegate <NSObject>
@optional
- (void)contextBarDidChangeFilter;
- (void)contextBarDidExitFilter;
- (void)contextBarDidExitHistory;
- (void)contextBarShouldEmptyTrash;
@end
@class HNHGradientView;
@class MPDocument;
@interface MPContextBarViewController : MPViewController
@property (nonatomic, readonly) BOOL hasFilter;
@property (nonatomic, weak) id<MPContextBarDelegate> delegate;
@property (weak) NSView *nextKeyView;
- (void)registerNotificationsForDocument:(MPDocument *)document;
- (IBAction)toggleFilterSpace:(id)sender;
- (IBAction)exitFilter:(id)sender;
- (BOOL)showsFilter;
- (BOOL)showsHistory;

View File

@@ -59,10 +59,6 @@ typedef NS_ENUM(NSUInteger, MPContextTab) {
_delegateRespondsToDidExitHistory = NO;
_delegateRespondsToShouldEmptyTrash = NO;
_delegateRespondsToDidChangeFilter = NO;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_updateFilterButtons)
name:MPDocumentDidChangeSearchFlags
object:nil];
}
return self;
}
@@ -94,15 +90,6 @@ typedef NS_ENUM(NSUInteger, MPContextTab) {
}
#pragma mark Properties
- (void)setDelegate:(id<MPContextBarDelegate>)delegate {
if(self.delegate != delegate) {
_delegate = delegate;
_delegateRespondsToDidChangeFilter = [_delegate respondsToSelector:@selector(contextBarDidChangeFilter)];
_delegateRespondsToDidExitFilter = [_delegate respondsToSelector:@selector(contextBarDidExitFilter)];
_delegateRespondsToDidExitHistory = [_delegate respondsToSelector:@selector(contextBarDidExitHistory)];
_delegateRespondsToShouldEmptyTrash = [_delegate respondsToSelector:@selector(contextBarShouldEmptyTrash)];
}
}
- (void)showFilter {
/* Select text if already visible */
@@ -111,13 +98,11 @@ typedef NS_ENUM(NSUInteger, MPContextTab) {
}
- (void)showHistory {
[self exitFilter:self];
self.activeTab = MPContextTabHistory;
[self _updateBindings];
}
- (void)showTrash {
[self exitFilter:self];
self.activeTab = MPContextTabTrash;
[self _updateBindings];
}
@@ -134,6 +119,18 @@ typedef NS_ENUM(NSUInteger, MPContextTab) {
return self.activeTab == MPContextTabTrash;
}
- (void)registerNotificationsForDocument:(MPDocument *)document {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_updateFilterButtons)
name:MPDocumentDidChangeSearchFlags
object:document];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(showFilter)
name:MPDocumentDidEnterSearchNotification
object:document];
}
/*
- (BOOL)control:(NSControl*)control textView:(NSTextView*)textView doCommandBySelector:(SEL)commandSelector {
if(commandSelector == @selector(insertNewline:)) {
@@ -143,12 +140,6 @@ typedef NS_ENUM(NSUInteger, MPContextTab) {
}
*/
- (void)_didChangeFilter {
if(_delegateRespondsToDidChangeFilter) {
[self.delegate contextBarDidChangeFilter];
}
}
#pragma mark UI Helper
- (void)_updateBindings {
// only the entry view has to be bound, the rest not

View File

@@ -8,6 +8,12 @@
#import "MPDocument.h"
FOUNDATION_EXPORT NSString *const MPDocumentDidEnterHistoryNotification;
FOUNDATION_EXPORT NSString *const MPDocumentDidExitHistoryNotification;
@interface MPDocument (HistoryBrowsing)
- (IBAction)showHistory:(id)sender;
- (IBAction)exitHistory:(id)sender;
@end

View File

@@ -8,6 +8,18 @@
#import "MPDocument+HistoryBrowsing.h"
NSString *const MPDocumentDidEnterHistoryNotification = @"MPDocumentDidEnterHistoryNotification";
NSString *const MPDocumentDidExitHistoryNotification = @"MPDocumentDidExitHistoryNotification";
@implementation MPDocument (HistoryBrowsing)
- (void)showHistory:(id)sender {
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidEnterHistoryNotification object:self];
}
- (void)exitHistory:(id)sender {
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidExitHistoryNotification object:self];
}
@end

View File

@@ -22,15 +22,23 @@ NSString *const MPDocumentDidExitSearchNotification = @"com.hicknhack.macpass.
#pragma mark Actions
- (void)performFindPanelAction:(id)sender {
self.hasSearch = YES;
NSWindow *window = [[self windowControllers][0] window];
NSToolbar *toolbar = [window toolbar];
if(![toolbar isVisible]) {
[toolbar setVisible:YES];
}
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidEnterSearchNotification object:self];
}
- (void)updateSearch:(id)sender {
self.hasSearch = YES;
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidChangeSearchNotification object:self];
}
- (void)exitSearch:(id)sender {
self.searchString = nil;
self.hasSearch = NO;
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidExitSearchNotification object:self];
}

View File

@@ -29,6 +29,8 @@ APPKIT_EXTERN NSString *const MPDocumentDidRevertNotifiation;
APPKIT_EXTERN NSString *const MPDocumentDidLockDatabaseNotification;
APPKIT_EXTERN NSString *const MPDocumentDidUnlockDatabaseNotification;
FOUNDATION_EXTERN NSString *const MPDocumentCurrentItemChangedNotification;
APPKIT_EXTERN NSString *const MPDocumentEntryKey;
APPKIT_EXTERN NSString *const MPDocumentGroupKey;
@@ -77,6 +79,7 @@ typedef NS_OPTIONS(NSUInteger, MPEntrySearchFlags) {
*/
@property (nonatomic, assign) MPEntrySearchFlags activeFlags;
@property (nonatomic, copy) NSString *searchString;
@property (nonatomic, assign) BOOL hasSearch;
+ (KPKVersion)versionForFileType:(NSString *)fileType;

View File

@@ -48,6 +48,8 @@ NSString *const MPDocumentDidRevertNotifiation = @"com.hicknhack.macp
NSString *const MPDocumentDidLockDatabaseNotification = @"com.hicknhack.macpass.MPDocumentDidLockDatabaseNotification";
NSString *const MPDocumentDidUnlockDatabaseNotification = @"com.hicknhack.macpass.MPDocumentDidUnlockDatabaseNotification";
NSString *const MPDocumentCurrentItemChangedNotification = @"com.hicknhack.macpass.MPDocumentCurrentItemChangedNotification";
NSString *const MPDocumentEntryKey = @"MPDocumentEntryKey";
NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
@@ -112,6 +114,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
_didLockFile = NO;
_readOnly = NO;
_activeFlags = MPEntrySearchTitles;
_hasSearch = NO;
self.tree = [KPKTree templateTree];
}
return self;
@@ -350,7 +353,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
- (void)setSelectedItem:(id)selectedItem {
if(_selectedItem != selectedItem) {
_selectedItem = selectedItem;
[[NSNotificationCenter defaultCenter] postNotificationName:MPCurrentItemChangedNotification object:self];
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentCurrentItemChangedNotification object:self];
}
}
- (void)setTree:(KPKTree *)tree {

View File

@@ -86,13 +86,13 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
[_entryViewController regsiterNotificationsForDocument:document];
[_inspectorViewController regsiterNotificationsForDocument:document];
[_outlineViewController regsiterNotificationsForDocument:document];
[_toolbarDelegate regsiterNotificationsForDocument:document];
[_toolbarDelegate registerNotificationsForDocument:document];
_toolbar = [[NSToolbar alloc] initWithIdentifier:@"MainWindowToolbar"];
[_toolbar setAutosavesConfiguration:YES];
[self.toolbar setAllowsUserCustomization:YES];
[self.toolbar setAllowsUserCustomization:NO];
[self.toolbar setDelegate:self.toolbarDelegate];
[self.window setToolbar:self.toolbar];

View File

@@ -28,7 +28,7 @@ typedef NS_ENUM( NSUInteger, MPCopyContentTypeTag) {
@class MPDocumentWindowController;
@class MPDocument;
@interface MPEntryViewController : MPViewController <NSTableViewDelegate, MPContextBarDelegate>
@interface MPEntryViewController : MPViewController <NSTableViewDelegate>
@property (weak,readonly) NSTableView *entryTable;
@property (readonly, strong) NSArrayController *entryArrayController;

View File

@@ -194,7 +194,7 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
- (void)regsiterNotificationsForDocument:(MPDocument *)document {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_didChangeCurrentItem:)
name:MPCurrentItemChangedNotification
name:MPDocumentCurrentItemChangedNotification
object:document];
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -207,6 +207,11 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
object:document];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_updateContextBar)
name:MPDocumentDidExitSearchNotification
object:document];
}
#pragma mark NSTableViewDelgate
@@ -309,7 +314,7 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
if(document.selectedItem == document.selectedGroup) {
/* If we change to a group selection, we should clear the filter */
if(_isDisplayingContextBar) {
[self.contextBarViewController exitFilter:self];
[document exitSearch:self];
}
else if([[self.entryArrayController content] count] > 0) {
KPKEntry *entry = [[self.entryArrayController content] lastObject];
@@ -365,10 +370,6 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
[self _showContextBar];
}
- (void)clearFilter:(id)sender {
[self.contextBarViewController exitFilter:sender];
}
#pragma mark ContextBar
- (void)_showTrashBar {
[self.contextBarViewController showTrash];
@@ -377,7 +378,7 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
- (void)_updateContextBar {
MPDocument *document = [[self windowController] document];
if(![self.contextBarViewController hasFilter]) {
if(!document.hasSearch) {
BOOL showTrash = document.useTrash && (document.selectedGroup == document.trash || [document isItemTrashed:document.selectedItem]);
if(showTrash) {
[self _showTrashBar];

View File

@@ -110,7 +110,7 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
- (void)regsiterNotificationsForDocument:(MPDocument *)document {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_didChangeCurrentItem:)
name:MPCurrentItemChangedNotification
name:MPDocumentCurrentItemChangedNotification
object:document];
[_entryViewController setupBindings:document];
[_groupViewController setupBindings:document];

View File

@@ -12,6 +12,5 @@
#import <Foundation/Foundation.h>
FOUNDATION_EXPORT NSString *const MPDidActivateViewNotification;
FOUNDATION_EXPORT NSString *const MPCurrentItemChangedNotification;
#endif

View File

@@ -9,4 +9,3 @@
#import "MPNotifications.h"
NSString *const MPDidActivateViewNotification = @"com.hicknhack.macpass.MPDidBecomeFirstResonderNotification";
NSString *const MPCurrentItemChangedNotification = @"com.hicknhack.macpass.MPCurrentItemChangedNotification";

View File

@@ -28,6 +28,6 @@
@property (weak, readonly) NSSearchField *searchField;
- (void)regsiterNotificationsForDocument:(MPDocument *)document;
- (void)registerNotificationsForDocument:(MPDocument *)document;
@end

View File

@@ -187,9 +187,9 @@ NSString *const MPToolbarItemSearch = @"TOOLBAR_SEARCH";
}
- (void)regsiterNotificationsForDocument:(MPDocument *)document {
- (void)registerNotificationsForDocument:(MPDocument *)document {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didExitSearch:) name:MPDocumentDidExitSearchNotification object:document];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didExitSearch:) name:MPDocumentDidEnterSearchNotification object:document];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didEnterSearch:) name:MPDocumentDidEnterSearchNotification object:document];
}
- (NSString *)_localizedLabelForToolbarItemIdentifier:(NSString *)identifier {
@@ -223,9 +223,17 @@ NSString *const MPToolbarItemSearch = @"TOOLBAR_SEARCH";
return [MPActionHelper actionOfType:actionType];
}
- (void)_didEnterSearch:(NSNotification *)notification {
[[self.searchField window] makeFirstResponder:self.searchField];
}
- (void)_didExitSearch:(NSNotification *)notification {
[self.searchField setStringValue:@""];
[[self.searchField window] makeFirstResponder:nil];
NSWindow *window = [self.searchField window];
/* Resign first responder form search field only if it was the first responder */
if([window firstResponder] == self.searchField ) {
[window makeFirstResponder:nil];
}
}
@end