mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-24 09:59:43 +00:00
Mingling on detecting UI introduces model changes
This commit is contained in:
13
MacPass/MPArrayController.h
Normal file
13
MacPass/MPArrayController.h
Normal 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
|
||||
18
MacPass/MPArrayController.m
Normal file
18
MacPass/MPArrayController.m
Normal 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
|
||||
@@ -14,4 +14,9 @@
|
||||
[super setBackgroundStyle:NSBackgroundStyleLight];
|
||||
}
|
||||
|
||||
- (void)setValue:(id)value forKeyPath:(NSString *)keyPath {
|
||||
NSLog(@"%@ setValue:forKeyPath:%@", NSStringFromClass([self class]), keyPath);
|
||||
[super setValue:value forKeyPath:keyPath];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
|
||||
#import "KeePassKit/KeePassKit.h"
|
||||
|
||||
#import "MPArrayController.h"
|
||||
|
||||
#import "HNHUi/HNHUi.h"
|
||||
|
||||
typedef NS_ENUM(NSUInteger, MPEntryTab) {
|
||||
@@ -68,9 +70,9 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
|
||||
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
||||
if (self) {
|
||||
_showPassword = NO;
|
||||
_attachmentsController = [[NSArrayController alloc] init];
|
||||
_customFieldsController = [[NSArrayController alloc] init];
|
||||
_windowAssociationsController = [[NSArrayController alloc] init];
|
||||
_attachmentsController = [[MPArrayController alloc] init];
|
||||
_customFieldsController = [[MPArrayController alloc] init];
|
||||
_windowAssociationsController = [[MPArrayController alloc] init];
|
||||
_attachmentTableDelegate = [[MPAttachmentTableViewDelegate alloc] init];
|
||||
_customFieldTableDelegate = [[MPCustomFieldTableViewDelegate alloc] init];
|
||||
_attachmentDataSource = [[MPAttachmentTableDataSource alloc] init];
|
||||
|
||||
27
MacPass/MPModelChangeObserving.h
Normal file
27
MacPass/MPModelChangeObserving.h
Normal 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
|
||||
22
MacPass/MPModelChangeObservingHelper.h
Normal file
22
MacPass/MPModelChangeObservingHelper.h
Normal 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
|
||||
28
MacPass/MPModelChangeObservingHelper.m
Normal file
28
MacPass/MPModelChangeObservingHelper.m
Normal 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
|
||||
@@ -7,8 +7,9 @@
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "MPModelChangeObserving.h"
|
||||
|
||||
@interface MPObjectController : NSObjectController
|
||||
@interface MPObjectController : NSObjectController <MPModelChangeObserving>
|
||||
|
||||
@property (weak) NSDocument *document;
|
||||
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
|
||||
#import "MPObjectController.h"
|
||||
|
||||
@interface MPObjectController ()
|
||||
@property (strong) NSMutableSet *observedModelKeyPaths;
|
||||
@end
|
||||
|
||||
@implementation MPObjectController
|
||||
|
||||
- (void)discardEditing {
|
||||
@@ -19,8 +23,33 @@
|
||||
}
|
||||
|
||||
- (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];
|
||||
}
|
||||
|
||||
- (void)didChangeModel {
|
||||
|
||||
}
|
||||
|
||||
- (void)willChangeModel {
|
||||
|
||||
}
|
||||
|
||||
- (void)beginObservingModelKeyPath:(NSString *)keyPath {
|
||||
[self.observedModelKeyPaths addObject:keyPath];
|
||||
}
|
||||
|
||||
- (void)endObservingModelKeyPath:(NSString *)keyPath {
|
||||
[self.observedModelKeyPaths removeObject:keyPath];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -33,10 +33,10 @@ NSString *const MPViewControllerDidChangeValueForRepresentedObjectKeyPathNotific
|
||||
}
|
||||
|
||||
- (void)updateResponderChain {
|
||||
if(self.view && [self.view nextResponder] != self) {
|
||||
NSResponder *nextResponder = [[self view] nextResponder];
|
||||
[[self view] setNextResponder:self];
|
||||
[self setNextResponder:nextResponder];
|
||||
if(self.view && self.view.nextResponder != self) {
|
||||
NSResponder *nextResponder = self.view.nextResponder;
|
||||
self.view.nextResponder = self;
|
||||
self.nextResponder = nextResponder;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user