Refacoted window and view controller to use windowNibName and nibName. Fixes #164

This commit is contained in:
michael starke
2014-08-11 20:44:40 +02:00
parent 4cbb23bed5
commit 0ac4b6f440
23 changed files with 95 additions and 66 deletions

View File

@@ -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];
}

View File

@@ -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");

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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 {

View File

@@ -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];
}

View File

@@ -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];

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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];

View File

@@ -33,7 +33,7 @@
}
- (id)initWithDocument:(MPDocument *)document {
self = [super init];
self = [super initWithWindow:nil];
if(self){
_allowsEmptyPasswordOrKey = YES;
_showPassword = NO;

View File

@@ -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 {

View File

@@ -14,9 +14,8 @@
@implementation MPPreviewViewController
- (instancetype)init {
self = [self initWithNibName:@"PreviewView" bundle:nil];
return self;
- (NSString *)nibName {
return @"PreviewView";
}
@end

View File

@@ -19,11 +19,8 @@
@implementation MPSavePanelAccessoryViewController
- (id)init {
self = [super initWithNibName:@"SavePanelAccessoryView" bundle:nil];
if(self) {
}
return self;
- (NSString *)nibName {
return @"SavePanelAccessoryView";
}
- (void)didLoadView {

View File

@@ -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];

View File

@@ -14,9 +14,8 @@
@implementation MPUpdateSettingsController
- (instancetype)init {
self = [super initWithNibName:@"UpdateSettings" bundle:nil];
return self;
- (NSString *)nibName {
return @"UpdateSettings";
}
- (NSString *)identifier {

View File

@@ -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 {