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

Commit

Permalink
Add a feature to toggle between panes in the core #10555 (#12853)
Browse files Browse the repository at this point in the history
* Added the feature to toggle between panes as requested by petetnt in issues #10555

* Added the feature to toggle between panes as requested by petetnt in issues #10555

* Bumping version Number to 1.9

* Edited the files and added a unit test for this feature as requested by petetnt and swmitra

* Removed duplicate/unnecessary code in Pane.js

* Removed additional duplicate/unnecessary code in Pane.js

* Edited 'should switch pane when alt-w is pressed' function in MainViewManager-test.js and the test is now passing

* Revert package.json and src/config.json to previous commit

* Added the feature to toggle between panes as requested by petetnt in issues #10555

* Added the feature to toggle between panes as requested by petetnt in issues #10555

* Edited the files and added a unit test for this feature as requested by petetnt and swmitra

* Removed duplicate/unnecessary code in Pane.js

* Removed additional duplicate/unnecessary code in Pane.js

* Edited 'should switch pane when alt-w is pressed' function in MainViewManager-test.js and the test is now passing

* Revert package.json and src/config.json to previous commit

* Modified test code to test CMD_SWITCH_PANE_FOCUS

* Removed unnecessary code in MainViewManager-test.js
  • Loading branch information
arthur801031 authored and petetnt committed Oct 28, 2016
1 parent b092dea commit e78688a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/command/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 22 additions & 3 deletions src/view/MainViewManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'});
}

/**
Expand Down Expand Up @@ -1658,8 +1676,8 @@ define(function (require, exports, module) {

return result;
}


/**
* Setup a ready event to initialize ourself
*/
Expand Down Expand Up @@ -1729,6 +1747,7 @@ define(function (require, exports, module) {

exports.getAllOpenFiles = getAllOpenFiles;
exports.focusActivePane = focusActivePane;
exports.switchPaneFocus = switchPaneFocus;

// Layout
exports.setLayoutScheme = setLayoutScheme;
Expand Down
28 changes: 28 additions & 0 deletions test/spec/MainViewManager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e78688a

Please sign in to comment.