Skip to content

Commit

Permalink
[vscode] Introduce EnhancedPreviewWidget interface #12696
Browse files Browse the repository at this point in the history
* allow widgets to customize the enhanced preview node

Contributed on behalf of STMicroelectronics

Signed-off-by: Johannes Faltermeier <[email protected]>
  • Loading branch information
jfaltermeier committed Aug 24, 2023
1 parent b80c556 commit 81de14d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/core/src/browser/shell/tab-bars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { Root, createRoot } from 'react-dom/client';
import { SelectComponent } from '../widgets/select-component';
import { createElement } from 'react';
import { PreviewableWidget } from '../widgets/previewable-widget';
import { EnhancedPreviewWidget } from '../widgets/enhanced-preview-widget';

/** The class name added to hidden content nodes, which are required to render vertical side bars. */
const HIDDEN_CONTENT_CLASS = 'theia-TabBar-hidden-content';
Expand Down Expand Up @@ -169,8 +170,8 @@ export class TabBarRenderer extends TabBar.Renderer {
const hover = this.tabBar && (this.tabBar.orientation === 'horizontal' && this.corePreferences?.['window.tabbar.enhancedPreview'] === 'classic')
? { title: title.caption }
: {
onmouseenter: this.handleMouseEnterEvent
};
onmouseenter: this.handleMouseEnterEvent
};

return h.li(
{
Expand Down Expand Up @@ -504,7 +505,13 @@ export class TabBarRenderer extends TabBar.Renderer {
labelElement.classList.add('theia-horizontal-tabBar-hover-title');
labelElement.textContent = title.label;
hoverBox.append(labelElement);
if (title.caption) {
const widget = title.owner;
if (EnhancedPreviewWidget.is(widget)) {
const enhancedPreviewNode = widget.getEnhancedPreviewNode();
if (enhancedPreviewNode) {
hoverBox.appendChild(enhancedPreviewNode);
}
} else if (title.caption) {
const captionElement = document.createElement('p');
captionElement.classList.add('theia-horizontal-tabBar-hover-caption');
captionElement.textContent = title.caption;
Expand Down
27 changes: 27 additions & 0 deletions packages/core/src/browser/widgets/enhanced-preview-widget.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// *****************************************************************************
// 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 { isFunction, isObject } from '../../common';

export interface EnhancedPreviewWidget {
getEnhancedPreviewNode(): Node | undefined;
}

export namespace EnhancedPreviewWidget {
export function is(arg: unknown): arg is EnhancedPreviewWidget {
return isObject<EnhancedPreviewWidget>(arg) && isFunction(arg.getEnhancedPreviewNode);
}
}

0 comments on commit 81de14d

Please sign in to comment.