This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
RemoveProjectCmd.ts
89 lines (75 loc) · 3.84 KB
/
RemoveProjectCmd.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*******************************************************************************
* Copyright (c) 2019, 2020 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
import * as vscode from "vscode";
import Translator from "../../constants/strings/Translator";
import StringNamespaces from "../../constants/strings/StringNamespaces";
import Log from "../../Logger";
import MCUtil from "../../MCUtil";
import Project from "../../codewind/project/Project";
import ConnectionManager from "../../codewind/connection/ConnectionManager";
import CWExtensionContext from "../../CWExtensionContext";
export default async function removeProjectCmd(project: Project): Promise<void> {
let deleteFiles: boolean;
let confirmDeletePrompt;
if (project.outgoingLinks.length > 0) {
const outgoingLinksList = MCUtil.joinList(project.outgoingLinks.map((link) => link.otherProjectName), "and");
confirmDeletePrompt = Translator.t(StringNamespaces.CMD_MISC, "confirmDeleteProjectWithLinksMsg", {
projectName: project.name,
connectionLabel: project.connection.label,
outgoingLinksList,
});
}
else {
confirmDeletePrompt = Translator.t(StringNamespaces.CMD_MISC, "confirmDeleteProjectMsg", {
projectName: project.name,
connectionLabel: project.connection.label
});
}
const deleteBtn = Translator.t(StringNamespaces.CMD_MISC, "confirmDeleteBtn", { projectName: project.name });
const deleteRes = await vscode.window.showInformationMessage(confirmDeletePrompt, { modal: true }, deleteBtn);
if (deleteRes !== deleteBtn) {
// cancelled
return;
}
// determine if the project files can be deleted from disk
const projectDirPath: string = project.localPath.fsPath;
const isProjectBoundElsewhere = ConnectionManager.instance.connections
.some((conn) => conn !== project.connection && conn.hasProjectAtPath(project.localPath));
if (isProjectBoundElsewhere) {
// Another connection is using this project, so we should not delete its files.
deleteFiles = false;
}
else {
// Ask user if they want to delete the files on disk too.
const cancelBtn = CWExtensionContext.get().isTheia ? "Close" : "Cancel";
const deleteDirMsg = Translator.t(StringNamespaces.CMD_MISC, "alsoDeleteDirMsg", {
projectName: project.name,
connectionLabel: project.connection.label,
dirPath: projectDirPath,
cancelBtn,
});
const deleteDirBtn = Translator.t(StringNamespaces.CMD_MISC, "alsoDeleteDirBtn");
const deleteDirRes = await vscode.window.showWarningMessage(deleteDirMsg, { modal: true }, deleteDirBtn);
deleteFiles = deleteDirRes === deleteDirBtn;
}
// We do not await the deleteFromCodewind since it modifies the workspace folders.
// If the workspace folder modification results in a reload, this command will get canceled
// and an error message is shown that this command was canceled.
// so by not awaiting, this command finishes early, but we don't have to worry about the cancellation.
// await project.deleteFromCodewind(deleteFiles);
project.deleteFromConnection(deleteFiles)
.then(() => Log.i(`Finished removeProjectCmd for ${project.name}`))
.catch((err) => {
const errMsg = `Failed to remove ${project.name}`;
Log.e(errMsg, err);
vscode.window.showInformationMessage(`${errMsg}: ${MCUtil.errToString(err)}`);
});
}