Permalink
Browse files

Preliminary work on Ctrl+Tab using MRU ordering instead of working se…

…t list

order. Needs more work: switching editors (even with Ctrl+Tab) updates the
MRU list, so you can never navigate between anything other than the 1st and
2nd items in the MRU order.
  • Loading branch information...
1 parent 54f8b66 commit f2d544a22a5b7127080309410593330331643359 @peterflynn peterflynn committed Apr 19, 2012
Showing with 44 additions and 15 deletions.
  1. +36 −15 src/document/DocumentManager.js
  2. +8 −0 src/file/NativeFileSystem.js
@@ -83,6 +83,13 @@ define(function (require, exports, module) {
*/
var _workingSet = [];
+ /**
+ * @private
+ * Contains the same set of items as _workinSet, but ordered by how recently they were _currentDocument (0 = most recent).
+ * @type {Array.<FileEntry>}
+ */
+ var _workingSetMRUOrder = [];
+
/**
* All documents with refCount > 0. Maps Document.file.fullPath -> Document.
* @private
@@ -91,7 +98,7 @@ define(function (require, exports, module) {
var _openDocuments = {};
/**
- * Returns an ordered list of items in the working set. May be 0-length, but never null.
+ * Returns a list of items in the working set in UI list order. May be 0-length, but never null.
*
* When a file is added this list, DocumentManager dispatches a "workingSetAdd" event.
* When a file is removed from list, DocumentManager dispatches a "workingSetRemove" event.
@@ -108,14 +115,18 @@ define(function (require, exports, module) {
}
/**
- * Returns the index of the file matching fullPath in the working set.
- * Returns -1 if not found.
- * @param {!string} fullPath
- * @returns {number} index
+ * Returns the index of the file matching fullPath in the working set.
+ * Returns -1 if not found.
+ * @param {!string} fullPath
+ * @param {Array.<FileEntry>=} list Pass this arg to search a different array of files. Internal
+ * use only.
+ * @returns {number} index
*/
- function findInWorkingSet(fullPath) {
+ function findInWorkingSet(fullPath, list) {
+ list = list || _workingSet;
+
var ret = -1;
- var found = _workingSet.some(function findByPath(file, i) {
+ var found = list.some(function findByPath(file, i) {
ret = i;
return file.fullPath === fullPath;
});
@@ -154,6 +165,7 @@ define(function (require, exports, module) {
// Add
_workingSet.push(file);
+ _workingSetMRUOrder.push(file);
// Dispatch event
$(exports).triggerHandler("workingSetAdd", file);
@@ -173,6 +185,7 @@ define(function (require, exports, module) {
// Remove
_workingSet.splice(index, 1);
+ _workingSetMRUOrder.splice(findInWorkingSet(file.fullPath, _workingSetMRUOrder), 1);
// Dispatch event
$(exports).triggerHandler("workingSetRemove", file);
@@ -200,6 +213,14 @@ define(function (require, exports, module) {
addToWorkingSet(document.file);
}
+ // Adjust MRU working set ordering
+ var mruI = findInWorkingSet(document.file.fullPath, _workingSetMRUOrder);
+ if (mruI !== -1) {
+ _workingSetMRUOrder.splice(mruI, 1);
+ _workingSetMRUOrder.unshift(document.file);
+ console.log("WorkingSetMRU -> " + _workingSetMRUOrder);
+ }
+
// Make it the current document
_currentDocument = document;
$(exports).triggerHandler("currentDocumentChange");
@@ -649,22 +670,22 @@ define(function (require, exports, module) {
*/
function getNextPrevFile(inc) {
if (_currentDocument) {
- var workingSetI = findInWorkingSet(_currentDocument.file.fullPath);
- if (workingSetI === -1) {
+ var mruI = findInWorkingSet(_currentDocument.file.fullPath, _workingSetMRUOrder);
+ if (mruI === -1) {
// If doc not in working set, return bottommost working set item
- if (_workingSet.length > 0) {
- return _workingSet[_workingSet.length - 1];
+ if (_workingSetMRUOrder.length > 0) {
+ return _workingSetMRUOrder[_workingSetMRUOrder.length - 1];
}
} else {
// If doc is in working set, return next/prev item with wrap-around
- var newI = workingSetI + inc;
- if (newI >= _workingSet.length) {
+ var newI = mruI + inc;
+ if (newI >= _workingSetMRUOrder.length) {
newI = 0;
} else if (newI < 0) {
- newI = _workingSet.length - 1;
+ newI = _workingSetMRUOrder.length - 1;
}
- return _workingSet[newI];
+ return _workingSetMRUOrder[newI];
}
}
@@ -207,6 +207,10 @@ define(function (require, exports, module) {
};
NativeFileSystem.FileEntry.prototype = new NativeFileSystem.Entry();
+ NativeFileSystem.FileEntry.prototype.toString = function () {
+ return "[FileEntry " + this.fullPath + "]";
+ };
+
/**
* Creates a new FileWriter associated with the file that this FileEntry represents.
*
@@ -437,6 +441,10 @@ define(function (require, exports, module) {
};
NativeFileSystem.DirectoryEntry.prototype = new NativeFileSystem.Entry();
+ NativeFileSystem.DirectoryEntry.prototype.toString = function () {
+ return "[DirectoryEntry " + this.fullPath + "]";
+ };
+
NativeFileSystem.DirectoryEntry.prototype.getDirectory = function (path, options, successCallback, errorCallback) {
// TODO (issue #241)
// http://www.w3.org/TR/2011/WD-file-system-api-20110419/#widl-DirectoryEntry-getDirectory

0 comments on commit f2d544a

Please sign in to comment.