From 0ac4b6f4401a18e29aac37cac7f75a22a867ce03 Mon Sep 17 00:00:00 2001 From: michael starke Date: Mon, 11 Aug 2014 20:44:40 +0200 Subject: [PATCH] Refacoted window and view controller to use windowNibName and nibName. Fixes #164 --- MacPass/MPContextBarViewController.m | 9 ++++---- MacPass/MPDatabaseSettingsWindowController.m | 6 +++++- MacPass/MPDatePickingViewController.m | 5 ++--- MacPass/MPDocument.h | 2 +- MacPass/MPDocument.m | 4 ++-- MacPass/MPDocumentWindowController.m | 22 ++++++++++++++++---- MacPass/MPEntryInspectorViewController.m | 10 ++++----- MacPass/MPEntryViewController.m | 9 ++++---- MacPass/MPGeneralSettingsController.m | 4 ++-- MacPass/MPGroupInspectorViewController.m | 4 ++-- MacPass/MPIconSelectViewController.m | 5 ++--- MacPass/MPInspectorViewController.m | 4 ++-- MacPass/MPIntegrationSettingsController.m | 11 +++++----- MacPass/MPOutlineViewController.m | 16 +++++++++++--- MacPass/MPOverlayWindowController.m | 6 +++++- MacPass/MPPasswordCreatorViewController.m | 8 +++++-- MacPass/MPPasswordEditWindowController.m | 2 +- MacPass/MPPasswordInputController.m | 5 ++--- MacPass/MPPreviewViewController.m | 5 ++--- MacPass/MPSavePanelAccessoryViewController.m | 7 ++----- MacPass/MPSettingsWindowController.m | 6 +++++- MacPass/MPUpdateSettingsController.m | 5 ++--- MacPass/MPWorkflowSettingsController.m | 6 ++---- 23 files changed, 95 insertions(+), 66 deletions(-) diff --git a/MacPass/MPContextBarViewController.m b/MacPass/MPContextBarViewController.m index de694655..18896fef 100644 --- a/MacPass/MPContextBarViewController.m +++ b/MacPass/MPContextBarViewController.m @@ -44,12 +44,13 @@ typedef NS_ENUM(NSUInteger, MPContextTab) { @implementation MPContextBarViewController -#pragma mark Livecycle -- (instancetype)init { - self = [self initWithNibName:@"ContextBar" bundle:nil]; - return self; +#pragma mark Nib handling +- (NSString *)nibName { + return @"ContextBar"; } +#pragma mark Livecycle + - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } diff --git a/MacPass/MPDatabaseSettingsWindowController.m b/MacPass/MPDatabaseSettingsWindowController.m index ec8cedd4..4fa23742 100644 --- a/MacPass/MPDatabaseSettingsWindowController.m +++ b/MacPass/MPDatabaseSettingsWindowController.m @@ -37,13 +37,17 @@ @implementation MPDatabaseSettingsWindowController +- (NSString *)windowNibName { + return @"DatabaseSettingsWindow"; +} + - (id)init { self = [self initWithDocument:nil]; return self; } - (id)initWithDocument:(MPDocument *)document { - self = [super initWithWindowNibName:@"DatabaseSettingsWindow"]; + self = [super initWithWindow:nil]; if(self) { _document = document; _missingFeature = NSLocalizedString(@"KDBX_ONLY_FEATURE", "Feature only available in kdbx databases"); diff --git a/MacPass/MPDatePickingViewController.m b/MacPass/MPDatePickingViewController.m index 8199916b..76f45ddc 100644 --- a/MacPass/MPDatePickingViewController.m +++ b/MacPass/MPDatePickingViewController.m @@ -27,9 +27,8 @@ typedef NS_ENUM(NSUInteger, MPDatePreset) { @implementation MPDatePickingViewController -- (id)init { - self = [self initWithNibName:@"DatePickingView" bundle:nil]; - return self; +- (NSString *)nibName { + return @"DatePickingView"; } - (void)awakeFromNib { diff --git a/MacPass/MPDocument.h b/MacPass/MPDocument.h index 3df594f8..a1936d62 100644 --- a/MacPass/MPDocument.h +++ b/MacPass/MPDocument.h @@ -30,7 +30,7 @@ APPKIT_EXTERN NSString *const MPDocumentDidLockDatabaseNotification; APPKIT_EXTERN NSString *const MPDocumentDidUnlockDatabaseNotification; FOUNDATION_EXTERN NSString *const MPDocumentCurrentItemChangedNotification; -FOUNDATION_EXTERN NSString *const MPDocumentItemAddedNotification; +FOUNDATION_EXTERN NSString *const MPDocumentDidAddEntryNotification; APPKIT_EXTERN NSString *const MPDocumentEntryKey; APPKIT_EXTERN NSString *const MPDocumentGroupKey; diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index 50e36495..06733812 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -53,7 +53,7 @@ NSString *const MPDocumentDidLockDatabaseNotification = @"com.hicknhack.macp NSString *const MPDocumentDidUnlockDatabaseNotification = @"com.hicknhack.macpass.MPDocumentDidUnlockDatabaseNotification"; NSString *const MPDocumentCurrentItemChangedNotification = @"com.hicknhack.macpass.MPDocumentCurrentItemChangedNotification"; -NSString *const MPDocumentItemAddedNotification = @"com.hicknhack.macpass.MPDocumentItemAddedNotification"; +NSString *const MPDocumentDidAddEntryNotification = @"com.hicknhack.macpass.MPDocumentDidAddEntryNotification"; NSString *const MPDocumentEntryKey = @"MPDocumentEntryKey"; NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; @@ -454,7 +454,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey } [parent addEntry:newEntry]; [parent.undoManager setActionName:NSLocalizedString(@"ADD_ENTRY", "")]; - [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentItemAddedNotification object:self]; + [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidAddEntryNotification object:self]; return newEntry; } diff --git a/MacPass/MPDocumentWindowController.m b/MacPass/MPDocumentWindowController.m index 3dcfa8b3..86151cef 100644 --- a/MacPass/MPDocumentWindowController.m +++ b/MacPass/MPDocumentWindowController.m @@ -57,8 +57,12 @@ typedef void (^MPPasswordChangedBlock)(void); @implementation MPDocumentWindowController +- (NSString *)windowNibName { + return @"DocumentWindow"; +} + -(id)init { - self = [super initWithWindowNibName:@"DocumentWindow" owner:self]; + self = [super initWithWindow:nil]; if( self ) { _firstResponder = nil; _toolbarDelegate = [[MPToolbarDelegate alloc] init]; @@ -85,14 +89,14 @@ typedef void (^MPPasswordChangedBlock)(void); [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didRevertDocument:) name:MPDocumentDidRevertNotifiation object:document]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showEntries) name:MPDocumentDidUnlockDatabaseNotification object:document]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didAddEntry:) name:MPDocumentDidAddEntryNotification object:document]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didAddGroup:) name:MPDocumentDidAddGroupNotification object:document]; [self.entryViewController regsiterNotificationsForDocument:document]; [self.inspectorViewController regsiterNotificationsForDocument:document]; [self.outlineViewController regsiterNotificationsForDocument:document]; [self.toolbarDelegate registerNotificationsForDocument:document]; - - self.toolbar = [[NSToolbar alloc] initWithIdentifier:@"MainWindowToolbar"]; [self.toolbar setAutosavesConfiguration:YES]; [self.toolbar setAllowsUserCustomization:YES]; @@ -169,6 +173,14 @@ typedef void (^MPPasswordChangedBlock)(void); [self showPasswordInput]; } +- (void)_didAddEntry:(NSNotification *)notification { + [self showInspector:self]; +} + +- (void)_didAddGroup:(NSNotification *)notification { + [self showInspector:self]; +} + #pragma mark Actions - (void)saveDocument:(id)sender { self.passwordChangedBlock = nil; @@ -324,7 +336,9 @@ typedef void (^MPPasswordChangedBlock)(void); } - (void)showInspector:(id)sender { - // TODO; + if(![self _isInspectorVisible]) { + [self toggleInspector:sender]; + } } - (void)focusEntries:(id)sender { diff --git a/MacPass/MPEntryInspectorViewController.m b/MacPass/MPEntryInspectorViewController.m index 3568a944..d36cf951 100644 --- a/MacPass/MPEntryInspectorViewController.m +++ b/MacPass/MPEntryInspectorViewController.m @@ -61,8 +61,8 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { @implementation MPEntryInspectorViewController -- (id)init { - return [self initWithNibName:@"EntryInspectorView" bundle:nil]; +- (NSString *)nibName { + return @"EntryInspectorView"; } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { @@ -123,8 +123,8 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { - (void)regsiterNotificationsForDocument:(MPDocument *)document { [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(_didAddItem:) - name:MPDocumentItemAddedNotification + selector:@selector(_didAddEntry:) + name:MPDocumentDidAddEntryNotification object:document]; } @@ -434,7 +434,7 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { #pragma mark - #pragma mark MPDocument Notifications -- (void)_didAddItem:(NSNotification *)notification { +- (void)_didAddEntry:(NSNotification *)notification { [self.tabView selectTabViewItemAtIndex:MPEntryTabGeneral]; [self.titleTextField becomeFirstResponder]; } diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index d5e41e04..a207f05c 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -93,9 +93,8 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; @implementation MPEntryViewController - -- (id)init { - return [[MPEntryViewController alloc] initWithNibName:@"EntryView" bundle:nil]; +- (NSString *)nibName { + return @"EntryView"; } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { @@ -208,7 +207,7 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didAddItem:) - name:MPDocumentItemAddedNotification + name:MPDocumentDidAddEntryNotification object:document]; [[NSNotificationCenter defaultCenter] addObserver:self @@ -653,7 +652,7 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; NSTableColumn *column = [self.entryTable tableColumns][[self.entryTable clickedColumn]]; NSString *identifier = [column identifier]; if([identifier isEqualToString:MPEntryTableTitleColumnIdentifier]) { - + [[self windowController] showInspector:nil]; } else if([identifier isEqualToString:MPEntryTablePasswordColumnIdentifier]) { [self copyPassword:nil]; diff --git a/MacPass/MPGeneralSettingsController.m b/MacPass/MPGeneralSettingsController.m index 5e2d93b0..248d38d5 100644 --- a/MacPass/MPGeneralSettingsController.m +++ b/MacPass/MPGeneralSettingsController.m @@ -14,8 +14,8 @@ NSString *const MPGeneralSetingsIdentifier = @"GeneralSettingsTab"; @implementation MPGeneralSettingsController -- (id)init { - return [self initWithNibName:@"GeneralSettings" bundle:[NSBundle mainBundle]]; +- (NSString *)nibName { + return @"GeneralSettings"; } - (NSString *)identifier { diff --git a/MacPass/MPGroupInspectorViewController.m b/MacPass/MPGroupInspectorViewController.m index e07eca2e..289b02a7 100644 --- a/MacPass/MPGroupInspectorViewController.m +++ b/MacPass/MPGroupInspectorViewController.m @@ -27,8 +27,8 @@ @implementation MPGroupInspectorViewController -- (id)init { - return [self initWithNibName:@"GroupInspectorView" bundle:nil]; +- (NSString *)nibName { + return @"GroupInspectorView"; } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { diff --git a/MacPass/MPIconSelectViewController.m b/MacPass/MPIconSelectViewController.m index f803885d..c96554c1 100644 --- a/MacPass/MPIconSelectViewController.m +++ b/MacPass/MPIconSelectViewController.m @@ -18,9 +18,8 @@ NSInteger const kMPDefaultIcon = -1; @implementation MPIconSelectViewController - -- (id)init { - return [self initWithNibName:@"IconSelection" bundle:nil]; +- (NSString *)nibName { + return @"IconSelection"; } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { diff --git a/MacPass/MPInspectorViewController.m b/MacPass/MPInspectorViewController.m index b16987b9..fbfc2ad0 100644 --- a/MacPass/MPInspectorViewController.m +++ b/MacPass/MPInspectorViewController.m @@ -56,8 +56,8 @@ typedef NS_ENUM(NSUInteger, MPContentTab) { @implementation MPInspectorViewController -- (id)init { - return [[MPInspectorViewController alloc] initWithNibName:@"InspectorView" bundle:nil]; +- (NSString *)nibName { + return @"InspectorView"; } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { diff --git a/MacPass/MPIntegrationSettingsController.m b/MacPass/MPIntegrationSettingsController.m index 07d5e006..2ca34d27 100644 --- a/MacPass/MPIntegrationSettingsController.m +++ b/MacPass/MPIntegrationSettingsController.m @@ -18,6 +18,10 @@ @implementation MPIntegrationSettingsController +- (NSString *)nibName { + return @"IntegrationSettings"; +} + - (NSString *)identifier { return @"Integration"; } @@ -30,11 +34,6 @@ return NSLocalizedString(@"INTEGRATION_SETTINGS", ""); } -- (id)init { - self = [super initWithNibName:@"IntegrationSettings" bundle:nil]; - return self; -} - - (void)awakeFromNib { NSUserDefaultsController *defaultsController = [NSUserDefaultsController sharedUserDefaultsController]; NSString *serverKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyEnableHttpServer]; @@ -46,7 +45,7 @@ [self.enableGlobalAutotypeCheckbutton bind:NSValueBinding toObject:defaultsController withKeyPath:globalAutotypeKeyPath options:nil]; [self.enableQuicklookCheckbutton bind:NSValueBinding toObject:defaultsController withKeyPath:quicklookKeyPath options:nil]; [self.globalAutotypeKeyData bind:NSValueBinding toObject:defaultsController withKeyPath:globalAutotypeDataKeyPath options:nil]; - + } @end diff --git a/MacPass/MPOutlineViewController.m b/MacPass/MPOutlineViewController.m index 60f5547a..dfeaa984 100644 --- a/MacPass/MPOutlineViewController.m +++ b/MacPass/MPOutlineViewController.m @@ -48,8 +48,8 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; @implementation MPOutlineViewController -- (id)init { - return [[MPOutlineViewController alloc] initWithNibName:@"OutlineView" bundle:nil]; +- (NSString *)nibName { + return @"OutlineView"; } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { @@ -78,6 +78,7 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; [self.outlineView setFloatsGroupRows:NO]; [self.outlineView registerForDraggedTypes:@[ KPKGroupUTI, KPKEntryUTI ]]; [self.outlineView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES]; + [self.outlineView setDoubleAction:@selector(_doubleClickedGroup:)]; [self.bottomBar setBorderType:HNHBorderTop|HNHBorderHighlight]; [self.addGroupButton setAction:[MPActionHelper actionOfType:MPActionAddGroup]]; @@ -140,7 +141,7 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; #pragma mark Notifications - (void)regsiterNotificationsForDocument:(MPDocument *)document { - // Nothing to do anymore + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didAddGroup:) name:MPDocumentDidAddGroupNotification object:document]; } - (void)clearSelection { @@ -156,6 +157,11 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; document.selectedItem = document.selectedGroup; } +# pragma mark MPDocument Notifications +- (void)_didAddGroup:(NSNotification *)notification { + //TODO: find group to expand! +} + - (id)itemUnderMouse { NSPoint mouseLocation = [[self.outlineView window] mouseLocationOutsideOfEventStream]; NSPoint localPoint = [self.outlineView convertPoint:mouseLocation fromView:[[self.outlineView window] contentView]]; @@ -187,6 +193,10 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; [[[self windowController] document] deleteGroup:[self _clickedOrSelectedGroup]]; } +- (void)_doubleClickedGroup:(id)sender { + [[self windowController] showInspector:sender]; +} + #pragma mark NSOutlineViewDelegate - (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item { NSTableCellView *view; diff --git a/MacPass/MPOverlayWindowController.m b/MacPass/MPOverlayWindowController.m index 0badf80e..56526182 100644 --- a/MacPass/MPOverlayWindowController.m +++ b/MacPass/MPOverlayWindowController.m @@ -23,11 +23,15 @@ static MPOverlayWindowController *sharedInstance; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - sharedInstance = [[MPOverlayWindowController alloc] initWithWindowNibName:@"OverlayWindow"]; + sharedInstance = [[MPOverlayWindowController alloc] initWithWindow:nil]; }); return sharedInstance; } +- (NSString *)windowNibName { + return @"OverlayWindow"; +} + - (id)initWithWindow:(NSWindow *)window { self = [super initWithWindow:window]; if (self) { diff --git a/MacPass/MPPasswordCreatorViewController.m b/MacPass/MPPasswordCreatorViewController.m index 9a364656..567db5d5 100644 --- a/MacPass/MPPasswordCreatorViewController.m +++ b/MacPass/MPPasswordCreatorViewController.m @@ -62,8 +62,12 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) { @implementation MPPasswordCreatorViewController -- (id)init { - self = [super initWithNibName:@"PasswordCreatorView" bundle:nil]; +- (NSString *)nibName { + return @"PasswordCreatorView"; +} + +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { _password = @""; _passwordLength = [[NSUserDefaults standardUserDefaults] integerForKey:kMPSettingsKeyDefaultPasswordLength]; diff --git a/MacPass/MPPasswordEditWindowController.m b/MacPass/MPPasswordEditWindowController.m index 112c26a5..7c4dc1fc 100644 --- a/MacPass/MPPasswordEditWindowController.m +++ b/MacPass/MPPasswordEditWindowController.m @@ -33,7 +33,7 @@ } - (id)initWithDocument:(MPDocument *)document { - self = [super init]; + self = [super initWithWindow:nil]; if(self){ _allowsEmptyPasswordOrKey = YES; _showPassword = NO; diff --git a/MacPass/MPPasswordInputController.m b/MacPass/MPPasswordInputController.m index 0860cc45..6021fef0 100644 --- a/MacPass/MPPasswordInputController.m +++ b/MacPass/MPPasswordInputController.m @@ -34,9 +34,8 @@ @implementation MPPasswordInputController -- (id)init { - self = [self initWithNibName:@"PasswordInputView" bundle:nil]; - return self; +- (NSString *)nibName { + return @"PasswordInputView"; } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { diff --git a/MacPass/MPPreviewViewController.m b/MacPass/MPPreviewViewController.m index fc9cfcad..1528ae9e 100644 --- a/MacPass/MPPreviewViewController.m +++ b/MacPass/MPPreviewViewController.m @@ -14,9 +14,8 @@ @implementation MPPreviewViewController -- (instancetype)init { - self = [self initWithNibName:@"PreviewView" bundle:nil]; - return self; +- (NSString *)nibName { + return @"PreviewView"; } @end diff --git a/MacPass/MPSavePanelAccessoryViewController.m b/MacPass/MPSavePanelAccessoryViewController.m index 6ef50707..6ae0f16e 100644 --- a/MacPass/MPSavePanelAccessoryViewController.m +++ b/MacPass/MPSavePanelAccessoryViewController.m @@ -19,11 +19,8 @@ @implementation MPSavePanelAccessoryViewController -- (id)init { - self = [super initWithNibName:@"SavePanelAccessoryView" bundle:nil]; - if(self) { - } - return self; +- (NSString *)nibName { + return @"SavePanelAccessoryView"; } - (void)didLoadView { diff --git a/MacPass/MPSettingsWindowController.m b/MacPass/MPSettingsWindowController.m index 35cfa2c1..db26d8e0 100644 --- a/MacPass/MPSettingsWindowController.m +++ b/MacPass/MPSettingsWindowController.m @@ -25,8 +25,12 @@ @implementation MPSettingsWindowController +- (NSString *)windowNibName { + return @"SettingsWindow"; +} + -(id)init { - self = [super initWithWindowNibName:@"SettingsWindow"]; + self = [super initWithWindow:nil]; if(self) { _toolbar = [[NSToolbar alloc] initWithIdentifier:@"SettingsToolBar"]; [self.toolbar setAllowsUserCustomization:NO]; diff --git a/MacPass/MPUpdateSettingsController.m b/MacPass/MPUpdateSettingsController.m index a72f0164..ac27aa36 100644 --- a/MacPass/MPUpdateSettingsController.m +++ b/MacPass/MPUpdateSettingsController.m @@ -14,9 +14,8 @@ @implementation MPUpdateSettingsController -- (instancetype)init { - self = [super initWithNibName:@"UpdateSettings" bundle:nil]; - return self; +- (NSString *)nibName { + return @"UpdateSettings"; } - (NSString *)identifier { diff --git a/MacPass/MPWorkflowSettingsController.m b/MacPass/MPWorkflowSettingsController.m index a91e3041..5a15d14f 100644 --- a/MacPass/MPWorkflowSettingsController.m +++ b/MacPass/MPWorkflowSettingsController.m @@ -16,10 +16,8 @@ @implementation MPWorkflowSettingsController -#pragma mark LifeCycle -- (id)init { - self = [self initWithNibName:@"WorkflowSettings" bundle:nil]; - return self; +- (NSString *)nibName { + return @"WorkflowSettings"; } - (void)didLoadView {