mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 17:32:17 +00:00
Reworked DatabaseSettings to be cancelable
Moved Password edit to Database settings
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPDocumentSettingsWindowController.h"
|
||||
#import "MPDatabaseSettingsWindowController.h"
|
||||
#import "MPDocument.h"
|
||||
#import "MPDocumentWindowController.h"
|
||||
#import "MPDatabaseVersion.h"
|
||||
@@ -16,20 +16,22 @@
|
||||
#import "Kdb4Node.h"
|
||||
#import "KdbGroup+MPAdditions.h"
|
||||
|
||||
@interface MPDocumentSettingsWindowController () {
|
||||
@interface MPDatabaseSettingsWindowController () {
|
||||
MPDocument *_document;
|
||||
}
|
||||
|
||||
@property (nonatomic,assign) BOOL trashEnabled;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPDocumentSettingsWindowController
|
||||
@implementation MPDatabaseSettingsWindowController
|
||||
|
||||
- (id)init {
|
||||
return [self initWithDocument:nil];
|
||||
}
|
||||
|
||||
- (id)initWithDocument:(MPDocument *)document {
|
||||
self = [super initWithWindowNibName:@"DocumentSettingsWindow"];
|
||||
self = [super initWithWindowNibName:@"DatabaseSettingsWindow"];
|
||||
if(self) {
|
||||
_document = document;
|
||||
}
|
||||
@@ -53,11 +55,40 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)save:(id)sender {
|
||||
|
||||
/* Protection */
|
||||
_document.password = [self.passwordTextField stringValue];
|
||||
_document.key = [self.keyfilePathControl URL];
|
||||
|
||||
/* General */
|
||||
_document.treeV4.databaseDescription = [self.databaseDescriptionTextView string];
|
||||
_document.treeV4.databaseName = [self.databaseNameTextField stringValue];
|
||||
|
||||
/* Display */
|
||||
|
||||
/* Advanced */
|
||||
_document.treeV4.recycleBinEnabled = self.trashEnabled;
|
||||
NSMenuItem *menuItem = [self.selectRecycleBinGroupPopUpButton selectedItem];
|
||||
KdbGroup *group = [menuItem representedObject];
|
||||
[_document useGroupAsTrash:group];
|
||||
|
||||
_document.treeV4.protectNotes = [self.protectNotesCheckButton state] == NSOnState;
|
||||
_document.treeV4.protectPassword = [self.protectPasswortCheckButton state] == NSOnState;
|
||||
_document.treeV4.protectTitle = [self.protectTitleCheckButton state] == NSOnState;
|
||||
_document.treeV4.protectUrl = [self.protectURLCheckButton state] == NSOnState;
|
||||
_document.treeV4.protectUserName = [self.protectUserNameCheckButton state] == NSOnState;
|
||||
|
||||
/* Close to finish */
|
||||
[self close:nil];
|
||||
}
|
||||
|
||||
- (IBAction)close:(id)sender {
|
||||
[NSApp endSheet:[self window]];
|
||||
[[self window] orderOut:nil];
|
||||
}
|
||||
|
||||
|
||||
- (void)update {
|
||||
/* Update all stuff that might have changed */
|
||||
Kdb4Tree *tree = _document.treeV4;
|
||||
@@ -66,36 +97,42 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)showSettingsTab:(MPDatabaseSettingsTab)tab {
|
||||
[self.sectionTabView selectTabViewItemAtIndex:tab];
|
||||
}
|
||||
|
||||
#pragma mark Actions
|
||||
- (IBAction)clearKey:(id)sender {
|
||||
[self.keyfilePathControl setURL:nil];
|
||||
}
|
||||
|
||||
- (IBAction)generateKey:(id)sender {
|
||||
}
|
||||
|
||||
#pragma mark Private Helper
|
||||
- (void)_setupDatabase:(Kdb4Tree *)tree {
|
||||
[self.databaseNameTextField bind:NSValueBinding toObject:tree withKeyPath:@"databaseName" options:nil];
|
||||
[self.databaseDescriptionTextView bind:NSValueBinding toObject:tree withKeyPath:@"databaseDescription" options:nil];
|
||||
[self.databaseNameTextField setStringValue:tree.databaseName];
|
||||
[self.databaseDescriptionTextView setString:tree.databaseDescription];
|
||||
}
|
||||
|
||||
- (void)_setupProtectionTab:(Kdb4Tree *)tree {
|
||||
[self.protectNotesCheckButton bind:NSValueBinding toObject:tree withKeyPath:@"protectNotes" options:nil];
|
||||
[self.protectPasswortCheckButton bind:NSValueBinding toObject:tree withKeyPath:@"protectPassword" options:nil];
|
||||
[self.protectTitleCheckButton bind:NSValueBinding toObject:tree withKeyPath:@"protectTitle" options:nil];
|
||||
[self.protectURLCheckButton bind:NSValueBinding toObject:tree withKeyPath:@"protectUrl" options:nil];
|
||||
[self.protectUserNameCheckButton bind:NSValueBinding toObject:tree withKeyPath:@"protectUserName" options:nil];
|
||||
[self.protectNotesCheckButton setState:tree.protectNotes ? NSOnState : NSOffState ];
|
||||
[self.protectNotesCheckButton setState:tree.protectPassword ? NSOnState : NSOffState];
|
||||
[self.protectTitleCheckButton setState:tree.protectTitle ? NSOnState : NSOffState];
|
||||
[self.protectURLCheckButton setState:tree.protectUrl ? NSOnState : NSOffState];
|
||||
[self.protectUserNameCheckButton setState:tree.protectUserName ? NSOnState : NSOffState];
|
||||
}
|
||||
|
||||
- (void)_setupAdvancedTab:(Kdb4Tree *)tree {
|
||||
[self.enableRecycleBinCheckButton bind:NSValueBinding toObject:tree withKeyPath:@"recycleBinEnabled" options:nil];
|
||||
[self.selectRecycleBinGroupPopUpButton bind:NSEnabledBinding toObject:tree withKeyPath:@"recycleBinEnabled" options:nil];
|
||||
self.trashEnabled = tree.recycleBinEnabled;
|
||||
[self.enableRecycleBinCheckButton bind:NSValueBinding toObject:self withKeyPath:@"trashEnabled" options:nil];
|
||||
[self.selectRecycleBinGroupPopUpButton bind:NSEnabledBinding toObject:self withKeyPath:@"trashEnabled" options:nil];
|
||||
[self _updateTrashFolders:tree];
|
||||
}
|
||||
|
||||
- (void)_setupPasswordTab:(Kdb4Tree *)tree {
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void)_didSelectTrashFolder:(id)sender {
|
||||
NSMenuItem *menuItem = sender;
|
||||
/* if we do not get a group, use nil to reset the trash */
|
||||
KdbGroup *group = [menuItem representedObject];
|
||||
[_document useGroupAsTrash:group];
|
||||
[self.passwordTextField setStringValue:_document.password ? _document.password : @""];
|
||||
[self.keyfilePathControl setURL:_document.key];
|
||||
}
|
||||
|
||||
- (void)_updateTrashFolders:(Kdb4Tree *)tree {
|
||||
@@ -105,22 +142,21 @@
|
||||
|
||||
- (NSMenu *)_buildTreeMenu:(Kdb4Tree *)tree {
|
||||
NSMenu *menu = [[NSMenu alloc] init];
|
||||
[menu setAutoenablesItems:NO];
|
||||
|
||||
for(Kdb4Group *group in tree.root.groups) {
|
||||
NSMenuItem *groupItem = [[NSMenuItem alloc] init];
|
||||
[groupItem setImage:group.icon];
|
||||
[groupItem setTitle:group.name];
|
||||
[groupItem setAction:@selector(_didSelectTrashFolder:)];
|
||||
[groupItem setTarget:self];
|
||||
[groupItem setRepresentedObject:group];
|
||||
[groupItem setEnabled:YES];
|
||||
if([group.uuid isEqual:tree.recycleBinUuid]) {
|
||||
[groupItem setState:NSOnState];
|
||||
}
|
||||
[menu addItem:groupItem];
|
||||
}
|
||||
NSMenuItem *selectItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"SELECT_RECYCLEBIN", @"Menu item if no reycleBin is selected") action:NULL keyEquivalent:@""];
|
||||
[selectItem setAction:@selector(_didSelectTrashFolder:)];
|
||||
[selectItem setTarget:self];
|
||||
[selectItem setEnabled:YES];
|
||||
[menu insertItem:selectItem atIndex:0];
|
||||
|
||||
return menu;
|
||||
|
||||
Reference in New Issue
Block a user