diff --git a/src/controllers/projectController.ts b/src/controllers/projectController.ts index 82427030..65ac64dc 100644 --- a/src/controllers/projectController.ts +++ b/src/controllers/projectController.ts @@ -16,8 +16,9 @@ export class ProjectController { if (!javaVersion) { return; } + const workspaceFolder = Utility.getDefaultWorkspaceFolder(); const location: Uri[] = await window.showOpenDialog({ - defaultUri: workspace.rootPath ? Uri.file(workspace.rootPath) : undefined, + defaultUri: workspaceFolder && workspaceFolder.uri, canSelectFiles: false, canSelectFolders: true, openLabel: "Select the location", diff --git a/src/utility.ts b/src/utility.ts index 64ed937a..d57f3286 100644 --- a/src/utility.ts +++ b/src/utility.ts @@ -2,7 +2,7 @@ import * as child_process from "child_process"; import * as findJavaHome from "find-java-home"; import * as fse from "fs-extra"; import * as path from "path"; -import { Uri, workspace } from "vscode"; +import { Uri, window, workspace, WorkspaceFolder } from "vscode"; import * as xml2js from "xml2js"; export class Utility { @@ -72,6 +72,21 @@ export class Utility { }); } + public static getDefaultWorkspaceFolder(): WorkspaceFolder | undefined { + const workspaceFolders: WorkspaceFolder[] | undefined = workspace.workspaceFolders; + if (workspaceFolders === undefined) { + return undefined; + } + if (workspaceFolders.length === 1) { + return workspaceFolders[0]; + } + if (window.activeTextEditor) { + const activeWorkspaceFolder: WorkspaceFolder | undefined = workspace.getWorkspaceFolder(window.activeTextEditor.document.uri); + return activeWorkspaceFolder; + } + return undefined; + } + private static openJDKDownload(reject, cause) { let jdkUrl = "http://developers.redhat.com/products/openjdk/overview/?from=vscode"; if (process.platform === "darwin") {