Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add open project functionality to Mac app.

  • Loading branch information...
commit c1a9df7caa987dad2266e076b6a4cae46a009843 1 parent cafe08a
Marco Aurélio authored
BIN  osx/Nide.xcodeproj/project.xcworkspace/xcuserdata/coreh.xcuserdatad/UserInterfaceState.xcuserstate
View
Binary file not shown
16 osx/Nide.xcodeproj/xcuserdata/coreh.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
View
@@ -2,4 +2,20 @@
<Bucket
type = "1"
version = "1.0">
+ <FileBreakpoints>
+ <FileBreakpoint
+ shouldBeEnabled = "No"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ isPathRelative = "1"
+ filePath = "Nide/NDProjectWindowController.m"
+ timestampString = "347469046.291576"
+ startingColumnNumber = "2147483647"
+ endingColumnNumber = "2147483647"
+ startingLineNumber = "14"
+ endingLineNumber = "14"
+ landmarkName = "-initWithWindowNibName:path:port:init:"
+ landmarkType = "5">
+ </FileBreakpoint>
+ </FileBreakpoints>
</Bucket>
2  osx/Nide/NDAppDelegate.h
View
@@ -8,7 +8,7 @@
#import <Cocoa/Cocoa.h>
-@interface NDAppDelegate : NSObject <NSApplicationDelegate> {
+@interface NDAppDelegate : NSObject <NSApplicationDelegate, NSOpenSavePanelDelegate> {
int port;
}
28 osx/Nide/NDAppDelegate.m
View
@@ -25,10 +25,36 @@ - (IBAction)newProject:(id)sender {
savePanel.title = @"Select a project name and location";
if ([savePanel runModal] == NSOKButton) {
- NDProjectWindowController *windowController = [[NDProjectWindowController alloc] initWithWindowNibName:@"ProjectWindow" path:[[savePanel URL] path] port:port];
+ NDProjectWindowController *windowController = [[NDProjectWindowController alloc] initWithWindowNibName:@"ProjectWindow" path:[[savePanel URL] path] port:port init:YES];
[windowController showWindow:self];
port += 2;
}
}
+- (IBAction)openDocument:(id)sender {
+ NSOpenPanel *openPanel = [NSOpenPanel openPanel];
+
+ openPanel.canChooseDirectories = YES;
+ openPanel.canChooseFiles = NO;
+ openPanel.title = @"Select a project folder";
+ openPanel.delegate = self;
+
+ if ([openPanel runModal] == NSOKButton) {
+ NDProjectWindowController *windowController = [[NDProjectWindowController alloc] initWithWindowNibName:@"ProjectWindow" path:[[openPanel URL] path] port:port init:NO];
+ [windowController showWindow:self];
+ port += 2;
+ }
+
+ openPanel.delegate = nil;
+}
+
+- (BOOL)panel:(id)sender shouldEnableURL:(NSURL *)url {
+ BOOL isDirectory;
+ if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/.nide", [url path]] isDirectory:&isDirectory]) {
+ return isDirectory;
+ } else {
+ return NO;
+ }
+}
+
@end
7 osx/Nide/NDProjectWindowController.h
View
@@ -12,10 +12,15 @@
@interface NDProjectWindowController : NSWindowController<NSWindowDelegate> {
NSString *projectPath;
int port;
+ BOOL shouldInit;
+ NSTimer *checkTimer;
+ NSTask *task;
+ NSPipe *output;
+ NSPipe *error;
IBOutlet NSWindow *window;
IBOutlet WebView *webView;
}
-- (id)initWithWindowNibName:(NSString *)windowNibName path:(NSString *)aProjectPath port:(int)port;
+- (id)initWithWindowNibName:(NSString *)windowNibName path:(NSString *)aProjectPath port:(int)aPort init:(BOOL)init;
@end
33 osx/Nide/NDProjectWindowController.m
View
@@ -10,12 +10,13 @@
@implementation NDProjectWindowController
-- (id)initWithWindowNibName:(NSString *)windowNibName path:(NSString *)aProjectPath port:(int)aPort {
+- (id)initWithWindowNibName:(NSString *)windowNibName path:(NSString *)aProjectPath port:(int)aPort init:(BOOL)init {
self = [super initWithWindowNibName:windowNibName];
if (self) {
projectPath = aProjectPath;
port = aPort;
+ shouldInit = init;
}
return self;
@@ -28,17 +29,43 @@ - (void)windowDidLoad
NSString *nidePath = [[NSBundle mainBundle] pathForResource:@"main" ofType:@"js"];
NSDictionary *env = [NSDictionary dictionaryWithObjectsAndKeys:@"/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin", @"PATH", nil];
NSString *portStr = [NSString stringWithFormat:@"%i", port];
+ output = [NSPipe pipe];
+ error = [NSPipe pipe];
- NSTask *task = [[NSTask alloc] init];
+ task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/local/bin/node"];
[task setEnvironment: env];
- [task setArguments:[NSArray arrayWithObjects: nidePath, @"init", projectPath, @"--no-browser", @"--host", @"127.0.0.1", @"--port", portStr, nil]];
+ [task setStandardOutput:output];
+ [task setStandardError:error];
+
+ if (shouldInit) {
+ [task setArguments:[NSArray arrayWithObjects: nidePath, @"init", projectPath, @"--no-browser", @"--host", @"127.0.0.1", @"--port", portStr, nil]];
+ } else {
+ [task setArguments:[NSArray arrayWithObjects: nidePath, @"listen", projectPath, @"--no-browser", @"--host", @"127.0.0.1", @"--port", portStr, nil]];
+ }
[task launch];
+ checkTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(checkIfTaskIsRunning) userInfo:nil repeats:YES];
+
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:%@", portStr]]]];
}
+- (void) checkIfTaskIsRunning {
+ if (![task isRunning]) {
+ NSString *errorMessage = [[NSString alloc] initWithData:[[error fileHandleForReading] readDataToEndOfFile] encoding:NSUTF8StringEncoding];
+ NSRunAlertPanel(@"Internal error at the local server", @"%@", @"Close", nil, nil, errorMessage);
+ [errorMessage release];
+ [checkTimer invalidate];
+ }
+}
+
+- (void)dealloc {
+ [task terminate];
+ [task release];
+
+ [super dealloc];
+}
@end
Please sign in to comment.
Something went wrong with that request. Please try again.