From 6a3ef03707024a58f2d6dbdbbd23875386c9b043 Mon Sep 17 00:00:00 2001 From: michael starke Date: Mon, 20 Jul 2015 11:41:58 +0200 Subject: [PATCH] Renaming, moving functionality to KeePassKit where suitable --- KeePassKit | 2 +- MacPass/Base.lproj/DatabaseSettingsWindow.xib | 11 ++- MacPass/MPContextBarViewController.m | 5 +- MacPass/MPDatabaseSettingsWindowController.h | 6 +- MacPass/MPDatabaseSettingsWindowController.m | 16 ++--- MacPass/MPDocument.h | 11 --- MacPass/MPDocument.m | 69 ++++--------------- MacPass/MPEntryViewController.m | 3 +- MacPass/MPOutlineContextMenuDelegate.m | 4 +- MacPass/MPOutlineDataSource.m | 2 +- MacPass/MPOutlineViewController.m | 10 +-- 11 files changed, 42 insertions(+), 97 deletions(-) diff --git a/KeePassKit b/KeePassKit index 00cad2b1..ea2208e6 160000 --- a/KeePassKit +++ b/KeePassKit @@ -1 +1 @@ -Subproject commit 00cad2b169280d153067ea57e8dc09b93f568744 +Subproject commit ea2208e6f2b251e35efc3616d90ba94a22cd80e8 diff --git a/MacPass/Base.lproj/DatabaseSettingsWindow.xib b/MacPass/Base.lproj/DatabaseSettingsWindow.xib index 6898aedd..696a4d78 100644 --- a/MacPass/Base.lproj/DatabaseSettingsWindow.xib +++ b/MacPass/Base.lproj/DatabaseSettingsWindow.xib @@ -1,8 +1,7 @@ - + - - + @@ -13,8 +12,8 @@ - - + + @@ -26,7 +25,7 @@ - + diff --git a/MacPass/MPContextBarViewController.m b/MacPass/MPContextBarViewController.m index a66b0144..bdb0a0ad 100644 --- a/MacPass/MPContextBarViewController.m +++ b/MacPass/MPContextBarViewController.m @@ -8,6 +8,8 @@ #import "MPContextBarViewController.h" #import "KPKEntry.h" +#import "KPKTree.h" +#import "KPKMetaData.h" #import "MPDocument+HistoryBrowsing.h" #import "MPDocument+Search.h" @@ -117,7 +119,8 @@ typedef NS_ENUM(NSUInteger, MPContextTab) { - (void)_didChangeCurrentItem:(NSNotification *)notification { MPDocument *document = [notification object]; - BOOL showTrash = document.useTrash && (document.selectedGroup == document.trash || [document isItemTrashed:document.selectedItem]); + + BOOL showTrash = document.tree.metaData.useTrash && (document.selectedItem.isTrashed || document.selectedItem.isTrash); if(showTrash && ! document.hasSearch) { self.activeTab = MPContextTabTrash; [self _updateBindings]; diff --git a/MacPass/MPDatabaseSettingsWindowController.h b/MacPass/MPDatabaseSettingsWindowController.h index 7281a51b..6ad5ad40 100644 --- a/MacPass/MPDatabaseSettingsWindowController.h +++ b/MacPass/MPDatabaseSettingsWindowController.h @@ -38,9 +38,9 @@ typedef NS_ENUM(NSUInteger, MPDatabaseSettingsTab) { @property (weak) IBOutlet NSButton *benchmarkButton; /* Advanced Tab*/ -@property (weak) IBOutlet NSButton *enableRecycleBinCheckButton; -@property (weak) IBOutlet NSButton *emptyRecycleBinOnQuitCheckButton; -@property (weak) IBOutlet NSPopUpButton *selectRecycleBinGroupPopUpButton; +@property (weak) IBOutlet NSButton *enableTrashCheckButton; +@property (weak) IBOutlet NSButton *emptyTrashOnQuitCheckButton; +@property (weak) IBOutlet NSPopUpButton *selectTrashGoupPopUpButton; @property (weak) IBOutlet NSTextField *defaultUsernameTextField; @property (weak) IBOutlet NSPopUpButton *templateGroupPopUpButton; diff --git a/MacPass/MPDatabaseSettingsWindowController.m b/MacPass/MPDatabaseSettingsWindowController.m index 8b53b878..27e7287d 100644 --- a/MacPass/MPDatabaseSettingsWindowController.m +++ b/MacPass/MPDatabaseSettingsWindowController.m @@ -80,10 +80,10 @@ } /* Advanced */ - metaData.recycleBinEnabled = self.trashEnabled; - NSMenuItem *trashMenuItem = [self.selectRecycleBinGroupPopUpButton selectedItem]; + metaData.useTrash = self.trashEnabled; + NSMenuItem *trashMenuItem = [self.selectTrashGoupPopUpButton selectedItem]; KPKGroup *trashGroup = [trashMenuItem representedObject]; - ((MPDocument *)self.document).trash = trashGroup; + ((MPDocument *)self.document).tree.trash = trashGroup; NSMenuItem *templateMenuItem = [self.templateGroupPopUpButton selectedItem]; KPKGroup *templateGroup = [templateMenuItem representedObject]; @@ -202,9 +202,9 @@ - (void)_setupAdvancedTab:(KPKTree *)tree { /* TODO Do not use bindings, as the user should be able to cancel */ - [self bind:@"trashEnabled" toObject:tree.metaData withKeyPath:@"recycleBinEnabled" options:nil]; - [self.enableRecycleBinCheckButton bind:NSValueBinding toObject:self withKeyPath:@"trashEnabled" options:nil]; - [self.selectRecycleBinGroupPopUpButton bind:NSEnabledBinding toObject:self withKeyPath:@"trashEnabled" options:nil]; + [self bind:NSStringFromSelector(@selector(trashEnabled)) toObject:tree.metaData withKeyPath:NSStringFromSelector(@selector(trashEnabled)) options:nil]; + [self.enableTrashCheckButton bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(trashEnabled)) options:nil]; + [self.selectTrashGoupPopUpButton bind:NSEnabledBinding toObject:self withKeyPath:NSStringFromSelector(@selector(trashEnabled)) options:nil]; [self _updateTrashFolders:tree]; [self.defaultUsernameTextField setStringValue:tree.metaData.defaultUserName]; @@ -253,7 +253,7 @@ - (void)_updateTrashFolders:(KPKTree *)tree { NSMenu *menu = [self _buildTrashTreeMenu:tree]; - [self.selectRecycleBinGroupPopUpButton setMenu:menu]; + [self.selectTrashGoupPopUpButton setMenu:menu]; } - (void)_updateTemplateGroup:(KPKTree *)tree { @@ -262,7 +262,7 @@ } - (NSMenu *)_buildTrashTreeMenu:(KPKTree *)tree { - NSMenu *menu = [self _buildTreeMenu:tree preselect:tree.metaData.recycleBinUuid]; + NSMenu *menu = [self _buildTreeMenu:tree preselect:tree.metaData.trashUuid]; NSMenuItem *selectItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"AUTOCREATE_TRASH_FOLDER", @"Menu item for automatic trash creation") action:NULL diff --git a/MacPass/MPDocument.h b/MacPass/MPDocument.h index dd373135..775bcfb6 100644 --- a/MacPass/MPDocument.h +++ b/MacPass/MPDocument.h @@ -67,8 +67,6 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey; @property (strong, readonly, nonatomic) KPKTree *tree; @property (nonatomic, weak, readonly) KPKGroup *root; -@property (nonatomic, weak) KPKGroup *trash; -@property (nonatomic, readonly) BOOL useTrash; @property (nonatomic, weak) KPKGroup *templates; @property (nonatomic, strong, readonly) KPKCompositeKey *compositeKey; @@ -147,15 +145,6 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey; - (BOOL)shouldRecommendPasswordChange; - (BOOL)shouldEnforcePasswordChange; -/** - * Determines, whether the given item is inside the trash. - * The trash group itself is not considered as trashed. - * Hence when sending this message with the trash group as item, NO is returned - * @param item Item to test if trashed or not - * @return YES, if the item is inside the trash, NO otherwise (and if item is trash group) - */ -- (BOOL)isItemTrashed:(id)item; - - (void)writeXMLToURL:(NSURL *)url; - (void)readXMLfromURL:(NSURL *)url; diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index 18b220a3..94fac1e6 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -364,15 +364,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey } - (KPKGroup *)trash { - /* Caching is dangerous, as we might have deleted the trashcan */ - if(self.useTrash) { - return [self findGroup:self.tree.metaData.recycleBinUuid]; - } - return nil; -} - -- (BOOL)useTrash { - return self.tree.metaData.recycleBinEnabled; + return self.tree.trash; } - (KPKGroup *)templates { @@ -384,14 +376,6 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey return self.searchContext != nil; } -- (void)setTrash:(KPKGroup *)trash { - if(self.useTrash) { - if(![self.tree.metaData.recycleBinUuid isEqual:trash.uuid]) { - self.tree.metaData.recycleBinUuid = trash.uuid; - } - } -} - - (void)setTemplates:(KPKGroup *)templates { if(![self.tree.metaData.entryTemplatesGroup isEqual:templates.uuid]) { self.tree.metaData.entryTemplatesGroup = templates.uuid; @@ -447,26 +431,6 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey return self.tree.allGroups; } -- (BOOL)isItemTrashed:(id)item { - BOOL validItem = [item isKindOfClass:[KPKEntry class]] || [item isKindOfClass:[KPKGroup class]]; - if(!item) { - return NO; - } - if(item == self.trash) { - return NO; // No need to look further as this is the trashcan - } - if(validItem) { - BOOL isTrashed = NO; - id parent = [item parent]; - while( parent && !isTrashed ) { - isTrashed = (parent == self.trash); - parent = [parent parent]; - } - return isTrashed; - } - return NO; -} - - (BOOL)shouldEnforcePasswordChange { KPKMetaData *metaData = self.tree.metaData; if(!metaData.enforceMasterKeyChange) { return NO; } @@ -484,12 +448,9 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey if(!parent) { return nil; // No parent } - if(parent == self.trash) { + if(parent.isTrash || parent.isTrashed) { return nil; // no new Groups in trash } - if([self isItemTrashed:parent]) { - return nil; - } KPKEntry *newEntry = [self.tree createEntry:parent]; newEntry.title = NSLocalizedString(@"DEFAULT_ENTRY_TITLE", @"Title for a newly created entry"); if([self.tree.metaData.defaultUserName length] > 0) { @@ -510,12 +471,9 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey if(!parent) { return nil; // no parent! } - if(parent == self.trash) { + if(parent.isTrash || parent.isTrashed) { return nil; // no new Groups in trash } - if([self isItemTrashed:parent]) { - return nil; - } KPKGroup *newGroup = [self.tree createGroup:parent]; newGroup.name = NSLocalizedString(@"DEFAULT_GROUP_NAME", @"Title for a newly created group"); newGroup.iconId = MPIconFolder; @@ -547,8 +505,8 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey if(!entry) { return; // Nothing to do; } - if(self.useTrash) { - if([self isItemTrashed:entry]) { + if(self.tree.metaData.useTrash) { + if(entry.isTrashed) { [self _presentTrashAlertForItem:entry]; return; } @@ -571,8 +529,8 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey if(!group) { return; // Nothing to do; } - if(self.useTrash) { - if([self isItemTrashed:group]) { + if(self.tree.metaData.useTrash) { + if(group.isTrashed) { [self _presentTrashAlertForItem:group]; return; } @@ -580,7 +538,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey [self _createTrashGroup]; } if(group == self.trash) { - return; //Groups is trash! + return; //Group is trash! } [group moveToGroup:self.trash atIndex:[self.trash.groups count]]; [[self undoManager] setActionName:NSLocalizedString(@"TRASH_GROUP", "Move Group to Trash")]; @@ -717,17 +675,18 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey switch([MPActionHelper typeForAction:[anItem action]]) { case MPActionAddGroup: valid &= (nil != targetGroup); - valid &= (self.trash != targetGroup); - valid &= ![self isItemTrashed:targetGroup]; + valid &= !targetGroup.isTrash; + valid &= !targetGroup.isTrashed; break; case MPActionAddEntry: valid &= (nil != targetGroup); - valid &= (self.trash != targetGroup); - valid &= ![self isItemTrashed:targetGroup]; + valid &= !targetGroup.isTrash; + valid &= !targetGroup.isTrashed; break; case MPActionDelete: valid &= (nil != targetNode); valid &= (self.trash != targetNode); + valid &= (targetNode != self.tree.root); //valid &= ![self isItemTrashed:targetNode]; break; case MPActionDuplicateEntry: @@ -798,7 +757,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey if(wasEnabled) { [self.undoManager enableUndoRegistration]; } - self.tree.metaData.recycleBinUuid = trash.uuid; + self.tree.metaData.trashUuid = trash.uuid; return trash; } diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index dde186d7..35c366ce 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -37,6 +37,7 @@ #import "KPKNode+IconImage.h" #import "KPKAttribute.h" #import "KPKTimeInfo.h" +#import "KPKTree.h" #import "KPKMetaData.h" #import "HNHTableHeaderCell.h" @@ -503,7 +504,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell"; - (void)_updateContextBar { MPDocument *document = [[self windowController] document]; if(!document.hasSearch) { - BOOL showTrash = document.useTrash && (document.selectedGroup == document.trash || [document isItemTrashed:document.selectedItem]); + BOOL showTrash = document.tree.metaData.useTrash && (document.selectedGroup.isTrash || document.selectedItem.isTrashed); if(showTrash) { [self _showContextBar]; } diff --git a/MacPass/MPOutlineContextMenuDelegate.m b/MacPass/MPOutlineContextMenuDelegate.m index fd780f5d..34c7f39d 100644 --- a/MacPass/MPOutlineContextMenuDelegate.m +++ b/MacPass/MPOutlineContextMenuDelegate.m @@ -62,13 +62,13 @@ NSString *const _MPOutlineMenuTemplate = @"Template"; if(group && document.root == group ) { } - if(group && document.trash == group) { + if(group.isTrash) { [self _updateTrashMenu:menu]; } else if( group && document.templates == group) { [self _updateTemplateMenu:menu]; } - else if([document isItemTrashed:group]) { + else if(group.isTrashed) { [self _updateTrashItemMenu:menu]; } else { diff --git a/MacPass/MPOutlineDataSource.m b/MacPass/MPOutlineDataSource.m index 4fcd40be..770d74e2 100644 --- a/MacPass/MPOutlineDataSource.m +++ b/MacPass/MPOutlineDataSource.m @@ -99,7 +99,7 @@ validTarget &= index != NSOutlineViewDropOnItemIndex; validTarget &= index != [self.localDraggedGroup.parent.groups indexOfObject:self.localDraggedGroup]; } - BOOL isAnchesor = [self.localDraggedGroup isAnchestorOfGroup:targetGroup]; + BOOL isAnchesor = [self.localDraggedGroup isAnchestorOf:targetGroup]; validTarget &= !isAnchesor; } else { diff --git a/MacPass/MPOutlineViewController.m b/MacPass/MPOutlineViewController.m index 0eb8011c..be4a2cc0 100644 --- a/MacPass/MPOutlineViewController.m +++ b/MacPass/MPOutlineViewController.m @@ -279,14 +279,8 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; if(![document validateUserInterfaceItem:menuItem]) { return NO; } - id selected = [[self currentTargetNode] asGroup]; - if(!selected) { - return NO; - } - if(selected == document.trash) { - return NO; - } - return ![document isItemTrashed:selected]; + KPKGroup *group = [[self currentTargetNode] asGroup]; + return group.isTrash && group.isTrashed; } - (NSMenu *)_contextMenu {