-
Notifications
You must be signed in to change notification settings - Fork 20
/
ProjectFiles.js
60 lines (43 loc) · 1.6 KB
/
ProjectFiles.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
60
/**
* Ternific Copyright (c) 2014 Miguel Castillo.
*
* Licensed under MIT
*/
define(function (require /*, exports, module*/) {
"use strict";
var ProjectManager = brackets.getModule("project/ProjectManager");
var FileSystem = brackets.getModule("filesystem/FileSystem");
var EventDispatcher = brackets.getModule("utils/EventDispatcher");
var Promise = require("node_modules/spromise/dist/spromise.min");
var FileStream = require("FileStream");
function ProjectFiles() {
}
EventDispatcher.makeEventDispatcher(ProjectFiles.prototype);
ProjectFiles.prototype.openFile = function(fileName /*, forceCreate*/) {
var filePath = this.currentProject.fullPath;
var handle = FileSystem.getFileForPath(filePath + fileName);
return new Promise(function(resolve, reject) {
handle.exists(function(err /*, exists*/) {
if (err) {
reject(err);
}
else {
resolve(new FileStream({
handle: handle,
fileName: fileName,
filePath: filePath
}));
}
});
});
};
ProjectFiles.prototype.resolveName = function(fileName) {
return this.currentProject.fullPath + fileName;
};
var projectFiles = new ProjectFiles();
ProjectManager.on("projectOpen", function(e, project) {
projectFiles.currentProject = project;
projectFiles.trigger("projectOpen", project);
});
return projectFiles;
});