-
Notifications
You must be signed in to change notification settings - Fork 315
/
AuthWindowController.m
81 lines (67 loc) · 1.94 KB
/
AuthWindowController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//
// AuthWindowController.m
// MongoHub
//
// Created by Syd on 10-5-6.
// Copyright 2010 ThePeppersStudio.COM. All rights reserved.
//
#import "Configure.h"
#import "AuthWindowController.h"
#import "DatabasesArrayController.h"
#import "Database.h"
#import "Connection.h"
@implementation AuthWindowController
@synthesize userTextField;
@synthesize passwordTextField;
@synthesize dbname;
@synthesize conn;
@synthesize managedObjectContext;
@synthesize databasesArrayController;
- (id)init {
if (![super initWithWindowNibName:@"Auth"]) return nil;
return self;
}
- (void)dealloc {
[userTextField release];
[passwordTextField release];
[dbname release];
[managedObjectContext release];
[databasesArrayController release];
[conn release];
[super dealloc];
}
- (void)windowDidLoad {
//NSLog(@"New Connection Window Loaded");
[super windowDidLoad];
}
- (void)windowWillClose:(NSNotification *)notification {
[[NSNotificationCenter defaultCenter] postNotificationName:kAuthWindowWillClose object:nil];
dbname = nil;
}
- (IBAction)cancel:(id)sender {
dbname = nil;
[self close];
}
- (IBAction)save:(id)sender {
Database *db = [databasesArrayController dbInfo:conn name:dbname];
if (db) {
db.user = [userTextField stringValue];
db.password = [passwordTextField stringValue];
}else {
db = [databasesArrayController newObjectWithConn:conn name:dbname user:[userTextField stringValue] password:[passwordTextField stringValue]];
[databasesArrayController addObject:db];
[db release];
}
[self saveAction];
[self close];
}
- (void) saveAction {
NSError *error = nil;
if (![[self managedObjectContext] commitEditing]) {
NSLog(@"%@:%s unable to commit editing before saving", [self class], _cmd);
}
if (![[self managedObjectContext] save:&error]) {
[[NSApplication sharedApplication] presentError:error];
}
}
@end