Skip to content

Commit

Permalink
Added separate commands to close main area widgets
Browse files Browse the repository at this point in the history
Signed-off-by: Miro Spönemann <miro.spoenemann@typefox.io>
  • Loading branch information
spoenemann committed Feb 12, 2020
1 parent 84b6f7f commit b9987e8
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 21 deletions.
63 changes: 42 additions & 21 deletions packages/core/src/browser/common-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ export namespace CommonCommands {
category: VIEW_CATEGORY,
label: 'Close All Tabs'
};
export const CLOSE_MAIN_TAB: Command = {
id: 'core.close.main.tab',
category: VIEW_CATEGORY,
label: 'Close Tab in Main Area'
};
export const CLOSE_OTHER_MAIN_TABS: Command = {
id: 'core.close.other.main.tabs',
category: VIEW_CATEGORY,
label: 'Close Other Tabs in Main Area'
};
export const CLOSE_ALL_MAIN_TABS: Command = {
id: 'core.close.all.main.tabs',
category: VIEW_CATEGORY,
label: 'Close All Tabs in Main Area'
};
export const COLLAPSE_PANEL: Command = {
id: 'core.collapse.tab',
category: VIEW_CATEGORY,
Expand Down Expand Up @@ -509,7 +524,7 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
execute: (event?: Event) => {
const tabBar = this.findTabBar(event)!;
const currentTitle = this.findTitle(tabBar, event);
this.shell.closeTabs(tabBar, (title, index) => title === currentTitle);
this.shell.closeTabs(tabBar, title => title === currentTitle);
}
});
commandRegistry.registerCommand(CommonCommands.CLOSE_OTHER_TABS, {
Expand All @@ -521,7 +536,7 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
const tabBar = this.findTabBar(event)!;
const currentTitle = this.findTitle(tabBar, event);
const area = this.shell.getAreaFor(tabBar)!;
this.shell.closeTabs(area, (title, index) => title !== currentTitle);
this.shell.closeTabs(area, title => title !== currentTitle);
}
});
commandRegistry.registerCommand(CommonCommands.CLOSE_RIGHT_TABS, {
Expand All @@ -536,31 +551,37 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
execute: (event?: Event) => {
const tabBar = this.findTabBar(event)!;
const currentIndex = tabBar.currentIndex;
this.shell.closeTabs(tabBar, (title, index) => index > currentIndex);
this.shell.closeTabs(tabBar, (_, index) => index > currentIndex);
}
});
commandRegistry.registerCommand(CommonCommands.CLOSE_ALL_TABS, {
isEnabled: (event?: Event) => {
if (event) {
return this.findTabBar(event) !== undefined;
} else {
return this.shell.mainAreaTabBars.find(tb => tb.titles.length > 0) !== undefined;
}
isEnabled: (event?: Event) => this.findTabBar(event) !== undefined,
execute: (event?: Event) => this.shell.closeTabs(this.findTabArea(event)!)
});
commandRegistry.registerCommand(CommonCommands.CLOSE_MAIN_TAB, {
isEnabled: () => this.shell.getCurrentWidget('main') !== undefined,
execute: () => this.shell.getCurrentWidget('main')!.close()
});
commandRegistry.registerCommand(CommonCommands.CLOSE_OTHER_MAIN_TABS, {
isEnabled: () => {
const tabBars = this.shell.mainAreaTabBars;
return tabBars.length > 1 || tabBars.length === 1 && tabBars[0].titles.length > 1;
},
execute: (event?: Event) => {
if (event) {
this.shell.closeTabs(this.findTabArea(event)!);
} else {
this.shell.closeTabs('main');
execute: () => {
const currentWidget = this.shell.getCurrentWidget('main');
if (currentWidget !== undefined) {
this.shell.closeTabs('main', title => title.owner !== currentWidget);
}
}
});
commandRegistry.registerCommand(CommonCommands.CLOSE_ALL_MAIN_TABS, {
isEnabled: () => this.shell.mainAreaTabBars.find(tb => tb.titles.length > 0) !== undefined,
execute: () => this.shell.closeTabs('main')
});
commandRegistry.registerCommand(CommonCommands.COLLAPSE_PANEL, {
isEnabled: (event?: Event) => ApplicationShell.isSideArea(this.findTabArea(event)),
isVisible: (event?: Event) => ApplicationShell.isSideArea(this.findTabArea(event)),
execute: (event?: Event) => {
this.shell.collapsePanel(this.findTabArea(event)!);
}
execute: (event?: Event) => this.shell.collapsePanel(this.findTabArea(event)!)
});
commandRegistry.registerCommand(CommonCommands.COLLAPSE_ALL_PANELS, {
execute: () => {
Expand Down Expand Up @@ -700,15 +721,15 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
keybinding: 'ctrlcmd+alt+a'
},
{
command: CommonCommands.CLOSE_TAB.id,
keybinding: (!this.isElectron() ? 'alt+w' : (isWindows ? 'ctrl+f4' : 'ctrlcmd+w'))
command: CommonCommands.CLOSE_MAIN_TAB.id,
keybinding: this.isElectron() ? (isWindows ? 'ctrl+f4' : 'ctrlcmd+w') : 'alt+w'
},
{
command: CommonCommands.CLOSE_OTHER_TABS.id,
command: CommonCommands.CLOSE_OTHER_MAIN_TABS.id,
keybinding: 'ctrlcmd+alt+t'
},
{
command: CommonCommands.CLOSE_ALL_TABS.id,
command: CommonCommands.CLOSE_ALL_MAIN_TABS.id,
keybinding: this.isElectron() ? 'ctrlCmd+k ctrlCmd+w' : 'alt+shift+w'
},
// Panels
Expand Down
24 changes: 24 additions & 0 deletions packages/core/src/browser/shell/application-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,30 @@ export class ApplicationShell extends Widget {
return this.tracker.activeWidget || undefined;
}

/**
* Returns the last active widget in the given shell area.
*/
getCurrentWidget(area: ApplicationShell.Area): Widget | undefined {
let title: Title<Widget> | null | undefined;
switch (area) {
case 'main':
title = this.mainPanel.currentTitle;
break;
case 'bottom':
title = this.bottomPanel.currentTitle;
break;
case 'left':
title = this.leftPanelHandler.tabBar.currentTitle;
break;
case 'right':
title = this.rightPanelHandler.tabBar.currentTitle;
break;
default:
throw new Error('Illegal argument: ' + area);
}
return title ? title.owner : undefined;
}

/**
* A signal emitted whenever the `currentWidget` property is changed.
*
Expand Down

0 comments on commit b9987e8

Please sign in to comment.