diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index 7bcc5080..e2ef0ca1 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -176,7 +176,7 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; [urlColumn setSortDescriptorPrototype:urlSortDescriptor]; [parentColumn setSortDescriptorPrototype:groupnameSortDescriptor]; [modifiedColumn setSortDescriptorPrototype:dateSortDescriptor]; - + [[parentColumn headerCell] setStringValue:NSLocalizedString(@"GROUP", "")]; [[titleColumn headerCell] setStringValue:NSLocalizedString(@"TITLE", "")]; [[userNameColumn headerCell] setStringValue:NSLocalizedString(@"USERNAME", "")]; @@ -189,7 +189,14 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; [self.entryTable bind:NSContentBinding toObject:self.entryArrayController withKeyPath:@"arrangedObjects" options:nil]; [self.entryTable bind:NSSortDescriptorsBinding toObject:self.entryArrayController withKeyPath:@"sortDescriptors" options:nil]; [self.entryTable setDataSource:_dataSource]; - + + // bind NSArrayController sorting so that sort order gets auto-saved + // see: http://simx.me/technonova/software_development/sort_descriptors_nstableview_bindings_a.html + [self.entryArrayController bind:NSSortDescriptorsBinding + toObject:[NSUserDefaultsController sharedUserDefaultsController] + withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyEntryTableSortDescriptors] + options:@{ NSValueTransformerNameBindingOption: NSUnarchiveFromDataTransformerName }]; + [self _setupHeaderMenu]; [parentColumn setHidden:YES]; } diff --git a/MacPass/MPSettingsHelper.h b/MacPass/MPSettingsHelper.h index af15b051..d1c2e5d4 100644 --- a/MacPass/MPSettingsHelper.h +++ b/MacPass/MPSettingsHelper.h @@ -32,6 +32,7 @@ APPKIT_EXTERN NSString *const kMPSettingsKeyIdleLockTimeOut; /* Autosaving states */ APPKIT_EXTERN NSString *const kMPSettingsKeyShowInspector; +APPKIT_EXTERN NSString *const kMPSettingsKeyEntryTableSortDescriptors; /* Kdb Hide/Show settings */ APPKIT_EXTERN NSString *const kMPSettingsKeyLegacyHideTitle; @@ -55,7 +56,17 @@ typedef NS_ENUM(NSUInteger, MPPasswordEncoding) { @interface MPSettingsHelper : NSObject +/** + * Registers all the defaults for the applciaiton + */ + (void)setupDefaults; +/** + * Convenience Method to create a bind path for the NSUserDefaultsController + * + * @param key SettingsKey (see MPSettingsHelper.h for available keys) + * + * @return NSString containing the bindpath for this property for the NSUserDefaultController + */ + (NSString *)defaultControllerPathForKey:(NSString *)key; @end \ No newline at end of file diff --git a/MacPass/MPSettingsHelper.m b/MacPass/MPSettingsHelper.m index 1f764c12..3f1a3440 100644 --- a/MacPass/MPSettingsHelper.m +++ b/MacPass/MPSettingsHelper.m @@ -20,6 +20,7 @@ NSString *const kMPSettingsKeyShowMenuItem = @"ShowMenuItem"; NSString *const kMPSettingsKeyLockOnSleep = @"LockOnSleep"; NSString *const kMPSettingsKeyIdleLockTimeOut = @"IdleLockTimeOut"; NSString *const kMPSettingsKeyShowInspector = @"ShowInspector"; +NSString *const kMPSettingsKeyEntryTableSortDescriptors = @"EntryTableSortDescriptors"; NSString *const kMPSettingsKeyLegacyHideTitle = @"LegacyHideTitle"; NSString *const kMPSettingsKeyLegacyHideUsername = @"LegacyHideUsername ";