From bf0c62eca562a2f4f2ecd0a501cfc951b2dfb49c Mon Sep 17 00:00:00 2001 From: nightwing Date: Mon, 23 Oct 2017 13:03:58 +0400 Subject: [PATCH 1/4] fix ctrl-r in sublime mode --- plugins/c9.ide.ace.keymaps/keymaps.js | 2 +- plugins/c9.ide.ace.keymaps/sublime/keymap.js | 17 +++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/plugins/c9.ide.ace.keymaps/keymaps.js b/plugins/c9.ide.ace.keymaps/keymaps.js index f8f3ca88..52282e78 100644 --- a/plugins/c9.ide.ace.keymaps/keymaps.js +++ b/plugins/c9.ide.ace.keymaps/keymaps.js @@ -173,7 +173,7 @@ define(function(require, exports, module) { } function normalize(str) { - return str && str.replace(/(^|-| )(\w)/g, function(_, a, b) { + return str && str.replace(/(^|-| |\|)(\w)/g, function(_, a, b) { return a + b.toUpperCase(); }); } diff --git a/plugins/c9.ide.ace.keymaps/sublime/keymap.js b/plugins/c9.ide.ace.keymaps/sublime/keymap.js index abe92e0f..bb969add 100644 --- a/plugins/c9.ide.ace.keymaps/sublime/keymap.js +++ b/plugins/c9.ide.ace.keymaps/sublime/keymap.js @@ -57,24 +57,14 @@ exports.ideKeymap = [ bindKey: { mac: "cmd-t|cmd-p", win: "ctrl-p" }, name: "navigate" }, { - bindKey: { mac: "cmd-r", win: "ctrl-r" }, + bindKey: { mac: "cmd-r|cmd-shift-r", win: "ctrl-r|ctrl-shift-r" }, name: "outline", args: { overlay: "goto", text: "@" } -}, { - bindKey: { mac: "cmd-shift-r", win: "ctrl-shift-r" }, - // todo: this should be project outline - name: "outline" }, { bindKey: { mac: "ctrl-g", win: "ctrl-g" }, name: "gotoline", args: { overlay: "goto", text: ":" } -}, -// todo what is this? -// { -// bindKey: {win: "ctrl-;"}, -// name: "show_overlay", -// args: {overlay: "goto", text: "#"} -// }, +}, { bindKey: { mac: "cmd-shift-p", win: "ctrl-shift-p" }, name: "commands" @@ -358,6 +348,9 @@ exports.ideKeymap = [ }, { bindKey: { mac: "cmd-shift-f", win: "ctrl-shift-f" }, name: "searchinfiles", +}, { + bindKey: { mac: "", win: "" }, + name: "restartc9", }, // { // bindKey: {mac: "f4", win: "f4"}, From 69a7f555bfb763ce60043fa0352ab74d56910f7a Mon Sep 17 00:00:00 2001 From: nightwing Date: Mon, 23 Oct 2017 13:58:45 +0400 Subject: [PATCH 2/4] move vfs client mock to separate file --- plugins/c9.vfs.client/vfs_client_mock.js | 324 ++++++++++++++++++ .../c9.vfs.standalone/www/ide.offline.html | 299 +--------------- 2 files changed, 325 insertions(+), 298 deletions(-) create mode 100644 plugins/c9.vfs.client/vfs_client_mock.js diff --git a/plugins/c9.vfs.client/vfs_client_mock.js b/plugins/c9.vfs.client/vfs_client_mock.js new file mode 100644 index 00000000..64efe287 --- /dev/null +++ b/plugins/c9.vfs.client/vfs_client_mock.js @@ -0,0 +1,324 @@ +/*global localStorage*/ +define(function(require, exports, module) { + "use strict"; + + main.consumes = ["Plugin"]; + main.provides = ["vfs", "vfs.ping", "vfs.log", "vfs.endpoint"]; + return main; + + function main(options, imports, register) { + var Plugin = imports.Plugin; + var plugin = new Plugin("Ajax.org", main.consumes); + + var id; + var vfsBaseUrl; + var serviceUrl; + + var fsData = {}; + + var Stream = require("stream").Stream; + var noop = function() { console.error("not implemented"); }; + var silent = function() {}; + var connection = {}; + + function load() { + // initialize mock fsData + findNode("/README.md", true, [ + "# Welcome to Cloud9 offline demo!", + "", + "This is a demo of Cloud9 ui, with a mock vfs server working with localStorage", + "Some features that need a real server have been disabled", + "So be sure to try the real thing at https://c9.io!" + ].join("\n")); + findNode("~", true); + if (options.storage != false) { + // Try loading data from localStorage + try { + fsData = JSON.parse(localStorage.fsData); + } catch (e) {} + window.addEventListener("beforeunload", function(e) { + localStorage.fsData = JSON.stringify(fsData); + }); + } + } + function unload() { + fsData = {}; + } + + function findNode(path, create, val) { + if (!path) path = "/"; + var parts = path.split("/"); + if (!parts[parts.length - 1]) + parts.pop(); + var data = fsData; + var prev = null; + for (var i = 0; i < parts.length; i++) { + prev = data; + data = data["!" + parts[i]]; + if (data == null) { + if (create && typeof prev != "string") + data = prev["!" + parts[i]] = {}; + else + return; + } + } + if (val) + data = prev["!" + parts[parts.length - 1]] = val; + return data; + } + + function ENOENT() { + var err = new Error("ENOENT"); + err.code = "ENOENT"; + return err; + } + + function sendStream(data, callback) { + var stream = new Stream(); + stream.readable = true; + callback(null, { stream: stream }); + if (Array.isArray(data)) { + data.forEach(function(x) { + stream.emit("data", x); + }); + } else { + stream.emit("data", data); + } + stream.emit("end"); + } + + plugin.on("load", load); + plugin.on("unload", unload); + + plugin.freezePublicAPI({ + on: function() {}, + once: function() {}, + connected: true, + + get connection() { return connection; }, + get connecting() { return false; }, + get connected() { return true }, + + get previewUrl() { throw new Error("gone"); }, + get serviceUrl() { return serviceUrl; }, + get id() { return id; }, + get baseUrl() { return vfsBaseUrl; }, + get region() { return ""; }, + + rest: noop, + download: noop, + url: noop, + reconnect: noop, + + vfsUrl: noop, + + // File management + resolve: noop, + stat: function(path, options, callback) { + var data = findNode(path); + var name = path.split("/").pop(); + setTimeout(function() { + if (data == null) + return callback(ENOENT()); + var isFile = typeof data == "string"; + var stat = { + name: name.substr(1), + size: isFile ? data.length : 1, + mtime: 0, + ctime: 0, + mime: isFile ? "" : "folder" + }; + callback(null, stat); + }, 20); + }, + readfile: function(path, options, callback) { + var data = findNode(path); + setTimeout(function() { + if (typeof data != "string") + return callback(ENOENT()); + sendStream(data, callback); + }, 20); + }, + readdir: function(path, options, callback) { + var data = findNode(path); + setTimeout(function() { + if (!data || typeof data == "string") + return callback(ENOENT()); + var stats = Object.keys(data).map(function(n) { + var isFile = typeof data[n] == "string"; + return { + name: n.substr(1), + size: isFile ? data[n].length : 1, + mtime: 0, + ctime: 0, + mime: isFile ? "" : "folder" + }; + }); + sendStream(stats, callback); + }); + }, + mkfile: function(path, options, callback) { + var parts = path.split("/"); + var name = "!" + parts.pop(); + var parent = findNode(parts.join("/"), true); + var val = ""; + options.stream.on("data", function(e) { + if (e) val += e; + }); + options.stream.on("end", function(e) { + if (e) val += e; + setTimeout(function() { + if (!parent || typeof parent[name] == "object") + return callback(ENOENT()); + parent[name] = val; + callback(null); + }); + }); + }, + mkdir: function(path, options, callback) { + var data = findNode(path, true); + setTimeout(function() { + if (!data) + return callback(ENOENT()); + callback(); + }); + }, + mkdirP: function(path, options, callback) { + var data = findNode(path, true); + setTimeout(function() { + if (!data) + return callback(ENOENT()); + callback(); + }); + }, + appendfile: noop, + rmfile: function(path, options, callback) { + var parts = path.split("/"); + var name = "!" + parts.pop(); + setTimeout(function() { + var parent = findNode(parts.join("/")); + if (!parent || !parent[name]) + return callback(ENOENT()); + if (typeof parent[name] != "string") + return callback(new Error("EISDIR")); + delete parent[name]; + callback(); + }); + }, + rmdir: function(path, options, callback) { + var parts = path.split("/"); + var name = "!" + parts.pop(); + setTimeout(function() { + var parent = findNode(parts.join("/")); + if (!parent || !parent[name]) + return callback(ENOENT()); + if (typeof parent[name] == "string") + return callback(new Error("EISFILE")); + delete parent[name]; + callback(); + }); + }, + rename: function(to, options, callback) { + setTimeout(function() { + var from = options.from; + var overwrite = options.overwrite; + + var parts = to.split("/"); + var toName = "!" + parts.pop(); + var toParent = findNode(parts.join("/")); + + parts = from.split("/"); + var fromName = "!" + parts.pop(); + var fromParent = findNode(parts.join("/")); + if (toParent[toName] != null && !overwrite) + return callback(ENOENT()); + + toParent[toName] = fromParent[fromName]; + delete fromParent[fromName]; + callback(null); + }); + }, + copy: function(from, options, callback) { + setTimeout(function() { + var to = options.to; + var overwrite = options.overwrite; + + var toParts = to.split("/"); + var toName = "!" + toParts.pop(); + var toParent = findNode(toParts.join("/")); + + var parts = from.split("/"); + var fromName = "!" + parts.pop(); + var fromParent = findNode(parts.join("/")); + var counter = 0; + var name = toName; + while (toParent[toName] != null && !options.overwrite) + toName = name + "." + (++counter); + + toParent[toName] = fromParent[fromName]; + toParts.push(toName.substr(1)); + callback(null, {to: toParts.join("/")}); + }); + }, + chmod: noop, + symlink: noop, + + // Save and retrieve Metadata + metadata: function(path, value, sync, callback) { + var parts = ("/.c9/metadata" + path).split("/"); + var name = "!" + parts.pop(); + var parent = findNode(parts.join("/"), true); + if (sync) { + parent[name] = JSON.stringify(value); + return callback(); + } + setTimeout(function() { + parent[name] = JSON.stringify(value); + callback(); + }); + }, + readFileWithMetadata: function(path, options, callback) { + var data = findNode(path); + var metadata = findNode("/.c9/metadata" + path); + setTimeout(function() { + if (typeof data != "string") + return callback(ENOENT()); + // TODO metadata + callback(null, data, metadata); + }); + return { abort: function() {} }; + }, + + // Wrapper around fs.watch or fs.watchFile + watch: silent, + + // Network connection + connect: noop, + + // Process Management + spawn: silent, + pty: silent, + tmux: silent, + execFile: silent, + killtree: silent, + + // Extending the API + use: silent, + extend: silent, + unextend: silent, + + isIdle: function() { return true }, + }); + + register(null, { + "vfs": plugin, + "vfs.ping": {}, + "vfs.log": { + log: function() {} + }, + "vfs.endpoint": { + clearCache: function() {} + } + }); + } +}); diff --git a/plugins/c9.vfs.standalone/www/ide.offline.html b/plugins/c9.vfs.standalone/www/ide.offline.html index 711aec9f..1b8e5868 100644 --- a/plugins/c9.vfs.standalone/www/ide.offline.html +++ b/plugins/c9.vfs.standalone/www/ide.offline.html @@ -47,303 +47,6 @@