-
Notifications
You must be signed in to change notification settings - Fork 315
/
AddCollectionController.m
58 lines (49 loc) · 1.46 KB
/
AddCollectionController.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
//
// AddCollectionController.m
// MongoHub
//
// Created by Syd on 10-4-28.
// Copyright 2010 ThePeppersStudio.COM. All rights reserved.
//
#import "Configure.h"
#import "AddCollectionController.h"
@implementation AddCollectionController
@synthesize dbname;
@synthesize collectionname;
@synthesize dbInfo;
- (id)init {
if (![super initWithWindowNibName:@"NewCollection"]) return nil;
return self;
}
- (void)dealloc {
[dbname release];
[collectionname release];
[dbInfo release];
[super dealloc];
}
- (void)windowWillClose:(NSNotification *)notification {
[[NSNotificationCenter defaultCenter] postNotificationName:kNewCollectionWindowWillClose object:dbInfo];
dbInfo = nil;
}
- (IBAction)cancel:(id)sender {
dbInfo = nil;
[self close];
}
- (IBAction)add:(id)sender {
if ([ [collectionname stringValue] length] == 0) {
NSRunAlertPanel(@"Error", @"Collection name could not be empty", @"OK", nil, nil);
return;
}
NSArray *keys = [[NSArray alloc] initWithObjects:@"dbname", @"collectionname", nil];
NSString *colname = [[NSString alloc] initWithString:[collectionname stringValue]];
NSArray *objs = [[NSArray alloc] initWithObjects:dbname, colname, nil];
[colname release];
if (!dbInfo) {
dbInfo = [[NSMutableDictionary alloc] initWithCapacity:2];
}
dbInfo = [NSMutableDictionary dictionaryWithObjects:objs forKeys:keys];
[objs release];
[keys release];
[self close];
}
@end