Skip to content

Commit

Permalink
Revert "Add keybinding for custom tree hovers"
Browse files Browse the repository at this point in the history
This reverts commit a00582c.
  • Loading branch information
alexr00 committed Feb 21, 2022
1 parent ad70ffe commit ef41956
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 93 deletions.
55 changes: 3 additions & 52 deletions src/vs/workbench/api/browser/viewsExtensionPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import { localize } from 'vs/nls';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Registry } from 'vs/platform/registry/common/platform';
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
import { Extensions as ViewletExtensions, PaneCompositeRegistry } from 'vs/workbench/browser/panecomposite';
import { CustomTreeView, RawCustomTreeViewContextKey, TreeViewPane } from 'vs/workbench/browser/parts/views/treeView';
import { CustomTreeView, TreeViewPane } from 'vs/workbench/browser/parts/views/treeView';
import { ViewPaneContainer } from 'vs/workbench/browser/parts/views/viewPaneContainer';
import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
import { Extensions as ViewContainerExtensions, ICustomTreeViewDescriptor, ICustomViewDescriptor, IViewContainersRegistry, IViewDescriptor, IViewsRegistry, ResolvableTreeItem, ViewContainer, ViewContainerLocation } from 'vs/workbench/common/views';
import { Extensions as ViewContainerExtensions, ICustomTreeViewDescriptor, ICustomViewDescriptor, IViewContainersRegistry, IViewDescriptor, IViewsRegistry, ViewContainer, ViewContainerLocation } from 'vs/workbench/common/views';
import { VIEWLET_ID as DEBUG } from 'vs/workbench/contrib/debug/common/debug';
import { VIEWLET_ID as EXPLORER } from 'vs/workbench/contrib/files/common/files';
import { VIEWLET_ID as REMOTE } from 'vs/workbench/contrib/remote/browser/remoteExplorer';
Expand All @@ -29,14 +29,6 @@ import { WebviewViewPane } from 'vs/workbench/contrib/webviewView/browser/webvie
import { isProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
import { ExtensionMessageCollector, ExtensionsRegistry, IExtensionPoint, IExtensionPointUser } from 'vs/workbench/services/extensions/common/extensionsRegistry';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { KeyChord, KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { IListService, WorkbenchListFocusContextKey } from 'vs/platform/list/browser/listService';
import { IHoverService } from 'vs/workbench/services/hover/browser/hover';
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import { AsyncDataTree } from 'vs/base/browser/ui/tree/asyncDataTree';
import { ITreeViewsService } from 'vs/workbench/services/views/common/treeViewsService';
import { HoverPosition } from 'vs/base/browser/ui/hover/hoverWidget';

export interface IUserFriendlyViewsContainerDescriptor {
id: string;
Expand Down Expand Up @@ -263,47 +255,6 @@ class ViewsExtensionHandler implements IWorkbenchContribution {
this.viewsRegistry = Registry.as<IViewsRegistry>(ViewContainerExtensions.ViewsRegistry);
this.handleAndRegisterCustomViewContainers();
this.handleAndRegisterCustomViews();

let showTreeHoverCancellation = new CancellationTokenSource();
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'workbench.action.showTreeHover',
handler: async (accessor: ServicesAccessor, ...args: any[]) => {
showTreeHoverCancellation.cancel();
showTreeHoverCancellation = new CancellationTokenSource();
const listService = accessor.get(IListService);
const treeViewsService = accessor.get(ITreeViewsService);
const hoverService = accessor.get(IHoverService);
const lastFocusedList = listService.lastFocusedList;
if (!(lastFocusedList instanceof AsyncDataTree)) {
return;
}
const focus = lastFocusedList.getFocus();
if (!focus || (focus.length === 0)) {
return;
}
const treeItem = focus[0];

if (treeItem instanceof ResolvableTreeItem) {
await treeItem.resolve(showTreeHoverCancellation.token);
}
if (!treeItem.tooltip) {
return;
}
const element = treeViewsService.getRenderedTreeElement(treeItem);
if (!element) {
return;
}
hoverService.showHover({
content: treeItem.tooltip,
target: element,
hoverPosition: HoverPosition.BELOW,
hideOnHover: false
}, true);
},
weight: KeybindingWeight.WorkbenchContrib,
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.CtrlCmd | KeyCode.KeyI),
when: ContextKeyExpr.and(RawCustomTreeViewContextKey, WorkbenchListFocusContextKey)
});
}

private handleAndRegisterCustomViewContainers() {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/api/common/extHostTreeViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { IMarkdownString } from 'vs/base/common/htmlContent';
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
import { Command } from 'vs/editor/common/languages';
import { TreeDataTransferConverter, TreeDataTransferDTO } from 'vs/workbench/api/common/shared/treeDataTransfer';
import { ITreeViewsService, TreeviewsService } from 'vs/workbench/services/views/common/treeViewsService';
import { ITreeViewsDragAndDropService, TreeViewsDragAndDropService } from 'vs/workbench/services/views/common/treeViewsDragAndDropService';

type TreeItemHandle = string;

Expand All @@ -50,7 +50,7 @@ function toTreeItemLabel(label: any, extension: IExtensionDescription): ITreeIte
export class ExtHostTreeViews implements ExtHostTreeViewsShape {

private treeViews: Map<string, ExtHostTreeView<any>> = new Map<string, ExtHostTreeView<any>>();
private treeDragAndDropService: ITreeViewsService<vscode.TreeDataTransfer> = new TreeviewsService<vscode.TreeDataTransfer>();
private treeDragAndDropService: ITreeViewsDragAndDropService<vscode.TreeDataTransfer> = new TreeViewsDragAndDropService<vscode.TreeDataTransfer>();

constructor(
private _proxy: MainThreadTreeViewsShape,
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/browser/parts/editor/editorDropTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
import { assertIsDefined, assertAllDefined } from 'vs/base/common/types';
import { Schemas } from 'vs/base/common/network';
import { URI } from 'vs/base/common/uri';
import { ITreeViewsService } from 'vs/workbench/services/views/common/treeViewsService';
import { ITreeViewsDragAndDropService } from 'vs/workbench/services/views/common/treeViewsDragAndDropService';
import { ITreeDataTransfer } from 'vs/workbench/common/views';

interface IDropOperation {
Expand Down Expand Up @@ -51,7 +51,7 @@ class DropOverlay extends Themable {
@IInstantiationService private instantiationService: IInstantiationService,
@IEditorService private readonly editorService: IEditorService,
@IEditorGroupsService private readonly editorGroupService: IEditorGroupsService,
@ITreeViewsService private readonly treeViewsDragAndDropService: ITreeViewsService<ITreeDataTransfer>
@ITreeViewsDragAndDropService private readonly treeViewsDragAndDropService: ITreeViewsDragAndDropService<ITreeDataTransfer>
) {
super(themeService);

Expand Down
13 changes: 3 additions & 10 deletions src/vs/workbench/browser/parts/views/treeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import { isCancellationError } from 'vs/base/common/errors';
import { ElementsDragAndDropData } from 'vs/base/browser/ui/list/listView';
import { CodeDataTransfers, DraggedTreeItemsIdentifier, fillEditorsDragData, LocalSelectionTransfer } from 'vs/workbench/browser/dnd';
import { Schemas } from 'vs/base/common/network';
import { ITreeViewsService } from 'vs/workbench/services/views/common/treeViewsService';
import { ITreeViewsDragAndDropService } from 'vs/workbench/services/views/common/treeViewsDragAndDropService';
import { generateUuid } from 'vs/base/common/uuid';
import { ILogService } from 'vs/platform/log/common/log';
import { Mimes } from 'vs/base/common/mime';
Expand Down Expand Up @@ -151,8 +151,6 @@ class Root implements ITreeItem {

const noDataProviderMessage = localize('no-dataprovider', "There is no data provider registered that can provide view data.");

export const RawCustomTreeViewContextKey = new RawContextKey<boolean>('customTreeView', false);

class Tree extends WorkbenchAsyncDataTree<ITreeItem, ITreeItem, FuzzyScore> { }

abstract class AbstractTreeView extends Disposable implements ITreeView {
Expand Down Expand Up @@ -557,8 +555,6 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
renderer.actionRunner = actionRunner;

this.tree.contextKeyService.createKey<boolean>(this.id, true);
const customTreeKey = RawCustomTreeViewContextKey.bindTo(this.tree.contextKeyService);
customTreeKey.set(true);
this._register(this.tree.onContextMenu(e => this.onContextMenu(treeMenus, e, actionRunner)));
this._register(this.tree.onDidChangeSelection(e => this._onDidChangeSelection.fire(e.elements)));
this._register(this.tree.onDidChangeCollapseState(e => {
Expand Down Expand Up @@ -899,8 +895,7 @@ class TreeRenderer extends Disposable implements ITreeRenderer<ITreeItem, FuzzyS
@IThemeService private readonly themeService: IThemeService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@ILabelService private readonly labelService: ILabelService,
@IHoverService private readonly hoverService: IHoverService,
@ITreeViewsService private readonly treeViewsService: ITreeViewsService<ITreeItem>
@IHoverService private readonly hoverService: IHoverService
) {
super();
this._hoverDelegate = {
Expand Down Expand Up @@ -1038,8 +1033,6 @@ class TreeRenderer extends Disposable implements ITreeRenderer<ITreeItem, FuzzyS
}
this.setAlignment(templateData.container, node);
disposableStore.add(this.themeService.onDidFileIconThemeChange(() => this.setAlignment(templateData.container, node)));
this.treeViewsService.addRenderedTreeItemElement(node, templateData.container);
disposableStore.add(toDisposable(() => this.treeViewsService.removeRenderedTreeItemElement(node)));
}

private setAlignment(container: HTMLElement, treeItem: ITreeItem) {
Expand Down Expand Up @@ -1272,7 +1265,7 @@ export class CustomTreeViewDragAndDrop implements ITreeDragAndDrop<ITreeItem> {
private readonly treeId: string,
@ILabelService private readonly labelService: ILabelService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@ITreeViewsService private readonly treeViewsDragAndDropService: ITreeViewsService<ITreeDataTransfer>,
@ITreeViewsDragAndDropService private readonly treeViewsDragAndDropService: ITreeViewsDragAndDropService<ITreeDataTransfer>,
@ILogService private readonly logService: ILogService) {
this.treeMimeType = `application/vnd.code.tree.${treeId.toLowerCase()}`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,17 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { ITreeDataTransfer } from 'vs/workbench/common/views';

export const ITreeViewsService = createDecorator<ITreeViewsService<ITreeDataTransfer>>('treeViewsService');
export interface ITreeViewsService<T> {
export const ITreeViewsDragAndDropService = createDecorator<ITreeViewsDragAndDropService<ITreeDataTransfer>>('treeViewsDragAndDropService');
export interface ITreeViewsDragAndDropService<T> {
readonly _serviceBrand: undefined;

removeDragOperationTransfer(uuid: string | undefined): Promise<T | undefined> | undefined;
addDragOperationTransfer(uuid: string, transferPromise: Promise<T | undefined>): void;

getRenderedTreeElement(node: T): HTMLElement | undefined;
addRenderedTreeItemElement(node: T, element: HTMLElement): void;
removeRenderedTreeItemElement(node: T): void;
}

export class TreeviewsService<T> implements ITreeViewsService<T> {
export class TreeViewsDragAndDropService<T> implements ITreeViewsDragAndDropService<T> {
_serviceBrand: undefined;
private _dragOperations: Map<string, Promise<T | undefined>> = new Map();
private _renderedElements: Map<T, HTMLElement> = new Map();

removeDragOperationTransfer(uuid: string | undefined): Promise<T | undefined> | undefined {
if ((uuid && this._dragOperations.has(uuid))) {
Expand All @@ -36,24 +31,6 @@ export class TreeviewsService<T> implements ITreeViewsService<T> {
addDragOperationTransfer(uuid: string, transferPromise: Promise<T | undefined>): void {
this._dragOperations.set(uuid, transferPromise);
}


getRenderedTreeElement(node: T): HTMLElement | undefined {
if (this._renderedElements.has(node)) {
return this._renderedElements.get(node);
}
return undefined;
}

addRenderedTreeItemElement(node: T, element: HTMLElement): void {
this._renderedElements.set(node, element);
}

removeRenderedTreeItemElement(node: T): void {
if (this._renderedElements.has(node)) {
this._renderedElements.delete(node);
}
}
}

registerSingleton(ITreeViewsService, TreeviewsService);
registerSingleton(ITreeViewsDragAndDropService, TreeViewsDragAndDropService);

0 comments on commit ef41956

Please sign in to comment.