forked from johnhidey/hdy.brackets-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojectWatcher.js
59 lines (41 loc) · 1.41 KB
/
projectWatcher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true,
indent: 4, maxerr: 50 */
/*global define, $, brackets */
define(function (require, exports) {
"use strict";
var ProjectManager = brackets.getModule("project/ProjectManager"),
AppInit = brackets.getModule("utils/AppInit"),
_projectOpenSubscribers = [];
function _watch() {
$(ProjectManager).on("projectOpen", function(evt, data) {
var cwd = _cleanPath(data._path);
for(var index in _projectOpenSubscribers) {
_projectOpenSubscribers[index](cwd);
}
});
}
function _cleanPath(cwd) {
if (cwd.substr(cwd.length-1, 1) === "/") {
cwd = cwd.substring(0, cwd.length-1);
}
if (brackets.platform === "win") {
cwd = cwd.replace(/\//g, "\\");
}
return cwd;
}
function _isFunction(functionToCheck) {
var getType = {};
return functionToCheck && getType.toString.call(functionToCheck) === "[object Function]";
}
function _register(callback) {
if (_isFunction(callback)) {
_projectOpenSubscribers.push(callback);
}
}
AppInit.appReady(function () {
});
exports.register = _register;
exports.watch = _watch;
exports.cleanPath = _cleanPath;
// exports.cwd = _getCurrentDirectory;
});