mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-14 09:59:47 -05:00
79 lines
3.0 KiB
TypeScript
79 lines
3.0 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import * as vscode from 'vscode';
|
|
import * as path from 'path';
|
|
import * as constants from '../../common/constants';
|
|
|
|
import { BaseProjectTreeItem } from './baseTreeItem';
|
|
import { ProjectRootTreeItem } from './projectTreeItem';
|
|
import { IconPathHelper } from '../../common/iconHelper';
|
|
|
|
/**
|
|
* Folder for containing SQLCMD variable nodes in the tree
|
|
*/
|
|
export class SqlCmdVariablesTreeItem extends BaseProjectTreeItem {
|
|
private sqlcmdVariableTreeItems: SqlCmdVariableTreeItem[] = [];
|
|
|
|
/**
|
|
* Constructor
|
|
* @param projectNodeName Name of the project node. Used for creating the relative path of the SQLCMD Variables node to the project
|
|
* @param sqlprojUri Full URI to the .sqlproj
|
|
* @param sqlCmdVariables Collection of SQLCMD variables in the project
|
|
* @param project
|
|
*/
|
|
constructor(projectNodeName: string, sqlprojUri: vscode.Uri, sqlCmdVariables: Record<string, string>, project: ProjectRootTreeItem) {
|
|
super(vscode.Uri.file(path.join(projectNodeName, constants.sqlcmdVariablesNodeName)), sqlprojUri, project);
|
|
|
|
this.construct(sqlCmdVariables);
|
|
}
|
|
|
|
private construct(sqlCmdVariables: Record<string, string>) {
|
|
if (!sqlCmdVariables) {
|
|
return;
|
|
}
|
|
|
|
for (const sqlCmdVariable of Object.keys(sqlCmdVariables)) {
|
|
if (sqlCmdVariable) {
|
|
this.sqlcmdVariableTreeItems.push(new SqlCmdVariableTreeItem(sqlCmdVariable, this.relativeProjectUri, this.projectFileUri, this));
|
|
}
|
|
}
|
|
}
|
|
|
|
public get children(): SqlCmdVariableTreeItem[] {
|
|
return this.sqlcmdVariableTreeItems;
|
|
}
|
|
|
|
public get treeItem(): vscode.TreeItem {
|
|
const sqlCmdVariableFolderItem = new vscode.TreeItem(this.relativeProjectUri, vscode.TreeItemCollapsibleState.Collapsed);
|
|
sqlCmdVariableFolderItem.contextValue = constants.DatabaseProjectItemType.sqlcmdVariablesRoot;
|
|
sqlCmdVariableFolderItem.iconPath = IconPathHelper.sqlCmdVariablesGroup;
|
|
|
|
return sqlCmdVariableFolderItem;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Represents a SQLCMD variable in a .sqlproj
|
|
*/
|
|
export class SqlCmdVariableTreeItem extends BaseProjectTreeItem {
|
|
constructor(private sqlcmdVar: string, sqlprojUri: vscode.Uri, sqlCmdNodeRelativeProjectUri: vscode.Uri, sqlcmdVarsTreeItem: SqlCmdVariablesTreeItem) {
|
|
super(vscode.Uri.file(path.join(sqlCmdNodeRelativeProjectUri.fsPath, sqlcmdVar)), sqlprojUri, sqlcmdVarsTreeItem);
|
|
}
|
|
|
|
public get children(): BaseProjectTreeItem[] {
|
|
return [];
|
|
}
|
|
|
|
public get treeItem(): vscode.TreeItem {
|
|
const sqlcmdVariableItem = new vscode.TreeItem(this.relativeProjectUri, vscode.TreeItemCollapsibleState.None);
|
|
sqlcmdVariableItem.label = this.sqlcmdVar;
|
|
sqlcmdVariableItem.contextValue = constants.DatabaseProjectItemType.sqlcmdVariable;
|
|
sqlcmdVariableItem.iconPath = IconPathHelper.sqlCmdVariable;
|
|
|
|
return sqlcmdVariableItem;
|
|
}
|
|
}
|