added index column and custom index sorting

This commit is contained in:
michael starke
2016-10-19 11:06:23 +02:00
parent 2e1e4ad5ac
commit 1ae41df2ce
3 changed files with 21 additions and 9 deletions

View File

@@ -1,3 +1,3 @@
github "sparkle-project/Sparkle" ~> 1.13.1
github "mstarke/KeePassKit" "d66c888b299358481da2ba2672ec7c644cce56ec"
github "mstarke/KeePassKit" "8803a3df186371827171f9a033d7c61eb56f25c1"
github "mstarke/HNHUi" ~> 1.1

View File

@@ -1,3 +1,3 @@
github "mstarke/HNHUi" "1.1"
github "mstarke/KeePassKit" "d66c888b299358481da2ba2672ec7c644cce56ec"
github "mstarke/KeePassKit" "8803a3df186371827171f9a033d7c61eb56f25c1"
github "sparkle-project/Sparkle" "1.14.0"

View File

@@ -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<KPKEntry *> *)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