forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChangedDocumentTracker.js
More file actions
1 lines (1 loc) · 1.39 KB
/
ChangedDocumentTracker.js
File metadata and controls
1 lines (1 loc) · 1.39 KB
1
define(function(require,exports,module){var DocumentManager=require("document/DocumentManager"),ProjectManager=require("project/ProjectManager");function ChangedDocumentTracker(){var self=this;this._changedPaths={},this._windowFocus=!0,this._addListener=this._addListener.bind(this),this._removeListener=this._removeListener.bind(this),this._onChange=this._onChange.bind(this),this._onWindowFocus=this._onWindowFocus.bind(this),DocumentManager.on("afterDocumentCreate",function(event,doc){ProjectManager.isWithinProject(doc.file.fullPath)&&self._addListener(doc)}),DocumentManager.on("beforeDocumentDelete",function(event,doc){self._removeListener(doc)}),$(window).focus(this._onWindowFocus)}ChangedDocumentTracker.prototype._addListener=function(doc){doc.on("change",this._onChange)},ChangedDocumentTracker.prototype._removeListener=function(doc){doc.off("change",this._onChange)},ChangedDocumentTracker.prototype._onWindowFocus=function(event,doc){this._windowFocus=!0},ChangedDocumentTracker.prototype._onChange=function(event,doc){this._changedPaths[doc.file.fullPath]=!0},ChangedDocumentTracker.prototype.reset=function(){this._changedPaths={},this._windowFocus=!1},ChangedDocumentTracker.prototype.isPathChanged=function(path){return this._windowFocus||this._changedPaths[path]},ChangedDocumentTracker.prototype.getChangedPaths=function(){return $.makeArray(this._changedPaths)},module.exports=ChangedDocumentTracker});