diff --git a/app.json b/app.json new file mode 100644 index 0000000..96b8a6a --- /dev/null +++ b/app.json @@ -0,0 +1,11 @@ +{ + "name": "Text Editor", + "title": "Text Editor", + "url": "/textEditor/index.html", + "icon": "logo.png", + "multipleWindows": true, + "opens": [ + "text/plain", + "*" + ] +} diff --git a/index.js b/index.js new file mode 100644 index 0000000..47e4411 --- /dev/null +++ b/index.js @@ -0,0 +1,48 @@ +var methods = Silk.methods; + +methods.add({ + "te/open": function (file, callObj, send) { + var fs = require("fs"); + var fileName = file; + console.log("fileName"); + fs.exists(fileName, function (exists) { + if (!exists) return send("this file does not exist"); + + fs.stat(fileName, function (err, stats) { + if (err) return send(err); + if (stats.isDirectory()) + return send(new Error("Editing directories in a text editor is not currently supported")); + fs.readFile(fileName, function (err, data) { + if (err) return send(err); + var ret = { + state: "ready", + content: data.toString("utf-8") + } + send(void(0), ret); + }) + }); + }); + return { + state: "loading" + } + } +}); + +methods.add({ + "te/save": function (data, callObj, send) { + var fs = require("fs"); + console.log(data); + path = data.path; + contents = data.contents; + console.log("=========="); + // console.log(contents); + fs.writeFile(path, contents, function (err) { + if (err) return console.log(err); + console.log("saved: " + path); + }); + console.log("finished"); + + // tricks silk into sending return value; + return " "; + } +}) \ No newline at end of file diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..11fca2e --- /dev/null +++ b/public/index.html @@ -0,0 +1,23 @@ + + + + + + + + +
+
+ +
+ + + + + + + + + + + diff --git a/public/js/Silk.js b/public/js/Silk.js new file mode 100644 index 0000000..8f169bb --- /dev/null +++ b/public/js/Silk.js @@ -0,0 +1,35 @@ +/*! Silk.js 2014-11-13 */ +var Silk = {}; + +Silk.events = {}, Silk.events.openFile = function() {}, Silk.event = function(name, func) { + switch (Silk.events[name] = func, name) { + case "openFile": + Silk.fileToOpen(); + } +}; + +var chan = Channel.build({ + window: window.parent, + origin: "*", + scope: "testScope" +}); + +Silk.openFile = function(path, mime) { + chan.notify({ + method: "openFile", + params: { + path: path, + mime: mime + } + }); +}, chan.bind("fileToOpen", function(context, data) { + Silk.events.openFile(data.path); +}), Silk.fileToOpen = function() { + name = "file", name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); + var regexS = "[\\?&]" + name + "=([^&#]*)", regex = new RegExp(regexS), results = regex.exec(window.location.href); + if (null == results) return null; + try { + Silk.events.openFile(decodeURIComponent(results[1])); + } catch (e) {} + return decodeURIComponent(results[1]); +}; diff --git a/public/js/mousetrap.js b/public/js/mousetrap.js new file mode 100644 index 0000000..d5f6af2 --- /dev/null +++ b/public/js/mousetrap.js @@ -0,0 +1,9 @@ +/* mousetrap v1.4.6 craig.is/killing/mice */ +(function(J,r,f){function s(a,b,d){a.addEventListener?a.addEventListener(b,d,!1):a.attachEvent("on"+b,d)}function A(a){if("keypress"==a.type){var b=String.fromCharCode(a.which);a.shiftKey||(b=b.toLowerCase());return b}return h[a.which]?h[a.which]:B[a.which]?B[a.which]:String.fromCharCode(a.which).toLowerCase()}function t(a){a=a||{};var b=!1,d;for(d in n)a[d]?b=!0:n[d]=0;b||(u=!1)}function C(a,b,d,c,e,v){var g,k,f=[],h=d.type;if(!l[a])return[];"keyup"==h&&w(a)&&(b=[a]);for(g=0;gg||h.hasOwnProperty(g)&&(p[h[g]]=g)}e=p[d]?"keydown":"keypress"}"keypress"==e&&f.length&&(e="keydown");return{key:c,modifiers:f,action:e}}function F(a,b,d,c,e){q[a+":"+d]=b;a=a.replace(/\s+/g," ");var f=a.split(" ");1":".","?":"/","|":"\\"},G={option:"alt",command:"meta","return":"enter",escape:"esc",mod:/Mac|iPod|iPhone|iPad/.test(navigator.platform)?"meta":"ctrl"},p,l={},q={},n={},D,z=!1,I=!1,u=!1;for(f=1;20>f;++f)h[111+f]="f"+f;for(f=0;9>=f;++f)h[f+96]=f;s(r,"keypress",y);s(r,"keydown",y);s(r,"keyup",y);var m={bind:function(a,b,d){a=a instanceof Array?a:[a];for(var c=0;c