Skip to content

Commit

Permalink
support next/previous tab 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 39c5090 commit 3b98660
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 13 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_GROUP: Command = {
id: 'core.nextTabGroup',
category: VIEW_CATEGORY,
label: 'Switch to Next Tab Group'
};
export const PREVIOUS_TAB_GROUP: Command = {
id: 'core.previousTabBar',
category: VIEW_CATEGORY,
label: 'Switch to Previous Tab Group'
};
export const CLOSE_TAB: Command = {
id: 'core.close.tab',
category: VIEW_CATEGORY,
Expand Down Expand Up @@ -529,6 +539,14 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
isEnabled: () => this.shell.currentTabBar !== undefined,
execute: () => this.shell.activatePreviousTab()
});
commandRegistry.registerCommand(CommonCommands.NEXT_TAB_GROUP, {
isEnabled: () => this.shell.nextTabBar() !== undefined,
execute: () => this.shell.activateNextTabBar()
});
commandRegistry.registerCommand(CommonCommands.PREVIOUS_TAB_GROUP, {
isEnabled: () => this.shell.previousTabBar() !== undefined,
execute: () => this.shell.activatePreviousTabBar()
});
commandRegistry.registerCommand(CommonCommands.CLOSE_TAB, {
isEnabled: (event?: Event) => {
const tabBar = this.findTabBar(event);
Expand Down
44 changes: 31 additions & 13 deletions packages/core/src/browser/shell/application-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1513,20 +1513,29 @@ export class ApplicationShell extends Widget {
current.currentTitle.owner.activate();
}
} else if (ci === current.titles.length - 1) {
const nextBar = this.nextTabBar(current);
nextBar.currentIndex = 0;
if (nextBar.currentTitle) {
nextBar.currentTitle.owner.activate();
}
this.activateNextTabBar(current);
}
}
}
}

activateNextTabBar(): void;
activateNextTabBar(nextBar: TabBar<Widget>): void;
activateNextTabBar(nextBar: TabBar<Widget> | undefined = this.nextTabBar()): void {
if (nextBar) {
nextBar.currentIndex = 0;
if (nextBar.currentTitle) {
nextBar.currentTitle.owner.activate();
}
}
}

/**
* Return the tab bar next to the given tab bar; return the given tab bar if there is no adjacent one.
*/
private nextTabBar(current: TabBar<Widget>): TabBar<Widget> {
nextTabBar(): TabBar<Widget> | undefined;
nextTabBar(current: TabBar<Widget>): TabBar<Widget>;
nextTabBar(current: TabBar<Widget> | undefined = this.currentTabBar): TabBar<Widget> | undefined {
let bars = toArray(this.bottomPanel.tabBars());
let len = bars.length;
let ci = ArrayExt.firstIndexOf(bars, current);
Expand Down Expand Up @@ -1558,21 +1567,30 @@ export class ApplicationShell extends Widget {
current.currentTitle.owner.activate();
}
} else if (ci === 0) {
const prevBar = this.previousTabBar(current);
const len = prevBar.titles.length;
prevBar.currentIndex = len - 1;
if (prevBar.currentTitle) {
prevBar.currentTitle.owner.activate();
}
this.activatePreviousTabBar(current);
}
}
}
}

activatePreviousTabBar(): void;
activatePreviousTabBar(nextBar: TabBar<Widget>): void;
activatePreviousTabBar(prevBar: TabBar<Widget> | undefined = this.previousTabBar()): void {
if (prevBar) {
const len = prevBar.titles.length;
prevBar.currentIndex = len - 1;
if (prevBar.currentTitle) {
prevBar.currentTitle.owner.activate();
}
}
}

/**
* Return the tab bar previous to the given tab bar; return the given tab bar if there is no adjacent one.
*/
private previousTabBar(current: TabBar<Widget>): TabBar<Widget> {
previousTabBar(): TabBar<Widget> | undefined;
previousTabBar(current: TabBar<Widget>): TabBar<Widget>;
previousTabBar(current: TabBar<Widget> | undefined = this.currentTabBar): TabBar<Widget> | undefined {
const bars = toArray(this.mainPanel.tabBars());
const len = bars.length;
const ci = ArrayExt.firstIndexOf(bars, current);
Expand Down

0 comments on commit 3b98660

Please sign in to comment.