Skip to content

Commit bfdd4fc

Browse files
committed
working on getting brackets stuff integrated
1 parent afb3e0c commit bfdd4fc

File tree

7 files changed

+358
-39
lines changed

7 files changed

+358
-39
lines changed

src/mac/node-shell-lib/node-shell-lib.xcodeproj/project.pbxproj

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
7F8AD1901576B9450056914F /* config.js in Resources */ = {isa = PBXBuildFile; fileRef = 7F8AD18B1576B90D0056914F /* config.js */; };
11+
7F8AD1911576B9490056914F /* clientProxy.js in Resources */ = {isa = PBXBuildFile; fileRef = 7F8AD18A1576B90D0056914F /* clientProxy.js */; };
12+
7F8AD1921576B94D0056914F /* server.js in Resources */ = {isa = PBXBuildFile; fileRef = 7F8AD18D1576B90D0056914F /* server.js */; };
1013
7FC7108F1576B348009262BF /* cocoanode.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7FC710491576A10A009262BF /* cocoanode.mm */; };
1114
7FC710901576B4D7009262BF /* cocoanode.node in Resources */ = {isa = PBXBuildFile; fileRef = 7FC7108B1576B334009262BF /* cocoanode.node */; };
1215
7FED295A1574F34F0027444F /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7FED29591574F34F0027444F /* Cocoa.framework */; };
@@ -16,7 +19,6 @@
1619
7FED296D1574F34F0027444F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7FED296C1574F34F0027444F /* AppDelegate.m */; };
1720
7FED29701574F34F0027444F /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7FED296E1574F34F0027444F /* MainMenu.xib */; };
1821
7FED29771574F5090027444F /* libnode.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 7FED29761574F5090027444F /* libnode.dylib */; };
19-
7FED299C1574F61F0027444F /* server.js in Resources */ = {isa = PBXBuildFile; fileRef = 7FED299A1574F5E80027444F /* server.js */; };
2022
7FED299F1574F6D50027444F /* NodeWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7FED299E1574F6D50027444F /* NodeWrapper.mm */; };
2123
7FED29A01574F7B60027444F /* libnode.dylib in Resources */ = {isa = PBXBuildFile; fileRef = 7FED29761574F5090027444F /* libnode.dylib */; };
2224
/* End PBXBuildFile section */
@@ -32,6 +34,10 @@
3234
/* End PBXContainerItemProxy section */
3335

3436
/* Begin PBXFileReference section */
37+
7F8AD18A1576B90D0056914F /* clientProxy.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = clientProxy.js; sourceTree = "<group>"; };
38+
7F8AD18B1576B90D0056914F /* config.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = config.js; sourceTree = "<group>"; };
39+
7F8AD18C1576B90D0056914F /* package.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = package.json; sourceTree = "<group>"; };
40+
7F8AD18D1576B90D0056914F /* server.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = server.js; sourceTree = "<group>"; };
3541
7FC710491576A10A009262BF /* cocoanode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = cocoanode.mm; sourceTree = "<group>"; };
3642
7FC710541576AA95009262BF /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
3743
7FC7108B1576B334009262BF /* cocoanode.node */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = cocoanode.node; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -72,7 +78,6 @@
7278
7FED29901574F55F0027444F /* v8-testing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "v8-testing.h"; sourceTree = "<group>"; };
7379
7FED29911574F55F0027444F /* v8.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = v8.h; sourceTree = "<group>"; };
7480
7FED29921574F55F0027444F /* v8stdint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = v8stdint.h; sourceTree = "<group>"; };
75-
7FED299A1574F5E80027444F /* server.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = server.js; sourceTree = "<group>"; };
7681
7FED299D1574F6D50027444F /* NodeWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NodeWrapper.h; sourceTree = "<group>"; };
7782
7FED299E1574F6D50027444F /* NodeWrapper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NodeWrapper.mm; sourceTree = "<group>"; };
7883
7FED29A21574FA3C0027444F /* libnode_readme.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = libnode_readme.txt; sourceTree = "<group>"; };
@@ -98,6 +103,17 @@
98103
/* End PBXFrameworksBuildPhase section */
99104

100105
/* Begin PBXGroup section */
106+
7F8AD1881576B90D0056914F /* server */ = {
107+
isa = PBXGroup;
108+
children = (
109+
7F8AD18A1576B90D0056914F /* clientProxy.js */,
110+
7F8AD18B1576B90D0056914F /* config.js */,
111+
7F8AD18C1576B90D0056914F /* package.json */,
112+
7F8AD18D1576B90D0056914F /* server.js */,
113+
);
114+
path = server;
115+
sourceTree = "<group>";
116+
};
101117
7FED294A1574F34F0027444F = {
102118
isa = PBXGroup;
103119
children = (
@@ -139,12 +155,12 @@
139155
7FED295F1574F34F0027444F /* node-shell-lib */ = {
140156
isa = PBXGroup;
141157
children = (
158+
7F8AD1881576B90D0056914F /* server */,
142159
7FED29781574F5300027444F /* include */,
143160
7FED296B1574F34F0027444F /* AppDelegate.h */,
144161
7FED296C1574F34F0027444F /* AppDelegate.m */,
145162
7FED296E1574F34F0027444F /* MainMenu.xib */,
146163
7FED29601574F34F0027444F /* Supporting Files */,
147-
7FED299A1574F5E80027444F /* server.js */,
148164
7FED299D1574F6D50027444F /* NodeWrapper.h */,
149165
7FED299E1574F6D50027444F /* NodeWrapper.mm */,
150166
7FC710491576A10A009262BF /* cocoanode.mm */,
@@ -257,6 +273,7 @@
257273
7FED29511574F34F0027444F /* Sources */,
258274
7FED29521574F34F0027444F /* Frameworks */,
259275
7FED29531574F34F0027444F /* Resources */,
276+
7F8AD1931576B9590056914F /* ShellScript */,
260277
);
261278
buildRules = (
262279
);
@@ -300,9 +317,11 @@
300317
isa = PBXResourcesBuildPhase;
301318
buildActionMask = 2147483647;
302319
files = (
320+
7F8AD1921576B94D0056914F /* server.js in Resources */,
321+
7F8AD1911576B9490056914F /* clientProxy.js in Resources */,
322+
7F8AD1901576B9450056914F /* config.js in Resources */,
303323
7FC710901576B4D7009262BF /* cocoanode.node in Resources */,
304324
7FED29A01574F7B60027444F /* libnode.dylib in Resources */,
305-
7FED299C1574F61F0027444F /* server.js in Resources */,
306325
7FED29641574F34F0027444F /* InfoPlist.strings in Resources */,
307326
7FED296A1574F34F0027444F /* Credits.rtf in Resources */,
308327
7FED29701574F34F0027444F /* MainMenu.xib in Resources */,
@@ -311,6 +330,22 @@
311330
};
312331
/* End PBXResourcesBuildPhase section */
313332

333+
/* Begin PBXShellScriptBuildPhase section */
334+
7F8AD1931576B9590056914F /* ShellScript */ = {
335+
isa = PBXShellScriptBuildPhase;
336+
buildActionMask = 2147483647;
337+
files = (
338+
);
339+
inputPaths = (
340+
);
341+
outputPaths = (
342+
);
343+
runOnlyForDeploymentPostprocessing = 0;
344+
shellPath = /bin/sh;
345+
shellScript = "cp -r ../../../node/node_modules $BUILT_PRODUCTS_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/";
346+
};
347+
/* End PBXShellScriptBuildPhase section */
348+
314349
/* Begin PBXSourcesBuildPhase section */
315350
7FC710871576B334009262BF /* Sources */ = {
316351
isa = PBXSourcesBuildPhase;
@@ -483,6 +518,7 @@
483518
7FC7108E1576B334009262BF /* Release */,
484519
);
485520
defaultConfigurationIsVisible = 0;
521+
defaultConfigurationName = Release;
486522
};
487523
7FED294F1574F34F0027444F /* Build configuration list for PBXProject "node-shell-lib" */ = {
488524
isa = XCConfigurationList;

src/mac/node-shell-lib/node-shell-lib/cocoanode.mm

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,69 @@
1212
#include <node.h>
1313
#include <v8.h>
1414

15-
v8::Handle<v8::Value> Method(const v8::Arguments& args);
15+
v8::Handle<v8::Value> getSomeFiles(const v8::Arguments& args);
1616
void init(v8::Handle<v8::Object> target);
17+
NSString* NSArrayToJSONString(NSArray* array);
18+
NSString* showOpenDialog();
1719

18-
v8::Handle<v8::Value> Method(const v8::Arguments& args) {
20+
21+
v8::Handle<v8::Value> getSomeFiles(const v8::Arguments& args) {
1922
v8::HandleScope scope;
20-
NSAlert *alert = [[NSAlert alloc] init];
21-
[alert addButtonWithTitle:@"OK"];
22-
[alert addButtonWithTitle:@"Cancel"];
23-
[alert setMessageText:@"Delete the record?"];
24-
[alert setInformativeText:@"Deleted records cannot be restored."];
25-
[alert setAlertStyle:NSWarningAlertStyle];
26-
[alert runModal];
27-
return scope.Close(v8::String::New("world shmirld"));
23+
NSString* result = showOpenDialog();
24+
return scope.Close(v8::String::New([result UTF8String]));
2825
}
2926

3027
void init(v8::Handle<v8::Object> target) {
31-
target->Set(v8::String::NewSymbol("hello"),
32-
v8::FunctionTemplate::New(Method)->GetFunction());
28+
target->Set(v8::String::NewSymbol("getSomeFiles"),
29+
v8::FunctionTemplate::New(getSomeFiles)->GetFunction());
30+
}
31+
32+
NSString* NSArrayToJSONString(NSArray* array) {
33+
int numItems = [array count];
34+
NSString* escapedStr = @"";
35+
NSMutableString* result = [[[NSMutableString alloc] initWithString:@"["] autorelease];
36+
NSString* item;
37+
38+
for (int i = 0; i < numItems; i++)
39+
{
40+
[result appendString:@"\""];
41+
42+
item = [array objectAtIndex:i];
43+
escapedStr = item; //EscapeJSONString(item, escapedStr);
44+
45+
[result appendString:escapedStr];
46+
[result appendString:@"\""];
47+
48+
49+
if (i < numItems - 1)
50+
[result appendString:@", "];
51+
}
52+
[result appendString:@"]"];
53+
54+
return result;
55+
}
56+
57+
58+
NSString* showOpenDialog() {
59+
NSString* result = @"";
60+
NSArray* allowedFileTypes = nil;
61+
62+
// Initialize the dialog
63+
NSOpenPanel* openPanel = [NSOpenPanel openPanel];
64+
[openPanel setCanChooseFiles:YES];
65+
[openPanel setCanChooseDirectories:NO];
66+
[openPanel setCanCreateDirectories:YES];
67+
[openPanel setAllowsMultipleSelection:NO];
68+
[openPanel setTitle: @"Exciting times!"];
69+
70+
[openPanel setAllowedFileTypes:allowedFileTypes];
71+
72+
if ([openPanel runModal] == NSOKButton)
73+
{
74+
NSArray *f = [openPanel filenames];
75+
result = NSArrayToJSONString(f);
76+
}
77+
78+
return result;
3379
}
3480
NODE_MODULE(cocoanode, init)

src/mac/node-shell-lib/node-shell-lib/server.js

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*
22+
*/
23+
24+
/*jslint sloppy: true, vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
25+
/*global global, require, exports, process, setInterval */
26+
27+
var fs = require('fs');
28+
var cocoa = require('./cocoanode');
29+
30+
var websocket = null;
31+
32+
// add some stuff to fs because the return types are sometimes complicated objects that don't jsonify
33+
fs.statBrackets = function (path, callback) {
34+
fs.stat(path, function (err, stats) {
35+
var result;
36+
if (err) {
37+
callback(err, null);
38+
} else {
39+
result = {};
40+
result.isFile = stats.isFile();
41+
result.isDirectory = stats.isDirectory();
42+
result.mtime = stats.mtime;
43+
result.filesize = stats.size;
44+
callback(0, result); // TODO: hack, need handling of error being null in callbacks on client side
45+
}
46+
});
47+
};
48+
49+
// A test namespace
50+
51+
var stupid = {};
52+
53+
stupid.reverse = function (s) {
54+
return s.split("").reverse().join("");
55+
};
56+
57+
// end test namespace
58+
59+
// app namespace
60+
61+
var app = {};
62+
63+
app.showOpenDialog = function(allowMultipleSelection, chooseDirectory, title, initialPath, fileTypes, callback) {
64+
console.log("trying to get some files");
65+
var files = cocoa.getSomeFiles();
66+
console.log("got some files: " + files);
67+
callback(null, JSON.parse(files));
68+
}
69+
70+
var namespaces = {
71+
app : app,
72+
fs : fs,
73+
stupid : stupid
74+
};
75+
76+
function createCallback(id, ws) {
77+
return function () {
78+
var args = Array.prototype.slice.call(arguments);
79+
if (websocket !== null) {
80+
console.warn("Sending callback for " + id + " with args " + args);
81+
websocket.send(JSON.stringify({id: id, result: args}));
82+
}
83+
};
84+
}
85+
86+
function doCommand(id, namespace, command, args, isAsync, ws) {
87+
try {
88+
var f = namespaces[namespace][command];
89+
var callback = createCallback(id, ws);
90+
if (isAsync) {
91+
args.push(callback);
92+
f.apply(global, args);
93+
} else {
94+
callback(f.apply(global, args));
95+
}
96+
} catch (e) {
97+
console.log("Error: Couldn't run the command " + namespace + "." + command + " with args " + JSON.stringify(args));
98+
}
99+
}
100+
101+
function receiveData(message) {
102+
var m;
103+
console.log('received: %s', message);
104+
try {
105+
m = JSON.parse(message);
106+
//console.log('parsed version:');
107+
//console.log(m);
108+
doCommand(m.id, m.namespace, m.command, m.args, m.isAsync);
109+
} catch (e) {
110+
console.log("Error: could't parse the message or something");
111+
}
112+
}
113+
114+
function setWebsocket(ws) {
115+
console.warn("setting new websocket");
116+
if (websocket !== null) {
117+
websocket.close();
118+
}
119+
websocket = ws;
120+
websocket.on('message', function (message) {
121+
var m;
122+
console.log('received: %s', message);
123+
try {
124+
m = JSON.parse(message);
125+
//console.log('parsed version:');
126+
//console.log(m);
127+
doCommand(m.id, m.namespace, m.command, m.args, m.isAsync, ws);
128+
} catch (e) {
129+
console.log("Error: could't parse the message or something");
130+
}
131+
});
132+
}
133+
134+
exports.setWebsocket = setWebsocket;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*
22+
*/
23+
24+
/*jslint sloppy: true, vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
25+
/*global module */
26+
27+
module.exports = {
28+
clientPath: '/Users/jbrandt/development/brackets-app/brackets/src/'
29+
};

0 commit comments

Comments
 (0)