Skip to content

Commit 51cbec1

Browse files
committed
Fix commands
1 parent b77dc90 commit 51cbec1

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,11 @@
333333
},
334334
{
335335
"command": "gitpod.workspaces.openContext",
336-
"when": "false"
336+
"when": "gitpod.authenticated == true && gitpod.inWorkspace == true"
337337
},
338338
{
339339
"command": "gitpod.workspaces.deleteWorkspace",
340-
"when": "gitpod.authenticated == true"
340+
"when": "gitpod.authenticated == true && gitpod.inWorkspace != true"
341341
},
342342
{
343343
"command": "gitpod.workspaces.deleteWorkspace_context",

src/commands/workspaces.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as vscode from 'vscode';
77
import { Command } from '../commandManager';
88
import { ISessionService } from '../services/sessionService';
99
import { WorkspaceData, rawWorkspaceToWorkspaceData } from '../publicApi';
10-
import { SSHConnectionParams, SSH_DEST_KEY, getLocalSSHDomain } from '../remote';
10+
import { SSHConnectionParams, SSH_DEST_KEY, getGitpodRemoteWindowConnectionInfo, getLocalSSHDomain } from '../remote';
1111
import SSHDestination from '../ssh/sshDestination';
1212
import { IHostService } from '../services/hostService';
1313
import { WorkspaceState } from '../workspaceState';
@@ -493,25 +493,26 @@ export class StopCurrentWorkspaceCommand implements Command {
493493
readonly id: string = 'gitpod.workspaces.stopCurrentWorkspace';
494494

495495
constructor(
496-
private readonly workspaceId: string | undefined,
496+
private readonly context: vscode.ExtensionContext,
497497
private readonly sessionService: ISessionService,
498498
private readonly hostService: IHostService,
499499
private readonly telemetryService: ITelemetryService,
500500
) { }
501501

502502
async execute() {
503-
if (!this.workspaceId) {
503+
const workspaceId = getGitpodRemoteWindowConnectionInfo(this.context)?.connectionInfo.workspaceId;
504+
if (!workspaceId) {
504505
return;
505506
}
506507

507508
this.telemetryService.sendTelemetryEvent('vscode_desktop_view_command', {
508509
name: getCommandName(this.id),
509510
gitpodHost: this.hostService.gitpodHost,
510-
workspaceId: this.workspaceId,
511+
workspaceId: workspaceId,
511512
location: 'commandPalette'
512513
});
513514

514-
await this.sessionService.getAPI().stopWorkspace(this.workspaceId);
515+
await this.sessionService.getAPI().stopWorkspace(workspaceId);
515516
await vscode.commands.executeCommand('workbench.action.remote.close');
516517
}
517518
}
@@ -520,36 +521,33 @@ export class StopCurrentWorkspaceCommandInline extends StopCurrentWorkspaceComma
520521
override readonly id = 'gitpod.workspaces.stopCurrentWorkspace_inline';
521522

522523
constructor(
523-
workspaceId: string | undefined,
524+
context: vscode.ExtensionContext,
524525
sessionService: ISessionService,
525526
hostService: IHostService,
526527
telemetryService: ITelemetryService,
527528
) {
528-
super(workspaceId, sessionService, hostService, telemetryService);
529+
super(context, sessionService, hostService, telemetryService);
529530
}
530531
}
531532

532533
export class OpenInBrowserCommand implements Command {
533534
readonly id = 'gitpod.workspaces.openInBrowser';
534535

535536
constructor(
537+
private readonly context: vscode.ExtensionContext,
536538
private readonly sessionService: ISessionService,
537539
private readonly hostService: IHostService,
538540
private readonly telemetryService: ITelemetryService,
539541
) { }
540542

541543
async execute(treeItem?: { id: string }) {
542-
let wsData: WorkspaceData | undefined;
543-
if (!treeItem?.id) {
544-
wsData = (await showWorkspacesPicker(this.sessionService, 'Select a workspace to connect...'));
545-
} else {
546-
wsData = rawWorkspaceToWorkspaceData(await this.sessionService.getAPI().getWorkspace(treeItem.id));
547-
}
548-
549-
if (!wsData) {
544+
let workspaceId = treeItem?.id || getGitpodRemoteWindowConnectionInfo(this.context)?.connectionInfo.workspaceId;
545+
if (!workspaceId) {
550546
return;
551547
}
552548

549+
const wsData = rawWorkspaceToWorkspaceData(await this.sessionService.getAPI().getWorkspace(workspaceId));
550+
553551
this.telemetryService.sendTelemetryEvent('vscode_desktop_view_command', {
554552
name: getCommandName(this.id),
555553
gitpodHost: this.hostService.gitpodHost,
@@ -616,18 +614,20 @@ export class OpenWorkspaceContextCommand implements Command {
616614
readonly id = 'gitpod.workspaces.openContext';
617615

618616
constructor(
617+
private readonly context: vscode.ExtensionContext,
619618
private readonly sessionService: ISessionService,
620619
private readonly hostService: IHostService,
621620
private readonly telemetryService: ITelemetryService,
622621
) { }
623622

624-
async execute(treeItem: { id: string }) {
625-
if (!treeItem?.id) {
623+
async execute(treeItem?: { id: string }) {
624+
let workspaceId = treeItem?.id || getGitpodRemoteWindowConnectionInfo(this.context)?.connectionInfo.workspaceId;
625+
if (!workspaceId) {
626626
return;
627627
}
628628

629-
const rawWsData = await this.sessionService.getAPI().getWorkspace(treeItem.id);
630-
const wsData = rawWorkspaceToWorkspaceData(await this.sessionService.getAPI().getWorkspace(treeItem.id));
629+
const rawWsData = await this.sessionService.getAPI().getWorkspace(workspaceId);
630+
const wsData = rawWorkspaceToWorkspaceData(await this.sessionService.getAPI().getWorkspace(workspaceId));
631631

632632
// Report if we couldn't parse contextUrl
633633
if (!wsData.contextUrl) {

src/workspacesExplorerView.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ export class WorkspacesExplorerView extends Disposable implements vscode.TreeDat
113113
commandManager.register(new StopWorkspaceCommand(sessionService, hostService, telemetryService));
114114
commandManager.register(new StopWorkspaceCommandContext(sessionService, hostService, telemetryService));
115115
commandManager.register(new StopWorkspaceCommandInline(sessionService, hostService, telemetryService));
116-
commandManager.register(new StopCurrentWorkspaceCommand(this.connectedWorkspaceId, sessionService, hostService, telemetryService));
117-
commandManager.register(new StopCurrentWorkspaceCommandInline(this.connectedWorkspaceId, sessionService, hostService, telemetryService));
118-
commandManager.register(new OpenInBrowserCommand(sessionService, hostService, telemetryService));
116+
commandManager.register(new StopCurrentWorkspaceCommand(context, sessionService, hostService, telemetryService));
117+
commandManager.register(new StopCurrentWorkspaceCommandInline(context, sessionService, hostService, telemetryService));
118+
commandManager.register(new OpenInBrowserCommand(context, sessionService, hostService, telemetryService));
119119
commandManager.register(new DeleteWorkspaceCommand(sessionService, hostService, telemetryService));
120120
commandManager.register(new DeleteWorkspaceCommandContext(sessionService, hostService, telemetryService));
121-
commandManager.register(new OpenWorkspaceContextCommand(sessionService, hostService, telemetryService));
121+
commandManager.register(new OpenWorkspaceContextCommand(context, sessionService, hostService, telemetryService));
122122
commandManager.register(new DisconnectWorkspaceCommand());
123123

124124
this._register(this.hostService.onDidChangeHost(() => this.refresh()));

0 commit comments

Comments
 (0)