Removed unnecessary document property on custom window controllers

This commit is contained in:
michael starke
2015-06-03 11:17:12 +02:00
parent 1e7d24d4ff
commit 0be2b677b8
5 changed files with 17 additions and 30 deletions

View File

@@ -49,8 +49,6 @@ typedef NS_ENUM(NSUInteger, MPDatabaseSettingsTab) {
@property (weak) IBOutlet NSTextField *recommendKeyChangeIntervalTextField; @property (weak) IBOutlet NSTextField *recommendKeyChangeIntervalTextField;
@property (weak) IBOutlet NSTextField *enforceKeyChangeIntervalTextField; @property (weak) IBOutlet NSTextField *enforceKeyChangeIntervalTextField;
- (id)initWithDocument:(MPDocument *)document;
- (void)showSettingsTab:(MPDatabaseSettingsTab)tab; - (void)showSettingsTab:(MPDatabaseSettingsTab)tab;
@end @end

View File

@@ -32,7 +32,6 @@
NSString *_missingFeature; NSString *_missingFeature;
} }
@property (nonatomic, weak) MPDocument *document;
@property (nonatomic,assign) BOOL trashEnabled; @property (nonatomic,assign) BOOL trashEnabled;
@end @end
@@ -43,15 +42,9 @@
return @"DatabaseSettingsWindow"; return @"DatabaseSettingsWindow";
} }
- (id)init { - (id)initWithWindow:(NSWindow *)window {
self = [self initWithDocument:nil]; self = [super initWithWindow:window];
return self;
}
- (id)initWithDocument:(MPDocument *)document {
self = [super initWithWindow:nil];
if(self) { if(self) {
self.document = document;
_missingFeature = NSLocalizedString(@"KDBX_ONLY_FEATURE", "Feature only available in kdbx databases"); _missingFeature = NSLocalizedString(@"KDBX_ONLY_FEATURE", "Feature only available in kdbx databases");
} }
return self; return self;
@@ -70,7 +63,7 @@
- (IBAction)save:(id)sender { - (IBAction)save:(id)sender {
/* General */ /* General */
KPKMetaData *metaData = self.document.tree.metaData; KPKMetaData *metaData = ((MPDocument *)self.document).tree.metaData;
metaData.databaseDescription = [self.databaseDescriptionTextView string]; metaData.databaseDescription = [self.databaseDescriptionTextView string];
metaData.databaseName = [self.databaseNameTextField stringValue]; metaData.databaseName = [self.databaseNameTextField stringValue];
@@ -90,11 +83,11 @@
metaData.recycleBinEnabled = self.trashEnabled; metaData.recycleBinEnabled = self.trashEnabled;
NSMenuItem *trashMenuItem = [self.selectRecycleBinGroupPopUpButton selectedItem]; NSMenuItem *trashMenuItem = [self.selectRecycleBinGroupPopUpButton selectedItem];
KPKGroup *trashGroup = [trashMenuItem representedObject]; KPKGroup *trashGroup = [trashMenuItem representedObject];
self.document.trash = trashGroup; ((MPDocument *)self.document).trash = trashGroup;
NSMenuItem *templateMenuItem = [self.templateGroupPopUpButton selectedItem]; NSMenuItem *templateMenuItem = [self.templateGroupPopUpButton selectedItem];
KPKGroup *templateGroup = [templateMenuItem representedObject]; KPKGroup *templateGroup = [templateMenuItem representedObject];
self.document.templates = templateGroup; ((MPDocument *)self.document).templates = templateGroup;
BOOL enforceMasterKeyChange = HNHBoolForState([self.enforceKeyChangeCheckButton state]); BOOL enforceMasterKeyChange = HNHBoolForState([self.enforceKeyChangeCheckButton state]);
@@ -152,10 +145,10 @@
return; return;
} }
/* Update all stuff that might have changed */ /* Update all stuff that might have changed */
KPKMetaData *metaData = self.document.tree.metaData; KPKMetaData *metaData = ((MPDocument *)self.document).tree.metaData;
[self _setupDatabaseTab:metaData]; [self _setupDatabaseTab:metaData];
[self _setupProtectionTab:metaData]; [self _setupProtectionTab:metaData];
[self _setupAdvancedTab:self.document.tree]; [self _setupAdvancedTab:((MPDocument *)self.document).tree];
self.isDirty = NO; self.isDirty = NO;
} }

View File

@@ -283,7 +283,7 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
if(!self.fixAutotypeWindowController) { if(!self.fixAutotypeWindowController) {
self.fixAutotypeWindowController = [[MPFixAutotypeWindowController alloc] init]; self.fixAutotypeWindowController = [[MPFixAutotypeWindowController alloc] init];
} }
self.fixAutotypeWindowController.workingDocument = [self document]; [self.document addWindowController:self.fixAutotypeWindowController];
[[self.fixAutotypeWindowController window] makeKeyAndOrderFront:sender]; [[self.fixAutotypeWindowController window] makeKeyAndOrderFront:sender];
} }
@@ -542,8 +542,9 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
- (void)_showDatabaseSetting:(MPDatabaseSettingsTab)tab { - (void)_showDatabaseSetting:(MPDatabaseSettingsTab)tab {
if(!self.documentSettingsWindowController) { if(!self.documentSettingsWindowController) {
_documentSettingsWindowController = [[MPDatabaseSettingsWindowController alloc] initWithDocument:[self document]]; _documentSettingsWindowController = [[MPDatabaseSettingsWindowController alloc] init];
} }
[self.document addWindowController:_documentSettingsWindowController];
[self.documentSettingsWindowController showSettingsTab:tab]; [self.documentSettingsWindowController showSettingsTab:tab];
[[NSApplication sharedApplication] beginSheet:[self.documentSettingsWindowController window] [[NSApplication sharedApplication] beginSheet:[self.documentSettingsWindowController window]
modalForWindow:[self window] modalForWindow:[self window]

View File

@@ -13,8 +13,6 @@
@interface MPFixAutotypeWindowController : NSWindowController <NSTableViewDataSource, NSTableViewDelegate> @interface MPFixAutotypeWindowController : NSWindowController <NSTableViewDataSource, NSTableViewDelegate>
@property (weak) IBOutlet NSTableView *tableView; @property (weak) IBOutlet NSTableView *tableView;
@property (nonatomic, weak) MPDocument *workingDocument;
/** /**
* Clears the autotype sequences for the selected entries, groups or window associations * Clears the autotype sequences for the selected entries, groups or window associations
* *

View File

@@ -65,13 +65,10 @@ NSString *const kMPIconCell = @"IconCell";
#pragma mark - #pragma mark -
#pragma mark Properties #pragma mark Properties
- (void)setDocument:(id)document {
- (void)setWorkingDocument:(MPDocument *)workingDocument { [super setDocument:document];
if(_workingDocument != workingDocument) {
_workingDocument = workingDocument;
}
if(!_didRegisterForUndoRedo) { if(!_didRegisterForUndoRedo) {
NSUndoManager *manager = [_workingDocument undoManager]; NSUndoManager *manager = [document undoManager];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didChangeDocument:) name:NSUndoManagerDidRedoChangeNotification object:manager]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didChangeDocument:) name:NSUndoManagerDidRedoChangeNotification object:manager];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didChangeDocument:) name:NSUndoManagerDidUndoChangeNotification object:manager]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didChangeDocument:) name:NSUndoManagerDidUndoChangeNotification object:manager];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didChangeDocument:) name:NSUndoManagerDidCloseUndoGroupNotification object:manager]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didChangeDocument:) name:NSUndoManagerDidCloseUndoGroupNotification object:manager];
@@ -84,7 +81,7 @@ NSString *const kMPIconCell = @"IconCell";
#pragma mark Actions #pragma mark Actions
- (void)clearAutotype:(id)sender { - (void)clearAutotype:(id)sender {
[[self.workingDocument undoManager] beginUndoGrouping]; [[self.document undoManager] beginUndoGrouping];
NSIndexSet *indexes = [self.tableView selectedRowIndexes]; NSIndexSet *indexes = [self.tableView selectedRowIndexes];
MPFixAutotypeWindowController __weak *weakSelf = self; MPFixAutotypeWindowController __weak *weakSelf = self;
[indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) { [indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
@@ -99,8 +96,8 @@ NSString *const kMPIconCell = @"IconCell";
[item setKeystrokeSequence:nil]; [item setKeystrokeSequence:nil];
} }
}]; }];
[[self.workingDocument undoManager] endUndoGrouping]; [[self.document undoManager] endUndoGrouping];
[[self.workingDocument undoManager] setActionName:@"Clear Autotype"]; [[self.document undoManager] setActionName:@"Clear Autotype"];
[self.tableView reloadDataForRowIndexes:indexes columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,2)]]; [self.tableView reloadDataForRowIndexes:indexes columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,2)]];
} }
@@ -203,7 +200,7 @@ NSString *const kMPIconCell = @"IconCell";
- (NSArray *)entriesAndGroups { - (NSArray *)entriesAndGroups {
if(nil == _itemsCache) { if(nil == _itemsCache) {
_itemsCache = [self.workingDocument malformedAutotypeItems]; _itemsCache = [self.document malformedAutotypeItems];
} }
return _itemsCache; return _itemsCache;
} }