Renaming, moving functionality to KeePassKit where suitable

This commit is contained in:
michael starke
2015-07-20 11:41:58 +02:00
parent 0cb398394a
commit 6a3ef03707
11 changed files with 42 additions and 97 deletions

View File

@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6254" systemVersion="13F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7706" systemVersion="14E46" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies> <dependencies>
<deployment identifier="macosx"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7706"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6254"/>
</dependencies> </dependencies>
<objects> <objects>
<customObject id="-2" userLabel="File's Owner" customClass="MPDatabaseSettingsWindowController"> <customObject id="-2" userLabel="File's Owner" customClass="MPDatabaseSettingsWindowController">
@@ -13,8 +12,8 @@
<outlet property="databaseDescriptionTextView" destination="1531" id="1553"/> <outlet property="databaseDescriptionTextView" destination="1531" id="1553"/>
<outlet property="databaseNameTextField" destination="231" id="655"/> <outlet property="databaseNameTextField" destination="231" id="655"/>
<outlet property="defaultUsernameTextField" destination="1730" id="1819"/> <outlet property="defaultUsernameTextField" destination="1730" id="1819"/>
<outlet property="emptyRecycleBinOnQuitCheckButton" destination="539" id="689"/> <outlet property="emptyTrashOnQuitCheckButton" destination="539" id="pgQ-AP-HB2"/>
<outlet property="enableRecycleBinCheckButton" destination="535" id="815"/> <outlet property="enableTrashCheckButton" destination="535" id="UNd-h9-aw3"/>
<outlet property="encryptionRoundsTextField" destination="1647" id="1773"/> <outlet property="encryptionRoundsTextField" destination="1647" id="1773"/>
<outlet property="enforceKeyChangeCheckButton" destination="upv-b3-vCc" id="JjM-CX-15q"/> <outlet property="enforceKeyChangeCheckButton" destination="upv-b3-vCc" id="JjM-CX-15q"/>
<outlet property="enforceKeyChangeIntervalTextField" destination="VYh-cm-fix" id="aqu-Dm-tlH"/> <outlet property="enforceKeyChangeIntervalTextField" destination="VYh-cm-fix" id="aqu-Dm-tlH"/>
@@ -26,7 +25,7 @@
<outlet property="recommendKeyChangeCheckButton" destination="Hqc-B0-xyz" id="3CK-D7-b8S"/> <outlet property="recommendKeyChangeCheckButton" destination="Hqc-B0-xyz" id="3CK-D7-b8S"/>
<outlet property="recommendKeyChangeIntervalTextField" destination="19r-LE-7X5" id="c5C-1h-LpD"/> <outlet property="recommendKeyChangeIntervalTextField" destination="19r-LE-7X5" id="c5C-1h-LpD"/>
<outlet property="sectionTabView" destination="357" id="699"/> <outlet property="sectionTabView" destination="357" id="699"/>
<outlet property="selectRecycleBinGroupPopUpButton" destination="678" id="690"/> <outlet property="selectTrashGoupPopUpButton" destination="678" id="MmE-QI-reD"/>
<outlet property="templateGroupPopUpButton" destination="1738" id="1796"/> <outlet property="templateGroupPopUpButton" destination="1738" id="1796"/>
<outlet property="window" destination="1" id="265"/> <outlet property="window" destination="1" id="265"/>
</connections> </connections>

View File

@@ -8,6 +8,8 @@
#import "MPContextBarViewController.h" #import "MPContextBarViewController.h"
#import "KPKEntry.h" #import "KPKEntry.h"
#import "KPKTree.h"
#import "KPKMetaData.h"
#import "MPDocument+HistoryBrowsing.h" #import "MPDocument+HistoryBrowsing.h"
#import "MPDocument+Search.h" #import "MPDocument+Search.h"
@@ -117,7 +119,8 @@ typedef NS_ENUM(NSUInteger, MPContextTab) {
- (void)_didChangeCurrentItem:(NSNotification *)notification { - (void)_didChangeCurrentItem:(NSNotification *)notification {
MPDocument *document = [notification object]; 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) { if(showTrash && ! document.hasSearch) {
self.activeTab = MPContextTabTrash; self.activeTab = MPContextTabTrash;
[self _updateBindings]; [self _updateBindings];

View File

@@ -38,9 +38,9 @@ typedef NS_ENUM(NSUInteger, MPDatabaseSettingsTab) {
@property (weak) IBOutlet NSButton *benchmarkButton; @property (weak) IBOutlet NSButton *benchmarkButton;
/* Advanced Tab*/ /* Advanced Tab*/
@property (weak) IBOutlet NSButton *enableRecycleBinCheckButton; @property (weak) IBOutlet NSButton *enableTrashCheckButton;
@property (weak) IBOutlet NSButton *emptyRecycleBinOnQuitCheckButton; @property (weak) IBOutlet NSButton *emptyTrashOnQuitCheckButton;
@property (weak) IBOutlet NSPopUpButton *selectRecycleBinGroupPopUpButton; @property (weak) IBOutlet NSPopUpButton *selectTrashGoupPopUpButton;
@property (weak) IBOutlet NSTextField *defaultUsernameTextField; @property (weak) IBOutlet NSTextField *defaultUsernameTextField;
@property (weak) IBOutlet NSPopUpButton *templateGroupPopUpButton; @property (weak) IBOutlet NSPopUpButton *templateGroupPopUpButton;

View File

@@ -80,10 +80,10 @@
} }
/* Advanced */ /* Advanced */
metaData.recycleBinEnabled = self.trashEnabled; metaData.useTrash = self.trashEnabled;
NSMenuItem *trashMenuItem = [self.selectRecycleBinGroupPopUpButton selectedItem]; NSMenuItem *trashMenuItem = [self.selectTrashGoupPopUpButton selectedItem];
KPKGroup *trashGroup = [trashMenuItem representedObject]; KPKGroup *trashGroup = [trashMenuItem representedObject];
((MPDocument *)self.document).trash = trashGroup; ((MPDocument *)self.document).tree.trash = trashGroup;
NSMenuItem *templateMenuItem = [self.templateGroupPopUpButton selectedItem]; NSMenuItem *templateMenuItem = [self.templateGroupPopUpButton selectedItem];
KPKGroup *templateGroup = [templateMenuItem representedObject]; KPKGroup *templateGroup = [templateMenuItem representedObject];
@@ -202,9 +202,9 @@
- (void)_setupAdvancedTab:(KPKTree *)tree { - (void)_setupAdvancedTab:(KPKTree *)tree {
/* TODO Do not use bindings, as the user should be able to cancel */ /* TODO Do not use bindings, as the user should be able to cancel */
[self bind:@"trashEnabled" toObject:tree.metaData withKeyPath:@"recycleBinEnabled" options:nil]; [self bind:NSStringFromSelector(@selector(trashEnabled)) toObject:tree.metaData withKeyPath:NSStringFromSelector(@selector(trashEnabled)) options:nil];
[self.enableRecycleBinCheckButton bind:NSValueBinding toObject:self withKeyPath:@"trashEnabled" options:nil]; [self.enableTrashCheckButton bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(trashEnabled)) options:nil];
[self.selectRecycleBinGroupPopUpButton bind:NSEnabledBinding toObject:self withKeyPath:@"trashEnabled" options:nil]; [self.selectTrashGoupPopUpButton bind:NSEnabledBinding toObject:self withKeyPath:NSStringFromSelector(@selector(trashEnabled)) options:nil];
[self _updateTrashFolders:tree]; [self _updateTrashFolders:tree];
[self.defaultUsernameTextField setStringValue:tree.metaData.defaultUserName]; [self.defaultUsernameTextField setStringValue:tree.metaData.defaultUserName];
@@ -253,7 +253,7 @@
- (void)_updateTrashFolders:(KPKTree *)tree { - (void)_updateTrashFolders:(KPKTree *)tree {
NSMenu *menu = [self _buildTrashTreeMenu:tree]; NSMenu *menu = [self _buildTrashTreeMenu:tree];
[self.selectRecycleBinGroupPopUpButton setMenu:menu]; [self.selectTrashGoupPopUpButton setMenu:menu];
} }
- (void)_updateTemplateGroup:(KPKTree *)tree { - (void)_updateTemplateGroup:(KPKTree *)tree {
@@ -262,7 +262,7 @@
} }
- (NSMenu *)_buildTrashTreeMenu:(KPKTree *)tree { - (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") NSMenuItem *selectItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"AUTOCREATE_TRASH_FOLDER", @"Menu item for automatic trash creation")
action:NULL action:NULL

View File

@@ -67,8 +67,6 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
@property (strong, readonly, nonatomic) KPKTree *tree; @property (strong, readonly, nonatomic) KPKTree *tree;
@property (nonatomic, weak, readonly) KPKGroup *root; @property (nonatomic, weak, readonly) KPKGroup *root;
@property (nonatomic, weak) KPKGroup *trash;
@property (nonatomic, readonly) BOOL useTrash;
@property (nonatomic, weak) KPKGroup *templates; @property (nonatomic, weak) KPKGroup *templates;
@property (nonatomic, strong, readonly) KPKCompositeKey *compositeKey; @property (nonatomic, strong, readonly) KPKCompositeKey *compositeKey;
@@ -147,15 +145,6 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
- (BOOL)shouldRecommendPasswordChange; - (BOOL)shouldRecommendPasswordChange;
- (BOOL)shouldEnforcePasswordChange; - (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)writeXMLToURL:(NSURL *)url;
- (void)readXMLfromURL:(NSURL *)url; - (void)readXMLfromURL:(NSURL *)url;

View File

@@ -364,15 +364,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
} }
- (KPKGroup *)trash { - (KPKGroup *)trash {
/* Caching is dangerous, as we might have deleted the trashcan */ return self.tree.trash;
if(self.useTrash) {
return [self findGroup:self.tree.metaData.recycleBinUuid];
}
return nil;
}
- (BOOL)useTrash {
return self.tree.metaData.recycleBinEnabled;
} }
- (KPKGroup *)templates { - (KPKGroup *)templates {
@@ -384,14 +376,6 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
return self.searchContext != nil; 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 { - (void)setTemplates:(KPKGroup *)templates {
if(![self.tree.metaData.entryTemplatesGroup isEqual:templates.uuid]) { if(![self.tree.metaData.entryTemplatesGroup isEqual:templates.uuid]) {
self.tree.metaData.entryTemplatesGroup = templates.uuid; self.tree.metaData.entryTemplatesGroup = templates.uuid;
@@ -447,26 +431,6 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
return self.tree.allGroups; 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 { - (BOOL)shouldEnforcePasswordChange {
KPKMetaData *metaData = self.tree.metaData; KPKMetaData *metaData = self.tree.metaData;
if(!metaData.enforceMasterKeyChange) { return NO; } if(!metaData.enforceMasterKeyChange) { return NO; }
@@ -484,12 +448,9 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
if(!parent) { if(!parent) {
return nil; // No parent return nil; // No parent
} }
if(parent == self.trash) { if(parent.isTrash || parent.isTrashed) {
return nil; // no new Groups in trash return nil; // no new Groups in trash
} }
if([self isItemTrashed:parent]) {
return nil;
}
KPKEntry *newEntry = [self.tree createEntry:parent]; KPKEntry *newEntry = [self.tree createEntry:parent];
newEntry.title = NSLocalizedString(@"DEFAULT_ENTRY_TITLE", @"Title for a newly created entry"); newEntry.title = NSLocalizedString(@"DEFAULT_ENTRY_TITLE", @"Title for a newly created entry");
if([self.tree.metaData.defaultUserName length] > 0) { if([self.tree.metaData.defaultUserName length] > 0) {
@@ -510,12 +471,9 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
if(!parent) { if(!parent) {
return nil; // no parent! return nil; // no parent!
} }
if(parent == self.trash) { if(parent.isTrash || parent.isTrashed) {
return nil; // no new Groups in trash return nil; // no new Groups in trash
} }
if([self isItemTrashed:parent]) {
return nil;
}
KPKGroup *newGroup = [self.tree createGroup:parent]; KPKGroup *newGroup = [self.tree createGroup:parent];
newGroup.name = NSLocalizedString(@"DEFAULT_GROUP_NAME", @"Title for a newly created group"); newGroup.name = NSLocalizedString(@"DEFAULT_GROUP_NAME", @"Title for a newly created group");
newGroup.iconId = MPIconFolder; newGroup.iconId = MPIconFolder;
@@ -547,8 +505,8 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
if(!entry) { if(!entry) {
return; // Nothing to do; return; // Nothing to do;
} }
if(self.useTrash) { if(self.tree.metaData.useTrash) {
if([self isItemTrashed:entry]) { if(entry.isTrashed) {
[self _presentTrashAlertForItem:entry]; [self _presentTrashAlertForItem:entry];
return; return;
} }
@@ -571,8 +529,8 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
if(!group) { if(!group) {
return; // Nothing to do; return; // Nothing to do;
} }
if(self.useTrash) { if(self.tree.metaData.useTrash) {
if([self isItemTrashed:group]) { if(group.isTrashed) {
[self _presentTrashAlertForItem:group]; [self _presentTrashAlertForItem:group];
return; return;
} }
@@ -580,7 +538,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
[self _createTrashGroup]; [self _createTrashGroup];
} }
if(group == self.trash) { if(group == self.trash) {
return; //Groups is trash! return; //Group is trash!
} }
[group moveToGroup:self.trash atIndex:[self.trash.groups count]]; [group moveToGroup:self.trash atIndex:[self.trash.groups count]];
[[self undoManager] setActionName:NSLocalizedString(@"TRASH_GROUP", "Move Group to Trash")]; [[self undoManager] setActionName:NSLocalizedString(@"TRASH_GROUP", "Move Group to Trash")];
@@ -717,17 +675,18 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
switch([MPActionHelper typeForAction:[anItem action]]) { switch([MPActionHelper typeForAction:[anItem action]]) {
case MPActionAddGroup: case MPActionAddGroup:
valid &= (nil != targetGroup); valid &= (nil != targetGroup);
valid &= (self.trash != targetGroup); valid &= !targetGroup.isTrash;
valid &= ![self isItemTrashed:targetGroup]; valid &= !targetGroup.isTrashed;
break; break;
case MPActionAddEntry: case MPActionAddEntry:
valid &= (nil != targetGroup); valid &= (nil != targetGroup);
valid &= (self.trash != targetGroup); valid &= !targetGroup.isTrash;
valid &= ![self isItemTrashed:targetGroup]; valid &= !targetGroup.isTrashed;
break; break;
case MPActionDelete: case MPActionDelete:
valid &= (nil != targetNode); valid &= (nil != targetNode);
valid &= (self.trash != targetNode); valid &= (self.trash != targetNode);
valid &= (targetNode != self.tree.root);
//valid &= ![self isItemTrashed:targetNode]; //valid &= ![self isItemTrashed:targetNode];
break; break;
case MPActionDuplicateEntry: case MPActionDuplicateEntry:
@@ -798,7 +757,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
if(wasEnabled) { if(wasEnabled) {
[self.undoManager enableUndoRegistration]; [self.undoManager enableUndoRegistration];
} }
self.tree.metaData.recycleBinUuid = trash.uuid; self.tree.metaData.trashUuid = trash.uuid;
return trash; return trash;
} }

View File

@@ -37,6 +37,7 @@
#import "KPKNode+IconImage.h" #import "KPKNode+IconImage.h"
#import "KPKAttribute.h" #import "KPKAttribute.h"
#import "KPKTimeInfo.h" #import "KPKTimeInfo.h"
#import "KPKTree.h"
#import "KPKMetaData.h" #import "KPKMetaData.h"
#import "HNHTableHeaderCell.h" #import "HNHTableHeaderCell.h"
@@ -503,7 +504,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
- (void)_updateContextBar { - (void)_updateContextBar {
MPDocument *document = [[self windowController] document]; MPDocument *document = [[self windowController] document];
if(!document.hasSearch) { 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) { if(showTrash) {
[self _showContextBar]; [self _showContextBar];
} }

View File

@@ -62,13 +62,13 @@ NSString *const _MPOutlineMenuTemplate = @"Template";
if(group && document.root == group ) { if(group && document.root == group ) {
} }
if(group && document.trash == group) { if(group.isTrash) {
[self _updateTrashMenu:menu]; [self _updateTrashMenu:menu];
} }
else if( group && document.templates == group) { else if( group && document.templates == group) {
[self _updateTemplateMenu:menu]; [self _updateTemplateMenu:menu];
} }
else if([document isItemTrashed:group]) { else if(group.isTrashed) {
[self _updateTrashItemMenu:menu]; [self _updateTrashItemMenu:menu];
} }
else { else {

View File

@@ -99,7 +99,7 @@
validTarget &= index != NSOutlineViewDropOnItemIndex; validTarget &= index != NSOutlineViewDropOnItemIndex;
validTarget &= index != [self.localDraggedGroup.parent.groups indexOfObject:self.localDraggedGroup]; validTarget &= index != [self.localDraggedGroup.parent.groups indexOfObject:self.localDraggedGroup];
} }
BOOL isAnchesor = [self.localDraggedGroup isAnchestorOfGroup:targetGroup]; BOOL isAnchesor = [self.localDraggedGroup isAnchestorOf:targetGroup];
validTarget &= !isAnchesor; validTarget &= !isAnchesor;
} }
else { else {

View File

@@ -279,14 +279,8 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
if(![document validateUserInterfaceItem:menuItem]) { if(![document validateUserInterfaceItem:menuItem]) {
return NO; return NO;
} }
id selected = [[self currentTargetNode] asGroup]; KPKGroup *group = [[self currentTargetNode] asGroup];
if(!selected) { return group.isTrash && group.isTrashed;
return NO;
}
if(selected == document.trash) {
return NO;
}
return ![document isItemTrashed:selected];
} }
- (NSMenu *)_contextMenu { - (NSMenu *)_contextMenu {