-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathworkspace.ts
More file actions
54 lines (46 loc) · 1.8 KB
/
workspace.ts
File metadata and controls
54 lines (46 loc) · 1.8 KB
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
import { workspace, QuickPickItem, window, Uri } from "vscode";
import { Platform } from "./platform";
import path = require('path');
import fs = require('fs-extra');
interface WorkspaceFolderItem extends QuickPickItem {
uri: Uri;
}
class CreateWorkspaceItem implements QuickPickItem {
constructor() { }
get label(): string { return `$(plus) Add new workspace folder.`; }
get description(): string { return 'Folder which does not have an openshift context'; }
}
export async function selectWorkspaceFolder(): Promise<Uri> {
let folder: WorkspaceFolderItem[] = [];
if (workspace.workspaceFolders && workspace.workspaceFolders.length > 0) {
folder = workspace.workspaceFolders.filter(
(value) => {
let result = true;
try {
result = !fs.statSync(path.join(value.uri.fsPath, '.odo', 'config.yaml')).isFile();
} catch (ignore) {
}
return result;
}
).map(
(folder) => ({ label: `$(file-directory) ${folder.uri.fsPath}`, uri: folder.uri })
);
}
const addWorkspaceFolder = new CreateWorkspaceItem();
const choice: any = await window.showQuickPick([addWorkspaceFolder, ...folder], {placeHolder: "Select workspace folder"});
let workspacePath: Uri;
if (choice === addWorkspaceFolder) {
const folders = await window.showOpenDialog({
canSelectFiles: false,
canSelectFolders: true,
canSelectMany: false,
defaultUri: Uri.file(Platform.getUserHomePath()),
openLabel: "Add workspace Folder for Component"
});
if (!folders) return null;
workspacePath = folders[0];
} else if (choice) {
workspacePath = choice.uri;
}
return workspacePath;
}