diff --git a/src/bramble/BrambleEvents.js b/src/bramble/BrambleEvents.js index 06e1cb5b642..6280bb9326a 100644 --- a/src/bramble/BrambleEvents.js +++ b/src/bramble/BrambleEvents.js @@ -44,4 +44,12 @@ define(function (require, exports, module) { exports.triggerSidebarExpanded = function() { exports.trigger("bramble:sidebarChange", true); }; + + // file delete and rename needs to get broadcast to live dev transport + exports.triggerFileRenamed = function(oldFilename, newFilename) { + exports.trigger("fileRenamed", oldFilename, newFilename); + }; + exports.triggerFileRemoved = function(filename) { + exports.trigger("fileRemoved", filename); + }; }); diff --git a/src/extensions/default/bramble/lib/PostMessageTransport.js b/src/extensions/default/bramble/lib/PostMessageTransport.js index a0437e5ceda..a6cabcd33bb 100644 --- a/src/extensions/default/bramble/lib/PostMessageTransport.js +++ b/src/extensions/default/bramble/lib/PostMessageTransport.js @@ -15,6 +15,7 @@ define(function (require, exports, module) { var EventDispatcher = brackets.getModule("utils/EventDispatcher"), LiveDevMultiBrowser = brackets.getModule("LiveDevelopment/LiveDevMultiBrowser"), BlobUtils = brackets.getModule("filesystem/impls/filer/BlobUtils"), + BrambleEvents = brackets.getModule("bramble/BrambleEvents"), Path = brackets.getModule("filesystem/impls/filer/BracketsFiler").Path; // The script that will be injected into the previewed HTML to handle the other side of the post message connection. @@ -81,6 +82,10 @@ define(function (require, exports, module) { */ function start(){ window.addEventListener("message", _listener); + + // Reload whenever files are removed or renamed + BrambleEvents.on("fileRemoved", reload); + BrambleEvents.on("fileRenamed", reload); } /** @@ -163,12 +168,23 @@ define(function (require, exports, module) { "\n"; } + // URL of document being rewritten/launched (if any) + var _pendingReloadUrl; + function reload() { var launcher = Launcher.getCurrentInstance(); var liveDoc = LiveDevMultiBrowser._getCurrentLiveDoc(); var url = BlobUtils.getUrl(liveDoc.doc.file.fullPath); - launcher.launch(url); + // Don't start rewriting a URL if it's already in process (prevents infinite loop) + if(_pendingReloadUrl === url) { + return; + } + + _pendingReloadUrl = url; + launcher.launch(url, function() { + _pendingReloadUrl = null; + }); } // Exports diff --git a/src/extensions/default/bramble/lib/launcher.js b/src/extensions/default/bramble/lib/launcher.js index 8211501affd..c2cd2d5ad8b 100644 --- a/src/extensions/default/bramble/lib/launcher.js +++ b/src/extensions/default/bramble/lib/launcher.js @@ -24,7 +24,7 @@ define(function (require, exports, module) { _launcherInstance = this; } - Launcher.prototype.launch = function(url) { + Launcher.prototype.launch = function(url, callback) { var server = this.server; var browser = this.browser; @@ -35,6 +35,10 @@ define(function (require, exports, module) { return; } browser.update(urlOrHTML); + + if(typeof callback === "function") { + callback(); + } }); }; diff --git a/src/filesystem/impls/filer/FilerFileSystem.js b/src/filesystem/impls/filer/FilerFileSystem.js index ec7faa18753..24ff063297e 100644 --- a/src/filesystem/impls/filer/FilerFileSystem.js +++ b/src/filesystem/impls/filer/FilerFileSystem.js @@ -9,9 +9,10 @@ define(function (require, exports, module) { Filer = require("filesystem/impls/filer/BracketsFiler"), BlobUtils = require("filesystem/impls/filer/BlobUtils"), decodePath = require("filesystem/impls/filer/FilerUtils").decodePath, - Handlers = require("filesystem/impls/filer/lib/handlers"), - Content = require("filesystem/impls/filer/lib/content"), - Async = require("utils/Async"); + Handlers = require("filesystem/impls/filer/lib/handlers"), + Content = require("filesystem/impls/filer/lib/content"), + Async = require("utils/Async"), + BrambleEvents = require("bramble/BrambleEvents"); var fs = Filer.fs(), Path = Filer.Path, @@ -184,6 +185,7 @@ define(function (require, exports, module) { if(stat.isFile) { BlobUtils.rename(oldPath, newPath); + BrambleEvents.triggerFileRenamed(oldPath, newPath); } callback(); @@ -349,6 +351,10 @@ define(function (require, exports, module) { // TODO: deal with the symlink case (i.e., only remove cache // item if file is really going away). BlobUtils.remove(path); + + if(!err) { + BrambleEvents.triggerFileRemoved(path); + } callback(_mapError(err)); }); });