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

Commit bd967ff

Browse files
author
Ian Wehrman
committed
Fix failing DocumentCommandHandlers tests
1 parent bfb113d commit bd967ff

File tree

7 files changed

+64
-55
lines changed

7 files changed

+64
-55
lines changed

src/document/DocumentCommandHandlers.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,9 @@ define(function (require, exports, module) {
695695
function _saveFileList(fileList) {
696696
// Do in serial because doSave shows error UI for each file, and we don't want to stack
697697
// multiple dialogs on top of each other
698-
var userCanceled = false;
698+
var userCanceled = false,
699+
savedFiles = [];
700+
699701
return Async.doSequentially(
700702
fileList,
701703
function (file) {
@@ -709,8 +711,7 @@ define(function (require, exports, module) {
709711
var savePromise = handleFileSave({doc: doc});
710712
savePromise
711713
.done(function (newFile) {
712-
file.fullPath = newFile.fullPath;
713-
file.name = newFile.name;
714+
savedFiles.push(newFile);
714715
})
715716
.fail(function (error) {
716717
if (error === USER_CANCELED) {
@@ -724,7 +725,9 @@ define(function (require, exports, module) {
724725
}
725726
},
726727
false
727-
);
728+
).then(function () {
729+
return savedFiles;
730+
});
728731
}
729732

730733
/**
@@ -962,8 +965,8 @@ define(function (require, exports, module) {
962965
result.reject();
963966
} else if (id === Dialogs.DIALOG_BTN_OK) {
964967
// Save all unsaved files, then if that succeeds, close all
965-
_saveFileList(list).done(function () {
966-
result.resolve();
968+
_saveFileList(list).done(function (savedFiles) {
969+
result.resolve(savedFiles);
967970
}).fail(function () {
968971
result.reject();
969972
});
@@ -977,9 +980,10 @@ define(function (require, exports, module) {
977980
// If all the unsaved-changes confirmations pan out above, then go ahead & close all editors
978981
// NOTE: this still happens before any done() handlers added by our caller, because jQ
979982
// guarantees that handlers run in the order they are added.
980-
result.done(function () {
983+
result.done(function (savedFiles) {
984+
savedFiles = savedFiles || list;
981985
if (!promptOnly) {
982-
DocumentManager.removeListFromWorkingSet(list, (clearCurrentDoc || true));
986+
DocumentManager.removeListFromWorkingSet(savedFiles, (clearCurrentDoc || true));
983987
}
984988
});
985989

src/filesystem/Directory.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ define(function (require, exports, module) {
6464
this._contentsCallbacks.push(callback);
6565
return;
6666
}
67-
68-
if (this._contents) {
69-
// Return cached contents
70-
callback(null, this._contents);
71-
return;
72-
}
7367

7468
this._contentsCallbacks = [callback];
7569

src/filesystem/File.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,13 @@ define(function (require, exports, module) {
6464
encoding = null;
6565
}
6666

67-
if (this._contents && this._stat) {
68-
callback(null, this._contents, this._stat);
69-
} else {
70-
this._impl.readFile(this._path, encoding ? {encoding: encoding} : {}, function (err, data, stat) {
71-
if (!err) {
72-
this._stat = stat;
73-
this._contents = data;
74-
}
75-
callback(err, data, stat);
76-
}.bind(this));
77-
}
67+
this._impl.readFile(this._path, encoding ? {encoding: encoding} : {}, function (err, data, stat) {
68+
if (!err) {
69+
this._stat = stat;
70+
// this._contents = data;
71+
}
72+
callback(err, data, stat);
73+
}.bind(this));
7874
};
7975

8076
/**
@@ -97,7 +93,7 @@ define(function (require, exports, module) {
9793
try {
9894
if (!err) {
9995
this._stat = stat;
100-
this._contents = data;
96+
// this._contents = data;
10197
}
10298
callback(err, stat);
10399
} finally {

src/filesystem/FileSystem.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -462,28 +462,35 @@ define(function (require, exports, module) {
462462
* passed.
463463
*/
464464
FileSystem.prototype._handleWatchResult = function (path, stat) {
465+
466+
var fireChangeEvent = function (entry) {
467+
// Trigger a change event
468+
$(exports).trigger("change", entry);
469+
console.log("change: ", entry);
470+
}.bind(this);
471+
465472
if (!this._index) {
466473
return;
467474
}
468475

476+
if (!path) {
477+
// This is a "wholesale" change event
478+
fireChangeEvent(null);
479+
return;
480+
}
481+
469482
path = _normalizePath(path, false);
470483
var entry = this._index.getEntry(path);
471484

472-
var fireChangeEvent = function () {
473-
// Trigger a change event
474-
$(exports).trigger("change", entry);
475-
console.log("change: ", entry);
476-
}.bind(this);
477-
478485
if (entry) {
479486
if (entry.isFile()) {
480487
// Update stat and clear contents, but only if out of date
481-
if (!stat || !entry._stat || (stat.mtime !== entry._stat.mtime)) {
488+
if (!stat || !entry._stat || (stat.mtime.getTime() !== entry._stat.mtime.getTime())) {
482489
entry._stat = stat;
483490
entry._contents = undefined;
484491
}
485492

486-
fireChangeEvent();
493+
fireChangeEvent(entry);
487494
} else {
488495
var oldContents = entry._contents || [];
489496

@@ -554,7 +561,9 @@ define(function (require, exports, module) {
554561
console.warn("Unable to get contents of changed directory: ", path, err);
555562
} else {
556563
removeOldEntries(function () {
557-
addNewEntries(fireChangeEvent);
564+
addNewEntries(function () {
565+
fireChangeEvent(entry);
566+
});
558567
});
559568
}
560569

src/filesystem/FileSystemEntry.js

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,7 @@ define(function (require, exports, module) {
115115
* @param {function (boolean)} callback Callback with a single parameter.
116116
*/
117117
FileSystemEntry.prototype.exists = function (callback) {
118-
// If we have _stat, the entry must exist
119-
if (this._stat) {
120-
callback(true);
121-
} else {
122-
// No _stat object yet, query the system
123-
this._impl.exists(this._path, function (val) {
124-
callback(val);
125-
});
126-
}
118+
this._impl.exists(this._path, callback);
127119
};
128120

129121
/**
@@ -133,16 +125,12 @@ define(function (require, exports, module) {
133125
* stats.
134126
*/
135127
FileSystemEntry.prototype.stat = function (callback) {
136-
if (this._stat) {
137-
callback(null, this._stat);
138-
} else {
139-
this._impl.stat(this._path, function (err, stat) {
140-
if (!err) {
141-
this._stat = stat;
142-
}
143-
callback(err, stat);
144-
}.bind(this));
145-
}
128+
this._impl.stat(this._path, function (err, stat) {
129+
if (!err) {
130+
this._stat = stat;
131+
}
132+
callback(err, stat);
133+
}.bind(this));
146134
};
147135

148136
/**

src/filesystem/impls/appshell/AppshellFileSystem.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ define(function (require, exports, module) {
7777
}
7878

7979
function init(callback) {
80+
/* Temporarily disable file watchers
8081
if (!_nodeConnectionDeferred) {
8182
_nodeConnectionDeferred = new $.Deferred();
8283
@@ -110,6 +111,7 @@ define(function (require, exports, module) {
110111
);
111112
});
112113
}
114+
*/
113115

114116
// Don't want to block on _nodeConnectionDeferred because we're needed as the 'root' fs
115117
// at startup -- and the Node-side stuff isn't needed for most functionality anyway.
@@ -249,6 +251,7 @@ define(function (require, exports, module) {
249251
appshell.fs.moveToTrash(path, _wrap(callback));
250252
}
251253

254+
/* File watchers are temporarily disabled
252255
function _notifyChanges(callback) {
253256
var change;
254257
@@ -282,38 +285,53 @@ define(function (require, exports, module) {
282285
_pendingChanges[change] = true;
283286
}
284287
}
288+
*/
285289

286290
function initWatchers(callback) {
291+
/* File watchers are temporarily disabled. For now, send
292+
a "wholesale" change when the window is focused. */
293+
$(window).on("focus", function () {
294+
callback(null);
295+
});
296+
297+
/*
287298
_nodeConnectionDeferred.done(function (nodeConnection) {
288299
if (nodeConnection.connected()) {
289300
_fileWatcherChange.callback = callback;
290301
$(nodeConnection).on("fileWatcher.change", _fileWatcherChange);
291302
}
292303
});
304+
*/
293305
}
294306

295307
function watchPath(path) {
308+
/*
296309
_nodeConnectionDeferred.done(function (nodeConnection) {
297310
if (nodeConnection.connected()) {
298311
nodeConnection.domains.fileWatcher.watchPath(path);
299312
}
300313
});
314+
*/
301315
}
302316

303317
function unwatchPath(path) {
318+
/*
304319
_nodeConnectionDeferred.done(function (nodeConnection) {
305320
if (nodeConnection.connected()) {
306321
nodeConnection.domains.fileWatcher.unwatchPath(path);
307322
}
308323
});
324+
*/
309325
}
310326

311327
function unwatchAll() {
328+
/*
312329
_nodeConnectionDeferred.done(function (nodeConnection) {
313330
if (nodeConnection.connected()) {
314331
nodeConnection.domains.fileWatcher.unwatchAll();
315332
}
316333
});
334+
*/
317335
}
318336

319337
// Export public API

src/project/ProjectManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ define(function (require, exports, module) {
16661666
*/
16671667
_fileSystemChange = function (event, item) {
16681668
// TODO: Batch multiple changes into a single refresh
1669-
if (item.isDirectory()) {
1669+
if (!item || item.isDirectory()) {
16701670
refreshFileTree();
16711671
}
16721672
FileSyncManager.syncOpenDocuments();

0 commit comments

Comments
 (0)