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

Add extended tab bar preview option #12350

Merged
merged 3 commits into from
Apr 13, 2023
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
6 changes: 6 additions & 0 deletions packages/core/src/browser/core-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ export const corePreferenceSchema: PreferenceSchema = {
default: 'code',
markdownDescription: nls.localizeByDefault('Controls the dispatching logic for key presses to use either `code` (recommended) or `keyCode`.')
},
'window.tabbar.enhancedPreview': {
type: 'boolean',
default: false,
description: nls.localize('theia/core/enhancedPreview', 'Controls whether more information about the tab should be displayed in horizontal tab bars.')
},
'window.menuBarVisibility': {
type: 'string',
enum: ['classic', 'visible', 'hidden', 'compact'],
Expand Down Expand Up @@ -258,6 +263,7 @@ export interface CoreConfiguration {
'breadcrumbs.enabled': boolean;
'files.encoding': string;
'keyboard.dispatch': 'code' | 'keyCode';
'window.tabbar.enhancedPreview': boolean;
'window.menuBarVisibility': 'classic' | 'visible' | 'hidden' | 'compact';
'window.title': string;
'window.titleSeparator': string;
Expand Down
13 changes: 12 additions & 1 deletion packages/core/src/browser/hover-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export interface HoverRequest {
* if the specified content does not fit in the window next to the target element
*/
position: HoverPosition
/**
* Additional css classes that should be added to the hover box.
* Used to style certain boxes different e.g. for the extended tab preview.
*/
cssClasses?: string []
}

@injectable()
Expand Down Expand Up @@ -101,7 +106,10 @@ export class HoverService {

protected async renderHover(request: HoverRequest): Promise<void> {
const host = this.hoverHost;
const { target, content, position } = request;
const { target, content, position, cssClasses } = request;
if (cssClasses) {
host.classList.add(...cssClasses);
}
this.hoverTarget = target;
if (content instanceof HTMLElement) {
host.appendChild(content);
Expand All @@ -124,6 +132,9 @@ export class HoverService {
dispose: () => {
this.lastHidHover = Date.now();
host.classList.remove(updatedPosition);
if (cssClasses) {
host.classList.remove(...cssClasses);
}
}
});

Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/browser/shell/application-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,14 @@ export class ApplicationShell extends Widget {
}
});
}

this.corePreferences.onPreferenceChanged(preference => {
if (preference.preferenceName === 'window.tabbar.enhancedPreview') {
this.allTabBars.forEach(tabBar => {
tabBar.update();
});
}
});
}

protected initializeShell(): void {
Expand Down
39 changes: 31 additions & 8 deletions packages/core/src/browser/shell/tab-bars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ export class TabBarRenderer extends TabBar.Renderer {
? nls.localizeByDefault('Unpin')
: nls.localizeByDefault('Close');

const hover = this.tabBar && this.tabBar.orientation === 'horizontal' ? {
title: title.caption
} : {
const hover = this.tabBar && (this.tabBar.orientation === 'horizontal' && !this.corePreferences?.['window.tabbar.enhancedPreview']) ? { title: title.caption } : {
onmouseenter: this.handleMouseEnterEvent
};

Expand Down Expand Up @@ -484,16 +482,41 @@ export class TabBarRenderer extends TabBar.Renderer {
return h.div({ className: baseClassName, style }, data.title.iconLabel);
}

protected renderEnhancedPreview = (title: Title<Widget>) => {
const hoverBox = document.createElement('div');
hoverBox.classList.add('theia-horizontal-tabBar-hover-div');
const labelElement = document.createElement('p');
labelElement.classList.add('theia-horizontal-tabBar-hover-title');
labelElement.textContent = title.label;
hoverBox.append(labelElement);
if (title.caption) {
const captionElement = document.createElement('p');
captionElement.classList.add('theia-horizontal-tabBar-hover-caption');
captionElement.textContent = title.caption;
hoverBox.appendChild(captionElement);
}
return hoverBox;
};

protected handleMouseEnterEvent = (event: MouseEvent) => {
if (this.tabBar && this.hoverService && event.currentTarget instanceof HTMLElement) {
const id = event.currentTarget.id;
const title = this.tabBar.titles.find(t => this.createTabId(t) === id);
if (title) {
this.hoverService.requestHover({
content: title.caption,
target: event.currentTarget,
position: 'right'
});
if (this.tabBar.orientation === 'horizontal') {
this.hoverService.requestHover({
content: this.renderEnhancedPreview(title),
target: event.currentTarget,
position: 'bottom',
cssClasses: ['extended-tab-preview']
});
} else {
this.hoverService.requestHover({
content: title.caption,
target: event.currentTarget,
position: 'right'
});
}
}
}
};
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/browser/style/hover-service.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,7 @@
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
}

.theia-hover.extended-tab-preview {
border-radius: 10px;
}
16 changes: 16 additions & 0 deletions packages/core/src/browser/style/tabs.css
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,19 @@
.p-TabBar[data-orientation='horizontal'] .p-TabBar-tab.p-mod-current .theia-tab-icon-label {
overflow: hidden;
}

.theia-horizontal-tabBar-hover-div {
margin: 0px 4px;
}

.theia-horizontal-tabBar-hover-title {
font-weight: bolder;
font-size: medium;
margin: 0px 0px;
}

.theia-horizontal-tabBar-hover-caption {
font-size: small;
margin: 0px 0px;
margin-top: 4px;
}