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

Commit

Permalink
Merge pull request #11223 from adobe/marcel/next-prev-doc-list-order
Browse files Browse the repository at this point in the history
Use Ctrl+PageUp/PageDown to traverse files in list order
  • Loading branch information
nethip committed Jun 30, 2015
2 parents 48725b3 + afc1d3b commit 7dea6c9
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 16 deletions.
12 changes: 11 additions & 1 deletion src/base-config/keyboard.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"file.newDoc": [
"Ctrl-N"
],
Expand Down Expand Up @@ -319,6 +319,16 @@
"platform": "mac"
}
],
"navigate.nextDocListOrder": [
{
"key": "Ctrl-PageDown"
}
],
"navigate.prevDocListOrder": [
{
"key": "Ctrl-PageUp"
}
],
"navigate.toggleQuickEdit": [
"Ctrl-E"
],
Expand Down
2 changes: 2 additions & 0 deletions src/command/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ define(function (require, exports, module) {
// NAVIGATE
exports.NAVIGATE_NEXT_DOC = "navigate.nextDoc"; // DocumentCommandHandlers.js handleGoNextDoc()
exports.NAVIGATE_PREV_DOC = "navigate.prevDoc"; // DocumentCommandHandlers.js handleGoPrevDoc()
exports.NAVIGATE_NEXT_DOC_LIST_ORDER = "navigate.nextDocListOrder"; // DocumentCommandHandlers.js handleGoNextDocListOrder()
exports.NAVIGATE_PREV_DOC_LIST_ORDER = "navigate.prevDocListOrder"; // DocumentCommandHandlers.js handleGoPrevDocListOrder()
exports.NAVIGATE_SHOW_IN_FILE_TREE = "navigate.showInFileTree"; // DocumentCommandHandlers.js handleShowInTree()
exports.NAVIGATE_SHOW_IN_OS = "navigate.showInOS"; // DocumentCommandHandlers.js handleShowInOS()
exports.NAVIGATE_QUICK_OPEN = "navigate.quickOpen"; // QuickOpen.js doFileSearch()
Expand Down
2 changes: 2 additions & 0 deletions src/command/DefaultMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ define(function (require, exports, module) {
menu.addMenuDivider();
menu.addMenuItem(Commands.NAVIGATE_NEXT_DOC);
menu.addMenuItem(Commands.NAVIGATE_PREV_DOC);
menu.addMenuItem(Commands.NAVIGATE_NEXT_DOC_LIST_ORDER);
menu.addMenuItem(Commands.NAVIGATE_PREV_DOC_LIST_ORDER);
menu.addMenuDivider();
menu.addMenuItem(Commands.NAVIGATE_SHOW_IN_FILE_TREE);
menu.addMenuDivider();
Expand Down
35 changes: 29 additions & 6 deletions src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1462,9 +1462,19 @@ define(function (require, exports, module) {
}
}

/** Navigate to the next/previous (MRU) document. Don't update MRU order yet */
function goNextPrevDoc(inc) {
var result = MainViewManager.traverseToNextViewByMRU(inc);
/**
* Navigate to the next/previous (MRU or list order) document. Don't update MRU order yet
* @param {!number} inc Delta indicating in which direction we're going
* @param {?boolean} listOrder Whether to navigate using MRU or list order. Defaults to MRU order
*/
function goNextPrevDoc(inc, listOrder) {
var result;
if (listOrder) {
result = MainViewManager.traverseToNextViewInListOrder(inc);
} else {
result = MainViewManager.traverseToNextViewByMRU(inc);
}

if (result) {
var file = result.file,
paneId = result.paneId;
Expand All @@ -1481,16 +1491,26 @@ define(function (require, exports, module) {
}
}

/** Next Doc command handler **/
/** Next Doc command handler (MRU order) **/
function handleGoNextDoc() {
goNextPrevDoc(+1);

}
/** Previous Doc command handler **/

/** Previous Doc command handler (MRU order) **/
function handleGoPrevDoc() {
goNextPrevDoc(-1);
}

/** Next Doc command handler (list order) **/
function handleGoNextDocListOrder() {
goNextPrevDoc(+1, true);
}

/** Previous Doc command handler (list order) **/
function handleGoPrevDocListOrder() {
goNextPrevDoc(-1, true);
}

/** Show in File Tree command handler **/
function handleShowInTree() {
ProjectManager.showInTree(MainViewManager.getCurrentlyViewedFile(MainViewManager.ACTIVE_PANE));
Expand Down Expand Up @@ -1725,6 +1745,9 @@ define(function (require, exports, module) {
CommandManager.register(Strings.CMD_NEXT_DOC, Commands.NAVIGATE_NEXT_DOC, handleGoNextDoc);
CommandManager.register(Strings.CMD_PREV_DOC, Commands.NAVIGATE_PREV_DOC, handleGoPrevDoc);

CommandManager.register(Strings.CMD_NEXT_DOC_LIST_ORDER, Commands.NAVIGATE_NEXT_DOC_LIST_ORDER, handleGoNextDocListOrder);
CommandManager.register(Strings.CMD_PREV_DOC_LIST_ORDER, Commands.NAVIGATE_PREV_DOC_LIST_ORDER, handleGoPrevDocListOrder);

// Special Commands
CommandManager.register(showInOS, Commands.NAVIGATE_SHOW_IN_OS, handleShowInOS);
CommandManager.register(quitString, Commands.FILE_QUIT, handleFileQuit);
Expand Down
2 changes: 2 additions & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ define({
"CMD_CSS_QUICK_EDIT_NEW_RULE" : "New Rule",
"CMD_NEXT_DOC" : "Next Document",
"CMD_PREV_DOC" : "Previous Document",
"CMD_NEXT_DOC_LIST_ORDER" : "Next Document (List Order)",
"CMD_PREV_DOC_LIST_ORDER" : "Previous Document (List Order)",
"CMD_SHOW_IN_TREE" : "Show in File Tree",
"CMD_SHOW_IN_EXPLORER" : "Show in Explorer",
"CMD_SHOW_IN_FINDER" : "Show in Finder",
Expand Down
45 changes: 36 additions & 9 deletions src/view/MainViewManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
/*global define, $ */

/**
* MainViewManager Manages the arrangement of all open panes as well as provides the controller
* MainViewManager manages the arrangement of all open panes as well as provides the controller
* logic behind all views in the MainView (e.g. ensuring that a file doesn't appear in 2 lists)
*
* Each pane contains one or more views wich are created by a view factory and inserted into a pane list.
* There may be several panes managed by the MainViewManager with each pane containing a list of views.
* The panes are always visible and the layout is determined by the MainViewManager and the user.
* There may be several panes managed by the MainViewManager with each pane containing a list of views.
* The panes are always visible and the layout is determined by the MainViewManager and the user.
*
* Currently we support only 2 panes.
*
Expand Down Expand Up @@ -354,7 +354,7 @@ define(function (require, exports, module) {

/**
* Makes the Pane's current file the most recent
* @param {!string} paneId - id of the pane to mae th file most recent or ACTIVE_PANE
* @param {!string} paneId - id of the pane to make the file most recent, or ACTIVE_PANE
* @param {!File} file - File object to make most recent
* @private
*/
Expand All @@ -367,7 +367,7 @@ define(function (require, exports, module) {
}

/**
* Switch active pane to the specified pane Id (or ACTIVE_PANE/ALL_PANES, in which case this
* Switch active pane to the specified pane id (or ACTIVE_PANE/ALL_PANES, in which case this
* call does nothing).
* @param {!string} paneId - the id of the pane to activate
*/
Expand Down Expand Up @@ -515,7 +515,7 @@ define(function (require, exports, module) {


/**
* Retrieves the WorkingSet for the given PaneId not including temporary views
* Retrieves the WorkingSet for the given paneId not including temporary views
* @param {!string} paneId - id of the pane in which to get the view list, ALL_PANES or ACTIVE_PANE
* @return {Array.<File>}
*/
Expand All @@ -532,7 +532,7 @@ define(function (require, exports, module) {


/**
* Retrieves the list of all open files inlcuding temporary views
* Retrieves the list of all open files including temporary views
* @return {array.<File>} the list of all open files in all open panes
*/
function getAllOpenFiles() {
Expand Down Expand Up @@ -916,8 +916,8 @@ define(function (require, exports, module) {
/**
* Get the next or previous file in the MRU list.
* @param {!number} direction - Must be 1 or -1 to traverse forward or backward
* @return {?{file:File, paneId:string}} The File object of the next item in the travesal order or null if there aren't any files to traverse.
* may return current file if there are no other files to traverse.
* @return {?{file:File, paneId:string}} The File object of the next item in the traversal order or null if there aren't any files to traverse.
* May return current file if there are no other files to traverse.
*/
function traverseToNextViewByMRU(direction) {
var file = getCurrentlyViewedFile(),
Expand All @@ -929,6 +929,32 @@ define(function (require, exports, module) {
return ViewUtils.traverseViewArray(_mruList, index, direction);
}

/**
* Get the next or previous file in list order.
* @param {!number} direction - Must be 1 or -1 to traverse forward or backward
* @return {?{file:File, paneId:string}} The File object of the next item in the traversal order or null if there aren't any files to traverse.
* May return current file if there are no other files to traverse.
*/
function traverseToNextViewInListOrder(direction) {
var file = getCurrentlyViewedFile(),
curPaneId = getActivePaneId(),
allFiles = [],
index;

getPaneIdList().forEach(function (paneId) {
var paneFiles = getWorkingSet(paneId).map(function (file) {
return { file: file, pane: paneId };
});
allFiles = allFiles.concat(paneFiles);
});

index = _.findIndex(allFiles, function (record) {
return (record.file === file && record.pane === curPaneId);
});

return ViewUtils.traverseViewArray(allFiles, index, direction);
}

/**
* Indicates that traversal has begun.
* Can be called any number of times.
Expand Down Expand Up @@ -1726,6 +1752,7 @@ define(function (require, exports, module) {
exports.beginTraversal = beginTraversal;
exports.endTraversal = endTraversal;
exports.traverseToNextViewByMRU = traverseToNextViewByMRU;
exports.traverseToNextViewInListOrder = traverseToNextViewInListOrder;

// PaneView Attributes
exports.getActivePaneId = getActivePaneId;
Expand Down
93 changes: 93 additions & 0 deletions test/spec/MainViewManager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -969,5 +969,98 @@ define(function (require, exports, module) {
});
});
});

describe("Traversing Files", function () {
beforeEach(function () {
runs(function () {
MainViewManager.setLayoutScheme(1, 2);
});
runs(function () {
promise = CommandManager.execute(Commands.FILE_OPEN, { fullPath: testPath + "/test.js",
paneId: "first-pane" });
waitsForDone(promise, Commands.FILE_OPEN);
});
runs(function () {
promise = CommandManager.execute(Commands.FILE_OPEN, { fullPath: testPath + "/test.css",
paneId: "first-pane" });
waitsForDone(promise, Commands.FILE_OPEN);
});
runs(function () {
promise = CommandManager.execute(Commands.FILE_OPEN, { fullPath: testPath + "/test.html",
paneId: "second-pane" });
waitsForDone(promise, Commands.FILE_OPEN);
});
runs(function () {
MainViewManager.addToWorkingSet("first-pane", getFileObject("test.js"));
MainViewManager.addToWorkingSet("first-pane", getFileObject("test.css"));
MainViewManager.addToWorkingSet("second-pane", getFileObject("test.html"));
});
});

it("should traverse in list order", function () {
runs(function () {
// Make test.js the active file
promise = new $.Deferred();
DocumentManager.getDocumentForPath(testPath + "/test.js")
.done(function (doc) {
MainViewManager._edit("first-pane", doc);
promise.resolve();
});
waitsForDone(promise, "MainViewManager._edit");
});
runs(function () {
var traverseResult = MainViewManager.traverseToNextViewInListOrder(1);

expect(traverseResult.file).toEqual(getFileObject("test.css"));
expect(traverseResult.pane).toEqual("first-pane");
});
});

it("should traverse between panes in list order", function () {
runs(function () {
var traverseResult = MainViewManager.traverseToNextViewInListOrder(1);

expect(traverseResult.file).toEqual(getFileObject("test.js"));
expect(traverseResult.pane).toEqual("first-pane");
});
});

it("should traverse to the first Working Set item if a file not in the Working Set is being viewed", function () {
runs(function () {
// Close test.js to then reopen it without being in the Working Set
CommandManager.execute(Commands.FILE_CLOSE, { file: getFileObject("test.js") });
promise = CommandManager.execute(Commands.FILE_OPEN, { fullPath: testPath + "/test.js",
paneId: "first-pane" });
waitsForDone(promise, Commands.FILE_OPEN);
});
runs(function () {
MainViewManager.setActivePaneId("first-pane");

var traverseResult = MainViewManager.traverseToNextViewInListOrder(1);

expect(traverseResult.file).toEqual(getFileObject("test.css"));
expect(traverseResult.pane).toEqual("first-pane");
});
});

it("should traverse between panes in reverse list order", function () {
runs(function () {
// Make test.js the active file
promise = new $.Deferred();
DocumentManager.getDocumentForPath(testPath + "/test.js")
.done(function (doc) {
MainViewManager._edit("first-pane", doc);
promise.resolve();
});
waitsForDone(promise, "MainViewManager._edit");
});
runs(function () {
var traverseResult = MainViewManager.traverseToNextViewInListOrder(-1);

expect(traverseResult.file).toEqual(getFileObject("test.html"));
expect(traverseResult.pane).toEqual("second-pane");
});
});
});
});
});

0 comments on commit 7dea6c9

Please sign in to comment.