diff --git a/src/command/Commands.js b/src/command/Commands.js index 03b1ec8d271..40eae36b16d 100644 --- a/src/command/Commands.js +++ b/src/command/Commands.js @@ -153,6 +153,7 @@ define(function (require, exports, module) { exports.CMD_SPLITVIEW_NONE = "cmd.splitViewNone"; // SidebarView.js _handleSplitNone() exports.CMD_SPLITVIEW_VERTICAL = "cmd.splitViewVertical"; // SidebarView.js _handleSplitVertical() exports.CMD_SPLITVIEW_HORIZONTAL = "cmd.splitViewHorizontal"; // SidebarView.js _handleSplitHorizontal() + exports.CMD_SWITCH_PANE_FOCUS = "cmd.switchPaneFocus"; // MainViewManager.js _switchPaneFocus() // File shell callbacks - string must MATCH string in native code (appshell/command_callbacks.h) exports.HELP_ABOUT = "help.about"; // HelpCommandHandlers.js _handleAboutDialog() diff --git a/src/nls/root/strings.js b/src/nls/root/strings.js index a0ee7f9e182..c504e64eb6f 100644 --- a/src/nls/root/strings.js +++ b/src/nls/root/strings.js @@ -418,6 +418,7 @@ define({ "CMD_SHOW_IN_EXPLORER" : "Show in Explorer", "CMD_SHOW_IN_FINDER" : "Show in Finder", "CMD_SHOW_IN_OS" : "Show in OS", + "CMD_SWITCH_PANE_FOCUS" : "Switch Pane Focus", // Help menu commands "HELP_MENU" : "Help", diff --git a/src/view/MainViewManager.js b/src/view/MainViewManager.js index 1b96c2c7938..1ae39be9940 100644 --- a/src/view/MainViewManager.js +++ b/src/view/MainViewManager.js @@ -92,7 +92,8 @@ define(function (require, exports, module) { AsyncUtils = require("utils/Async"), ViewUtils = require("utils/ViewUtils"), Resizer = require("utils/Resizer"), - Pane = require("view/Pane").Pane; + Pane = require("view/Pane").Pane, + KeyBindingManager = brackets.getModule("command/KeyBindingManager"); /** * Preference setting name for the MainView Saved State @@ -844,6 +845,19 @@ define(function (require, exports, module) { return result.promise(); } + /** + * Switch between panes + */ + function switchPaneFocus() { + var $firstPane = $('#first-pane'), $secondPane = $('#second-pane'); + if($firstPane.hasClass('active-pane')) { + $secondPane.click(); + } + else { + $firstPane.click(); + } + } + /** * DocumentManager.pathDeleted Event handler to remove a file * from the MRU list @@ -1616,6 +1630,10 @@ define(function (require, exports, module) { // get an event handler for workspace events and we don't listen // to the event before we've been initialized WorkspaceManager.on("workspaceUpdateLayout", _updateLayout); + + // Listen to key Alt-W to toggle between panes + CommandManager.register(Strings.CMD_SWITCH_PANE_FOCUS, Commands.CMD_SWITCH_PANE_FOCUS, switchPaneFocus); + KeyBindingManager.addBinding(Commands.CMD_SWITCH_PANE_FOCUS, {key: 'Alt-W'}); } /** @@ -1658,8 +1676,8 @@ define(function (require, exports, module) { return result; } - - + + /** * Setup a ready event to initialize ourself */ @@ -1729,6 +1747,7 @@ define(function (require, exports, module) { exports.getAllOpenFiles = getAllOpenFiles; exports.focusActivePane = focusActivePane; + exports.switchPaneFocus = switchPaneFocus; // Layout exports.setLayoutScheme = setLayoutScheme; diff --git a/test/spec/MainViewManager-test.js b/test/spec/MainViewManager-test.js index 4712b04159c..ac36df78757 100644 --- a/test/spec/MainViewManager-test.js +++ b/test/spec/MainViewManager-test.js @@ -536,6 +536,34 @@ define(function (require, exports, module) { expect(MainViewManager.getLayoutScheme()).toEqual({rows: 1, columns: 1}); }); }); + it("should switch pane when Commands.CMD_SWITCH_PANE_FOCUS is called", function () { + runs(function () { + MainViewManager.setLayoutScheme(1, 2); + }); + runs(function () { + $('#first-pane').click(); + CommandManager.execute(Commands.CMD_SWITCH_PANE_FOCUS); + expect(MainViewManager.getActivePaneId()).toEqual("second-pane"); + }); + runs(function () { + $('#second-pane').click(); + CommandManager.execute(Commands.CMD_SWITCH_PANE_FOCUS); + expect(MainViewManager.getActivePaneId()).toEqual("first-pane"); + }); + runs(function () { + MainViewManager.setLayoutScheme(2, 1); + }); + runs(function () { + $('#first-pane').click(); + CommandManager.execute(Commands.CMD_SWITCH_PANE_FOCUS); + expect(MainViewManager.getActivePaneId()).toEqual("second-pane"); + }); + runs(function () { + $('#second-pane').click(); + CommandManager.execute(Commands.CMD_SWITCH_PANE_FOCUS); + expect(MainViewManager.getActivePaneId()).toEqual("first-pane"); + }); + }); it("should activate pane when editor gains focus", function () { var editors = {}, handler = function (e, doc, editor, paneId) {