diff --git a/src/brackets.js b/src/brackets.js index bb14c4d8d34..5671892293e 100644 --- a/src/brackets.js +++ b/src/brackets.js @@ -101,6 +101,7 @@ define(function (require, exports, module) { require("help/HelpCommandHandlers"); require("search/FindInFiles"); require("search/FindReplace"); + require("fsDrives/fs"); require("extensions/default/dropbox/dropbox"); PerfUtils.addMeasurement("brackets module dependencies resolved"); diff --git a/src/brackets_shell.js b/src/brackets_shell.js new file mode 100644 index 00000000000..35feadf1c66 --- /dev/null +++ b/src/brackets_shell.js @@ -0,0 +1,325 @@ +if (!window.require) { + window.require = function () { + return null; + } +} +var gui = require('nw.gui'); +var child_process = require('child_process'); +var liveBrowser; +var ports = {}; +var nodeFs = require('fs'); +var os = require('os'); +var upDate = new Date(); +function _nodeErrorToBracketsError (err) { + if (!err) { + err = brackets.fs.NO_ERROR; + } + if (err && err.code === "ENOENT") { + err = brackets.fs.ERR_NOT_FOUND; + } + return err; +} +function _dropboxErrorToBracketsError (err) { + if (!err) { + err = brackets.fs.NO_ERROR; + } + if (err && err.status === 404) { + err = brackets.fs.ERR_NOT_FOUND; + } + return err; +} +var execDeviceCommand = function (cmd, callback) { + console.log("cmd:" + cmd); + child_process.exec("sdb -s " + window.device + " " + cmd, callback); +}; +function ShowOpenDialog ( callback, allowMultipleSelection, chooseDirectories, + title, initialPath, fileTypes) { + var file = $(""); + if (chooseDirectories) + file.attr("nwdirectory", true); + if (allowMultipleSelection) + file.attr("multiple", true); + file.click().change(function(evt) { + var files = []; + for (var i = 0; i < this.files.length; ++i) + files.push(this.files[i].path.replace(/\\/g, "/")); + callback(0, files); + }); +} +function ReadDir(){ + throw arguments.callee.name +} +function MakeDir(){ + throw arguments.callee.name +} +function Rename(){ + throw arguments.callee.name +} +function GetFileModificationTime(){ + return process.uptime() * 1000; +} +function QuitApplication(){ + gui.App.Quit(); +} +function AbortQuit(){ + throw arguments.callee.name +} +function ShowDeveloperTools(){ + if (gui) + gui.Window.get().showDevTools(); +} +function ReadFile(){ + throw arguments.callee.name +} +function WriteFile(){ + throw arguments.callee.name +} +function SetPosixPermissions(){ + throw arguments.callee.name +} +function DeleteFileOrDirectory(){ + throw arguments.callee.name +} +function GetElapsedMilliseconds(){ + return new Date().getTime() - upDate.getTime() ; +} +function OpenBrowserWindowIfNeeded(url){ + if (window.device === "Simulator" && (!liveBrowser || !liveBrowser.onbeforeunload)) { + liveBrowser = window.open(url, "Simulator", "toolbar=no,status=no,directories=no,location=no,titlebar=no"); + liveBrowser.onbeforeunload = function () { + liveBrowser = null; + }; + } +} +function OpenLiveBrowser(callback, url, enableRemoteDebugging){ + // enableRemoteDebugging flag is ignored on mac + var NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem; + var ProjectManager = require("project/ProjectManager"), + projectRoot = ProjectManager.getProjectRoot(); + + if (window.device && window.device.indexOf("RemoteEmulator") === 0) { + NativeFileSystem.requestNativeFileSystem(projectRoot.fullPath, function (fs) { + var copyDirectoryToServer = function (dirEntry) { + var result = new $.Deferred(); + dirEntry.createReader().readEntries(function (entries) { + var promises = []; + entries.forEach(function(entry) { + var result, promise; + if (entry.isDirectory) { + promise = copyDirectoryToServer(entry); + } + else { + result = new $.Deferred(); + promise = result.promise(); + brackets.fs.readFile(entry.fullPath, null, function (err, data) { + if (err === brackets.fs.NO_ERROR) { + now.writeProjectFile(entry.fullPath, data) + this.resolve(); + } + else + this.reject(); + }.bind(result)); + } + promises.push(promise); + }); + $.when.apply(null, promises).then( function () { + this.resolve(); + }.bind(this)); + + }.bind(result)); + return result.promise(); + }; + copyDirectoryToServer(fs.root).done(function () { + var Inspector = require("LiveDevelopment/Inspector/Inspector"); + var iframe = $('') + .attr("src", "http://" + location.hostname + ":" + 6080 + "/vnc.html") + var div = $('
').append(iframe).css("overflow", "hidden") + .dialog({width:"550", height:"770", minWidth: "550", + minHeight: "770", position:"right", + close: function () { + Inspector.setSocketsGetter(null); + Inspector.disconnect(); + } + }) + $(Inspector).off('connect.RemoteEmulator'); + $(Inspector).on('connect.RemoteEmulator', function () { + this.dialog("open"); + }.bind(div)); + $(Inspector).on('disconnect', function () { + this.dialog("close"); + }.bind(div)); + now.setDebuggingPort = function (port) { + console.log("setting debugging port:" + port); + Inspector.setSocketsGetter(function () { + var result = new $.Deferred(); + $.getJSON("/WidgetDebug?port="+port, function (data) { + console.log("got debug url:" + data.inspector_url); + result.resolve ([{ + webSocketDebuggerUrl:"ws://" + location.hostname + ":" + location.port +"/devtools/page/1?port=" + port, + url:url, + devtoolsFrontendUrl: "/" + data.inspector_url + "&&port=" + port + }]); + }); + return result; + }); + callback(0,0); + } + now.startProject(window.device.split(":")[1], ProjectManager.getProjectRoot(), function (projectId) { + ProjectManager.setProjectId(projectId); + }); + }); + }); + return; + } + else if (window.device && window.device !== "Simulator") { + var ProjectManager = require("project/ProjectManager"); + var projectRoot = ProjectManager.getProjectRoot(); + var projectName = projectRoot.name; + var projectId = ProjectManager.getProjectId(); + console.log(projectRoot.fullPath.substr(10)); + if (projectRoot.fullPath.indexOf("dropbox://") === 0) { + process.chdir(os.tmpDir() + projectRoot.fullPath.substr(10)); + } + else + process.chdir(projectRoot.fullPath); + if (brackets.fs.existsSync(projectName + ".wgt")) + brackets.fs.unlinkSync(projectName + ".wgt"); + child_process.exec("web-packaging", function (err, stdout, stderr) { + console.log(stdout); + console.log(stderr); + execDeviceCommand("shell mdkir -p /opt/apps/widgets/test-widgets", function () { + execDeviceCommand("push " + projectName + ".wgt /tmp/"+ projectName + ".wgt", function(err, stdout, stderr) { + console.log(stdout); + console.log(stderr); + //execDeviceCommand("shell '/usr/bin/wrt-launcher --developer-mode 1 && wrt-installer -iu /opt/apps/widgets/test-widgets/" + projectName + ".wgt && /usr/bin/wrt-launcher --start " + projectId + " --debug --timeout=90'", function (err, stdout, stderr) { + execDeviceCommand("shell 'unzip -p /tmp/" + projectName + ".wgt > t && unzip -p /opt/usr/apps/widgets/test-widgets/" + projectName + ".wgt> t1 && if [ " + ports[window.device + "." + projectId] + " == undefined ] || ! diff t t1 >/dev/null ; then cp /tmp/" + projectName + ".wgt" + " /opt/usr/apps/widgets/test-widgets && /usr/bin/wrt-launcher --developer-mode 1 && pkgcmd -s -n " + projectId + " -t wgt && pkgcmd -u -n " + projectId + " -q -t wgt; pkgcmd -i -q -t wgt -p /opt/apps/widgets/test-widgets/" + projectName + ".wgt && /usr/bin/wrt-launcher --start " + projectId + " --debug --timeout=90 ; else echo port: " + ports[window.device + "." + projectId] + "; fi'", function (err, stdout, stderr) { + console.log("got stdout:" + stdout.split("\n").length); + stdout.split("\n").forEach (function (line) { + console.log("line:" + line); + if (line.indexOf("port:") !== -1) { + var port = line.split(" ")[1]; + var Inspector = require("LiveDevelopment/Inspector/Inspector"); + console.log("got port:" + port); + ports[ window.device + "." + projectId ] = port; + Inspector.setSocketsGetter(function () { + var result = new $.Deferred(); + console.log("setting up forward " + port); + child_process.exec("sdb -s " + window.device + " forward tcp:" + port + " tcp:" + port, function() { + console.log("getting debug url:" + port); + $.getJSON("http://localhost:" + port + "/WidgetDebug", function (data) { + console.log("got debug url:" + data.inspector_url); + result.resolve ([{ + webSocketDebuggerUrl:"ws://localhost:" + port +"/devtools/page/1", + url:url, + devtoolsFrontendUrl: "/" + data.inspector_url + }]); + }); + }); + return result; + }); + callback(0, port) + } + }) + + }); + }); + }); + }) + return; + } + setTimeout(function() { + var args = []; + var newHeight = screen.availHeight/2; + var nwWindow; + var simulatorPath, questionMarkIndex; + if (!gui) { + OpenBrowserWindowIfNeeded(url); + this( 0 , 1); + return; + } + if (enableRemoteDebugging) { + args.push('--remote-debugging-port=9222'); + args.push('--no-toolbar'); + } + nwWindow = gui.Window.get(); + questionMarkIndex = url.indexOf("?"); + simulatorPath = url.substr(0, questionMarkIndex); + simulatorPath = simulatorPath.slice(7); + simulatorPath = simulatorPath.substr(0, simulatorPath.lastIndexOf("/")); + if (simulatorPath && brackets.platform === "win" && simulatorPath.charAt(0) === "/") { + simulatorPath = simulatorPath.slice(1); + } + (new NativeFileSystem.DirectoryEntry(simulatorPath)).getFile(simulatorPath + "/package.json", {create: true}, function (fileEntry) { + var packageJson = { + name: "Brackets", + main: url + } + require("file/FileUtils").writeText(fileEntry, JSON.stringify(packageJson)).done( function () { + args.push('--allow-file-access-from-files'); + args.push("."); + liveBrowser = child_process.spawn(process.execPath, args, {cwd: simulatorPath}); + liveBrowser.on('close', function () { + liveBrowser = null; + }); + nwWindow.on('close', function() { + appshell.app.closeLiveBrowser(); + nwWindow.close(true); + }); + //Ubuntu 11.10 Unity env + if ((process.env["XDG_CURRENT_DESKTOP"] && process.env["XDG_CURRENT_DESKTOP"] === "Unity") + //Ubuntu 11.04 Unity env + || process.env["DESKTOP_SESSION"] === "gnome") + newHeight -= (window.outerHeight - window.innerHeight); + window.resizeTo(window.outerWidth, newHeight); + nwWindow.moveTo((screen.availWidth - window.outerWidth)/2, + screen.availTop + screen.availHeight/2); + callback(liveBrowser.pid > 0 ? 0: -1, liveBrowser.pid) + }); + }) + + }.bind(callback), 0); +} +function CloseLiveBrowser(callback){ + if (callback && liveBrowser) { + if (liveBrowser.pid) + liveBrowser.on('close', function () { + callback(0); + }); + else + $(liveBrowser).bind("beforeunload", function (){ + callback(0); + }) + } + else if (callback) + callback(-1); + if (liveBrowser) + if (liveBrowser.pid) + process.kill(liveBrowser.pid, "SIGTERM"); + else { + liveBrowser.close(); + liveBrowser = null; + } + +} +function OpenURLInDefaultBrowser(){ + throw arguments.callee.name +} +function GetCurrentLanguage(){ + return navigator.language +} +function GetApplicationSupportDirectory(){ + var groupName = "Adobe", + appName = "Brackets"; + if (!window.process) { + return location.pathname.substr(0, location.pathname.lastIndexOf("/")); + } + if (process.platform === "win32") + return process.env["APPDATA"]+ "\\" + groupName + "\\" + appName; + else + return process.env["HOME"]+"/Library/Application Support/"+ groupName + + "/" + appName; +} +function ShowOSFolder(){ + throw arguments.callee.name +} +window.require = undefined diff --git a/src/extensions/default/github/.github.js.swp b/src/extensions/default/github/.github.js.swp new file mode 100644 index 00000000000..65db8b91f57 Binary files /dev/null and b/src/extensions/default/github/.github.js.swp differ diff --git a/src/extensions/default/github/.gitignore b/src/extensions/default/github/.gitignore new file mode 100644 index 00000000000..5239f5589d3 --- /dev/null +++ b/src/extensions/default/github/.gitignore @@ -0,0 +1,4 @@ +_site/* +.DS_Store + +test/.DS_Store \ No newline at end of file diff --git a/src/extensions/default/github/.main.js.swn b/src/extensions/default/github/.main.js.swn new file mode 100644 index 00000000000..17cf32a9ea8 Binary files /dev/null and b/src/extensions/default/github/.main.js.swn differ diff --git a/src/extensions/default/github/.main.js.swo b/src/extensions/default/github/.main.js.swo new file mode 100644 index 00000000000..3699f7c8976 Binary files /dev/null and b/src/extensions/default/github/.main.js.swo differ diff --git a/src/extensions/default/github/.main.js.swp b/src/extensions/default/github/.main.js.swp new file mode 100644 index 00000000000..c0110144da9 Binary files /dev/null and b/src/extensions/default/github/.main.js.swp differ diff --git a/src/extensions/default/github/LICENSE b/src/extensions/default/github/LICENSE new file mode 100644 index 00000000000..6f66ed8197e --- /dev/null +++ b/src/extensions/default/github/LICENSE @@ -0,0 +1,25 @@ +Copyright (c) 2012 Michael Aufreiter, Development Seed +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. +- Neither the name "Development Seed" nor the names of its contributors may be + used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/src/extensions/default/github/README.md b/src/extensions/default/github/README.md new file mode 100644 index 00000000000..f2c8d8d0703 --- /dev/null +++ b/src/extensions/default/github/README.md @@ -0,0 +1,275 @@ +# Github.js + +Github.js provides a minimal higher-level wrapper around git's [plumbing commands](http://git-scm.com/book/en/Git-Internals-Plumbing-and-Porcelain), exposing an API for manipulating GitHub repositories on the file level. It is being developed in the context of [Prose](http://prose.io), a content editor for GitHub. + +This repo is now officially maintained by [DevelopmentSeed](https://github.com/developmentseed), the people behind [Prose.io](http://prose.io). + + +## Usage + +Create a Github instance. + +```js +var github = new Github({ + username: "YOU_USER", + password: "YOUR_PASSWORD", + auth: "basic" +}); +``` + +Or if you prefer OAuth, it looks like this: + +```js +var github = new Github({ + token: "OAUTH_TOKEN" + auth: "oauth" +}); +``` + +## Repository API + + +```js +var repo = github.getRepo(username, reponame); +``` + +Show repository information + +```js +repo.show(function(err, repo) {}); +``` + +Get contents at a particular path. + +```js +repo.contents("path/to/dir", function(err, contents) {}); +``` + +Fork repository. This operation runs asynchronously. You may want to poll for `repo.contents` until the forked repo is ready. + +```js +repo.fork(function(err) {}); +``` + +Create Pull Request. + +```js +var pull = { + title: message, + body: "This pull request has been automatically generated by Prose.io.", + base: "gh-pages", + head: "michael" + ":" + "prose-patch", +}; +repo.createPullRequest(pull, function(err, pullRequest) {}); +``` + + +Retrieve all available branches (aka heads) of a repository. + +```js +repo.listBranches(function(err, branches) {}); +``` + +Store contents at a certain path, where files that don't yet exist are created on the fly. + +```js +repo.write('master', 'path/to/file', 'YOUR_NEW_CONTENTS', 'YOUR_COMMIT_MESSAGE', function(err) {}); +``` + +Not only can you can write files, you can of course read them. + +```js +repo.read('master', 'path/to/file', function(err, data) {}); +``` + +Move a file from A to B. + +```js +repo.move('master', 'path/to/file', 'path/to/new_file', function(err) {}); +``` + +Remove a file. + +```js +repo.remove('master', 'path/to/file', function(err) {}); +``` + +Exploring files of a repository is easy too by accessing the top level tree object. + +```js +repo.getTree('master', function(err, tree) {}); +``` + +If you want to access all blobs and trees recursively, you can add `?recursive=true`. + +```js +repo.getTree('master?recursive=true', function(err, tree) {}); +``` + +Given a filepath, retrieve the reference blob or tree sha. + +```js +repo.getSha('master', '/path/to/file', function(err, sha) {}); +``` + +For a given reference, get the corresponding commit sha. + +```js +repo.getRef('heads/master', function(err, sha) {}); +``` + +Create a new reference. + +```js +var refSpec = { + "ref": "refs/heads/my-new-branch-name", + "sha": "827efc6d56897b048c772eb4087f854f46256132" +}; +repo.createRef(refSpec, function(err) {}); +``` + +Delete a reference. + +```js +repo.deleteRef('heads/gh-pages', function(err) {}); +``` + + +## User API + + +```js +var user = github.getUser(); +``` + +List all repositories of the authenticated user, including private repositories and repositories in which the user is a collaborator and not an owner. + +```js +user.repos(function(err, repos) {}); +``` + +List organizations the autenticated user belongs to. + +```js +user.orgs(function(err, orgs) {}); +``` + +List authenticated user's gists. + +```js +user.gists(username, function(err, gists) {}); +``` + +Show user information for a particular username. Also works for organizations. + +```js +user.show(username, function(err, user) {}); +``` + +List public repositories for a particular user. + +```js +user.userRepos(username, function(err, repos) {}); +``` + +List repositories for a particular organization. Includes private repositories if you are authorized. + +```js +user.orgRepos(orgname, function(err, repos) {}); +``` + +List all gists of a particular user. If username is ommitted gists of the current authenticated user are returned. + +```js +user.userGists(username, function(err, gists) {}); +``` + +## Gist API + +```js +var gist = github.getGist(3165654); +``` + +Read the contents of a Gist. + +```js +gist.read(function(err, gist) { + +}); +``` + +Updating the contents of a Git. Please consult the documentation on [GitHub](http://developer.github.com/v3/gists/). + +```js +var delta = { + "description": "the description for this gist", + "files": { + "file1.txt": { + "content": "updated file contents" + }, + "old_name.txt": { + "filename": "new_name.txt", + "content": "modified contents" + }, + "new_file.txt": { + "content": "a new file" + }, + "delete_this_file.txt": null + } +}; + +gist.update(delta, function(err, gist) { + +}); +``` + + +## Tests + +Github.js is automatically™ tested by the users of [Prose](http://prose.io). Because of that, we decided to save some time by not maintaining a test suite. Yes, you heard right. :) However, you can still consider it stable since it is used in production. + +##Setup + +Github.js has the following dependencies: + +- Underscore +- Base64 (for basic auth). You can leave this if you are not using basic auth. + +Include these before github.js : + +``` + + diff --git a/src/node-github_shell.js b/src/node-github_shell.js new file mode 100644 index 00000000000..e173273de1e --- /dev/null +++ b/src/node-github_shell.js @@ -0,0 +1,10 @@ +function doJsoConfigure(url) { + jso_configure({ + "github" :{ + client_id: "461a47b142a0daac99bd", + authorization: url, + scope : ["repo", "user"], + isDefault : true + }, + }); +} diff --git a/src/node-webkit_shell.js b/src/node-webkit_shell.js index fb265296138..7960978837b 100644 --- a/src/node-webkit_shell.js +++ b/src/node-webkit_shell.js @@ -6,6 +6,12 @@ if (!window.require) { var gui = require('nw.gui'); var child_process = require('child_process'); var liveBrowser; +var repo, + repoName, + userName, + dirLocation, + branch = "master", + githubPrefix = "github://"; var ports = {}; var nodeFs = require('fs'); var os = require('os'); @@ -57,6 +63,25 @@ function dropboxHandler(path, callback) { } return false; } +function githubHandler(path) { + if (path.indexOf("github://") === 0) + return true; + else + return false; +} +function splitPath(path) { + var subPath = path.split("/"); + return subPath; +} +function isRepo(path) { + var subPath = splitPath(path); + dirLocation = subPath[0].length + subPath[1].length + 2; + var url = userName + "/" + repoName; + if (url === path || (url + '/') === path) + return true; + else + return false; +} function _nodeErrorToBracketsError (err) { if (!err) { err = brackets.fs.NO_ERROR; @@ -103,6 +128,10 @@ $.extend(true, brackets.fs, nodeFs , { this(err, stats); }.bind(callback)); } + else if (githubHandler(path)) { + path = path.replace(githubPrefix,""); + githubStat (path, callback); + } else { $.ajax({ url: path, @@ -148,6 +177,10 @@ $.extend(true, brackets.fs, nodeFs , { })) { if (nodeFs) nodeFs.readdir(path, callback); + else if (githubHandler(path)) { + path = path.replace(githubPrefix,""); + readGithubDir(path, callback); + } else { $.ajax({ url: path + "/manifest.json", @@ -185,6 +218,10 @@ $.extend(true, brackets.fs, nodeFs , { })) { if(nodeFs) nodeFs.mkdir(path, callback); + else if (githubHandler(path)) { + path = path.replace(githubPrefix,""); + MakeDir(path, permissions, callback); + } else { callback(brackets.fs.ERR_CANT_WRITE); } @@ -202,6 +239,10 @@ $.extend(true, brackets.fs, nodeFs , { err = _nodeErrorToBracketsError(err); this(err, data); }.bind(callback)); + else if (githubHandler(path)) { + path = path.replace(githubPrefix,""); + readGithubFile(path, encoding, callback); + } else { $.get(path, function (data, textStatus, jqXHR) { var err = brackets.fs.NO_ERROR; @@ -222,6 +263,10 @@ $.extend(true, brackets.fs, nodeFs , { nodeFs.writeFile(path, data, encoding, function (err) { callback(_nodeErrorToBracketsError(err)); }); + else if (githubHandler(path)) { + path = path.replace(githubPrefix,""); + writeGithubFile(path,data,encoding,callback); + } else { callback(brackets.fs.NO_ERROR); } @@ -245,7 +290,128 @@ function ShowOpenDialog ( callback, allowMultipleSelection, chooseDirectories, files.push(this.files[i].path.replace(/\\/g, "/")); callback(0, files); }); -} +} +function MakeDir(path, permissions, callback){ + var data = "# Ignore everything in this directory\n" + "*\n" + "# Except this file\n" + "!.gitignore"; + repo.write(branch, path + "/.gitignore", data, "make dir", function (err) { + return callback (brackets.fs.ERR_CANT_WRITE); + }); + callback (brackets.fs.NO_ERR); +} +function githubStat (path, callback) { + var subPath = splitPath(path); + userName = subPath[0]; + repoName = subPath[1]; + console.log("the repoName is :" + repoName); + console.log("the userName is: " + userName); + repo = github.getRepo(userName, repoName); + if (isRepo(path)) { + if (repo !== null) { + callback (brackets.fs.NO_ERROR, null); + } else { + callback (brackets.fs.ERR_NOT_FOUND, null); + } + } + else { + path = path.substring(dirLocation); + repo.getTree(branch+"?recursive=true", function (err, tree) { + var file = _.select(tree, function(file) { + return file.path === path; + })[0]; + if (file) { + if (file.type === "tree") { + callback (brackets.fs.NO_ERROR, { + isDirectory: function () { + return true; + }, + isFile: function () { + return false; + }, + mtime: new Date() + }); + } + else { + callback (brackets.fs.NO_ERROR, { + isDirectory: function () { + return false; + }, + isFile: function () { + return true; + }, + mtime: new Date() + }); + } + } + else { + callback (brackets.fs.ERR_NOT_FOUND, null); + } + }); + } +} +function readGithubDir(path, callback) { + if (isRepo(path)) { + path = path.substring(dirLocation, path.length); + } + else + path = path.substring(dirLocation, path.length-1); + repo.getSha(branch, path, function (err, res) { + if (res == null) + { + err = brackets.fs.ERR_NOT_FOUND; + callback (err, null); + } + else { + repo.getTree(res, function (err, result) { + if (!err) + { + var fileList = new Array(); + for(var i = 0;i< result.length; i++) { + fileList[i] = result[i].path; + } + console.log("the fileList is : " +fileList); + console.log(fileList); + callback (brackets.fs.NO_ERROR, fileList); + } + else { + callback (brackets.fs.ERR_NOT_FOUND, null); + } + }); + } + }); +} +function readGithubFile (path, encoding, callback) { + // file path just like "tests/spec/gh3Spec.js" + path = path.substring(dirLocation, path.length); + repo.getSha(branch, path, function (err, res) { + // file doesn't exist + if (res == null) + { + err = brackets.fs.ERR_NOT_FOUND; + callback (err, null); + } + else { + repo.getBlob(res, function (err, data) { + if (data == true) + { + err = brackets.fs.ERR_NOT_FOUND; + callback (err, null); + } else { + err = brackets.fs.NO_ERROR; + callback (err, data); + } + + }); + } + }); +} +function writeGithubFile (path, data, encoding, callback) { + repo.write(branch, path.substring(path.lastIndexOf("/")+1), data, "yunpeng write file test", function (err) { + if(!err) + return callback (brackets.fs.NO_ERROR); + else + callback(brackets.fs.NOT_FOUND_ERROR); + }); +} function ReadDir(){ throw arguments.callee.name } @@ -333,14 +499,6 @@ function OpenLiveBrowser(callback, url, enableRemoteDebugging){ var Inspector = require("LiveDevelopment/Inspector/Inspector"); var iframe = $('') .attr("src", "http://" + location.hostname + ":" + 6080 + "/vnc.html") - .load(function () { - iframe.contents().find("#noVNC_canvas").click( function() { - iframe[0].contentWindow.focus(); - }); - $(window).click( function () { - window.focus(); - }); - }) var div = $('
').append(iframe).css("overflow", "hidden") .dialog({width:"550", height:"770", minWidth: "550", minHeight: "770", position:"right", @@ -349,20 +507,6 @@ function OpenLiveBrowser(callback, url, enableRemoteDebugging){ Inspector.disconnect(); } }) - .dialogExtend({ - "close" : true, - "maximize" : true, - "minimize" : true, - "dblclick": "collapse" - }); - iframe.load( function () { - iframe.contents().find("#noVNC_canvas").click( function () { - iframe[0].contentWindow.focus(); - }) - $(window).click(function () { - window.focus(); - }) - }) $(Inspector).off('connect.RemoteEmulator'); $(Inspector).on('connect.RemoteEmulator', function () { this.dialog("open");