Using bindings for iconImage for instant updates

Icon setting now gets registered via NSUndoManager
Refactored iconId property
This commit is contained in:
michael starke
2013-12-04 01:57:54 +01:00
parent c59ce56f4d
commit fa52de144c
6 changed files with 12 additions and 12 deletions

View File

@@ -15,13 +15,13 @@
@implementation KPKNode (IconImage)
+ (NSSet *)keyPathsForValuesAffectingIconImage {
return [NSSet setWithArray:@[@"customIcon", @"icon"]];
return [NSSet setWithArray:@[@"customIcon", @"iconId"]];
}
- (NSImage *)iconImage {
if(self.customIcon) {
return self.customIcon.image;
}
return [MPIconHelper icon:(MPIconType)self.icon];
return [MPIconHelper icon:(MPIconType)self.iconId];
}
@end

View File

@@ -455,7 +455,7 @@ typedef NS_ENUM(NSUInteger, MPAlertType) {
}
KPKGroup *newGroup = [self.tree createGroup:parent];
newGroup.name = NSLocalizedString(@"DEFAULT_GROUP_NAME", @"Title for a newly created group");
newGroup.icon = MPIconFolder;
newGroup.iconId = MPIconFolder;
[parent addGroup:newGroup];
NSDictionary *userInfo = @{ MPDocumentGroupKey : newGroup };
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidAddGroupNotification object:self userInfo:userInfo];
@@ -607,7 +607,7 @@ typedef NS_ENUM(NSUInteger, MPAlertType) {
BOOL wasEnabled = [self.undoManager isUndoRegistrationEnabled];
[self.undoManager disableUndoRegistration];
trash.name = NSLocalizedString(@"TRASH", @"Name for the trash group");
trash.icon = MPIconTrash;
trash.iconId = MPIconTrash;
[self.tree.root addGroup:trash];
if(wasEnabled) {
[self.undoManager enableUndoRegistration];

View File

@@ -237,12 +237,12 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
view = [tableView makeViewWithIdentifier:_MPTableImageCellView owner:self];
if( isTitleColumn ) {
[[view textField] bind:NSValueBinding toObject:entry withKeyPath:@"title" options:nil];
[[view imageView] setImage:entry.iconImage];
[[view imageView] bind:NSValueBinding toObject:entry withKeyPath:@"iconImage" options:nil];
}
else {
assert(entry.parent);
[[view textField] bind:NSValueBinding toObject:entry.parent withKeyPath:@"name" options:nil];
[[view imageView] setImage:entry.iconImage];
[[view imageView] bind:NSValueBinding toObject:entry.parent withKeyPath:@"iconImage" options:nil];
}
}
else if(isPasswordColum) {

View File

@@ -179,11 +179,11 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
BOOL useDefault = (viewController.selectedIcon == -1);
switch (self.activeTab) {
case MPGroupTab:
document.selectedGroup.icon = useDefault ? MPIconFolder : viewController.selectedIcon;
document.selectedGroup.iconId = useDefault ? [KPKGroup defaultIcon] : viewController.selectedIcon;
break;
case MPEntryTab:
document.selectedEntry.icon = useDefault ? MPIconPassword : viewController.selectedIcon;
document.selectedEntry.iconId = useDefault ? [KPKEntry defaultIcon]: viewController.selectedIcon;
break;
default:

View File

@@ -196,9 +196,9 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
KPKGroup *group = [item representedObject];
view = [outlineView makeViewWithIdentifier:_MPOutlineViewDataViewIdentifier owner:self];
[view.imageView setImage:group.iconImage];
[view.textField bind:NSValueBinding toObject:group withKeyPath:@"name" options:nil];
[view.textField bind:@"count" toObject:group withKeyPath:@"entries.@count" options:nil];
[[view imageView] bind:NSValueBinding toObject:group withKeyPath:@"iconImage" options:nil];
[[view textField] bind:NSValueBinding toObject:group withKeyPath:@"name" options:nil];
[[view textField] bind:@"count" toObject:group withKeyPath:@"entries.@count" options:nil];
}
return view;