Got rid of everything on the Objective-C side that we don't need.

This commit is contained in:
Corey Johnson
2011-11-10 14:31:01 -08:00
parent ddcd9d4e0f
commit bccd592310
3 changed files with 20 additions and 91 deletions

View File

@@ -12,28 +12,14 @@
@synthesize controllers;
- (AtomController *)createController:(NSString *)path {
if (path) {
NSMutableArray *openedPaths = [self storageGet:@"app.openedPaths" defaultValue:[NSMutableArray array]];
if (![openedPaths containsObject:path]) {
[openedPaths addObject:path];
[self storageSet:@"app.openedPaths" value:openedPaths];
}
}
AtomController *controller = [[AtomController alloc] initWithPath:path];
[controllers addObject:controller];
// window.coffee will set the window size
[[controller window] setFrame:NSMakeRect(0, 0, 0, 0) display:YES animate:NO];
return controller;
}
- (void)removeController:(AtomController *)controller {
[controllers removeObject:controller];
NSMutableArray *openedPaths = [self storageGet:@"app.openedPaths" defaultValue:[NSMutableArray array]];
[openedPaths removeObject:controller.path];
[self storageSet:@"app.openedPaths" value:openedPaths];
[controllers removeObject:controller];
}
- (void)open:(NSString *)path {
@@ -45,15 +31,6 @@
path = [[[panel URLs] lastObject] path];
}
// Not ready for this yet. window.open calls app.open
// for (AtomController *controller in controllers) {
// JSValueRef value = [controller.jscocoa callJSFunctionNamed:@"canOpen" withArguments:path, nil];
// if ([controller.jscocoa toBool:value]) {
// [controller.jscocoa callJSFunctionNamed:@"open" withArguments:path, nil];
// return;
// }
// }
[self createController:path];
}
@@ -95,74 +72,12 @@
- (void)applicationWillFinishLaunching:(NSNotification *)aNotification {
self.controllers = [NSMutableArray array];
// Hack to make localStorage work
WebPreferences* prefs = [WebPreferences standardPreferences];
[prefs _setLocalStorageDatabasePath:WEB_STORAGE_PATH];
[prefs setLocalStorageEnabled:YES];
NSDictionary *defaults = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], @"WebKitDeveloperExtras",
nil];
NSDictionary *defaults = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"WebKitDeveloperExtras", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSError *error = nil;
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:ATOM_USER_PATH withIntermediateDirectories:YES attributes:nil error:&error];
if (!success || error) {
[NSException raise:@"Atom: Failed to open storage path at '%@'. %@" format:ATOM_USER_PATH, [error localizedDescription]];
}
NSArray *openedPaths = [self storageGet:@"app.openedPaths" defaultValue:[NSMutableArray array]];
if (openedPaths.count == 0) {
[self createController:NULL];
}
else {
for (NSString *path in openedPaths) {
[self createController:path];
}
}
}
// Helper Methods that should probably go elsewhere
- (id)storage {
id storage = [NSMutableDictionary dictionaryWithContentsOfFile:ATOM_STORAGE_PATH];
if (!storage) storage = [NSMutableDictionary dictionary];
return storage;
}
- (id)storageGet:(NSString *)keyPath defaultValue:(id)defaultValue {
id storage = [NSMutableDictionary dictionaryWithContentsOfFile:ATOM_STORAGE_PATH];
if (!storage) storage = [NSMutableDictionary dictionary];
id value = [storage valueForKeyPath:keyPath];
if (!value) value = defaultValue;
return value;
}
- (id)storageSet:(NSString *)keyPath value:(id)value {
id storage = [NSMutableDictionary dictionaryWithContentsOfFile:ATOM_STORAGE_PATH];
if (!storage) storage = [NSMutableDictionary dictionary];
NSArray *keys = [keyPath componentsSeparatedByString:@"."];
id parent = storage;
for (int i = 0; i < keys.count - 1; i++) {
NSString *key = [keys objectAtIndex:i];
id newParent = [parent valueForKey:key];
if (!newParent) {
newParent = [NSMutableDictionary dictionary];
[parent setValue:newParent forKey:key];
}
parent = newParent;
}
[storage setValue:value forKeyPath:keyPath];
[storage writeToFile:ATOM_STORAGE_PATH atomically:YES];
return value;
[self createController:nil];
}
@end

View File

@@ -11,5 +11,6 @@
@property (retain) JSCocoa *jscocoa;
- (AtomController *)initWithPath:(NSString *)aPath;
- (NSString *)tempfile;
@end

View File

@@ -20,12 +20,14 @@
[super dealloc];
}
- (id)initWithPath:(NSString *)aPath {
aPath = aPath ? aPath : @"/tmp";
- (id)initWithPath:(NSString *)_path {
if (!_path) _path = [self tempfile];
self = [super initWithWindowNibName:@"AtomWindow"];
path = [[aPath stringByStandardizingPath] retain];
path = [[_path stringByStandardizingPath] retain];
[self.window makeKeyWindow];
return self;
}
@@ -60,4 +62,15 @@
return YES;
}
// Helper methods that should go elsewhere
- (NSString *)tempfile {
char *directory = "/tmp";
char *prefix = "temp-file";
char *tmpPath = tempnam(directory, prefix);
NSString *tmpPathString = [NSString stringWithUTF8String:tmpPath];
free(tmpPath);
return tmpPathString;
}
@end