mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 16:22:21 +00:00
Created view and supporting code to create a new file
Created a new view CreationView, and supporting ViewController. Design closely mirrors that of opening an existing file. Added the viewcontrollers to the main window controller. Creation of a new file sort of works, the file is created and can be saved, but one can't add anything to it.
This commit is contained in:
1248
MacPass/CreationView.xib
Normal file
1248
MacPass/CreationView.xib
Normal file
File diff suppressed because it is too large
Load Diff
15
MacPass/MPCreationViewController.h
Normal file
15
MacPass/MPCreationViewController.h
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// MPCreationViewController.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Nathaniel Madura on 18/04/13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPViewController.h"
|
||||
|
||||
@interface MPCreationViewController : MPViewController
|
||||
|
||||
@property (retain) NSURL *fileURL;
|
||||
|
||||
@end
|
||||
76
MacPass/MPCreationViewController.m
Normal file
76
MacPass/MPCreationViewController.m
Normal file
@@ -0,0 +1,76 @@
|
||||
//
|
||||
// MPCreationViewController.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Nathaniel Madura on 18/04/13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPCreationViewController.h"
|
||||
#import "MPKeyfilePathControlDelegate.h"
|
||||
#import "MPDatabaseController.h"
|
||||
#import "MPDatabaseDocument.h"
|
||||
|
||||
@interface MPCreationViewController ()
|
||||
|
||||
@property (assign) IBOutlet NSSecureTextField *passwordTextField;
|
||||
@property (assign) IBOutlet NSSecureTextField *validatePasswordTextField;
|
||||
@property (assign) IBOutlet NSPathControl *keyPathControl;
|
||||
@property (retain) MPKeyfilePathControlDelegate *pathControlDelegate;
|
||||
@property (assign) IBOutlet NSTextField *errorInfoTextField;
|
||||
|
||||
- (IBAction)_new:(id)sender;
|
||||
- (void)_showError;
|
||||
- (void)_reset;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPCreationViewController
|
||||
|
||||
- (id)init {
|
||||
return [[MPCreationViewController alloc] initWithNibName:@"CreationView" bundle:nil];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[_fileURL release];
|
||||
[_pathControlDelegate release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)didLoadView {
|
||||
[self.keyPathControl setDelegate:self.pathControlDelegate];
|
||||
[self _reset];
|
||||
}
|
||||
|
||||
- (NSResponder *)reconmendedFirstResponder {
|
||||
return self.passwordTextField;
|
||||
}
|
||||
|
||||
- (IBAction)_new:(id)sender {
|
||||
NSString *password = self.passwordTextField.stringValue;
|
||||
NSURL *keyfile = [self.keyPathControl URL];
|
||||
if ([password compare:self.validatePasswordTextField.stringValue] != NSOrderedSame)
|
||||
{
|
||||
[self.errorInfoTextField setStringValue:@"Passwords do not match"];
|
||||
[self.errorInfoTextField setHidden:NO];
|
||||
}
|
||||
[self _reset];
|
||||
|
||||
[[MPDatabaseController defaultController] newDatabaseAtURL:self.fileURL
|
||||
databaseVersion:MPDatabaseVersion4
|
||||
password:password
|
||||
keyfile:keyfile];
|
||||
}
|
||||
|
||||
- (void)_reset {
|
||||
[self.passwordTextField setStringValue:@""];
|
||||
[self.validatePasswordTextField setStringValue:@""];
|
||||
[self.keyPathControl setURL:nil];
|
||||
[self.errorInfoTextField setHidden:YES];
|
||||
}
|
||||
|
||||
- (void)_showError {
|
||||
[self.errorInfoTextField setHidden:NO];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -13,6 +13,7 @@
|
||||
@class MPInspectorTabViewController;
|
||||
@class MPPasswordInputController;
|
||||
@class MPOutlineViewController;
|
||||
@class MPCreationViewController;
|
||||
|
||||
@interface MPMainWindowController : NSWindowController
|
||||
|
||||
@@ -20,6 +21,7 @@
|
||||
@property (readonly, retain) MPEntryViewController *entryViewController;
|
||||
@property (readonly, retain) MPOutlineViewController *outlineViewController;
|
||||
@property (readonly, retain) MPInspectorTabViewController *inspectorTabViewController;
|
||||
@property (readonly, retain) MPCreationViewController *creationViewController;
|
||||
|
||||
|
||||
- (void)showEntries;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#import "MPMainWindowSplitViewDelegate.h"
|
||||
#import "MPInspectorTabViewController.h"
|
||||
#import "MPAppDelegate.h"
|
||||
#import "MPCreationViewController.h"
|
||||
|
||||
@interface MPMainWindowController ()
|
||||
|
||||
@@ -32,6 +33,7 @@
|
||||
@property (retain) MPEntryViewController *entryViewController;
|
||||
@property (retain) MPOutlineViewController *outlineViewController;
|
||||
@property (retain) MPInspectorTabViewController *inspectorTabViewController;
|
||||
@property (retain) MPCreationViewController *creationViewController;
|
||||
|
||||
@property (retain) MPToolbarDelegate *toolbarDelegate;
|
||||
@property (retain) MPMainWindowSplitViewDelegate *splitViewDelegate;
|
||||
@@ -54,6 +56,7 @@
|
||||
_outlineViewController = [[MPOutlineViewController alloc] init];
|
||||
_inspectorTabViewController = [[MPInspectorTabViewController alloc] init];
|
||||
_splitViewDelegate = [[MPMainWindowSplitViewDelegate alloc] init];
|
||||
_creationViewController = [[MPCreationViewController alloc] init];
|
||||
|
||||
[[NSBundle mainBundle] loadNibNamed:@"WelcomeView" owner:self topLevelObjects:NULL];
|
||||
[self.welcomeView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
||||
@@ -76,6 +79,7 @@
|
||||
[_entryViewController release];
|
||||
[_outlineViewController release];
|
||||
[_inspectorTabViewController release];
|
||||
[_creationViewController release];
|
||||
|
||||
[_toolbarDelegate release];
|
||||
[_splitViewDelegate release];
|
||||
@@ -248,6 +252,31 @@
|
||||
- (void)showEditForm:(id)sender {
|
||||
}
|
||||
|
||||
- (void)newDocument:(id)sender {
|
||||
if (!self.creationViewController) {
|
||||
self.creationViewController = [[[MPCreationViewController alloc] init] autorelease];
|
||||
}
|
||||
|
||||
NSSavePanel *savePanel = [NSSavePanel savePanel];
|
||||
[savePanel setAllowedFileTypes:@[@"kdbx", @"kdb"]];
|
||||
[savePanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {
|
||||
if (result == NSFileHandlingPanelOKButton) {
|
||||
NSURL *file = [savePanel URL];
|
||||
NSLog(@"Will create file at: %@", file);
|
||||
self.creationViewController.fileURL = file;
|
||||
[self _setContentViewController:self.creationViewController];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)saveDocument:(id)sender
|
||||
{
|
||||
NSLog(@"Attempting to save document");
|
||||
if ([[MPDatabaseController defaultController].database save])
|
||||
NSLog(@"Save successful");
|
||||
else
|
||||
NSLog(@"Save failed");
|
||||
}
|
||||
|
||||
#pragma mark Helper
|
||||
|
||||
|
||||
Reference in New Issue
Block a user