diff --git a/package.json b/package.json index ebb512b7..287155c9 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "c9.ide.preview": "#3c4dded23f", "c9.ide.preview.browser": "#be197b0464", "c9.ide.preview.markdown": "#bf952685f6", - "c9.ide.pubsub": "#e6526a20f7", + "c9.ide.pubsub": "#7dd0a37571", "c9.ide.readonly": "#f6f07bbe42", "c9.ide.recentfiles": "#7c099abf40", "c9.ide.remote": "#37773d905b", diff --git a/plugins/c9.core/c9.js b/plugins/c9.core/c9.js index 6e7f9b1c..502871af 100644 --- a/plugins/c9.core/c9.js +++ b/plugins/c9.core/c9.js @@ -37,7 +37,7 @@ define(function(require, module, exports) { if (!skipProps[prop]) plugin[prop] = options[prop]; } - var totalLoadTime; + var totalLoadTime, startLoadTime; function load() { if (loaded) return false; @@ -279,6 +279,11 @@ define(function(require, module, exports) { */ get totalLoadTime(){ return totalLoadTime; }, set totalLoadTime(v){ totalLoadTime = v; }, + /** + * + */ + get startLoadTime(){ return startLoadTime; }, + set startLoadTime(v){ startLoadTime = v; }, _events: [ /** diff --git a/plugins/c9.ide.editors/document.js b/plugins/c9.ide.editors/document.js index 013a49f0..5326b831 100644 --- a/plugins/c9.ide.editors/document.js +++ b/plugins/c9.ide.editors/document.js @@ -26,7 +26,7 @@ define(function(require, module, exports) { var meta = {}; var hasValue = options && (typeof options.value === "string"); - var tab, lastState, title, tooltip, editor, recentValue; + var tab, lastState, title, tooltip, editor, recentValue, ready; plugin.on("newListener", function(type, listener) { if (type == "state.set" && lastState) { @@ -332,6 +332,16 @@ define(function(require, module, exports) { editor = v; emit("setEditor", {editor: v}); }, + /** + * Whether the document is fully loaded + * @property {Boolean} ready + */ + get ready(){ return ready; }, + set ready(v) { + if (ready) throw new Error("Permission Denied"); + ready = true; + emit.sticky("ready"); + }, /** * The tooltip displayed when hovering over the tab button * @property {String} tooltip diff --git a/plugins/c9.ide.editors/tabmanager.js b/plugins/c9.ide.editors/tabmanager.js index 5f7f8b3d..a52b9e6c 100644 --- a/plugins/c9.ide.editors/tabmanager.js +++ b/plugins/c9.ide.editors/tabmanager.js @@ -1113,6 +1113,7 @@ define(function(require, module, exports) { if (!doc.meta.timestamp) doc.meta.timestamp = Date.now() - settings.timeOffset; + doc.ready = true; emit("open", { tab: tab, options: options }); callback && callback(null, tab); } @@ -1123,7 +1124,7 @@ define(function(require, module, exports) { // Hooks for plugins that want to override value and state loading var event = { - options: options, + options: options, tab: tab, loadFromDisk: loadFromDisk, setLoading: setLoading, @@ -1161,7 +1162,10 @@ define(function(require, module, exports) { }); } else { - done(null, null); + // done has to be called asynchronously + setTimeout(function() { + done(null, null); + }); } return tab; diff --git a/plugins/c9.ide.editors/tabmanager_test.js b/plugins/c9.ide.editors/tabmanager_test.js index bd7c47fa..fcd05eb0 100644 --- a/plugins/c9.ide.editors/tabmanager_test.js +++ b/plugins/c9.ide.editors/tabmanager_test.js @@ -247,20 +247,22 @@ require(["lib/architect/architect", "lib/chai/chai"], it('should rename a directory - change tab path', function(done) { var vpath = "/dir/stuff.json"; - tabs.openFile(vpath, function(err, tab) { - expect(tab.path).to.equal(vpath); - expect(tab.title).to.equal("stuff.json"); - - fs.rename("/dir", "/dir2", function(err) { - if (err) - throw err; - expect(tab.path).to.equal("/dir2/stuff.json"); + fs.rmdir("/dir2", { recursive: true }, function(){ + tabs.openFile(vpath, function(err, tab) { + expect(tab.path).to.equal(vpath); expect(tab.title).to.equal("stuff.json"); - tab.unload(); - fs.rename("/dir2", "/dir", function (err) { + + fs.rename("/dir", "/dir2", function(err) { if (err) throw err; - done(); + expect(tab.path).to.equal("/dir2/stuff.json"); + expect(tab.title).to.equal("stuff.json"); + tab.unload(); + fs.rename("/dir2", "/dir", function (err) { + if (err) + throw err; + done(); + }); }); }); });