Files
azuredatastudio/src/sql/workbench/services/fileBrowser/browser/fileBrowserRenderer.ts
Anthony Dresser 87765e8673 Vscode merge (#4582)
* Merge from vscode 37cb23d3dd4f9433d56d4ba5ea3203580719a0bd

* fix issues with merges

* bump node version in azpipe

* replace license headers

* remove duplicate launch task

* fix build errors

* fix build errors

* fix tslint issues

* working through package and linux build issues

* more work

* wip

* fix packaged builds

* working through linux build errors

* wip

* wip

* wip

* fix mac and linux file limits

* iterate linux pipeline

* disable editor typing

* revert series to parallel

* remove optimize vscode from linux

* fix linting issues

* revert testing change

* add work round for new node

* readd packaging for extensions

* fix issue with angular not resolving decorator dependencies
2019-03-19 17:44:35 -07:00

82 lines
2.9 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { FileNode } from 'sql/workbench/services/fileBrowser/common/fileNode';
import { ITree, IRenderer } from 'vs/base/parts/tree/browser/tree';
import { FileKind } from 'vs/platform/files/common/files';
import { URI } from 'vs/base/common/uri';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { toDisposable } from 'vs/base/common/lifecycle';
import { ResourceLabels, DEFAULT_LABELS_CONTAINER } from 'vs/workbench/browser/labels';
import { IFileTemplateData } from 'vs/workbench/contrib/files/browser/views/explorerViewer';
const EmptyDisposable = toDisposable(() => null);
/**
* Renders the tree items.
* Uses the dom template to render file browser.
*/
export class FileBrowserRenderer implements IRenderer {
public static readonly FILE_HEIGHT = 22;
private static readonly FILE_TEMPLATE_ID = 'carbonFileBrowser';
private resourceLabels: ResourceLabels;
constructor(
@IInstantiationService private instantiationService: IInstantiationService
) {
this.resourceLabels = this.instantiationService.createInstance(ResourceLabels, DEFAULT_LABELS_CONTAINER);
}
/**
* Returns the element's height in the tree, in pixels.
*/
public getHeight(tree: ITree, element: any): number {
return FileBrowserRenderer.FILE_HEIGHT;
}
/**
* Returns a template ID for a given element.
*/
public getTemplateId(tree: ITree, element: any): string {
return FileBrowserRenderer.FILE_TEMPLATE_ID;
}
/**
* Render template in a dom element based on template id
*/
public renderTemplate(tree: ITree, templateId: string, container: HTMLElement): IFileTemplateData {
const label = this.resourceLabels.create(container);
const elementDisposable = EmptyDisposable;
return { elementDisposable, label, container };
}
/**
* Render a element, given an object bag returned by the template
*/
public renderElement(tree: ITree, element: FileNode, templateId: string, templateData: IFileTemplateData): void {
if (element) {
templateData.label.element.style.display = 'flex';
const extraClasses = ['explorer-item'];
var fileuri = URI.file(element.fullPath);
var filekind;
if (element.parent === null) {
filekind = FileKind.ROOT_FOLDER;
} else if (element.isFile === false) {
filekind = FileKind.FOLDER;
} else {
filekind = FileKind.FILE;
}
templateData.label.setFile(fileuri, { hidePath: true, fileKind: filekind, extraClasses });
}
}
public disposeTemplate(tree: ITree, templateId: string, templateData: IFileTemplateData): void {
templateData.label.dispose();
}
}