From 7985c7df44b1a152891a61e2a7f775760fe1a6a9 Mon Sep 17 00:00:00 2001 From: Zhao Yunpeng Date: Fri, 24 May 2013 21:38:08 +0800 Subject: [PATCH 1/6] Initial implement github project read write and preview for bracketes --- src/extensions/default/github/.github.js.swp | Bin 0 -> 16384 bytes src/extensions/default/github/.gitignore | 4 + src/extensions/default/github/.main.js.swn | Bin 0 -> 20480 bytes src/extensions/default/github/.main.js.swo | Bin 0 -> 20480 bytes src/extensions/default/github/.main.js.swp | Bin 0 -> 16384 bytes src/extensions/default/github/LICENSE | 25 + src/extensions/default/github/README.md | 275 ++++++++ src/extensions/default/github/css/github.css | 23 + src/extensions/default/github/github.js | 507 +++++++++++++++ .../.gh-open-folder-dialog.html.swp | Bin 0 -> 12288 bytes .../htmlContent/gh-open-folder-dialog.html | 21 + src/extensions/default/github/img/file.png | Bin 0 -> 476 bytes src/extensions/default/github/img/folder.png | Bin 0 -> 591 bytes src/extensions/default/github/jso | 1 + src/extensions/default/github/lib/base64.js | 82 +++ src/extensions/default/github/lib/jso.js | 602 ++++++++++++++++++ src/extensions/default/github/lib/json2.js | 487 ++++++++++++++ .../default/github/lib/localstorage.js | 3 + .../default/github/lib/modernizr.js | 4 + .../default/github/lib/underscore-min.js | 5 + src/extensions/default/github/main.js | 240 +++++++ src/index.html | 1 + src/node-github_shell.js | 10 + src/node-webkit_shell.js | 182 +++++- 24 files changed, 2449 insertions(+), 23 deletions(-) create mode 100644 src/extensions/default/github/.github.js.swp create mode 100644 src/extensions/default/github/.gitignore create mode 100644 src/extensions/default/github/.main.js.swn create mode 100644 src/extensions/default/github/.main.js.swo create mode 100644 src/extensions/default/github/.main.js.swp create mode 100644 src/extensions/default/github/LICENSE create mode 100644 src/extensions/default/github/README.md create mode 100644 src/extensions/default/github/css/github.css create mode 100644 src/extensions/default/github/github.js create mode 100644 src/extensions/default/github/htmlContent/.gh-open-folder-dialog.html.swp create mode 100755 src/extensions/default/github/htmlContent/gh-open-folder-dialog.html create mode 100644 src/extensions/default/github/img/file.png create mode 100644 src/extensions/default/github/img/folder.png create mode 160000 src/extensions/default/github/jso create mode 100644 src/extensions/default/github/lib/base64.js create mode 100644 src/extensions/default/github/lib/jso.js create mode 100644 src/extensions/default/github/lib/json2.js create mode 100644 src/extensions/default/github/lib/localstorage.js create mode 100755 src/extensions/default/github/lib/modernizr.js create mode 100644 src/extensions/default/github/lib/underscore-min.js create mode 100644 src/extensions/default/github/main.js create mode 100644 src/node-github_shell.js diff --git a/src/extensions/default/github/.github.js.swp b/src/extensions/default/github/.github.js.swp new file mode 100644 index 0000000000000000000000000000000000000000..65db8b91f57086323a56ec84d8183b054e5ee665 GIT binary patch literal 16384 zcmeI3e~jEl6~|3U`ZJ}4iXT-AOc(XmOE%uSB-g@)>*<=LNy=S&$!$v86b0{k_Rh(k zZS3(~E#5dzUl5Y(!ms{B$_qy{Px(Ld6J0uhBGBm@#jMIc0lA|if>qS7LQ3g0&# zd%fOGcCS%|5VrJ@*W;Nt^WMC9^W%KA!8^80vKx&x8m=of?eVu=we6N+5W%Y5KzzF>CwQPS5nkVx{Jr_1#OW zV)2Fdy+-h zndqj)a^9$(532iK^&)<+lJi?`f!qSQ1#%1I7RW7-TOhYUZh_naxdn0ywZa0Du3F_y2#sLeoxwd%+Gc4Az1H@DA{oH)+~);78yK;9;-_*uVsTzg*K^ z0?&ZQzJ8}!LyfY+SA|=ct0qE z-(P~Zf?ePquob)=yct{xH1OiZn)X-lGw>wX0*1i#;977E_~%8Mb{hNv{1AK+IG_gZ z0(XK6co%plICG(V!IDqo;y;frTG%d zDJ4ySs?@;9SDZ(rep6l$$-!h!ffICHpjOvQANGX(#tAjVlqqIIk3wN zDh~Qqk_v935@{`CY5l5cGAdCFn5?^B-FkL83C$?icc(AO03F@DR0B}{*VMl~Y*2US z=1j*rr^hN!Vr<^@nJR$Jj8$M`7(7`^vJsV7h=-!|_+a)m5BX^-D$QU!4cDKOF5k-& z)Y$Lkp6ghn~K}O%HdB z9I5}v+qa%_Sa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ku&Sm$2^9s}+NdcY2F3NV3NfR6*$0B;};@NM8;fB~;#{r^3{13m`) z1$Dm({1Kp-z>C0-0kY`=pf1ILVn8vV7*Gr-1{4E|0mXo(J+yEH6JuNyLQMm!hGBYG zvmi2X9%~I;^3Ow3Pj)5iJ-YXE)StW|ew=5{p~y3UuQ(5ozjjS{+>f{#iw zq0%xdV6`ZvYL#|p*KF*zYjK_38ZUwPH6uZ5IL2s#h z_bu_{T*=-j396&o=|CX1LvB`0v7jKkoYHbUf#yiWJMr zNWcO!Y0fz8okgeO{*-PTEoNH{HB>kggU>=!SY+X%kQLo0k$-ejnL?>_O>*M*_;2y3 zA?#!L6C5kf6iCG=&aA^nr|)pPBG>^f&B@;ju_7qL7Sdb^sb?4=Sk}fTatWb#sm8-D z*=1`e9(6_ohX3ZhQlLG&xcSzw{dj;C4P+UV%1Y8+C!`2FyNea*wZO1L7Ke`uY=PwU zu{S6f$7nNfuG7V%B47v=T1&Jcv_hJtUV6iGR*BqfLp4R#bFt)KNot|(Js642#-gn5 z*im6;5-@1VL8zo~Y+mh`*eFasgSQw9J=wPHf6U0du0(F*3#MC$?Y|>({r^+!sXs>R zY^?vw$xq8gtottjUj(**CE!ZnWvu;w20RBm3OoYzfm6WUz)9dZ@Hedce+@hjd>?oQ zco3j70*8TrAr9~g@Dt!!-~#YXfCDFi0`ObJ2A%~T2Ob9K3_%k(0DKhqGi;_f0ond# z;3S|f#eiZ!F`yVw3@8Q^1B!unVj#bMxSSJ)`SR)W<>>L#!c+Il(xlEjKA@#6Ca1R4 tnMZZzQFe(%rp`RF&G-!E|LB=VoYX8&BAOH{Oh5MA{q2wRQ6U)``!~UE$3*}D literal 0 HcmV?d00001 diff --git a/src/extensions/default/github/.main.js.swp b/src/extensions/default/github/.main.js.swp new file mode 100644 index 0000000000000000000000000000000000000000..c0110144da968bdb44dd4d6df693a82ccc3fd8d1 GIT binary patch literal 16384 zcmeHOTZklA87`BJnrJRYQH-Mhc7okA+tanV8fPy_?{v>jC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zGExO|4&vf5Eab${^+jnm0!xX)WfB*{K*mv-CaSye)MKa>%(9`z6n>B=`3#ie z0P~eEB+nwBq8;0F9ey0x1H7Qn%iJM8EG6|8Vj&PQ@`AqYkyfBg50qzJqm0*=?*zM? z(OfAayen4e z(W6QoZ5Y++)rQqN-6g9WSy;wax6Y4kJa<@3!>XRL8dmRIna*z1IhG|=@uvkrIK=ik2$reW?x4D) z^jWK0FH^N+b)h4R;wh)y>2ij(_U5^cb$X*m8|_A|j>uDWRaK)->qxJ*&e2+ITDj*Oo%He-Ay`?gu;Q)j_x?-O)HE zKZxA{qOl~yx6%=XLQdR>-$H3pH0J91f?R*#O&#Ijft6sS;t3^(Q|Y_W80i>FPC!vm zX4UvD%rU&q!xZEN7#bsf**UJ#bX6IINt`XgD}83zq5);CVxSd_`4+LAki0t%CM=!> zaV^R)m4ca~tZY?tfIHm7UC0p+z-b=~%W)ZRTAoV!(-@J^)&m(nN-0?|Lx5A)S7K+j z^3pVz#+Y*TECjB~2{~+9n(Vm~H@4YE7RHS0Mgdh((kjX(ti^(Xi@C-DYlA7qzAlx_ zH6=EwkXEjy&Sl!1w-UsSg%tfg8cB2l;b1W-h2XjdV_O*uj%eM{E!c21vE?spPk!YLnSX9-WJRakiBgp}UR$T0B3nve%{ee=kqCHtF zTq8@0ic1wcglo z#LyCVuf;Q-Kq3q!TNpX;Q0h*sqoS;!8+02n3FE!=CBwSHjS+hG-X + + 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..254b5a4119a 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,20 @@ function dropboxHandler(path, callback) { } return false; } +function githubHandler(path) { + if (path.indexOf("github://") === 0) + return true; + else + return false; +} +function isRepo(path) { + dirLocation = path.indexOf(repoName)+repoName.length+1; + var url = githubPrefix + userName + "/" + repoName; + if (url === path || (url + '/') === path) + return true; + else + return false; +} function _nodeErrorToBracketsError (err) { if (!err) { err = brackets.fs.NO_ERROR; @@ -103,6 +123,9 @@ $.extend(true, brackets.fs, nodeFs , { this(err, stats); }.bind(callback)); } + else if (githubHandler(path)) { + githubStat (path, callback); + } else { $.ajax({ url: path, @@ -148,6 +171,9 @@ $.extend(true, brackets.fs, nodeFs , { })) { if (nodeFs) nodeFs.readdir(path, callback); + else if (githubHandler(path)) { + readGithubDir(path, callback); + } else { $.ajax({ url: path + "/manifest.json", @@ -185,6 +211,9 @@ $.extend(true, brackets.fs, nodeFs , { })) { if(nodeFs) nodeFs.mkdir(path, callback); + else if (githubHandler(path)) { + MakeDir(path, permissions, callback); + } else { callback(brackets.fs.ERR_CANT_WRITE); } @@ -202,6 +231,9 @@ $.extend(true, brackets.fs, nodeFs , { err = _nodeErrorToBracketsError(err); this(err, data); }.bind(callback)); + else if (githubHandler(path)) { + readGithubFile(path, encoding, callback); + } else { $.get(path, function (data, textStatus, jqXHR) { var err = brackets.fs.NO_ERROR; @@ -222,6 +254,9 @@ $.extend(true, brackets.fs, nodeFs , { nodeFs.writeFile(path, data, encoding, function (err) { callback(_nodeErrorToBracketsError(err)); }); + else if (githubHandler(path)) { + writeGithubFile(path,data,encoding,callback); + } else { callback(brackets.fs.NO_ERROR); } @@ -245,7 +280,130 @@ 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 tempPath = path.replace(githubPrefix,""); + userName = tempPath.substring(0,tempPath.indexOf("/")); + tempPath = tempPath.replace(userName+"/","") + "/"; + repoName = tempPath.substring(0,tempPath.indexOf("/")); + console.log("the repoName is :" + repoName); + console.log("the userName is: " + userName); + repo = github.getRepo(userName, repoName); + // test whether this is only a repo + if (isRepo(path)) { + if (repo !== null) { + callback (brackets.fs.ERR_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 +491,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 +499,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"); From e33a3dcf7f797850e0a941f8ab5a06ede24dd45b Mon Sep 17 00:00:00 2001 From: Zhao Yunpeng Date: Fri, 24 May 2013 22:40:54 +0800 Subject: [PATCH 2/6] Fix the problem that couldn't load github project repo name same as username --- src/node-webkit_shell.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/node-webkit_shell.js b/src/node-webkit_shell.js index 254b5a4119a..7960978837b 100644 --- a/src/node-webkit_shell.js +++ b/src/node-webkit_shell.js @@ -69,9 +69,14 @@ function githubHandler(path) { else return false; } +function splitPath(path) { + var subPath = path.split("/"); + return subPath; +} function isRepo(path) { - dirLocation = path.indexOf(repoName)+repoName.length+1; - var url = githubPrefix + userName + "/" + repoName; + var subPath = splitPath(path); + dirLocation = subPath[0].length + subPath[1].length + 2; + var url = userName + "/" + repoName; if (url === path || (url + '/') === path) return true; else @@ -124,6 +129,7 @@ $.extend(true, brackets.fs, nodeFs , { }.bind(callback)); } else if (githubHandler(path)) { + path = path.replace(githubPrefix,""); githubStat (path, callback); } else { @@ -172,6 +178,7 @@ $.extend(true, brackets.fs, nodeFs , { if (nodeFs) nodeFs.readdir(path, callback); else if (githubHandler(path)) { + path = path.replace(githubPrefix,""); readGithubDir(path, callback); } else { @@ -212,7 +219,8 @@ $.extend(true, brackets.fs, nodeFs , { if(nodeFs) nodeFs.mkdir(path, callback); else if (githubHandler(path)) { - MakeDir(path, permissions, callback); + path = path.replace(githubPrefix,""); + MakeDir(path, permissions, callback); } else { callback(brackets.fs.ERR_CANT_WRITE); @@ -232,6 +240,7 @@ $.extend(true, brackets.fs, nodeFs , { this(err, data); }.bind(callback)); else if (githubHandler(path)) { + path = path.replace(githubPrefix,""); readGithubFile(path, encoding, callback); } else { @@ -255,6 +264,7 @@ $.extend(true, brackets.fs, nodeFs , { callback(_nodeErrorToBracketsError(err)); }); else if (githubHandler(path)) { + path = path.replace(githubPrefix,""); writeGithubFile(path,data,encoding,callback); } else { @@ -284,22 +294,20 @@ function ShowOpenDialog ( callback, allowMultipleSelection, chooseDirectories, 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); + return callback (brackets.fs.ERR_CANT_WRITE); }); callback (brackets.fs.NO_ERR); } function githubStat (path, callback) { - var tempPath = path.replace(githubPrefix,""); - userName = tempPath.substring(0,tempPath.indexOf("/")); - tempPath = tempPath.replace(userName+"/","") + "/"; - repoName = tempPath.substring(0,tempPath.indexOf("/")); + 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); - // test whether this is only a repo if (isRepo(path)) { if (repo !== null) { - callback (brackets.fs.ERR_NO_ERROR, null); + callback (brackets.fs.NO_ERROR, null); } else { callback (brackets.fs.ERR_NOT_FOUND, null); } From 32a4504c7ff681b5875c9f636b9db2a9d82eded2 Mon Sep 17 00:00:00 2001 From: Zhao Yunpeng Date: Fri, 24 May 2013 22:42:16 +0800 Subject: [PATCH 3/6] Fix the bug that load too large github project 'SecurityError' --- src/file/NativeFileSystem.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/file/NativeFileSystem.js b/src/file/NativeFileSystem.js index f000d65a715..156210b0a18 100644 --- a/src/file/NativeFileSystem.js +++ b/src/file/NativeFileSystem.js @@ -120,7 +120,7 @@ define(function (require, exports, module) { * @const * @type {number} */ - ASYNC_TIMEOUT: brackets.inBrowser ? 50000 : 2000, + ASYNC_TIMEOUT: brackets.inBrowser ? 50000 : 20000, /** * Shows a modal dialog for selecting and opening files From ecb605ad65e8c03d4092d97861d8f3fb03942f69 Mon Sep 17 00:00:00 2001 From: Zhao Yunpeng Date: Fri, 24 May 2013 22:48:26 +0800 Subject: [PATCH 4/6] rename node-brackets_shell.js to brackets_shell.js that more appropriate --- src/brackets_shell.js | 691 ++++++++++++++++++++++++++++++++++++++++++ src/index.html | 2 +- 2 files changed, 692 insertions(+), 1 deletion(-) create mode 100644 src/brackets_shell.js diff --git a/src/brackets_shell.js b/src/brackets_shell.js new file mode 100644 index 00000000000..7960978837b --- /dev/null +++ b/src/brackets_shell.js @@ -0,0 +1,691 @@ +if (!window.require) { + window.require = function () { + return null; + } +} +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'); +var upDate = new Date(); +function getDropbox(callback) { + if (!window.dropbox) { + var Dialogs = require("widgets/Dialogs"); + var dropboxOAuthDriver = $.extend({}, new Dropbox.Drivers.Redirect ({rememberUser: true}), { + //url: function() { return ""; }, + url: function() { return "";}, + doAuthorize: function(authUrl, token, tokenSecret, callback) { + var $dlg = $("." + Dialogs.DIALOG_ID_INFO + ".template") + .clone() + .removeClass("template") + .addClass("instance") + .appendTo(window.document.body); + $(".dialog-title", $dlg).html("Welcome to use Dropbox as your project storage"); + $(".dialog-message", $dlg).html("A new window will be opened for Dropbox now. Please login and click 'Allow' to allow us to use your dropbox as a project storage. Don't forget to close the window after allowing"); + $dlg.one("click", ".dialog-button", function (e) { + $dlg.modal(true).hide(); + var w = window.showModalDialog(authUrl, null, "dialogWidth:950; dialogHeight:550;dialogLeft:300"); + callback(token); + }); + $dlg.modal({ + backdrop: "static", + show: true, + keyboard: true + }); + } + }); + + window.dropbox = new Dropbox.Client({ + key: "xbfa6vr2n1nk082", secret: "dze5e13g0j4vf07", sandbox: true + }); + + //dropbox.authDriver(new Dropbox.Drivers.Redirect({ rememberUser: true})); + dropbox.authDriver(dropboxOAuthDriver); + dropbox.authenticate(callback); + } + else + callback(null, dropbox); +} +function dropboxHandler(path, callback) { + if (path.indexOf("dropbox://") === 0) { + getDropbox(function (err, dropbox) { + callback(path.replace("dropbox://", ""), dropbox); + }); + return true; + } + 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; + } + 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; +} +$.extend(true, brackets.fs, nodeFs , { + stat: function (path, callback) { + if (!dropboxHandler(path, function (path, dropbox) { + dropbox.stat(path, function(err, stats) { + if (!err) { + err = brackets.fs.NO_ERROR; + stats.isDirectory = function () { + return this.isFolder; + }.bind(stats) + stats.isFile = function () { + return this.isFile; + }.bind($.extend({}, stats)) + stats.mtime = stats.modifiedAt; + } + if (err && err.status === 404) { + err = brackets.fs.ERR_NOT_FOUND; + } + this(err, stats); + }.bind(callback)); + })) { + if (nodeFs) { + nodeFs.stat(path, function (err, stats) { + err = _nodeErrorToBracketsError(err); + if (!err) + stats.mtime = new Date(); + this(err, stats); + }.bind(callback)); + } + else if (githubHandler(path)) { + path = path.replace(githubPrefix,""); + githubStat (path, callback); + } + else { + $.ajax({ + url: path, + type: "HEAD", + dataType: "html", + error: function( jqXHR, textStatus, errorThrown) { + if (jqXHR.status === 403) { + this.callback(brackets.fs.NO_ERROR, { + isDirectory: function () { + return true; + }, + isFile: function () { + return false; + }, + mtime: new Date() + }); + } + else { + console.warn("stat " + path + " " + textStatus + ": " + errorThrown); + this.callback(brackets.fs.ERR_NOT_FOUND); + } + }.bind({path: path, callback:callback}), + success: function(data, textStatus, jqXHR){ + this(brackets.fs.NO_ERROR, { + isDirectory: function () { + return this.getResponseHeader("IsDirectory"); + }.bind(jqXHR), + isFile: function () { + return !this.getResponseHeader("IsDirectory"); + }.bind(jqXHR), + mtime: new Date(jqXHR.getResponseHeader("Last-Modified")) + }); + }.bind(callback) + }); + } + } + }, + readdir: function (path, callback ) { + if (!dropboxHandler(path, function (path, dropbox) { + dropbox.readdir(path.replace("dropbox://", ""), function(error, fileNames, folder, files) { + this(error, fileNames); + }.bind(callback)); + })) { + if (nodeFs) + nodeFs.readdir(path, callback); + else if (githubHandler(path)) { + path = path.replace(githubPrefix,""); + readGithubDir(path, callback); + } + else { + $.ajax({ + url: path + "/manifest.json", + dataType: 'json', + data: '{}', + headers: { + Accept : "text/json; charset=utf-8" + }, + error: function (jqXHR, textStatus, errorThrown) { + console.error("getting " + path + " failed:" + errorThrown); + }, + success: function (data, textStatus, jqXHR) { + var err = brackets.fs.NO_ERROR; + var files; + if (jqXHR.status === 404) + err = brackets.fs.ERR_NOT_FOUND; + if (data) { + files = []; + $(data).find('tr > td > a').each(function (i, link) { + if ($(link).text() !== "Parent Directory") + files.push($(link).attr('href')); + }) + } + this(err, data); + }.bind(callback) + }); + } + } + }, + makedir: function (path, permissions, callback ) { + if (!dropboxHandler(path, function (path, dropbox) { + dropbox.mkdir(path, function (err, stat) { + callback && callback(_dropboxErrorToBracketsError(err)); + }); + })) { + 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); + } + } + }, + readFile: function (path, encoding, callback ) { + if (!dropboxHandler(path, function (path, dropbox) { + dropbox.readFile(path, {binary:true}, function (err, data) { + err = _dropboxErrorToBracketsError(err); + this(err, data); + }.bind(this)); + }.bind(callback))) { + if (nodeFs) + nodeFs.readFile(path, encoding, function (err, data) { + 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; + if (jqXHR.status === 404) + err = brackets.fs.ERR_NOT_FOUND; + this(err, data); + }.bind(callback), "html") + } + } + }, + writeFile: function (path, data, encoding, callback ) { + if (!dropboxHandler(path, function (path, dropbox) { + dropbox.writeFile(path, data, {binary:true}, function (err) { + callback(_dropboxErrorToBracketsError(err)) + }); + })){ + if (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); + } + } + } +}); +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 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 +} +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/index.html b/src/index.html index 492be4c78ed..b6512bd59b1 100644 --- a/src/index.html +++ b/src/index.html @@ -119,7 +119,7 @@ --> - + From 6aab67a6013fd0caaa8125b77fcfcc84a2cf4244 Mon Sep 17 00:00:00 2001 From: Zhao Yunpeng Date: Mon, 27 May 2013 09:39:18 +0800 Subject: [PATCH 5/6] Extract fs API from brackets_shell.js as independent module 'githubFs' 'nodeFs' 'httpFs' 'dropboxFs' --- src/brackets.js | 1 + src/extensions/default/github/main.js | 131 +++++++------------------- 2 files changed, 37 insertions(+), 95 deletions(-) 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/extensions/default/github/main.js b/src/extensions/default/github/main.js index 336987e260c..cab199eeb8a 100644 --- a/src/extensions/default/github/main.js +++ b/src/extensions/default/github/main.js @@ -39,7 +39,8 @@ define(function (require, exports, module) { ExtensionUtils = brackets.getModule("utils/ExtensionUtils"), FileUtils = brackets.getModule("file/FileUtils"), Commands = brackets.getModule("command/Commands"), - Menu = brackets.getModule("command/Menus"); + Menu = brackets.getModule("command/Menus"), + githubFs = brackets.getModule("fsDrives/githubFs"); var OPEN_MENU_NAME = "Open Github Project...", OPEN_COMMAND_ID = "github.open"; var githublib = require("github"), @@ -57,14 +58,12 @@ define(function (require, exports, module) { username, path, repoList; - /** - * Invoke Tizen project conversions dialog. - */ function loadGithubProject() { - getGithub(); + githubFs.getGithub(function(token){ + access_token = token; + performOajax(); + }); } - - /** * Read repo of Github and populate the Open Folder dialog with the list of files * @param github @@ -74,67 +73,14 @@ define(function (require, exports, module) { /** * Load Tizen project extension. */ - function getGithub() { - var $dlg = $("." + Dialogs.DIALOG_ID_INFO + ".template") - .clone() - .removeClass("template") - .addClass("instance") - .appendTo(window.document.body); - $(".dialog-title", $dlg).html("Welcome to use Github as your project storage"); - $(".dialog-message", $dlg).html("A new window will be opened for Github now. Please login and click 'Allow' to allow us to use your github as a project storage. Don't forget to close the window after allowing"); - $dlg.one("click", ".dialog-button", function (e) { - $dlg.modal(true).hide(); - access_token = jso_getToken("github" ,["repo","user"]); - console.log(access_token); - if (access_token == null) { - doOauth(); - } - else{ - doJsoConfigure(url); - performOajax(); - } - }); - $dlg.modal({ - backdrop: "static", - show: true, - keyboard: true - }); - } - function doOauth() { - var client_id = "461a47b142a0daac99bd", - client_secret = "9adb3fe4a3d471c38541ed785add8fca466e41ee", - forTokenUrl = "https://api.github.com/user#access_token=", - getTokenUrl = "https://github.com/login/oauth/access_token", - code, - state, - win; - doJsoConfigure(url); - jso_registerRedirectHandler(function(url) { - var win = window.open(url); - setTimeout(function checkClose() { - if (win.closed) { - var uri = window.authURL; - code = uri.substring((uri.indexOf("code=")+5),uri.indexOf("&state")); - state = uri.substring(uri.indexOf("state=")+6); - getTokenUrl = getTokenUrl+ "?client_id=" + client_id + "&client_secret=" + client_secret + "&code=" + code; - console.log(getTokenUrl); - $.get(getTokenUrl, function(data , status){ - access_token = data.substring(13, data.indexOf("&")); - jso_checkfortoken('github', forTokenUrl+access_token,function() { - console.log("the forTokenUrl+access_token url is " + forTokenUrl+access_token); - }); - performOajax(); - }); - } - else - setTimeout(checkClose, 100) - }, 100); - }); - jso_ensureTokens({ - "github": ["repo", "user"], - }) - } function performOajax() { + if(!window.github) { + window.github = new Github ({ + token : access_token, + auth : "oauth" + }); + } + var user = github.getUser(); $.oajax({ type: "GET", url: userUrl+ access_token, @@ -143,12 +89,6 @@ define(function (require, exports, module) { dataType: 'json', sync : false, success: function(data) { - window.github = new Github ({ - token : access_token, - auth : "oauth" - }); - //get the user repoList - var user = github.getUser(); username = data["login"]; console.log("the username is :" + username); user.userRepos(String(username), function(err, content) { @@ -162,8 +102,9 @@ define(function (require, exports, module) { }, error: function(jqXHR, textStatus, errorThrown) { alert(jqXHR.status); - alert(errorThrown); } - }); + alert(errorThrown); + } + }); } function readGithubRepo(repoList, path) { console.log("the repoList is :"); @@ -178,15 +119,15 @@ define(function (require, exports, module) { } $('.github-user').html('Github user: ' + username); $('.github-file-rows').empty(); - var len = folder.length; - for (var i = 0; i' + - ' '+'' +''+ - repo[i] + - ''); - } + var len = folder.length; + for (var i = 0; i' + + ' '+'' +''+ + repo[i] + + ''); + } Dialogs.showModalDialog("gh-open-folder-dialog"); } function readGithubFolder(github, path) { @@ -225,16 +166,16 @@ define(function (require, exports, module) { projMenu.addMenuItem(OPEN_COMMAND_ID, "", Menu.LAST_IN_SECTION, Menu.MenuSection.FILE_LIVE); moduleDir = FileUtils.getNativeModuleDirectoryPath(module); - $('body').on('mouseover', '.file-row', function(event) { - $(event.currentTarget).addClass('highlight'); - }); - $('body').on('mouseout', '.file-row', function(event) { - $(event.currentTarget).removeClass('highlight'); - }); - $('body').on('click', '.file-row', function(event) { - readGithubFolder(github, $(event.currentTarget).data('path')); - }); - } - //Initialize + $('body').on('mouseover', '.file-row', function(event) { + $(event.currentTarget).addClass('highlight'); + }); + + $('body').on('mouseout', '.file-row', function(event) { + $(event.currentTarget).removeClass('highlight'); + }); + $('body').on('click', '.file-row', function(event) { + readGithubFolder(github, $(event.currentTarget).data('path')); + }); + } initialGithub(); }); From 039244d42c81c19cc440fcff5355cc1e4e917083 Mon Sep 17 00:00:00 2001 From: Zhao Yunpeng Date: Sun, 9 Jun 2013 15:20:55 +0800 Subject: [PATCH 6/6] Trying to merge github and dropbox open dialog --- src/brackets_shell.js | 366 --------------- src/extensions/default/github/lib/LICENSE | 25 + src/extensions/default/github/lib/README.md | 275 +++++++++++ src/extensions/default/web-simulator | 1 + src/extensions/user | 1 + src/fsDrives/css/github.css | 23 + src/fsDrives/dropboxFs.js | 296 ++++++++++++ src/fsDrives/fs.js | 111 +++++ src/fsDrives/githubFs.js | 438 ++++++++++++++++++ .../htmlContent/gh-open-folder-dialog.html | 24 + src/fsDrives/httpFs.js | 100 ++++ src/fsDrives/img/file.png | Bin 0 -> 476 bytes src/fsDrives/img/folder.png | Bin 0 -> 591 bytes src/fsDrives/nodeFs.js | 35 ++ src/index.html | 1 - 15 files changed, 1329 insertions(+), 367 deletions(-) create mode 100644 src/extensions/default/github/lib/LICENSE create mode 100644 src/extensions/default/github/lib/README.md create mode 120000 src/extensions/default/web-simulator create mode 120000 src/extensions/user create mode 100644 src/fsDrives/css/github.css create mode 100644 src/fsDrives/dropboxFs.js create mode 100644 src/fsDrives/fs.js create mode 100644 src/fsDrives/githubFs.js create mode 100755 src/fsDrives/htmlContent/gh-open-folder-dialog.html create mode 100644 src/fsDrives/httpFs.js create mode 100644 src/fsDrives/img/file.png create mode 100644 src/fsDrives/img/folder.png create mode 100644 src/fsDrives/nodeFs.js diff --git a/src/brackets_shell.js b/src/brackets_shell.js index 7960978837b..35feadf1c66 100644 --- a/src/brackets_shell.js +++ b/src/brackets_shell.js @@ -6,82 +6,10 @@ 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'); var upDate = new Date(); -function getDropbox(callback) { - if (!window.dropbox) { - var Dialogs = require("widgets/Dialogs"); - var dropboxOAuthDriver = $.extend({}, new Dropbox.Drivers.Redirect ({rememberUser: true}), { - //url: function() { return ""; }, - url: function() { return "";}, - doAuthorize: function(authUrl, token, tokenSecret, callback) { - var $dlg = $("." + Dialogs.DIALOG_ID_INFO + ".template") - .clone() - .removeClass("template") - .addClass("instance") - .appendTo(window.document.body); - $(".dialog-title", $dlg).html("Welcome to use Dropbox as your project storage"); - $(".dialog-message", $dlg).html("A new window will be opened for Dropbox now. Please login and click 'Allow' to allow us to use your dropbox as a project storage. Don't forget to close the window after allowing"); - $dlg.one("click", ".dialog-button", function (e) { - $dlg.modal(true).hide(); - var w = window.showModalDialog(authUrl, null, "dialogWidth:950; dialogHeight:550;dialogLeft:300"); - callback(token); - }); - $dlg.modal({ - backdrop: "static", - show: true, - keyboard: true - }); - } - }); - - window.dropbox = new Dropbox.Client({ - key: "xbfa6vr2n1nk082", secret: "dze5e13g0j4vf07", sandbox: true - }); - - //dropbox.authDriver(new Dropbox.Drivers.Redirect({ rememberUser: true})); - dropbox.authDriver(dropboxOAuthDriver); - dropbox.authenticate(callback); - } - else - callback(null, dropbox); -} -function dropboxHandler(path, callback) { - if (path.indexOf("dropbox://") === 0) { - getDropbox(function (err, dropbox) { - callback(path.replace("dropbox://", ""), dropbox); - }); - return true; - } - 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; @@ -100,179 +28,6 @@ function _dropboxErrorToBracketsError (err) { } return err; } -$.extend(true, brackets.fs, nodeFs , { - stat: function (path, callback) { - if (!dropboxHandler(path, function (path, dropbox) { - dropbox.stat(path, function(err, stats) { - if (!err) { - err = brackets.fs.NO_ERROR; - stats.isDirectory = function () { - return this.isFolder; - }.bind(stats) - stats.isFile = function () { - return this.isFile; - }.bind($.extend({}, stats)) - stats.mtime = stats.modifiedAt; - } - if (err && err.status === 404) { - err = brackets.fs.ERR_NOT_FOUND; - } - this(err, stats); - }.bind(callback)); - })) { - if (nodeFs) { - nodeFs.stat(path, function (err, stats) { - err = _nodeErrorToBracketsError(err); - if (!err) - stats.mtime = new Date(); - this(err, stats); - }.bind(callback)); - } - else if (githubHandler(path)) { - path = path.replace(githubPrefix,""); - githubStat (path, callback); - } - else { - $.ajax({ - url: path, - type: "HEAD", - dataType: "html", - error: function( jqXHR, textStatus, errorThrown) { - if (jqXHR.status === 403) { - this.callback(brackets.fs.NO_ERROR, { - isDirectory: function () { - return true; - }, - isFile: function () { - return false; - }, - mtime: new Date() - }); - } - else { - console.warn("stat " + path + " " + textStatus + ": " + errorThrown); - this.callback(brackets.fs.ERR_NOT_FOUND); - } - }.bind({path: path, callback:callback}), - success: function(data, textStatus, jqXHR){ - this(brackets.fs.NO_ERROR, { - isDirectory: function () { - return this.getResponseHeader("IsDirectory"); - }.bind(jqXHR), - isFile: function () { - return !this.getResponseHeader("IsDirectory"); - }.bind(jqXHR), - mtime: new Date(jqXHR.getResponseHeader("Last-Modified")) - }); - }.bind(callback) - }); - } - } - }, - readdir: function (path, callback ) { - if (!dropboxHandler(path, function (path, dropbox) { - dropbox.readdir(path.replace("dropbox://", ""), function(error, fileNames, folder, files) { - this(error, fileNames); - }.bind(callback)); - })) { - if (nodeFs) - nodeFs.readdir(path, callback); - else if (githubHandler(path)) { - path = path.replace(githubPrefix,""); - readGithubDir(path, callback); - } - else { - $.ajax({ - url: path + "/manifest.json", - dataType: 'json', - data: '{}', - headers: { - Accept : "text/json; charset=utf-8" - }, - error: function (jqXHR, textStatus, errorThrown) { - console.error("getting " + path + " failed:" + errorThrown); - }, - success: function (data, textStatus, jqXHR) { - var err = brackets.fs.NO_ERROR; - var files; - if (jqXHR.status === 404) - err = brackets.fs.ERR_NOT_FOUND; - if (data) { - files = []; - $(data).find('tr > td > a').each(function (i, link) { - if ($(link).text() !== "Parent Directory") - files.push($(link).attr('href')); - }) - } - this(err, data); - }.bind(callback) - }); - } - } - }, - makedir: function (path, permissions, callback ) { - if (!dropboxHandler(path, function (path, dropbox) { - dropbox.mkdir(path, function (err, stat) { - callback && callback(_dropboxErrorToBracketsError(err)); - }); - })) { - 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); - } - } - }, - readFile: function (path, encoding, callback ) { - if (!dropboxHandler(path, function (path, dropbox) { - dropbox.readFile(path, {binary:true}, function (err, data) { - err = _dropboxErrorToBracketsError(err); - this(err, data); - }.bind(this)); - }.bind(callback))) { - if (nodeFs) - nodeFs.readFile(path, encoding, function (err, data) { - 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; - if (jqXHR.status === 404) - err = brackets.fs.ERR_NOT_FOUND; - this(err, data); - }.bind(callback), "html") - } - } - }, - writeFile: function (path, data, encoding, callback ) { - if (!dropboxHandler(path, function (path, dropbox) { - dropbox.writeFile(path, data, {binary:true}, function (err) { - callback(_dropboxErrorToBracketsError(err)) - }); - })){ - if (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); - } - } - } -}); var execDeviceCommand = function (cmd, callback) { console.log("cmd:" + cmd); child_process.exec("sdb -s " + window.device + " " + cmd, callback); @@ -291,127 +46,6 @@ function ShowOpenDialog ( callback, allowMultipleSelection, chooseDirectories, 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 } diff --git a/src/extensions/default/github/lib/LICENSE b/src/extensions/default/github/lib/LICENSE new file mode 100644 index 00000000000..6f66ed8197e --- /dev/null +++ b/src/extensions/default/github/lib/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/lib/README.md b/src/extensions/default/github/lib/README.md new file mode 100644 index 00000000000..f2c8d8d0703 --- /dev/null +++ b/src/extensions/default/github/lib/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 : + +``` + -