Skip to content

Commit

Permalink
Merge pull request #7673 from qntnrbns/feature/activate-tab-bar
Browse files Browse the repository at this point in the history
Add commands to move to next/prev tab bar in shell
  • Loading branch information
tgeorgeux committed Dec 30, 2019
2 parents 8fbb4ff + 77a6557 commit fbaf591
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/application-extension/schema/main.json
Expand Up @@ -13,6 +13,16 @@
"keys": ["Ctrl Shift ["],
"selector": "body"
},
{
"command": "application:activate-next-tab-bar",
"keys": ["Ctrl Shift ."],
"selector": "body"
},
{
"command": "application:activate-previous-tab-bar",
"keys": ["Ctrl Shift ,"],
"selector": "body"
},
{
"command": "application:close",
"keys": ["Alt W"],
Expand Down
21 changes: 21 additions & 0 deletions packages/application-extension/src/index.tsx
Expand Up @@ -54,6 +54,11 @@ namespace CommandIDs {
export const activatePreviousTab: string =
'application:activate-previous-tab';

export const activateNextTabBar: string = 'application:activate-next-tab-bar';

export const activatePreviousTabBar: string =
'application:activate-previous-tab-bar';

export const close = 'application:close';

export const closeOtherTabs = 'application:close-other-tabs';
Expand Down Expand Up @@ -575,6 +580,22 @@ function addCommands(app: JupyterLab, palette: ICommandPalette): void {
});
palette.addItem({ command: CommandIDs.activatePreviousTab, category });

commands.addCommand(CommandIDs.activateNextTabBar, {
label: 'Activate Next Tab Bar',
execute: () => {
shell.activateNextTabBar();
}
});
palette.addItem({ command: CommandIDs.activateNextTabBar, category });

commands.addCommand(CommandIDs.activatePreviousTabBar, {
label: 'Activate Previous Tab Bar',
execute: () => {
shell.activatePreviousTabBar();
}
});
palette.addItem({ command: CommandIDs.activatePreviousTabBar, category });

// A CSS selector targeting tabs in the main area. This is a very
// specific selector since we really only want tabs that are
// in the main area, as opposed to those in sidebars, ipywidgets, etc.
Expand Down
24 changes: 24 additions & 0 deletions packages/application/src/shell.ts
Expand Up @@ -499,6 +499,30 @@ export class LabShell extends Widget implements JupyterFrontEnd.IShell {
}
}

/*
* Activate the next TabBar.
*/
activateNextTabBar(): void {
let nextBar = this._adjacentBar('next');
if (nextBar) {
if (nextBar.currentTitle) {
nextBar.currentTitle.owner.activate();
}
}
}

/*
* Activate the next TabBar.
*/
activatePreviousTabBar(): void {
let nextBar = this._adjacentBar('previous');
if (nextBar) {
if (nextBar.currentTitle) {
nextBar.currentTitle.owner.activate();
}
}
}

add(
widget: Widget,
area: ILabShell.Area = 'main',
Expand Down
2 changes: 2 additions & 0 deletions packages/mainmenu-extension/src/index.ts
Expand Up @@ -723,6 +723,8 @@ export function createTabsMenu(
[
{ command: 'application:activate-next-tab' },
{ command: 'application:activate-previous-tab' },
{ command: 'application:activate-next-tab-bar' },
{ command: 'application:activate-previous-tab-bar' },
{ command: CommandIDs.activatePreviouslyUsedTab }
],
0
Expand Down

0 comments on commit fbaf591

Please sign in to comment.