mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-18 09:35:39 -05:00
Benjin/delete (#11054)
* Adding delete to package.json * checkpoint * Delete file working * Working for nested folders * Added file/folder deletion test * addressing feedback * Swapping QuickPick for modal * Adding Exclude functionality * reverting change to package.json
This commit is contained in:
@@ -18,9 +18,9 @@ import { IConnectionProfile, TaskExecutionMode } from 'azdata';
|
||||
import { promises as fs } from 'fs';
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
import { DeployDatabaseDialog } from '../dialogs/deployDatabaseDialog';
|
||||
import { Project, DatabaseReferenceLocation, SystemDatabase, TargetPlatform } from '../models/project';
|
||||
import { Project, DatabaseReferenceLocation, SystemDatabase, TargetPlatform, ProjectEntry } from '../models/project';
|
||||
import { SqlDatabaseProjectTreeViewProvider } from './databaseProjectTreeViewProvider';
|
||||
import { FolderNode } from '../models/tree/fileFolderTreeItem';
|
||||
import { FolderNode, FileNode } from '../models/tree/fileFolderTreeItem';
|
||||
import { IDeploymentProfile, IGenerateScriptProfile, PublishSettings } from '../models/IDeploymentProfile';
|
||||
import { BaseProjectTreeItem } from '../models/tree/baseTreeItem';
|
||||
import { ProjectRootTreeItem } from '../models/tree/projectTreeItem';
|
||||
@@ -155,7 +155,7 @@ export class ProjectsController {
|
||||
}
|
||||
|
||||
public closeProject(treeNode: BaseProjectTreeItem) {
|
||||
const project = ProjectsController.getProjectFromContext(treeNode);
|
||||
const project = this.getProjectFromContext(treeNode);
|
||||
this.projects = this.projects.filter((e) => { return e !== project; });
|
||||
this.refreshProjectsTree();
|
||||
}
|
||||
@@ -173,7 +173,7 @@ export class ProjectsController {
|
||||
*/
|
||||
public async buildProject(project: Project): Promise<string>;
|
||||
public async buildProject(context: Project | BaseProjectTreeItem): Promise<string | undefined> {
|
||||
const project: Project = ProjectsController.getProjectFromContext(context);
|
||||
const project: Project = this.getProjectFromContext(context);
|
||||
|
||||
// Check mssql extension for project dlls (tracking issue #10273)
|
||||
await this.buildHelper.createBuildDirFolder();
|
||||
@@ -205,7 +205,7 @@ export class ProjectsController {
|
||||
*/
|
||||
public async deployProject(project: Project): Promise<DeployDatabaseDialog>;
|
||||
public async deployProject(context: Project | BaseProjectTreeItem): Promise<DeployDatabaseDialog> {
|
||||
const project: Project = ProjectsController.getProjectFromContext(context);
|
||||
const project: Project = this.getProjectFromContext(context);
|
||||
let deployDatabaseDialog = this.getDeployDialog(project);
|
||||
|
||||
deployDatabaseDialog.deploy = async (proj, prof) => await this.executionCallback(proj, prof);
|
||||
@@ -266,7 +266,7 @@ export class ProjectsController {
|
||||
await this.buildProject(treeNode);
|
||||
|
||||
// start schema compare with the dacpac produced from build
|
||||
const project = ProjectsController.getProjectFromContext(treeNode);
|
||||
const project = this.getProjectFromContext(treeNode);
|
||||
const dacpacPath = path.join(project.projectFolderPath, 'bin', 'Debug', `${project.projectFileName}.dacpac`);
|
||||
|
||||
// check that dacpac exists
|
||||
@@ -281,7 +281,7 @@ export class ProjectsController {
|
||||
}
|
||||
|
||||
public async addFolderPrompt(treeNode: BaseProjectTreeItem) {
|
||||
const project = ProjectsController.getProjectFromContext(treeNode);
|
||||
const project = this.getProjectFromContext(treeNode);
|
||||
const newFolderName = await this.promptForNewObjectName(new templates.ProjectScriptType(templates.folder, constants.folderFriendlyName, ''), project);
|
||||
|
||||
if (!newFolderName) {
|
||||
@@ -296,7 +296,7 @@ export class ProjectsController {
|
||||
}
|
||||
|
||||
public async addItemPromptFromNode(treeNode: BaseProjectTreeItem, itemTypeName?: string) {
|
||||
await this.addItemPrompt(ProjectsController.getProjectFromContext(treeNode), this.getRelativePath(treeNode), itemTypeName);
|
||||
await this.addItemPrompt(this.getProjectFromContext(treeNode), this.getRelativePath(treeNode), itemTypeName);
|
||||
}
|
||||
|
||||
public async addItemPrompt(project: Project, relativePath: string, itemTypeName?: string) {
|
||||
@@ -337,12 +337,58 @@ export class ProjectsController {
|
||||
this.refreshProjectsTree();
|
||||
}
|
||||
|
||||
public async exclude(context: FileNode | FolderNode): Promise<void> {
|
||||
const project = this.getProjectFromContext(context);
|
||||
|
||||
const fileEntry = this.getProjectEntry(project, context);
|
||||
|
||||
if (fileEntry) {
|
||||
await project.exclude(fileEntry);
|
||||
} else {
|
||||
this.apiWrapper.showErrorMessage(constants.unableToPerformAction(constants.excludeAction, context.uri.path));
|
||||
}
|
||||
|
||||
this.refreshProjectsTree();
|
||||
}
|
||||
|
||||
public async delete(context: BaseProjectTreeItem): Promise<void> {
|
||||
const project = this.getProjectFromContext(context);
|
||||
|
||||
const confirmationPrompt = context instanceof FolderNode ? constants.deleteConfirmationContents(context.friendlyName) : constants.deleteConfirmation(context.friendlyName);
|
||||
const response = await this.apiWrapper.showWarningMessageOptions(confirmationPrompt, { modal: true }, constants.yesString);
|
||||
|
||||
if (response !== constants.yesString) {
|
||||
return;
|
||||
}
|
||||
|
||||
let success = false;
|
||||
|
||||
if (context instanceof FileNode || FolderNode) {
|
||||
const fileEntry = this.getProjectEntry(project, context);
|
||||
|
||||
if (fileEntry) {
|
||||
await project.deleteFileFolder(fileEntry);
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (success) {
|
||||
this.refreshProjectsTree();
|
||||
} else {
|
||||
this.apiWrapper.showErrorMessage(constants.unableToPerformAction(constants.deleteAction, context.uri.path));
|
||||
}
|
||||
}
|
||||
|
||||
private getProjectEntry(project: Project, context: BaseProjectTreeItem): ProjectEntry | undefined {
|
||||
return project.files.find(x => utils.getPlatformSafeFileEntryPath(x.relativePath) === utils.getPlatformSafeFileEntryPath(utils.trimUri(context.root.uri, context.uri)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a database reference to the project
|
||||
* @param treeNode a treeItem in a project's hierarchy, to be used to obtain a Project
|
||||
* @param context a treeItem in a project's hierarchy, to be used to obtain a Project
|
||||
*/
|
||||
public async addDatabaseReference(context: Project | BaseProjectTreeItem): Promise<void> {
|
||||
const project = ProjectsController.getProjectFromContext(context);
|
||||
const project = this.getProjectFromContext(context);
|
||||
|
||||
try {
|
||||
// choose if reference is to master or a dacpac
|
||||
@@ -504,7 +550,7 @@ export class ProjectsController {
|
||||
}
|
||||
}
|
||||
|
||||
private static getProjectFromContext(context: Project | BaseProjectTreeItem) {
|
||||
private getProjectFromContext(context: Project | BaseProjectTreeItem) {
|
||||
if (context instanceof Project) {
|
||||
return context;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user