From 1ae41df2cebd1cf0b7f8df25e69cd9454540f535 Mon Sep 17 00:00:00 2001 From: michael starke Date: Wed, 19 Oct 2016 11:06:23 +0200 Subject: [PATCH] added index column and custom index sorting --- Cartfile | 2 +- Cartfile.resolved | 2 +- MacPass/MPEntryViewController.m | 26 +++++++++++++++++++------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Cartfile b/Cartfile index 94656ccd..1d7c5d52 100644 --- a/Cartfile +++ b/Cartfile @@ -1,3 +1,3 @@ github "sparkle-project/Sparkle" ~> 1.13.1 -github "mstarke/KeePassKit" "d66c888b299358481da2ba2672ec7c644cce56ec" +github "mstarke/KeePassKit" "8803a3df186371827171f9a033d7c61eb56f25c1" github "mstarke/HNHUi" ~> 1.1 diff --git a/Cartfile.resolved b/Cartfile.resolved index 5db8a76d..0b1f72e9 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,3 +1,3 @@ github "mstarke/HNHUi" "1.1" -github "mstarke/KeePassKit" "d66c888b299358481da2ba2672ec7c644cce56ec" +github "mstarke/KeePassKit" "8803a3df186371827171f9a033d7c61eb56f25c1" github "sparkle-project/Sparkle" "1.14.0" diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index 471228fb..fee6a160 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -45,6 +45,7 @@ typedef NS_ENUM(NSUInteger,MPOVerlayInfoType) { MPOverlayInfoCustom, }; +NSString *const MPEntryTableIndexColumnIdentifier = @"MPEntryTableIndexColumnIdentifier"; NSString *const MPEntryTableUserNameColumnIdentifier = @"MPUserNameColumnIdentifier"; NSString *const MPEntryTableTitleColumnIdentifier = @"MPTitleColumnIdentifier"; NSString *const MPEntryTablePasswordColumnIdentifier = @"MPPasswordColumnIdentifier"; @@ -130,14 +131,17 @@ NSString *const _MPTableSecurCellView = @"PasswordCell"; NSTableColumn *notesColumn = [[NSTableColumn alloc] initWithIdentifier:MPEntryTableNotesColumnIdentifier]; NSTableColumn *modifiedColumn = [[NSTableColumn alloc] initWithIdentifier:MPEntryTableModfiedColumnIdentifier]; NSTableColumn *historyColumn = [[NSTableColumn alloc] initWithIdentifier:MPEntryTableHistoryColumnIdentifier]; + NSTableColumn *indexColumn = [[NSTableColumn alloc] initWithIdentifier:MPEntryTableIndexColumnIdentifier]; notesColumn.minWidth = 40.0; attachmentsColumn.minWidth = 40.0; modifiedColumn.minWidth = 40.0; historyColumn.minWidth = 40.0; + indexColumn.minWidth = 16.0; [self.entryTable addTableColumn:notesColumn]; [self.entryTable addTableColumn:attachmentsColumn]; [self.entryTable addTableColumn:modifiedColumn]; [self.entryTable addTableColumn:historyColumn]; + [self.entryTable addTableColumn:indexColumn]; parentColumn.identifier = MPEntryTableParentColumnIdentifier; titleColumn.identifier = MPEntryTableTitleColumnIdentifier; @@ -151,12 +155,15 @@ NSString *const _MPTableSecurCellView = @"PasswordCell"; NSString *parentTitleKeyPath = [[NSString alloc] initWithFormat:@"%@.%@", NSStringFromSelector(@selector(parent)), NSStringFromSelector(@selector(title))]; NSString *timeInfoModificationTimeKeyPath = [[NSString alloc] initWithFormat:@"%@.%@", NSStringFromSelector(@selector(timeInfo)), NSStringFromSelector(@selector(modificationDate))]; + indexColumn.sortDescriptorPrototype = [NSSortDescriptor sortDescriptorWithKey:NSStringFromSelector(@selector(index)) ascending:YES selector:@selector(compare:)]; 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:parentTitleKeyPath ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)]; modifiedColumn.sortDescriptorPrototype = [NSSortDescriptor sortDescriptorWithKey:timeInfoModificationTimeKeyPath ascending:YES selector:@selector(compare:)]; + + indexColumn.headerCell.stringValue = @""; parentColumn.headerCell.stringValue = NSLocalizedString(@"GROUP", ""); titleColumn.headerCell.stringValue = NSLocalizedString(@"TITLE", ""); userNameColumn.headerCell.stringValue = NSLocalizedString(@"USERNAME", ""); @@ -232,6 +239,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell"; - (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { + BOOL isIndexColumn = [tableColumn.identifier isEqualToString:MPEntryTableIndexColumnIdentifier]; BOOL isTitleColumn = [tableColumn.identifier isEqualToString:MPEntryTableTitleColumnIdentifier]; BOOL isGroupColumn = [tableColumn.identifier isEqualToString:MPEntryTableParentColumnIdentifier]; BOOL isPasswordColum = [tableColumn.identifier isEqualToString:MPEntryTablePasswordColumnIdentifier]; @@ -285,6 +293,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell"; /* clean up old formatter that might be left */ view.textField.formatter = nil; } + if(isModifedColumn) { if(!view.textField.formatter) { /* Just use one formatter instance since it's expensive to create */ @@ -333,10 +342,13 @@ NSString *const _MPTableSecurCellView = @"PasswordCell"; } else if(isHistoryColumn) { NSString *historyCountKeyPath = [NSString stringWithFormat:@"%@.%@.@count", - NSStringFromSelector(@selector(objectValue)), - NSStringFromSelector(@selector(history))]; + NSStringFromSelector(@selector(objectValue)), + NSStringFromSelector(@selector(history))]; [view.textField bind:NSValueBinding toObject:view withKeyPath:historyCountKeyPath options:nil]; } + else if(isIndexColumn) { + view.textField.stringValue = @""; + } } return view; } @@ -360,10 +372,10 @@ NSString *const _MPTableSecurCellView = @"PasswordCell"; #pragma mark MPTargetItemResolving - (NSArray *)currentTargetEntries { /*NSInteger activeRow = self.entryTable.clickedRow; - if(activeRow > -1) { - return @[ [self.entryArrayController arrangedObjects][activeRow] ]; - } - */ + if(activeRow > -1) { + return @[ [self.entryArrayController arrangedObjects][activeRow] ]; + } + */ return self.entryArrayController.selectedObjects; } @@ -614,7 +626,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell"; [item bind:NSValueBinding toObject:column withKeyPath:NSHiddenBinding options:options]; } - [[self.entryTable headerView] setMenu:headerMenu]; + self.entryTable.headerView.menu = headerMenu; } #pragma mark Actions