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