Mingling on detecting UI introduces model changes

This commit is contained in:
michael starke
2016-08-27 13:53:27 +02:00
parent 2cf5c765f1
commit bd3eb7950c
11 changed files with 168 additions and 9 deletions

View File

@@ -195,6 +195,8 @@
4CAD748E15B88AC100104512 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CAD748D15B88AC100104512 /* libz.dylib */; }; 4CAD748E15B88AC100104512 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CAD748D15B88AC100104512 /* libz.dylib */; };
4CB915941A0159A20089CE5B /* DuplicateEntryOptionsWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CB915931A0159A20089CE5B /* DuplicateEntryOptionsWindow.xib */; }; 4CB915941A0159A20089CE5B /* DuplicateEntryOptionsWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CB915931A0159A20089CE5B /* DuplicateEntryOptionsWindow.xib */; };
4CB9339916D3A0DD00A13B5D /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 4CB9339716D3A0DD00A13B5D /* Credits.rtf */; }; 4CB9339916D3A0DD00A13B5D /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 4CB9339716D3A0DD00A13B5D /* Credits.rtf */; };
4CB9D77F1D70CE6B00F43F76 /* MPModelChangeObservingHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CB9D77E1D70CE6B00F43F76 /* MPModelChangeObservingHelper.m */; };
4CB9D7821D71AFBE00F43F76 /* MPArrayController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CB9D7811D71AFBE00F43F76 /* MPArrayController.m */; };
4CBA2ABA17074C07006D8139 /* MPSettingsHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CBA2AB917074C07006D8139 /* MPSettingsHelper.m */; }; 4CBA2ABA17074C07006D8139 /* MPSettingsHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CBA2AB917074C07006D8139 /* MPSettingsHelper.m */; };
4CC0D2CE17974A47000B4BDA /* MPCustomFieldTableViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC0D2CD17974A47000B4BDA /* MPCustomFieldTableViewDelegate.m */; }; 4CC0D2CE17974A47000B4BDA /* MPCustomFieldTableViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC0D2CD17974A47000B4BDA /* MPCustomFieldTableViewDelegate.m */; };
4CC0D2D117974A5A000B4BDA /* MPAttachmentTableViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC0D2D017974A5A000B4BDA /* MPAttachmentTableViewDelegate.m */; }; 4CC0D2D117974A5A000B4BDA /* MPAttachmentTableViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC0D2D017974A5A000B4BDA /* MPAttachmentTableViewDelegate.m */; };
@@ -589,6 +591,11 @@
4CB63A6018986530002DEC4C /* MPFlagsHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPFlagsHelper.h; sourceTree = "<group>"; }; 4CB63A6018986530002DEC4C /* MPFlagsHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPFlagsHelper.h; sourceTree = "<group>"; };
4CB915931A0159A20089CE5B /* DuplicateEntryOptionsWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DuplicateEntryOptionsWindow.xib; sourceTree = "<group>"; }; 4CB915931A0159A20089CE5B /* DuplicateEntryOptionsWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DuplicateEntryOptionsWindow.xib; sourceTree = "<group>"; };
4CB9339816D3A0DD00A13B5D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = en; path = en.lproj/Credits.rtf; sourceTree = "<group>"; }; 4CB9339816D3A0DD00A13B5D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = en; path = en.lproj/Credits.rtf; sourceTree = "<group>"; };
4CB9D77C1D70CBCE00F43F76 /* MPModelChangeObserving.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPModelChangeObserving.h; sourceTree = "<group>"; };
4CB9D77D1D70CE6B00F43F76 /* MPModelChangeObservingHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPModelChangeObservingHelper.h; sourceTree = "<group>"; };
4CB9D77E1D70CE6B00F43F76 /* MPModelChangeObservingHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPModelChangeObservingHelper.m; sourceTree = "<group>"; };
4CB9D7801D71AFBE00F43F76 /* MPArrayController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPArrayController.h; sourceTree = "<group>"; };
4CB9D7811D71AFBE00F43F76 /* MPArrayController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPArrayController.m; sourceTree = "<group>"; };
4CBA2AB617074B59006D8139 /* MPSettingsHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPSettingsHelper.h; sourceTree = "<group>"; }; 4CBA2AB617074B59006D8139 /* MPSettingsHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPSettingsHelper.h; sourceTree = "<group>"; };
4CBA2AB917074C07006D8139 /* MPSettingsHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPSettingsHelper.m; sourceTree = "<group>"; }; 4CBA2AB917074C07006D8139 /* MPSettingsHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPSettingsHelper.m; sourceTree = "<group>"; };
4CC0D2CC17974A47000B4BDA /* MPCustomFieldTableViewDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPCustomFieldTableViewDelegate.h; sourceTree = "<group>"; }; 4CC0D2CC17974A47000B4BDA /* MPCustomFieldTableViewDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPCustomFieldTableViewDelegate.h; sourceTree = "<group>"; };
@@ -1299,6 +1306,7 @@
children = ( children = (
4CA0B30D15BCB6FD00654E32 /* MPSettingsTab.h */, 4CA0B30D15BCB6FD00654E32 /* MPSettingsTab.h */,
4C2B0B7419F66F6400E48913 /* MPTargetNodeResolving.h */, 4C2B0B7419F66F6400E48913 /* MPTargetNodeResolving.h */,
4CB9D77C1D70CBCE00F43F76 /* MPModelChangeObserving.h */,
); );
name = Protocolls; name = Protocolls;
sourceTree = "<group>"; sourceTree = "<group>";
@@ -1364,6 +1372,10 @@
4C6AEEF81A043E2B00CA2420 /* MPDocumentController.m */, 4C6AEEF81A043E2B00CA2420 /* MPDocumentController.m */,
4CDE7B141D660983008C4160 /* MPObjectController.h */, 4CDE7B141D660983008C4160 /* MPObjectController.h */,
4CDE7B151D660983008C4160 /* MPObjectController.m */, 4CDE7B151D660983008C4160 /* MPObjectController.m */,
4CB9D77D1D70CE6B00F43F76 /* MPModelChangeObservingHelper.h */,
4CB9D77E1D70CE6B00F43F76 /* MPModelChangeObservingHelper.m */,
4CB9D7801D71AFBE00F43F76 /* MPArrayController.h */,
4CB9D7811D71AFBE00F43F76 /* MPArrayController.m */,
); );
name = "Data Controller"; name = "Data Controller";
sourceTree = "<group>"; sourceTree = "<group>";
@@ -1695,6 +1707,7 @@
4C2E382316D1421B00037A9D /* MPIconHelper.m in Sources */, 4C2E382316D1421B00037A9D /* MPIconHelper.m in Sources */,
4C2E382616D1470200037A9D /* MPViewController.m in Sources */, 4C2E382616D1470200037A9D /* MPViewController.m in Sources */,
4C65FAE916D16DDB006E0577 /* MPPasswordInputController.m in Sources */, 4C65FAE916D16DDB006E0577 /* MPPasswordInputController.m in Sources */,
4CB9D7821D71AFBE00F43F76 /* MPArrayController.m in Sources */,
4CDF01A316D1B76700D0AC08 /* MPEntryViewController.m in Sources */, 4CDF01A316D1B76700D0AC08 /* MPEntryViewController.m in Sources */,
4C3BD51516D276F800389F1F /* MPToolbarDelegate.m in Sources */, 4C3BD51516D276F800389F1F /* MPToolbarDelegate.m in Sources */,
4C7B63731C0CB51F00D7038C /* TTTDataTransformer.m in Sources */, 4C7B63731C0CB51F00D7038C /* TTTDataTransformer.m in Sources */,
@@ -1705,6 +1718,7 @@
4CE8246F16E2E93400573141 /* MPOverlayWindowController.m in Sources */, 4CE8246F16E2E93400573141 /* MPOverlayWindowController.m in Sources */,
4CE8247516E2F2B900573141 /* MPOverlayView.m in Sources */, 4CE8247516E2F2B900573141 /* MPOverlayView.m in Sources */,
4C7B63761C0CB51F00D7038C /* TTTJSONTransformer.m in Sources */, 4C7B63761C0CB51F00D7038C /* TTTJSONTransformer.m in Sources */,
4CB9D77F1D70CE6B00F43F76 /* MPModelChangeObservingHelper.m in Sources */,
4C77547516E55FE800970E02 /* MPInspectorViewController.m in Sources */, 4C77547516E55FE800970E02 /* MPInspectorViewController.m in Sources */,
4C89F524182FB4740069C73C /* MPAutotypeCommand.m in Sources */, 4C89F524182FB4740069C73C /* MPAutotypeCommand.m in Sources */,
4CFC53BF16E94729007396BE /* MPShadowBox.m in Sources */, 4CFC53BF16E94729007396BE /* MPShadowBox.m in Sources */,

View File

@@ -0,0 +1,13 @@
//
// MPArrayController.h
// MacPass
//
// Created by Michael Starke on 27/08/16.
// Copyright © 2016 HicknHack Software GmbH. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface MPArrayController : NSArrayController
@end

View File

@@ -0,0 +1,18 @@
//
// MPArrayController.m
// MacPass
//
// Created by Michael Starke on 27/08/16.
// Copyright © 2016 HicknHack Software GmbH. All rights reserved.
//
#import "MPArrayController.h"
@implementation MPArrayController
- (void)setValue:(id)value forKeyPath:(NSString *)keyPath {
NSLog(@"%@ setValue:forKeyPath:%@", NSStringFromClass([self class]), keyPath);
[super setValue:value forKeyPath:keyPath];
}
@end

View File

@@ -14,4 +14,9 @@
[super setBackgroundStyle:NSBackgroundStyleLight]; [super setBackgroundStyle:NSBackgroundStyleLight];
} }
- (void)setValue:(id)value forKeyPath:(NSString *)keyPath {
NSLog(@"%@ setValue:forKeyPath:%@", NSStringFromClass([self class]), keyPath);
[super setValue:value forKeyPath:keyPath];
}
@end @end

View File

@@ -26,6 +26,8 @@
#import "KeePassKit/KeePassKit.h" #import "KeePassKit/KeePassKit.h"
#import "MPArrayController.h"
#import "HNHUi/HNHUi.h" #import "HNHUi/HNHUi.h"
typedef NS_ENUM(NSUInteger, MPEntryTab) { typedef NS_ENUM(NSUInteger, MPEntryTab) {
@@ -68,9 +70,9 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) { if (self) {
_showPassword = NO; _showPassword = NO;
_attachmentsController = [[NSArrayController alloc] init]; _attachmentsController = [[MPArrayController alloc] init];
_customFieldsController = [[NSArrayController alloc] init]; _customFieldsController = [[MPArrayController alloc] init];
_windowAssociationsController = [[NSArrayController alloc] init]; _windowAssociationsController = [[MPArrayController alloc] init];
_attachmentTableDelegate = [[MPAttachmentTableViewDelegate alloc] init]; _attachmentTableDelegate = [[MPAttachmentTableViewDelegate alloc] init];
_customFieldTableDelegate = [[MPCustomFieldTableViewDelegate alloc] init]; _customFieldTableDelegate = [[MPCustomFieldTableViewDelegate alloc] init];
_attachmentDataSource = [[MPAttachmentTableDataSource alloc] init]; _attachmentDataSource = [[MPAttachmentTableDataSource alloc] init];

View File

@@ -0,0 +1,27 @@
//
// MPModelChangeObserving.h
// MacPass
//
// Created by Michael Starke on 26/08/16.
// Copyright © 2016 HicknHack Software GmbH. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@protocol MPModelChangeObserving <NSObject>
FOUNDATION_EXTERN NSString *const MPWillChangeModelNotification;
FOUNDATION_EXTERN NSString *const MPDidChangreModelNotification;
FOUNDATION_EXTERN NSString *const MPModelChangeObservingKeyPathKey;
@required
- (void)willChangeModel;
- (void)didChangeModel;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,22 @@
//
// MPModelChangeObserver.h
// MacPass
//
// Created by Michael Starke on 26/08/16.
// Copyright © 2016 HicknHack Software GmbH. All rights reserved.
//
#import <Foundation/Foundation.h>
/**
* This class is usefull to implement modelchangeobserving by just forwarding the protocoll calls to the helper
*/
@protocol MPModelChangeObserving;
@interface MPModelChangeObservingHelper : NSObject
+ (void)willChangeModelKeyPath:(NSString *)keyPath observer:(id<MPModelChangeObserving>)observer;
+ (void)didChangeModelKeyPath:(NSString *)keyPath observer:(id<MPModelChangeObserving>)observer;
@end

View File

@@ -0,0 +1,28 @@
//
// MPModelChangeObserver.m
// MacPass
//
// Created by Michael Starke on 26/08/16.
// Copyright © 2016 HicknHack Software GmbH. All rights reserved.
//
#import "MPModelChangeObservingHelper.h"
#import "MPModelChangeObserving.h"
NSString *const MPWillChangeModelNotification = @"com.hicknhack.macpass.MPWillChangeModelNotification";
NSString *const MPDidChangreModelNotification = @"com.hicknhack.macpass.MPDidChangeModelNotification";
NSString *const MPModelChangeObservingKeyPathKey = @"MPModelChangeObservingKeyPathKey";
@implementation MPModelChangeObservingHelper
+ (void)willChangeModelKeyPath:(NSString *)keyPath observer:(id<MPModelChangeObserving>)observer {
[[NSNotificationCenter defaultCenter] postNotificationName:MPWillChangeModelNotification object:observer userInfo:@{ MPModelChangeObservingKeyPathKey : keyPath }];
}
+ (void)didChangeModelKeyPath:(NSString *)keyPath observer:(id<MPModelChangeObserving>)observer {
[[NSNotificationCenter defaultCenter] postNotificationName:MPDidChangreModelNotification object:observer userInfo:@{ MPModelChangeObservingKeyPathKey : keyPath }];
}
@end

View File

@@ -7,8 +7,9 @@
// //
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import "MPModelChangeObserving.h"
@interface MPObjectController : NSObjectController @interface MPObjectController : NSObjectController <MPModelChangeObserving>
@property (weak) NSDocument *document; @property (weak) NSDocument *document;

View File

@@ -8,6 +8,10 @@
#import "MPObjectController.h" #import "MPObjectController.h"
@interface MPObjectController ()
@property (strong) NSMutableSet *observedModelKeyPaths;
@end
@implementation MPObjectController @implementation MPObjectController
- (void)discardEditing { - (void)discardEditing {
@@ -19,8 +23,33 @@
} }
- (void)setValue:(id)value forKeyPath:(NSString *)keyPath { - (void)setValue:(id)value forKeyPath:(NSString *)keyPath {
NSLog(@"[%@ setValue:%@ forKeyPath:%@]", NSStringFromClass([self class]), value, keyPath); BOOL observerd = NO;
for(NSString *observedKeyPath in self.observedModelKeyPaths) {
observerd = ([keyPath hasPrefix:observedKeyPath]);
if(observerd) {
break;
}
}
if(observerd) {
}
[super setValue:value forKeyPath:keyPath]; [super setValue:value forKeyPath:keyPath];
} }
- (void)didChangeModel {
}
- (void)willChangeModel {
}
- (void)beginObservingModelKeyPath:(NSString *)keyPath {
[self.observedModelKeyPaths addObject:keyPath];
}
- (void)endObservingModelKeyPath:(NSString *)keyPath {
[self.observedModelKeyPaths removeObject:keyPath];
}
@end @end

View File

@@ -33,10 +33,10 @@ NSString *const MPViewControllerDidChangeValueForRepresentedObjectKeyPathNotific
} }
- (void)updateResponderChain { - (void)updateResponderChain {
if(self.view && [self.view nextResponder] != self) { if(self.view && self.view.nextResponder != self) {
NSResponder *nextResponder = [[self view] nextResponder]; NSResponder *nextResponder = self.view.nextResponder;
[[self view] setNextResponder:self]; self.view.nextResponder = self;
[self setNextResponder:nextResponder]; self.nextResponder = nextResponder;
} }
} }