Using NSObjectController for Group Inspector

This commit is contained in:
michael starke
2015-12-16 12:52:32 +01:00
parent f04793f146
commit 0074b369a4

View File

@@ -15,12 +15,11 @@
#import "HNHUi/HNHUi.h" #import "HNHUi/HNHUi.h"
@interface MPGroupInspectorViewController () { @interface MPGroupInspectorViewController ()
NSObjectController *_entryController;
}
@property (nonatomic, weak) KPKGroup *group; //@property (nonatomic, weak) KPKGroup *group;
@property (strong) NSPopover *popover; @property (strong) NSPopover *popover;
@property (strong) NSObjectController *groupController;
@end @end
@@ -33,7 +32,7 @@
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) { if (self) {
_entryController = [[NSObjectController alloc] init]; _groupController = [[NSObjectController alloc] init];
} }
return self; return self;
} }
@@ -81,44 +80,38 @@
[searchMenu addItem:includeInSearch]; [searchMenu addItem:includeInSearch];
[searchMenu addItem:excludeFromSearch]; [searchMenu addItem:excludeFromSearch];
/* [self _establishBindings];
void(^copyBlock)(NSTextField *textField) = ^void(NSTextField *textField) {
[[MPPasteBoardController defaultController] copyObjects:@[ textField.stringValue ]];
};
self.titleTextField.copyActionBlock = copyBlock;
*/
} }
- (void)setupBindings:(MPDocument *)document { - (void)setupBindings:(MPDocument *)document {
[self bind:NSStringFromSelector(@selector(group)) toObject:document withKeyPath:NSStringFromSelector(@selector(selectedGroup)) options:nil]; [self.groupController bind:NSContentObjectBinding toObject:document withKeyPath:NSStringFromSelector(@selector(selectedGroup)) options:nil];
} }
- (void)setGroup:(KPKGroup *)group { - (void)_establishBindings {
if(_group != group) { [self.titleTextField bind:NSValueBinding
_group = group; toObject:self.groupController
[self _updateBindings]; withKeyPath:[NSString stringWithFormat:@"%@.%@", NSContentBinding, NSStringFromSelector(@selector(title))]
} options:@{NSNullPlaceholderBindingOption: NSLocalizedString(@"NONE", @"")}];
} [self.expiresCheckButton bind:NSValueBinding
toObject:self.groupController
- (void)_updateBindings { withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSContentBinding, NSStringFromSelector(@selector(timeInfo)), NSStringFromSelector(@selector(expires))]
if(self.group) { options:nil];
[self.titleTextField bind:NSValueBinding toObject:self.group withKeyPath:NSStringFromSelector(@selector(title)) options:nil]; [self.expiresCheckButton bind:NSTitleBinding
[self.expiresCheckButton bind:NSValueBinding toObject:self.group.timeInfo withKeyPath:NSStringFromSelector(@selector(expires)) options:nil]; toObject:self.groupController
[self.expiresCheckButton bind:NSTitleBinding toObject:self.group.timeInfo withKeyPath:NSStringFromSelector(@selector(expirationDate)) options:@{ NSValueTransformerNameBindingOption:MPExpiryDateValueTransformer }]; withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSContentBinding, NSStringFromSelector(@selector(timeInfo)), NSStringFromSelector(@selector(expirationDate))]
[self.autotypePopupButton bind:NSSelectedTagBinding toObject:self.group withKeyPath:NSStringFromSelector(@selector(isAutoTypeEnabled)) options:nil]; options:@{ NSValueTransformerNameBindingOption:MPExpiryDateValueTransformer }];
[self.autotypeSequenceTextField bind:NSValueBinding toObject:self.group withKeyPath:NSStringFromSelector(@selector(defaultAutoTypeSequence)) options:nil]; [self.autotypePopupButton bind:NSSelectedTagBinding
[self.searchPopupButton bind:NSSelectedTagBinding toObject:self.group withKeyPath:NSStringFromSelector(@selector(isSearchEnabled)) options:nil]; toObject:self.groupController
} withKeyPath:[NSString stringWithFormat:@"%@.%@", NSContentBinding, NSStringFromSelector(@selector(isAutoTypeEnabled))]
else { options:nil];
[self.titleTextField unbind:NSValueBinding]; [self.autotypeSequenceTextField bind:NSValueBinding
[self.expiresCheckButton unbind:NSValueBinding]; toObject:self.groupController
[self.expiresCheckButton unbind:NSTitleBinding]; withKeyPath:[NSString stringWithFormat:@"%@.%@", NSContentBinding, NSStringFromSelector(@selector(defaultAutoTypeSequence))]
[self.expiresCheckButton setTitle:NSLocalizedString(@"EXPIRES", "")]; options:@{NSNullPlaceholderBindingOption: NSLocalizedString(@"NONE", @"")}];
[self.searchPopupButton unbind:NSSelectedTagBinding]; [self.searchPopupButton bind:NSSelectedTagBinding
[self.autotypePopupButton unbind:NSSelectedTagBinding]; toObject:self.groupController
[self.autotypeSequenceTextField unbind:NSValueBinding]; withKeyPath:[NSString stringWithFormat:@"%@.%@", NSContentBinding, NSStringFromSelector(@selector(isSearchEnabled))]
} options:nil];
} }
@end @end