-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework sidepanel behavior on tab overflow (#12593)
Rework behavior of the sidepanels if there more tabs than they can fit. Introduce behavior similar to VS Code: Overflowing tabs will simply be hidden or 'merged' into one menu button at the end of the tabbar. Clicking the button allows revealing of a currently hidden view. Special handling is implemented to ensure that the currently selected view never gets hidden away. Contributed on behalf of STMicroelectronics Fixes #12416
- Loading branch information
Showing
6 changed files
with
257 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/core/src/browser/shell/additional-views-menu-widget.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2023 STMicroelectronics and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
|
||
import { inject, injectable } from '../../../shared/inversify'; | ||
import { Command, CommandRegistry, Disposable, MenuModelRegistry, MenuPath, nls } from '../../common'; | ||
import { Title, Widget, codicon } from '../widgets'; | ||
import { SidebarMenuWidget } from './sidebar-menu-widget'; | ||
import { SideTabBar } from './tab-bars'; | ||
|
||
export const AdditionalViewsMenuWidgetFactory = Symbol('AdditionalViewsMenuWidgetFactory'); | ||
export type AdditionalViewsMenuWidgetFactory = (side: 'left' | 'right') => AdditionalViewsMenuWidget; | ||
|
||
export const ADDITIONAL_VIEWS_MENU_PATH: MenuPath = ['additional_views_menu']; | ||
|
||
@injectable() | ||
export class AdditionalViewsMenuWidget extends SidebarMenuWidget { | ||
static readonly ID = 'sidebar.additional.views'; | ||
|
||
side: 'left' | 'right'; | ||
|
||
@inject(CommandRegistry) | ||
protected readonly commandRegistry: CommandRegistry; | ||
|
||
@inject(MenuModelRegistry) | ||
protected readonly menuModelRegistry: MenuModelRegistry; | ||
|
||
protected menuDisposables: Disposable[] = []; | ||
|
||
updateAdditionalViews(sender: SideTabBar, event: { titles: Title<Widget>[], startIndex: number }): void { | ||
if (event.startIndex === -1) { | ||
this.removeMenu(AdditionalViewsMenuWidget.ID); | ||
} else { | ||
this.addMenu({ | ||
title: nls.localizeByDefault('Additional Views'), | ||
iconClass: codicon('ellipsis'), | ||
id: AdditionalViewsMenuWidget.ID, | ||
menuPath: ADDITIONAL_VIEWS_MENU_PATH, | ||
order: 0 | ||
}); | ||
} | ||
|
||
this.menuDisposables.forEach(disposable => disposable.dispose()); | ||
this.menuDisposables = []; | ||
event.titles.forEach((title, i) => this.registerMenuAction(sender, title, i)); | ||
} | ||
|
||
protected registerMenuAction(sender: SideTabBar, title: Title<Widget>, index: number): void { | ||
const command: Command = { id: `reveal.${title.label}.${index}`, label: title.label }; | ||
this.menuDisposables.push(this.commandRegistry.registerCommand(command, { | ||
execute: () => { | ||
window.requestAnimationFrame(() => { | ||
sender.currentIndex = sender.titles.indexOf(title); | ||
}); | ||
} | ||
})); | ||
this.menuDisposables.push(this.menuModelRegistry.registerMenuAction(ADDITIONAL_VIEWS_MENU_PATH, { commandId: command.id, order: index.toString() })); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.