Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 598007f

Browse files
committed
Merge pull request #5797 from adobe/glenn/file-system
New FileSystem API
2 parents 24a3c64 + 60c8cd0 commit 598007f

File tree

79 files changed

+5026
-4163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+5026
-4163
lines changed

src/LiveDevelopment/LiveDevelopment.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,14 @@ define(function LiveDevelopment(require, exports, module) {
7777
var STATUS_SYNC_ERROR = exports.STATUS_SYNC_ERROR = 5;
7878

7979
var Async = require("utils/Async"),
80-
FileIndexManager = require("project/FileIndexManager"),
8180
Dialogs = require("widgets/Dialogs"),
8281
DefaultDialogs = require("widgets/DefaultDialogs"),
8382
DocumentManager = require("document/DocumentManager"),
8483
EditorManager = require("editor/EditorManager"),
8584
FileServer = require("LiveDevelopment/Servers/FileServer").FileServer,
85+
FileSystemError = require("filesystem/FileSystemError"),
8686
FileUtils = require("file/FileUtils"),
8787
LiveDevServerManager = require("LiveDevelopment/LiveDevServerManager"),
88-
NativeFileError = require("file/NativeFileError"),
8988
NativeApp = require("utils/NativeApp"),
9089
PreferencesDialogs = require("preferences/PreferencesDialogs"),
9190
ProjectManager = require("project/ProjectManager"),
@@ -674,7 +673,7 @@ define(function LiveDevelopment(require, exports, module) {
674673
var baseUrl = ProjectManager.getBaseUrl(),
675674
hasOwnServerForLiveDevelopment = (baseUrl && baseUrl.length);
676675

677-
FileIndexManager.getFileInfoList("all").done(function (allFiles) {
676+
ProjectManager.getAllFiles().done(function (allFiles) {
678677
var projectRoot = ProjectManager.getProjectRoot().fullPath,
679678
containingFolder,
680679
indexFileFound = false,
@@ -1090,7 +1089,7 @@ define(function LiveDevelopment(require, exports, module) {
10901089
var message;
10911090

10921091
_setStatus(STATUS_ERROR);
1093-
if (err === NativeFileError.NOT_FOUND_ERR) {
1092+
if (err === FileSystemError.NOT_FOUND) {
10941093
message = Strings.ERROR_CANT_FIND_CHROME;
10951094
} else {
10961095
message = StringUtils.format(Strings.ERROR_LAUNCHING_BROWSER, err);

src/brackets.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ define(function (require, exports, module) {
7676
CommandManager = require("command/CommandManager"),
7777
CodeHintManager = require("editor/CodeHintManager"),
7878
PerfUtils = require("utils/PerfUtils"),
79-
FileIndexManager = require("project/FileIndexManager"),
79+
FileSystem = require("filesystem/FileSystem"),
8080
QuickOpen = require("search/QuickOpen"),
8181
Menus = require("command/Menus"),
8282
FileUtils = require("file/FileUtils"),
@@ -89,7 +89,6 @@ define(function (require, exports, module) {
8989
Async = require("utils/Async"),
9090
UpdateNotification = require("utils/UpdateNotification"),
9191
UrlParams = require("utils/UrlParams").UrlParams,
92-
NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem,
9392
PreferencesManager = require("preferences/PreferencesManager"),
9493
Resizer = require("utils/Resizer"),
9594
LiveDevelopmentMain = require("LiveDevelopment/main"),
@@ -114,8 +113,17 @@ define(function (require, exports, module) {
114113
require("extensibility/InstallExtensionDialog");
115114
require("extensibility/ExtensionManagerDialog");
116115

116+
// Compatibility shims for filesystem API migration
117+
require("project/FileIndexManager");
118+
require("file/NativeFileSystem");
119+
require("file/NativeFileError");
120+
117121
PerfUtils.addMeasurement("brackets module dependencies resolved");
122+
118123

124+
// Initialize the file system
125+
FileSystem.init(require("filesystem/impls/appshell/AppshellFileSystem"));
126+
119127
// Local variables
120128
var params = new UrlParams();
121129

@@ -141,7 +149,7 @@ define(function (require, exports, module) {
141149
JSUtils : JSUtils,
142150
CommandManager : CommandManager,
143151
FileSyncManager : FileSyncManager,
144-
FileIndexManager : FileIndexManager,
152+
FileSystem : FileSystem,
145153
Menus : Menus,
146154
KeyBindingManager : KeyBindingManager,
147155
CodeHintManager : CodeHintManager,
@@ -162,6 +170,7 @@ define(function (require, exports, module) {
162170
RemoteAgent : require("LiveDevelopment/Agents/RemoteAgent"),
163171
HTMLInstrumentation : require("language/HTMLInstrumentation"),
164172
MultiRangeInlineEditor : require("editor/MultiRangeInlineEditor").MultiRangeInlineEditor,
173+
LanguageManager : LanguageManager,
165174
doneLoading : false
166175
};
167176

@@ -172,7 +181,7 @@ define(function (require, exports, module) {
172181

173182
function _onReady() {
174183
PerfUtils.addMeasurement("window.document Ready");
175-
184+
176185
EditorManager.setEditorHolder($("#editor-holder"));
177186

178187
// Let the user know Brackets doesn't run in a web browser yet
@@ -223,12 +232,14 @@ define(function (require, exports, module) {
223232
if (!params.get("skipSampleProjectLoad") && !prefs.getValue("afterFirstLaunch")) {
224233
prefs.setValue("afterFirstLaunch", "true");
225234
if (ProjectManager.isWelcomeProjectPath(initialProjectPath)) {
226-
var dirEntry = new NativeFileSystem.DirectoryEntry(initialProjectPath);
227-
228-
dirEntry.getFile("index.html", {}, function (fileEntry) {
229-
var promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, { fullPath: fileEntry.fullPath });
230-
promise.then(deferred.resolve, deferred.reject);
231-
}, deferred.reject);
235+
FileSystem.resolve(initialProjectPath + "index.html", function (err, file) {
236+
if (!err) {
237+
var promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, { fullPath: file.fullPath });
238+
promise.then(deferred.resolve, deferred.reject);
239+
} else {
240+
deferred.reject();
241+
}
242+
});
232243
} else {
233244
deferred.resolve();
234245
}
@@ -333,8 +344,9 @@ define(function (require, exports, module) {
333344

334345
// TODO: (issue 269) to support IE, need to listen to document instead (and even then it may not work when focus is in an input field?)
335346
$(window).focus(function () {
347+
// This call to syncOpenDocuments() *should* be a no-op now that we have
348+
// file watchers, but is still here as a safety net.
336349
FileSyncManager.syncOpenDocuments();
337-
FileIndexManager.markDirty();
338350
});
339351

340352
// Prevent unhandled middle button clicks from triggering native behavior

src/document/Document.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
define(function (require, exports, module) {
2929
"use strict";
3030

31-
var NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem,
32-
EditorManager = require("editor/EditorManager"),
31+
var EditorManager = require("editor/EditorManager"),
3332
FileUtils = require("file/FileUtils"),
33+
InMemoryFile = require("document/InMemoryFile"),
3434
PerfUtils = require("utils/PerfUtils"),
3535
LanguageManager = require("language/LanguageManager");
3636

@@ -69,7 +69,7 @@ define(function (require, exports, module) {
6969
* deleted -- When the file for this document has been deleted. All views onto the document should
7070
* be closed. The document will no longer be editable or dispatch "change" events.
7171
*
72-
* @param {!FileEntry} file Need not lie within the project.
72+
* @param {!File} file Need not lie within the project.
7373
* @param {!Date} initialTimestamp File's timestamp when we read it off disk.
7474
* @param {!string} rawText Text content of the file.
7575
*/
@@ -90,9 +90,9 @@ define(function (require, exports, module) {
9090
Document.prototype._refCount = 0;
9191

9292
/**
93-
* The FileEntry for this document. Need not lie within the project.
94-
* If Document is untitled, this is an InaccessibleFileEntry object.
95-
* @type {!FileEntry}
93+
* The File for this document. Need not lie within the project.
94+
* If Document is untitled, this is an InMemoryFile object.
95+
* @type {!File}
9696
*/
9797
Document.prototype.file = null;
9898

@@ -240,11 +240,16 @@ define(function (require, exports, module) {
240240
if (useOriginalLineEndings) {
241241
return this._text;
242242
} else {
243-
return this._text.replace(/\r\n/g, "\n");
243+
return Document.normalizeText(this._text);
244244
}
245245
}
246246
};
247247

248+
/** Normalizes line endings the same way CodeMirror would */
249+
Document.normalizeText = function (text) {
250+
return text.replace(/\r\n/g, "\n");
251+
};
252+
248253
/**
249254
* Sets the contents of the document. Treated as an edit. Line endings will be rewritten to
250255
* match the document's current line-ending style.
@@ -415,16 +420,14 @@ define(function (require, exports, module) {
415420

416421
// TODO: (issue #295) fetching timestamp async creates race conditions (albeit unlikely ones)
417422
var thisDoc = this;
418-
this.file.getMetadata(
419-
function (metadata) {
420-
thisDoc.diskTimestamp = metadata.modificationTime;
421-
$(exports).triggerHandler("_documentSaved", thisDoc);
422-
},
423-
function (error) {
423+
this.file.stat(function (err, stat) {
424+
if (!err) {
425+
thisDoc.diskTimestamp = stat.mtime;
426+
} else {
424427
console.log("Error updating timestamp after saving file: " + thisDoc.file.fullPath);
425-
$(exports).triggerHandler("_documentSaved", thisDoc);
426428
}
427-
);
429+
$(exports).triggerHandler("_documentSaved", thisDoc);
430+
});
428431
};
429432

430433
/* (pretty toString(), to aid debugging) */
@@ -468,7 +471,7 @@ define(function (require, exports, module) {
468471
* @return {boolean} - whether or not the document is untitled
469472
*/
470473
Document.prototype.isUntitled = function () {
471-
return this.file instanceof NativeFileSystem.InaccessibleFileEntry;
474+
return this.file instanceof InMemoryFile;
472475
};
473476

474477

0 commit comments

Comments
 (0)