Skip to content

Commit

Permalink
support next/previous tab in group commands
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kosyakov <[email protected]>
  • Loading branch information
akosyakov committed May 1, 2020
1 parent 3b98660 commit 6bb2a12
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/core/src/browser/common-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ export namespace CommonCommands {
category: VIEW_CATEGORY,
label: 'Switch to Previous Tab'
};
export const NEXT_TAB_IN_GROUP: Command = {
id: 'core.nextTabInGroup',
category: VIEW_CATEGORY,
label: 'Switch to Next Tab in Group'
};
export const PREVIOUS_TAB_IN_GROUP: Command = {
id: 'core.previousTabInGroup',
category: VIEW_CATEGORY,
label: 'Switch to Previous Tab in Group'
};
export const NEXT_TAB_GROUP: Command = {
id: 'core.nextTabGroup',
category: VIEW_CATEGORY,
Expand Down Expand Up @@ -539,6 +549,14 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
isEnabled: () => this.shell.currentTabBar !== undefined,
execute: () => this.shell.activatePreviousTab()
});
commandRegistry.registerCommand(CommonCommands.NEXT_TAB_IN_GROUP, {
isEnabled: () => this.shell.nextTabIndexInTabBar() !== -1,
execute: () => this.shell.activateNextTabInTabBar()
});
commandRegistry.registerCommand(CommonCommands.PREVIOUS_TAB_IN_GROUP, {
isEnabled: () => this.shell.previousTabIndexInTabBar() !== -1,
execute: () => this.shell.activatePreviousTabInTabBar()
});
commandRegistry.registerCommand(CommonCommands.NEXT_TAB_GROUP, {
isEnabled: () => this.shell.nextTabBar() !== undefined,
execute: () => this.shell.activateNextTabBar()
Expand Down
54 changes: 54 additions & 0 deletions packages/core/src/browser/shell/application-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,33 @@ export class ApplicationShell extends Widget {
/*
* Activate the next tab in the current tab bar.
*/
activateNextTabInTabBar(): boolean {
const current = this.currentTabBar;
const index = this.nextTabIndexInTabBar(current);
if (!current || index === -1) {
return false;
}
current.currentIndex = index;
if (current.currentTitle) {
current.currentTitle.owner.activate();
}
return true;
}

nextTabIndexInTabBar(current: TabBar<Widget> | undefined = this.currentTabBar): number {
if (!current || current.titles.length <= 1) {
return -1;
}
const index = current.currentIndex;
if (index === -1) {
return -1;
}
if (index < current.titles.length - 1) {
return index + 1;
}
return 0;
}

activateNextTab(): void {
const current = this.currentTabBar;
if (current) {
Expand Down Expand Up @@ -1556,6 +1583,33 @@ export class ApplicationShell extends Widget {
/*
* Activate the previous tab in the current tab bar.
*/
activatePreviousTabInTabBar(): boolean {
const current = this.currentTabBar;
const index = this.previousTabIndexInTabBar(current);
if (!current || index === -1) {
return false;
}
current.currentIndex = index;
if (current.currentTitle) {
current.currentTitle.owner.activate();
}
return true;
}

previousTabIndexInTabBar(current: TabBar<Widget> | undefined = this.currentTabBar): number {
if (!current || current.titles.length <= 1) {
return -1;
}
const index = current.currentIndex;
if (index === -1) {
return -1;
}
if (index > 0) {
return index - 1;
}
return current.titles.length - 1;
}

activatePreviousTab(): void {
const current = this.currentTabBar;
if (current) {
Expand Down

0 comments on commit 6bb2a12

Please sign in to comment.