mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 04:42:29 +00:00
more usage of properites, improvements on node-editing
Signed-off-by: michael starke <michael.starke@hicknhack-software.com>
This commit is contained in:
@@ -34,7 +34,12 @@ NSString *const MPDocumentDidCommitChangesToSelectedItem = @"com.hicknhack.mac
|
|||||||
|
|
||||||
/* update the data */
|
/* update the data */
|
||||||
[self.editingSession.source updateToNode:self.editingSession.node];
|
[self.editingSession.source updateToNode:self.editingSession.node];
|
||||||
[self.undoManager setActionName:NSLocalizedString(@"UPDATE_ENTRY", "")];
|
if(self.editingSession.node.asEntry) {
|
||||||
|
[self.undoManager setActionName:NSLocalizedString(@"UPDATE_ENTRY", "")];
|
||||||
|
}
|
||||||
|
else if(self.editingSession.node.asGroup) {
|
||||||
|
[self.undoManager setActionName:NSLocalizedString(@"UPDATE_GROUP", "")];
|
||||||
|
}
|
||||||
self.editingSession = nil;
|
self.editingSession = nil;
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidCommitChangesToSelectedItem object:self];
|
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidCommitChangesToSelectedItem object:self];
|
||||||
}
|
}
|
||||||
@@ -51,7 +56,7 @@ NSString *const MPDocumentDidCommitChangesToSelectedItem = @"com.hicknhack.mac
|
|||||||
if(nil == self.selectedItem) {
|
if(nil == self.selectedItem) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.editingSession = [[MPEditingSession alloc] initWithSource:self.selectedItem];
|
self.editingSession = [MPEditingSession editingSessionWithSource:self.selectedItem];
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidBeginEditingSelectedItem object:self];
|
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidBeginEditingSelectedItem object:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,15 +8,23 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@class KPKNode;
|
@class KPKNode;
|
||||||
|
|
||||||
@interface MPEditingSession : NSObject
|
@interface MPEditingSession : NSObject
|
||||||
|
|
||||||
@property (copy, readonly) KPKNode *node;
|
@property (copy, readonly) KPKNode *node;
|
||||||
@property (weak, readonly) KPKNode *source;
|
@property (nullable, weak, readonly) KPKNode *source;
|
||||||
|
|
||||||
|
+ (instancetype)editingSessionWithSource:(KPKNode *)node;
|
||||||
- (instancetype)initWithSource:(KPKNode *)node;
|
- (instancetype)initWithSource:(KPKNode *)node;
|
||||||
|
|
||||||
|
- (instancetype)init NS_UNAVAILABLE;
|
||||||
|
|
||||||
- (BOOL)hasChanges;
|
- (BOOL)hasChanges;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
||||||
|
|||||||
@@ -18,9 +18,8 @@
|
|||||||
|
|
||||||
@implementation MPEditingSession
|
@implementation MPEditingSession
|
||||||
|
|
||||||
- (instancetype)init {
|
+ (instancetype)editingSessionWithSource:(KPKNode *)node {
|
||||||
self = [self initWithSource:nil];
|
return [[MPEditingSession alloc] initWithSource:node];
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithSource:(KPKNode *)node {
|
- (instancetype)initWithSource:(KPKNode *)node {
|
||||||
|
|||||||
@@ -138,6 +138,21 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
|
|||||||
selector:@selector(_willSave:)
|
selector:@selector(_willSave:)
|
||||||
name:MPDocumentWillSaveNotification
|
name:MPDocumentWillSaveNotification
|
||||||
object:document];
|
object:document];
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(_didBeginEditingSelectedItem:)
|
||||||
|
name:MPDocumentDidBeginEditingSelectedItem
|
||||||
|
object:document];
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(_didCancelOrCommitChangesToSelectedItem:)
|
||||||
|
name:MPDocumentDidCommitChangesToSelectedItem
|
||||||
|
object:document];
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(_didCancelOrCommitChangesToSelectedItem:)
|
||||||
|
name:MPDocumentDidCancelChangesToSelectedItem
|
||||||
|
object:document];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
@@ -318,27 +333,27 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
|
|||||||
HNHScrollView *scrollView = [[HNHScrollView alloc] init];
|
HNHScrollView *scrollView = [[HNHScrollView alloc] init];
|
||||||
scrollView.actAsFlipped = NO;
|
scrollView.actAsFlipped = NO;
|
||||||
scrollView.showBottomShadow = NO;
|
scrollView.showBottomShadow = NO;
|
||||||
[scrollView setHasVerticalScroller:YES];
|
scrollView.hasVerticalScroller = YES;
|
||||||
[scrollView setDrawsBackground:NO];
|
scrollView.drawsBackground = NO;
|
||||||
[scrollView setTranslatesAutoresizingMaskIntoConstraints:NO];
|
scrollView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||||
NSView *clipView = [scrollView contentView];
|
NSView *clipView = scrollView.contentView;
|
||||||
|
|
||||||
NSTabViewItem *tabViewItem = [self.tabView tabViewItemAtIndex:tab];
|
NSTabViewItem *tabViewItem = [self.tabView tabViewItemAtIndex:tab];
|
||||||
NSView *tabView = [tabViewItem view];
|
NSView *tabView = tabViewItem.view;
|
||||||
/*
|
/*
|
||||||
DO NEVER SET setTranslatesAutoresizingMaskIntoConstraints on NSTabViewItem's view
|
DO NEVER SET setTranslatesAutoresizingMaskIntoConstraints on NSTabViewItem's view
|
||||||
[tabView setTranslatesAutoresizingMaskIntoConstraints:NO];
|
[tabView setTranslatesAutoresizingMaskIntoConstraints:NO];
|
||||||
*/
|
*/
|
||||||
[scrollView setDocumentView:view];
|
scrollView.documentView = view;
|
||||||
[tabView addSubview:scrollView];
|
[tabView addSubview:scrollView];
|
||||||
[tabViewItem setInitialFirstResponder:scrollView];
|
tabViewItem.initialFirstResponder = scrollView;
|
||||||
|
|
||||||
NSDictionary *views = NSDictionaryOfVariableBindings(view, scrollView);
|
NSDictionary *views = NSDictionaryOfVariableBindings(view, scrollView);
|
||||||
[[scrollView superview] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[scrollView]|"
|
[scrollView.superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[scrollView]|"
|
||||||
options:0
|
options:0
|
||||||
metrics:nil
|
metrics:nil
|
||||||
views:views ]];
|
views:views ]];
|
||||||
[[scrollView superview] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[scrollView]|"
|
[scrollView.superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[scrollView]|"
|
||||||
options:0
|
options:0
|
||||||
metrics:nil
|
metrics:nil
|
||||||
views:views]];
|
views:views]];
|
||||||
@@ -445,21 +460,18 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)_toggleEditing:(BOOL)edit {
|
- (void)_toggleEditing:(BOOL)edit {
|
||||||
/* TODO: not fully working right now */
|
NSArray <NSTextField *> *textFields = @[self.titleTextField,
|
||||||
|
self.usernameTextField,
|
||||||
[_titleTextField setEditable:edit];
|
self.URLTextField,
|
||||||
[_titleTextField setSelectable:edit];
|
self.passwordTextField,
|
||||||
[_usernameTextField setEditable:edit];
|
self.tagsTokenField
|
||||||
[_usernameTextField setSelectable:edit];
|
/*self.createdTextField,
|
||||||
[_URLTextField setEditable:edit];
|
self.modifiedTextField*/
|
||||||
[_URLTextField setSelectable:edit];
|
];
|
||||||
[_passwordTextField setEditable:edit];
|
for(NSTextField *t in textFields) {
|
||||||
[_passwordTextField setSelectable:edit];
|
t.editable = edit;
|
||||||
|
t.selectable = edit;
|
||||||
[_createdTextField setEditable:edit];
|
}
|
||||||
[_createdTextField setSelectable:edit];
|
|
||||||
[_modifiedTextField setEditable:edit];
|
|
||||||
[_modifiedTextField setSelectable:edit];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
@@ -475,4 +487,11 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
|
|||||||
[[[self view] window] makeFirstResponder:nil];
|
[[[self view] window] makeFirstResponder:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)_didBeginEditingSelectedItem:(NSNotification *)notification {
|
||||||
|
[self _toggleEditing:YES];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)_didCancelOrCommitChangesToSelectedItem:(NSNotification *)notification {
|
||||||
|
[self _toggleEditing:NO];
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -23,5 +23,7 @@
|
|||||||
@property (weak) IBOutlet HNHRoundedTextField *autotypeSequenceTextField;
|
@property (weak) IBOutlet HNHRoundedTextField *autotypeSequenceTextField;
|
||||||
|
|
||||||
- (void)setupBindings:(MPDocument *)document;
|
- (void)setupBindings:(MPDocument *)document;
|
||||||
|
- (void)beginEditing;
|
||||||
|
- (void)endEditing;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -18,7 +18,9 @@
|
|||||||
#import "HNHRoundedTextField.h"
|
#import "HNHRoundedTextField.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;
|
||||||
@@ -34,28 +36,29 @@
|
|||||||
- (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];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)awakeFromNib {
|
- (void)awakeFromNib {
|
||||||
HNHScrollView *scrollView = (HNHScrollView *)[self view];
|
HNHScrollView *scrollView = (HNHScrollView *)self.view;
|
||||||
|
|
||||||
scrollView.actAsFlipped = NO;
|
scrollView.actAsFlipped = NO;
|
||||||
scrollView.showBottomShadow = NO;
|
scrollView.showBottomShadow = NO;
|
||||||
[scrollView setHasVerticalScroller:YES];
|
scrollView.hasVerticalRuler = YES;
|
||||||
[scrollView setDrawsBackground:NO];
|
scrollView.drawsBackground = NO;
|
||||||
[scrollView setTranslatesAutoresizingMaskIntoConstraints:NO];
|
scrollView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||||
NSView *clipView = [scrollView contentView];
|
NSView *clipView = scrollView.contentView;
|
||||||
|
|
||||||
[scrollView setDocumentView:self.contentView];
|
scrollView.documentView = self.contentView;
|
||||||
|
|
||||||
NSDictionary *views = NSDictionaryOfVariableBindings(_contentView);
|
NSDictionary *views = NSDictionaryOfVariableBindings(_contentView);
|
||||||
[clipView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_contentView]|"
|
[clipView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_contentView]|"
|
||||||
options:0
|
options:0
|
||||||
metrics:nil
|
metrics:nil
|
||||||
views:views]];
|
views:views]];
|
||||||
[[self view] layoutSubtreeIfNeeded];
|
[self.view layoutSubtreeIfNeeded];
|
||||||
|
|
||||||
NSMenu *autotypeMenu = self.autotypePopupButton.menu;
|
NSMenu *autotypeMenu = self.autotypePopupButton.menu;
|
||||||
NSMenuItem *inheritAutotype = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"AUTOTYPE_INHERIT", "") action:NULL keyEquivalent:@""];
|
NSMenuItem *inheritAutotype = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"AUTOTYPE_INHERIT", "") action:NULL keyEquivalent:@""];
|
||||||
|
|||||||
@@ -108,11 +108,12 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
|||||||
[[self view] layout];
|
[[self view] layout];
|
||||||
|
|
||||||
/* Init edit and cancel buttons */
|
/* Init edit and cancel buttons */
|
||||||
[self.editButton setAction:@selector(beginEditingSelectedItem:)];
|
self.editButton.action = @selector(beginEditingSelectedItem:);
|
||||||
[self.cancelEditButton setAction:@selector(cancelChangesToSelectedItem:)];
|
self.cancelEditButton.action = @selector(cancelChangesToSelectedItem:);
|
||||||
[self.cancelEditButton setHidden:YES];
|
self.cancelEditButton.hidden = YES;
|
||||||
|
|
||||||
[self _updateBindings:nil];
|
[self _updateBindings:nil];
|
||||||
|
[self _toggleEditors:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)regsiterNotificationsForDocument:(MPDocument *)document {
|
- (void)regsiterNotificationsForDocument:(MPDocument *)document {
|
||||||
@@ -265,70 +266,70 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
|
|||||||
- (void)_updateBindings:(id)item {
|
- (void)_updateBindings:(id)item {
|
||||||
if(!item) {
|
if(!item) {
|
||||||
[self.itemNameTextField unbind:NSValueBinding];
|
[self.itemNameTextField unbind:NSValueBinding];
|
||||||
[self.itemNameTextField unbind:NSEnabledBinding];
|
self.itemNameTextField.hidden = YES;
|
||||||
[self.itemNameTextField setHidden:YES];
|
|
||||||
[self.itemImageView unbind:NSValueBinding];
|
[self.itemImageView unbind:NSValueBinding];
|
||||||
[self.itemImageView unbind:NSEnabledBinding];
|
self.itemImageView.hidden = YES;
|
||||||
[self.itemImageView setHidden:YES];
|
|
||||||
[[self.notesTextView enclosingScrollView] setHidden:YES];
|
self.notesTextView.enclosingScrollView.hidden = YES;
|
||||||
[self.notesTextView unbind:NSValueBinding];
|
[self.notesTextView unbind:NSValueBinding];
|
||||||
[self.notesTextView unbind:NSEditableBinding];
|
self.notesTextView.string = @"";
|
||||||
[self.notesTextView setString:@""];
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Disable if item is not editable */
|
/* Disable if item is not editable */
|
||||||
[self.itemNameTextField bind:NSEnabledBinding toObject:item withKeyPath:NSStringFromSelector(@selector(isEditable)) options:nil];
|
|
||||||
[self.itemImageView bind:NSEnabledBinding toObject:item withKeyPath:NSStringFromSelector(@selector(isEditable)) options:nil];
|
|
||||||
[self.notesTextView bind:NSEditableBinding toObject:item withKeyPath:NSStringFromSelector(@selector(isEditable)) options:nil];
|
|
||||||
|
|
||||||
[self.itemImageView bind:NSValueBinding toObject:item withKeyPath:NSStringFromSelector(@selector(iconImage)) options:nil];
|
[self.itemImageView bind:NSValueBinding toObject:item withKeyPath:NSStringFromSelector(@selector(iconImage)) options:nil];
|
||||||
[[self.notesTextView enclosingScrollView] setHidden:NO];
|
self.notesTextView.enclosingScrollView.hidden = NO;
|
||||||
[self.notesTextView bind:NSValueBinding toObject:item withKeyPath:NSStringFromSelector(@selector(notes)) options:nil];
|
[self.notesTextView bind:NSValueBinding toObject:item withKeyPath:NSStringFromSelector(@selector(notes)) options:nil];
|
||||||
[self.itemNameTextField bind:NSValueBinding toObject:item withKeyPath:NSStringFromSelector(@selector(title)) options:nil];
|
[self.itemNameTextField bind:NSValueBinding toObject:item withKeyPath:NSStringFromSelector(@selector(title)) options:nil];
|
||||||
[self.itemImageView setHidden:NO];
|
self.itemImageView.hidden = NO;
|
||||||
[self.itemNameTextField setHidden:NO];
|
self.itemNameTextField.hidden = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark -
|
||||||
|
#pragma mark Editing
|
||||||
|
- (void)_toggleEditors:(BOOL)editable {
|
||||||
|
self.itemImageView.enabled = editable;
|
||||||
|
self.itemNameTextField.enabled = editable;
|
||||||
|
self.itemImageView.enabled = editable;
|
||||||
|
self.notesTextView.editable = editable;
|
||||||
|
}
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
#pragma mark MPDocument Notifications
|
#pragma mark MPDocument Notifications
|
||||||
|
|
||||||
- (void)_didChangeCurrentItem:(NSNotification *)notification {
|
- (void)_didChangeCurrentItem:(NSNotification *)notification {
|
||||||
MPDocument *document = [notification object];
|
MPDocument *document = notification.object;
|
||||||
if(!document.selectedItem) {
|
if(document.selectedItem.asGroup) {
|
||||||
/* show emty tab and hide edit button */
|
self.activeTab = MPGroupTab;
|
||||||
self.activeTab = MPEmptyTab;
|
}
|
||||||
|
else if(document.selectedItem.asEntry) {
|
||||||
|
self.activeTab = MPEntryTab;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
BOOL isGroup = document.selectedItem == document.selectedGroup;
|
self.activeTab = MPEmptyTab;
|
||||||
BOOL isEntry = document.selectedItem == document.selectedEntry;
|
|
||||||
if(isGroup) {
|
|
||||||
self.activeTab = MPGroupTab;
|
|
||||||
}
|
|
||||||
else if(isEntry) {
|
|
||||||
self.activeTab = MPEntryTab;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// self.representedObject = document.selectedItem;
|
||||||
|
// self.entryViewController.representedObject = document.selectedItem.asEntry;
|
||||||
|
// self.groupViewController.representedObject = document.selectedItem.asGroup;
|
||||||
[self _updateBindings:document.selectedItem];
|
[self _updateBindings:document.selectedItem];
|
||||||
|
|
||||||
/* disable the entry text fields whenever the entry selection changes */
|
|
||||||
//[self.entryViewController endEditing];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_didBeginEditingSelectedItem:(NSNotification *)notification {
|
- (void)_didBeginEditingSelectedItem:(NSNotification *)notification {
|
||||||
MPDocument *document = [notification object];
|
MPDocument *document = notification.object;
|
||||||
[self.editButton setAction:@selector(commitChangesToSelectedItem:)];
|
self.editButton.action = @selector(commitChangesToSelectedItem:);
|
||||||
[self.editButton setTitle:NSLocalizedString(@"DONE", "")];
|
self.editButton.title = NSLocalizedString(@"SAVE", "");
|
||||||
[self.cancelEditButton setHidden:NO];
|
self.cancelEditButton.hidden = NO;
|
||||||
[self _updateBindings:document.editingSession.node];
|
[self _updateBindings:document.editingSession.node];
|
||||||
|
[self _toggleEditors:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_didCancelOrCommitChangesToSelectedItem:(NSNotification *)notification {
|
- (void)_didCancelOrCommitChangesToSelectedItem:(NSNotification *)notification {
|
||||||
MPDocument *document = [notification object];
|
MPDocument *document = notification.object;
|
||||||
[self.editButton setTitle:NSLocalizedString(@"EDIT", "")];
|
self.editButton.title = NSLocalizedString(@"EDIT", "");
|
||||||
[self.cancelEditButton setHidden:YES];
|
self.cancelEditButton.hidden = YES;
|
||||||
[self.editButton setAction:@selector(beginEditingSelectedItem:)];
|
self.editButton.action = @selector(beginEditingSelectedItem:);
|
||||||
[self _updateBindings:document.selectedItem];
|
[self _updateBindings:document.selectedItem];
|
||||||
|
[self _toggleEditors:NO];
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -15,8 +15,6 @@
|
|||||||
- (void)didLoadView;
|
- (void)didLoadView;
|
||||||
- (NSResponder *)reconmendedFirstResponder;
|
- (NSResponder *)reconmendedFirstResponder;
|
||||||
/* Returns the associated window controller */
|
/* Returns the associated window controller */
|
||||||
|
|
||||||
|
|
||||||
- (void)updateResponderChain;
|
- (void)updateResponderChain;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
Reference in New Issue
Block a user