mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-13 22:52:26 +00:00
iconselection and date picking now get registered as user interaction
This commit is contained in:
@@ -60,7 +60,9 @@ typedef NS_ENUM(NSUInteger, MPDatePreset) {
|
||||
|
||||
- (IBAction)useDate:(id)sender {
|
||||
KPKTimeInfo *timeInfo = [self.representedObject timeInfo];
|
||||
[self willChangeValueForRepresentedObjectKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(timeInfo)), NSStringFromSelector(@selector(expirationDate))]];
|
||||
timeInfo.expirationDate = self.datePicker.dateValue;
|
||||
[self didChangeValueForRepresentedObjectKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(timeInfo)), NSStringFromSelector(@selector(expirationDate))]];
|
||||
[self.view.window performClose:sender];
|
||||
}
|
||||
|
||||
|
||||
@@ -60,9 +60,6 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
|
||||
|
||||
@implementation MPEntryInspectorViewController
|
||||
|
||||
static NSString *kMPContentBindingString2 = @"content.%@.%@";
|
||||
static NSString *kMPContentBindingString3 = @"content.%@.%@.%@";
|
||||
|
||||
- (NSString *)nibName {
|
||||
return @"EntryInspectorView";
|
||||
}
|
||||
|
||||
@@ -34,8 +34,9 @@
|
||||
|
||||
- (IBAction)useDefault:(id)sender {
|
||||
KPKNode *node = self.representedObject;
|
||||
[self willChangeValueForRepresentedObjectKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(iconId))]];
|
||||
node.iconId = [[node class] defaultIcon];
|
||||
|
||||
[self didChangeValueForRepresentedObjectKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(iconId))]];
|
||||
[self.view.window performClose:sender];
|
||||
}
|
||||
|
||||
@@ -49,7 +50,11 @@
|
||||
NSUInteger buttonIndex = [self.iconCollectionView.content indexOfObject:image];
|
||||
NSInteger newIconId = ((NSNumber *)[MPIconHelper databaseIconTypes][buttonIndex]).integerValue;
|
||||
KPKNode *node = self.representedObject;
|
||||
[self willChangeValueForRepresentedObjectKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(iconId))]];
|
||||
node.iconId = newIconId;
|
||||
[self didChangeValueForRepresentedObjectKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(iconId))]];
|
||||
[self.view.window performClose:sender];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@@ -176,6 +176,10 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
||||
self.popover.delegate = self;
|
||||
self.popover.behavior = NSPopoverBehaviorTransient;
|
||||
MPIconSelectViewController *vc = [[MPIconSelectViewController alloc] init];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(_willChangeValueForRepresentedObjectNotification:)
|
||||
name:MPViewControllerWillChangeValueForRepresentedObjectKeyPathNotification
|
||||
object:vc];
|
||||
vc.representedObject = self.representedObject;
|
||||
vc.popover = self.popover;
|
||||
self.popover.contentViewController = vc;
|
||||
@@ -191,6 +195,10 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
||||
self.popover.delegate = self;
|
||||
self.popover.behavior = NSPopoverBehaviorTransient;
|
||||
MPDatePickingViewController *vc = [[MPDatePickingViewController alloc] init];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(_willChangeValueForRepresentedObjectNotification:)
|
||||
name:MPViewControllerWillChangeValueForRepresentedObjectKeyPathNotification
|
||||
object:vc];
|
||||
vc.representedObject = self.representedObject;
|
||||
self.popover.contentViewController = vc;
|
||||
[self.popover showRelativeToRect:NSZeroRect ofView:sender preferredEdge:NSMinYEdge];
|
||||
@@ -202,6 +210,8 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
||||
|
||||
- (void)popoverDidClose:(NSNotification *)notification {
|
||||
/* clear out the popover */
|
||||
NSPopover *po = notification.object;
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPViewControllerWillChangeValueForRepresentedObjectKeyPathNotification object:po.contentViewController];
|
||||
self.popover = nil;
|
||||
}
|
||||
|
||||
@@ -209,6 +219,7 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
||||
#pragma mark Bindings
|
||||
|
||||
- (void)willChangeValueForRepresentedObjectKeyPath:(NSString *)keyPath {
|
||||
[super willChangeValueForKey:keyPath];
|
||||
[self _recordChangesForCurrentNode];
|
||||
}
|
||||
|
||||
@@ -246,7 +257,7 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
||||
self.activeTab = MPEmptyTab;
|
||||
}
|
||||
self.didPushHistory = NO;
|
||||
|
||||
|
||||
self.representedObject = node;
|
||||
self.entryViewController.representedObject = node.asEntry;
|
||||
self.groupViewController.representedObject = node.asGroup;
|
||||
|
||||
@@ -24,19 +24,19 @@ APPKIT_EXTERN NSString *const MPViewControllerDidChangeValueForRepresentedObject
|
||||
* Override this to get notificied when setValue:forKeyPath will be called with a keypath starting with representedObject.
|
||||
* This is always called via the binding system, hence it's usefull to anticipate model changes via the ui
|
||||
*
|
||||
* The default implementation calls this just befor setValue:forKeyPath:
|
||||
* The default implementation calls this just befor setValue:forKeyPath: and posts a MPViewControllerWillChangeValueForRepresentedObjectKeyPathNotification
|
||||
* If you override this, you shoudl call super to ensure well defined behaviour
|
||||
*
|
||||
* @param keyPath the full key path about to be affected
|
||||
*/
|
||||
- (void)willChangeValueForRepresentedObjectKeyPath:(NSString *)keyPath;
|
||||
/**
|
||||
* Override this to get notified when setValue:forKeyPath was called with a keypath starting with representedObject.
|
||||
* The default implementation calls this right after setValue:forKeyPath:
|
||||
* The default implementation calls this right after setValue:forKeyPath: and will post a MPViewControllerDidChangeValueForRepresentedObjectKeyPathNotification.
|
||||
* If you override this, you should call super to ensure well defined behavoir
|
||||
*
|
||||
* @param keyPath the full key path affected
|
||||
*/
|
||||
- (void)didChangeValueForRepresentedObjectKeyPath:(NSString *)keyPath;
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@@ -43,10 +43,8 @@ NSString *const MPViewControllerDidChangeValueForRepresentedObjectKeyPathNotific
|
||||
#pragma mark Binding observation
|
||||
- (void)setValue:(id)value forKeyPath:(NSString *)keyPath {
|
||||
if([keyPath hasPrefix:@"representedObject."]) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPViewControllerWillChangeValueForRepresentedObjectKeyPathNotification object:self];
|
||||
[self willChangeValueForRepresentedObjectKeyPath:keyPath];
|
||||
[super setValue:value forKeyPath:keyPath];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPViewControllerDidChangeValueForRepresentedObjectKeyPathNotification object:self];
|
||||
[self didChangeValueForRepresentedObjectKeyPath:keyPath];
|
||||
}
|
||||
else {
|
||||
@@ -55,11 +53,11 @@ NSString *const MPViewControllerDidChangeValueForRepresentedObjectKeyPathNotific
|
||||
}
|
||||
|
||||
- (void)willChangeValueForRepresentedObjectKeyPath:(NSString *)keyPath {
|
||||
NSLog(@"[%@ willChangeValueForRepresentedObjectKeyPath:%@]", NSStringFromClass([self class]), keyPath);
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPViewControllerWillChangeValueForRepresentedObjectKeyPathNotification object:self];
|
||||
}
|
||||
|
||||
- (void)didChangeValueForRepresentedObjectKeyPath:(NSString *)keyPath {
|
||||
NSLog(@"[%@ didChangeValueForRepresentedObjectKeyPath:%@]", NSStringFromClass([self class]), keyPath);
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPViewControllerDidChangeValueForRepresentedObjectKeyPathNotification object:self];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user