Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Show Open Workspace button on creation
Browse files Browse the repository at this point in the history
If user is not in workspace already
Fix eclipse-archived/codewind#151

Signed-off-by: Tim Etchells <timetchells@ibm.com>
  • Loading branch information
Tim Etchells authored and jopit committed Sep 5, 2019
1 parent 9306c2c commit 96eee88
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
5 changes: 3 additions & 2 deletions dev/.vscode/launch.json
Expand Up @@ -11,7 +11,8 @@
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
"--extensionDevelopmentPath=${workspaceFolder}",
"/Users/tim/programs/codewind/codewind-workspace"
],
"outFiles": [
"${workspaceFolder}/dev/out/**/*.js"
Expand All @@ -30,7 +31,7 @@
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test",
// Replace below with your local codewind-workspace
"/Users/tim/programs/tempest/codewind-workspace"
"/Users/tim/programs/codewind/codewind-workspace"
// "/Users/tim/codewind-workspace/"
],
"outFiles": [
Expand Down
13 changes: 4 additions & 9 deletions dev/src/command/connection/ActivateConnectionCmd.ts
Expand Up @@ -17,8 +17,9 @@ import Connection from "../../codewind/connection/Connection";
import CWEnvironment from "../../codewind/connection/CWEnvironment";
import Translator from "../../constants/strings/translator";
import StringNamespaces from "../../constants/strings/StringNamespaces";
import Commands from "../../constants/Commands";
import { CWConfigurations } from "../../constants/Configurations";
import MCUtil from "../../MCUtil";
import openWorkspaceCmd from "../OpenWorkspaceCmd";

const STRING_NS = StringNamespaces.STARTUP;

Expand All @@ -39,14 +40,8 @@ export default async function activateConnection(url: vscode.Uri): Promise<void>
*/
async function onConnectSuccess(connection: Connection): Promise<void> {
Log.i("Successfully connected to codewind at " + connection.url);
let isInWorkspace = false;
// See if the user has this connection's workspace open
const wsFolders = vscode.workspace.workspaceFolders;
if (wsFolders != null) {
isInWorkspace = wsFolders.some((folder) => folder.uri.fsPath.includes(connection.workspacePath.fsPath));
}

if (!isInWorkspace) {
if (!await MCUtil.isUserInCwWorkspaceOrProject()) {
// Provide a button to change their workspace to the codewind-workspace if they wish, and haven't disabled this feature.
let promptOpenWs = vscode.workspace.getConfiguration().get(CWConfigurations.PROMPT_TO_OPEN_WORKSPACE);
if (promptOpenWs == null) {
Expand All @@ -63,7 +58,7 @@ async function onConnectSuccess(connection: Connection): Promise<void> {
);

if (openWsRes === openWsBtn) {
vscode.commands.executeCommand(Commands.VSC_OPEN_FOLDER, connection.workspacePath);
openWorkspaceCmd(connection);
}
else if (openWsRes === dontShowAgainBtn) {
vscode.window.showInformationMessage(
Expand Down
10 changes: 9 additions & 1 deletion dev/src/command/connection/BindProjectCmd.ts
Expand Up @@ -16,6 +16,7 @@ import Connection from "../../codewind/connection/Connection";
import MCUtil from "../../MCUtil";
import UserProjectCreator from "../../codewind/connection/UserProjectCreator";
import { isRegistrySet, onRegistryNotSet } from "../../codewind/connection/Registry";
import { showOpenWorkspacePrompt } from "./CreateUserProjectCmd";

/**
* @param create true for Create page, false for Import page
Expand Down Expand Up @@ -46,7 +47,14 @@ export default async function bindProject(connection: Connection): Promise<void>
if (response == null) {
return;
}
vscode.window.showInformationMessage(`Adding ${MCUtil.containerPathToFsPath(response.projectPath)} as ${response.projectName}`);

const addedMsg = `Added ${MCUtil.containerPathToFsPath(response.projectPath)} as ${response.projectName}`;
if (await MCUtil.isUserInCwWorkspaceOrProject()) {
vscode.window.showInformationMessage(addedMsg);
}
else {
showOpenWorkspacePrompt(connection, addedMsg);
}
}
catch (err) {
const errMsg = "Error importing project: ";
Expand Down
20 changes: 19 additions & 1 deletion dev/src/command/connection/CreateUserProjectCmd.ts
Expand Up @@ -17,6 +17,7 @@ import MCUtil from "../../MCUtil";
import UserProjectCreator, { IMCTemplateData } from "../../codewind/connection/UserProjectCreator";
import Requester from "../../codewind/project/Requester";
import { isRegistrySet, onRegistryNotSet } from "../../codewind/connection/Registry";
import openWorkspaceCmd from "../OpenWorkspaceCmd";

const CREATE_PROJECT_WIZARD_TITLE = "Create a New Project";
const CREATE_PROJECT_WIZARD_NO_STEPS = 2;
Expand Down Expand Up @@ -59,7 +60,14 @@ export default async function createProject(connection: Connection): Promise<voi
// user cancelled
return;
}
vscode.window.showInformationMessage(`Created project ${response.projectName} at ${MCUtil.containerPathToFsPath(response.projectPath)}`);

const createdMsg = `Created project ${response.projectName} at ${MCUtil.containerPathToFsPath(response.projectPath)}`;
if (await MCUtil.isUserInCwWorkspaceOrProject()) {
vscode.window.showInformationMessage(createdMsg);
}
else {
showOpenWorkspacePrompt(connection, createdMsg);
}
}
catch (err) {
const errMsg = "Error creating new project: ";
Expand All @@ -68,6 +76,16 @@ export default async function createProject(connection: Connection): Promise<voi
}
}

export async function showOpenWorkspacePrompt(connection: Connection, msg: string): Promise<void> {
const openWorkspaceBtn = "Open Workspace";
vscode.window.showInformationMessage(msg, openWorkspaceBtn)
.then((res) => {
if (res === openWorkspaceBtn) {
openWorkspaceCmd(connection);
}
});
}

const TEMPLATE_QP_PLACEHOLDER = "Select the project type to create";

async function promptForTemplate(connection: Connection): Promise<IMCTemplateData | undefined> {
Expand Down

0 comments on commit 96eee88

Please sign in to comment.