Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve hovers in title bar #153166

Merged
merged 1 commit into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/vs/base/browser/ui/menu/menubar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,7 @@ export class MenuBar extends Disposable {

createOverflowMenu(): void {
const label = this.isCompact ? nls.localize('mAppMenu', 'Application Menu') : nls.localize('mMore', 'More');
const title = this.isCompact ? label : undefined;
const buttonElement = $('div.menubar-menu-button', { 'role': 'menuitem', 'tabindex': this.isCompact ? 0 : -1, 'aria-label': label, 'title': title, 'aria-haspopup': true });
const buttonElement = $('div.menubar-menu-button', { 'role': 'menuitem', 'tabindex': this.isCompact ? 0 : -1, 'aria-label': label, 'aria-haspopup': true });
const titleElement = $('div.menubar-menu-title.toolbar-toggle-more' + Codicon.menuBarMore.cssSelector, { 'role': 'none', 'aria-hidden': true });

buttonElement.appendChild(titleElement);
Expand Down
23 changes: 1 addition & 22 deletions src/vs/workbench/browser/parts/titlebar/commandCenterControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { assertType } from 'vs/base/common/types';
import { localize } from 'vs/nls';
import { createActionViewItem, createAndFillInContextMenuActions, MenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { IMenuService, MenuId, MenuItemAction } from 'vs/platform/actions/common/actions';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
Expand All @@ -25,7 +24,6 @@ import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
import * as colors from 'vs/platform/theme/common/colorRegistry';
import { WindowTitle } from 'vs/workbench/browser/parts/titlebar/windowTitle';
import { MENUBAR_SELECTION_BACKGROUND, MENUBAR_SELECTION_FOREGROUND, PANEL_BORDER, TITLE_BAR_ACTIVE_FOREGROUND } from 'vs/workbench/common/theme';
import { IHoverService } from 'vs/workbench/services/hover/browser/hover';

export class CommandCenterControl {

Expand All @@ -38,35 +36,16 @@ export class CommandCenterControl {

constructor(
windowTitle: WindowTitle,
hoverDelegate: IHoverDelegate,
@IContextMenuService contextMenuService: IContextMenuService,
@IContextKeyService contextKeyService: IContextKeyService,
@IInstantiationService instantiationService: IInstantiationService,
@IMenuService menuService: IMenuService,
@IQuickInputService quickInputService: IQuickInputService,
@IHoverService hoverService: IHoverService,
@IConfigurationService configurationService: IConfigurationService,
@IKeybindingService keybindingService: IKeybindingService,
) {
this.element.classList.add('command-center');

const hoverDelegate = new class implements IHoverDelegate {

private _lastHoverHideTime: number = 0;

readonly showHover = hoverService.showHover.bind(hoverService);
readonly placement = 'element';

get delay(): number {
return Date.now() - this._lastHoverHideTime < 200
? 0 // show instantly when a hover was recently shown
: configurationService.getValue<number>('workbench.hover.delay');
}

onDidHideHover() {
this._lastHoverHideTime = Date.now();
}
};

const titleToolbar = new ToolBar(this.element, contextMenuService, {
actionViewItemProvider: (action) => {

Expand Down
27 changes: 25 additions & 2 deletions src/vs/workbench/browser/parts/titlebar/titlebarPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import { getIconRegistry } from 'vs/platform/theme/common/iconRegistry';
import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
import { WindowTitle } from 'vs/workbench/browser/parts/titlebar/windowTitle';
import { CommandCenterControl } from 'vs/workbench/browser/parts/titlebar/commandCenterControl';
import { IHoverDelegate } from 'vs/base/browser/ui/iconLabel/iconHoverDelegate';
import { IHoverService } from 'vs/workbench/services/hover/browser/hover';

export class TitlebarPart extends Part implements ITitleService {

Expand Down Expand Up @@ -71,6 +73,8 @@ export class TitlebarPart extends Part implements ITitleService {
private layoutToolbar: ToolBar | undefined;
protected lastLayoutDimensions: Dimension | undefined;

private hoverDelegate: IHoverDelegate;

private readonly titleDisposables = this._register(new DisposableStore());
private titleBarStyle: 'native' | 'custom';

Expand All @@ -91,13 +95,32 @@ export class TitlebarPart extends Part implements ITitleService {
@IMenuService private readonly menuService: IMenuService,
@IContextKeyService private readonly contextKeyService: IContextKeyService,
@IHostService private readonly hostService: IHostService,
@IHoverService hoverService: IHoverService,
) {
super(Parts.TITLEBAR_PART, { hasTitle: false }, themeService, storageService, layoutService);
this.windowTitle = this._register(instantiationService.createInstance(WindowTitle));
this.contextMenu = this._register(menuService.createMenu(MenuId.TitleBarContext, contextKeyService));

this.titleBarStyle = getTitleBarStyle(this.configurationService);

this.hoverDelegate = new class implements IHoverDelegate {

private _lastHoverHideTime: number = 0;

readonly showHover = hoverService.showHover.bind(hoverService);
readonly placement = 'element';

get delay(): number {
return Date.now() - this._lastHoverHideTime < 200
? 0 // show instantly when a hover was recently shown
: configurationService.getValue<number>('workbench.hover.delay');
}

onDidHideHover() {
this._lastHoverHideTime = Date.now();
}
};

this.registerListeners();
}

Expand Down Expand Up @@ -203,7 +226,7 @@ export class TitlebarPart extends Part implements ITitleService {
}));
} else {
// Menu Title
const commandCenter = this.instantiationService.createInstance(CommandCenterControl, this.windowTitle);
const commandCenter = this.instantiationService.createInstance(CommandCenterControl, this.windowTitle, this.hoverDelegate);
reset(this.title, commandCenter.element);
this.titleDisposables.add(commandCenter);
this.titleDisposables.add(commandCenter.onDidChangeVisibility(this.adjustTitleMarginToCenter, this));
Expand Down Expand Up @@ -252,7 +275,7 @@ export class TitlebarPart extends Part implements ITitleService {

this.layoutToolbar = new ToolBar(this.layoutControls, this.contextMenuService, {
actionViewItemProvider: action => {
return createActionViewItem(this.instantiationService, action);
return createActionViewItem(this.instantiationService, action, { hoverDelegate: this.hoverDelegate });
},
allowContextMenu: true
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { getTitleBarStyle, useWindowControlsOverlay } from 'vs/platform/window/c
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Codicon } from 'vs/base/common/codicons';
import { NativeMenubarControl } from 'vs/workbench/electron-sandbox/parts/titlebar/menubarControl';
import { IHoverService } from 'vs/workbench/services/hover/browser/hover';

export class TitlebarPart extends BrowserTitleBarPart {
private maxRestoreControl: HTMLElement | undefined;
Expand Down Expand Up @@ -60,8 +61,9 @@ export class TitlebarPart extends BrowserTitleBarPart {
@IContextKeyService contextKeyService: IContextKeyService,
@IHostService hostService: IHostService,
@INativeHostService private readonly nativeHostService: INativeHostService,
@IHoverService hoverService: IHoverService,
) {
super(contextMenuService, configurationService, environmentService, instantiationService, themeService, storageService, layoutService, menuService, contextKeyService, hostService);
super(contextMenuService, configurationService, environmentService, instantiationService, themeService, storageService, layoutService, menuService, contextKeyService, hostService, hoverService);

this.environmentService = environmentService;
}
Expand Down