Moder Objective-C. Adoping changed KeePassKit API

Signed-off-by: michael starke <michael.starke@hicknhack-software.com>
This commit is contained in:
michael starke
2015-08-04 17:18:08 +02:00
parent fa4094ee01
commit 731384ca1e
11 changed files with 133 additions and 34 deletions

View File

@@ -256,6 +256,7 @@
4C80BB6F176DE06F00E5E248 /* HNHScrollDocumentViewAdapter.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C80BB6E176DE06F00E5E248 /* HNHScrollDocumentViewAdapter.m */; };
4C811C8316ECD06E00C4BAC6 /* MPKeyfilePathControlDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C811C8216ECD06E00C4BAC6 /* MPKeyfilePathControlDelegate.m */; };
4C83814215BF4677001AE468 /* MPDocumentWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C83814115BF4677001AE468 /* MPDocumentWindowController.m */; };
4C8775201B70CA4B00069609 /* KPKTestUndo.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C87751F1B70CA4B00069609 /* KPKTestUndo.m */; };
4C888C9016EB6C91003D34A1 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4C888C8E16EB6C91003D34A1 /* Localizable.strings */; };
4C888C9316EB6F5E003D34A1 /* MPToolbarItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C888C9216EB6F5E003D34A1 /* MPToolbarItem.m */; };
4C888C9716EB754B003D34A1 /* MPActionHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C888C9616EB754B003D34A1 /* MPActionHelper.m */; };
@@ -854,6 +855,7 @@
4C811C8216ECD06E00C4BAC6 /* MPKeyfilePathControlDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPKeyfilePathControlDelegate.m; sourceTree = "<group>"; };
4C83814015BF4677001AE468 /* MPDocumentWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPDocumentWindowController.h; sourceTree = "<group>"; };
4C83814115BF4677001AE468 /* MPDocumentWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDocumentWindowController.m; sourceTree = "<group>"; };
4C87751F1B70CA4B00069609 /* KPKTestUndo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KPKTestUndo.m; sourceTree = "<group>"; };
4C888C8F16EB6C91003D34A1 /* en */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; lineEnding = 0; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.simpleColoring; };
4C888C9116EB6F5E003D34A1 /* MPToolbarItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPToolbarItem.h; sourceTree = "<group>"; };
4C888C9216EB6F5E003D34A1 /* MPToolbarItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPToolbarItem.m; sourceTree = "<group>"; };
@@ -1602,6 +1604,7 @@
4C59745018B3CE7200C8EBD1 /* KPKTestAutotype.m */,
4C3F25201A3B0C95007DD98B /* KPKTextXMLUtilities.m */,
4C4B6E3D1B5E56600082EEF2 /* KPKTestEntryLookup.m */,
4C87751F1B70CA4B00069609 /* KPKTestUndo.m */,
);
name = KeePassKit;
sourceTree = "<group>";
@@ -2534,6 +2537,7 @@
4C19E503178E2871002F2CD0 /* MPDatabasePasswordAndKeyfile.m in Sources */,
4C305F3C179A19F90082334F /* KPKIconLoading.m in Sources */,
4C1842B8179B348600E2F5BC /* KPKTestLegacyLoading.m in Sources */,
4C8775201B70CA4B00069609 /* KPKTestUndo.m in Sources */,
4C6BC6601A36717E00BDDF3D /* MPDatabaseSearch.m in Sources */,
4CFC8743179DFD3E000DFC03 /* KPKTestXmlLoading.m in Sources */,
4C79E80617A9400500AC6CD2 /* KPKTestNSCoding.m in Sources */,

View File

@@ -253,12 +253,12 @@
- (void)_updateTrashFolders:(KPKTree *)tree {
NSMenu *menu = [self _buildTrashTreeMenu:tree];
[self.selectTrashGoupPopUpButton setMenu:menu];
self.selectTrashGoupPopUpButton.menu = menu;
}
- (void)_updateTemplateGroup:(KPKTree *)tree {
NSMenu *menu = [self _buildTemplateTreeMenu:tree];
[self.templateGroupPopUpButton setMenu:menu];
self.templateGroupPopUpButton.menu = menu;
}
- (NSMenu *)_buildTrashTreeMenu:(KPKTree *)tree {
@@ -267,7 +267,7 @@
NSMenuItem *selectItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"AUTOCREATE_TRASH_FOLDER", @"Menu item for automatic trash creation")
action:NULL
keyEquivalent:@""];
[selectItem setEnabled:YES];
selectItem.enabled = YES;
[menu insertItem:selectItem atIndex:0];
return menu;
@@ -279,7 +279,7 @@
NSMenuItem *selectItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"NO_TEMPLATE_GROUP", @"Menu item to reset the template groups")
action:NULL
keyEquivalent:@""];
[selectItem setEnabled:YES];
selectItem.enabled = YES;
[menu insertItem:selectItem atIndex:0];
return menu;
@@ -288,7 +288,7 @@
- (NSMenu *)_buildTreeMenu:(KPKTree *)tree preselect:(NSUUID *)uuid {
NSMenu *menu = [[NSMenu alloc] init];
[menu setAutoenablesItems:NO];
menu.autoenablesItems = NO;
for(KPKGroup *group in tree.root.groups) {
[self _insertMenuItemsForGroup:group atLevel:0 inMenu:menu preselect:uuid];
}
@@ -297,14 +297,14 @@
- (void)_insertMenuItemsForGroup:(KPKGroup *)group atLevel:(NSUInteger)level inMenu:(NSMenu *)menu preselect:(NSUUID *)uuid{
NSMenuItem *groupItem = [[NSMenuItem alloc] init];
[groupItem setImage:group.iconImage];
[groupItem setTitle:group.name];
[groupItem setRepresentedObject:group];
[groupItem setEnabled:YES];
groupItem.image = group.iconImage;
groupItem.title = group.title;
groupItem.representedObject = group;
groupItem.enabled = YES;
if(uuid && [group.uuid isEqual:uuid]) {
[groupItem setState:NSOnState];
groupItem.state = NSOnState;
}
[groupItem setIndentationLevel:level];
groupItem.indentationLevel = level;
[menu addItem:groupItem];
for(KPKGroup *childGroup in group.groups) {
[self _insertMenuItemsForGroup:childGroup atLevel:level + 1 inMenu:menu preselect:uuid];

View File

@@ -476,7 +476,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
return nil; // no new Groups in trash
}
KPKGroup *newGroup = [self.tree createGroup:parent];
newGroup.name = NSLocalizedString(@"DEFAULT_GROUP_NAME", @"Title for a newly created group");
newGroup.title = NSLocalizedString(@"DEFAULT_GROUP_NAME", @"Title for a newly created group");
newGroup.iconId = MPIconFolder;
[parent addGroup:newGroup];
NSDictionary *userInfo = @{ MPDocumentGroupKey : newGroup };
@@ -615,7 +615,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
if(entryUUID) {
KPKEntry *templateEntry = [self findEntry:entryUUID];
if(templateEntry && self.selectedGroup) {
KPKEntry *copy = [templateEntry copyWithTitle:templateEntry.title];
KPKEntry *copy = [templateEntry copyWithTitle:templateEntry.title options:kKPKCopyOptionNone];
[self.selectedGroup addEntry:copy];
[self.selectedGroup.undoManager setActionName:NSLocalizedString(@"ADD_TREMPLATE_ENTRY", "")];
}
@@ -623,7 +623,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
}
- (void)duplicateEntry:(id)sender {
KPKEntry *duplicate = [self.selectedEntry copyWithTitle:nil];
KPKEntry *duplicate = [self.selectedEntry copyWithTitle:nil options:kKPKCopyOptionNone];
[self.selectedEntry.parent addEntry:duplicate];
[self.undoManager setActionName:NSLocalizedString(@"DUPLICATE_ENTRY", "")];
}
@@ -751,7 +751,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
KPKGroup *trash = [self.tree createGroup:self.tree.root];
BOOL wasEnabled = [self.undoManager isUndoRegistrationEnabled];
[self.undoManager disableUndoRegistration];
trash.name = NSLocalizedString(@"TRASH", @"Name for the trash group");
trash.title = NSLocalizedString(@"TRASH", @"Name for the trash group");
trash.iconId = MPIconTrash;
[self.tree.root addGroup:trash];
if(wasEnabled) {

View File

@@ -169,12 +169,12 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
self.entryTable.autosaveTableColumns = YES;
NSString *parentNameKeyPath = [[NSString alloc] initWithFormat:@"%@.%@", NSStringFromSelector(@selector(parent)), NSStringFromSelector(@selector(name))];
NSString *parentTitleKeyPath = [[NSString alloc] initWithFormat:@"%@.%@", NSStringFromSelector(@selector(parent)), NSStringFromSelector(@selector(title))];
titleColumn.sortDescriptorPrototype = [NSSortDescriptor sortDescriptorWithKey:NSStringFromSelector(@selector(title))ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
userNameColumn.sortDescriptorPrototype = [NSSortDescriptor sortDescriptorWithKey:NSStringFromSelector(@selector(username)) ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
urlColumn.sortDescriptorPrototype = [NSSortDescriptor sortDescriptorWithKey:NSStringFromSelector(@selector(url)) ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
parentColumn.sortDescriptorPrototype = [NSSortDescriptor sortDescriptorWithKey:parentNameKeyPath ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
parentColumn.sortDescriptorPrototype = [NSSortDescriptor sortDescriptorWithKey:parentTitleKeyPath ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
modifiedColumn.sortDescriptorPrototype = [NSSortDescriptor sortDescriptorWithKey:[MPEntryViewController timeInfoModificationTimeKeyPath] ascending:YES selector:@selector(compare:)];
[parentColumn.headerCell setStringValue:NSLocalizedString(@"GROUP", "")];
@@ -276,15 +276,15 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
KPKEntry *entry = [self.entryArrayController arrangedObjects][row];
NSAssert(entry.parent != nil, @"Entry needs to have a parent");
NSString *parentNameKeyPath = [NSString stringWithFormat:@"%@.%@.%@",
NSString *parentTitleKeyPath = [NSString stringWithFormat:@"%@.%@.%@",
NSStringFromSelector(@selector(objectValue)),
NSStringFromSelector(@selector(parent)),
NSStringFromSelector(@selector(name))];
NSStringFromSelector(@selector(title))];
NSString *parentIconImageKeyPath = [NSString stringWithFormat:@"%@.%@.%@",
NSStringFromSelector(@selector(objectValue)),
NSStringFromSelector(@selector(parent)),
NSStringFromSelector(@selector(iconImage))];
[view.textField bind:NSValueBinding toObject:view withKeyPath:parentNameKeyPath options:nil];
[view.textField bind:NSValueBinding toObject:view withKeyPath:parentTitleKeyPath options:nil];
[view.imageView bind:NSValueBinding toObject:view withKeyPath:parentIconImageKeyPath options:nil];
}
}

View File

@@ -103,7 +103,7 @@
- (void)_updateBindings {
if(self.group) {
[self.titleTextField bind:NSValueBinding toObject:self.group withKeyPath:NSStringFromSelector(@selector(name)) options:nil];
[self.titleTextField bind:NSValueBinding toObject:self.group withKeyPath:NSStringFromSelector(@selector(title)) options:nil];
[self.expiresCheckButton bind:NSValueBinding toObject:self.group.timeInfo withKeyPath:NSStringFromSelector(@selector(expires)) options:nil];
[self.expiresCheckButton bind:NSTitleBinding toObject:self.group.timeInfo withKeyPath:NSStringFromSelector(@selector(expirationDate)) options:@{ NSValueTransformerNameBindingOption:MPExpiryDateValueTransformer }];
[self.autotypePopupButton bind:NSSelectedTagBinding toObject:self.group withKeyPath:NSStringFromSelector(@selector(isAutoTypeEnabled)) options:nil];

View File

@@ -285,12 +285,7 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
[self.itemImageView bind:NSValueBinding toObject:item withKeyPath:NSStringFromSelector(@selector(iconImage)) options:nil];
[[self.notesTextView enclosingScrollView] setHidden:NO];
[self.notesTextView bind:NSValueBinding toObject:item withKeyPath:NSStringFromSelector(@selector(notes)) options:nil];
if([item respondsToSelector:@selector(title)]) {
[self.itemNameTextField bind:NSValueBinding toObject:item withKeyPath:NSStringFromSelector(@selector(title)) options:nil];
}
else if( [item respondsToSelector:@selector(name)]) {
[self.itemNameTextField bind:NSValueBinding toObject:item withKeyPath:NSStringFromSelector(@selector(name)) options:nil];
}
[self.itemImageView setHidden:NO];
[self.itemNameTextField setHidden:NO];
}

View File

@@ -143,7 +143,7 @@
KPKGroup *targetGroup = (KPKGroup *)targetItem;
if(draggedGroup) {
if(copyItem || (nil == self.localDraggedGroup) ) {
draggedGroup = [draggedGroup copyWithName:nil];
draggedGroup = [draggedGroup copyWithTitle:nil options:kKPKCopyOptionNone];
[targetGroup addGroup:draggedGroup atIndex:index];
[targetGroup.undoManager setActionName:NSLocalizedString(@"COPY_GROUP", "")];
return YES;
@@ -159,7 +159,7 @@
}
else if(draggedEntry) {
if(copyItem || (nil == self.localDraggedEntry)) {
draggedEntry = [draggedEntry copyWithTitle:nil];
draggedEntry = [draggedEntry copyWithTitle:nil options:kKPKCopyOptionNone];
[targetGroup addEntry:draggedEntry];
[targetGroup.undoManager setActionName:NSLocalizedString(@"COPY_ENTRY", "")];
return YES;

View File

@@ -216,9 +216,9 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
view = [outlineView makeViewWithIdentifier:_MPOutlineViewDataViewIdentifier owner:self];
NSString *iconImageKeyPath = [NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(iconImage))];
NSString *nameKeyPath = [NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(name))];
NSString *titleKeyPath = [NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(title))];
[[view imageView] bind:NSValueBinding toObject:item withKeyPath:iconImageKeyPath options:nil];
[[view textField] bind:NSValueBinding toObject:item withKeyPath:nameKeyPath options:nil];
[[view textField] bind:NSValueBinding toObject:item withKeyPath:titleKeyPath options:nil];
NSString *entriesCountKeyPath = [[NSString alloc] initWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(entries)), @"@count"];

View File

@@ -102,7 +102,7 @@
- (void)testGroupCoding {
KPKGroup *group = [[KPKGroup alloc] init];
group.name = @"A Group";
group.title = @"A Group";
group.iconId = 50;
group.notes = @"Some notes";
KPKEntry *entry = [[KPKEntry alloc] init];
@@ -114,7 +114,7 @@
KPKGroup *decodedGroup = [self decode:data ofClass:[KPKGroup class]];
XCTAssertTrue([group.uuid isEqual:decodedGroup.uuid]);
XCTAssertTrue([group.name isEqualToString:decodedGroup.name]);
XCTAssertTrue([group.title isEqualToString:decodedGroup.title]);
XCTAssertEqual([group.entries count], [decodedGroup.entries count]);
XCTAssertEqual(group.iconId, decodedGroup.iconId);
XCTAssertTrue([group.notes isEqualToString:decodedGroup.notes]);

View File

@@ -28,7 +28,7 @@
self.tree = [[KPKTree alloc] init];
self.tree.root = [[KPKGroup alloc] init];
self.tree.root.name = @"Root";
self.tree.root.title = @"Root";
KPKEntry *entry1 = [self.tree createEntry:self.tree.root];
KPKEntry *entry2 = [self.tree createEntry:self.tree.root];

100
MacPassTests/KPKTestUndo.m Normal file
View File

@@ -0,0 +1,100 @@
//
// KPKUndo.m
// MacPass
//
// Created by Michael Starke on 04/08/15.
// Copyright (c) 2015 HicknHack Software GmbH. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import <XCTest/XCTest.h>
#import "KPKTree.h"
#import "KPKGroup.h"
#import "KPKEntry.h"
@interface KPKTestUndo : XCTestCase <KPKTreeDelegate> {
NSUndoManager *_undoManager;
KPKTree *_tree;
KPKGroup *_groupA, *_groupB;
KPKEntry *_entryA, *_entryB;
}
@end
@implementation KPKTestUndo
- (NSUndoManager *)undoManagerForTree:(KPKTree *)tree {
return _undoManager;
}
- (void)setUp {
[super setUp];
_undoManager = [[NSUndoManager alloc] init];
_tree = [[KPKTree alloc] init];
_tree.delegate = self;
_groupA = [[KPKGroup alloc] init];
_groupB = [[KPKGroup alloc] init];
_entryA = [[KPKEntry alloc] init];
_entryB = [[KPKEntry alloc] init];
[_undoManager disableUndoRegistration];
[_undoManager enableUndoRegistration];
}
- (void)tearDown {
_undoManager = nil;
[super tearDown];
}
- (void)testUndoRedoCreateEntry {
XCTFail(@"Missing Test");
}
- (void)testUndoRedoCreateGroup {
XCTFail(@"Missing Test");
}
- (void)testUndoRedoCopyEntry {
XCTFail(@"Missing Test");
}
- (void)testUndoRedoCopyGroup {
XCTFail(@"Missing Test");
}
- (void)testUndoRedoMoveEntry {
XCTFail(@"Missing Test");
}
- (void)testUndoRedoMoveGroup {
XCTFail(@"Missing Test");
}
- (void)testUndoRedoDeleteGroupWithoutTrash {
XCTFail(@"Missing Test");
}
- (void)testUndoRedoDeleteEntryWithoutTrash {
XCTFail(@"Missing Test");
}
- (void)testUndoRedoDeleteGroupWithTrash {
XCTFail(@"Missing Test");
}
- (void)testUndoRedoDeleteEntryWithTrash {
XCTFail(@"Missing Test");
}
- (void)testUndoRedoEditEntry {
XCTFail(@"Missing Test");
}
- (void)testUndoRedoEditGroup {
XCTFail(@"Missing Test");
}
@end