Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 6e6c493

Browse files
committed
Open workspace from Che Theia
Signed-off-by: Vladyslav Zhukovskyi <vzhukovs@redhat.com>
1 parent 05bfef1 commit 6e6c493

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

extensions/eclipse-che-theia-workspace/src/browser/che-quick-open-workspace.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class QuickOpenCheWorkspace implements QuickOpenModel {
7979
acceptor(this.items);
8080
}
8181

82-
async select(acceptor: (workspace: che.workspace.Workspace) => void): Promise<void> {
82+
async select(recent: boolean, acceptor: (workspace: che.workspace.Workspace) => void): Promise<void> {
8383
this.items = [];
8484

8585
const token = await this.oAuthUtils.getUserToken();
@@ -92,9 +92,15 @@ export class QuickOpenCheWorkspace implements QuickOpenModel {
9292
return;
9393
}
9494

95-
const workspaces = await this.cheApi.getAllByNamespace(this.currentWorkspace.namespace, token);
95+
let workspaces = await this.cheApi.getAllByNamespace(this.currentWorkspace.namespace, token);
9696

97-
workspaces.sort(CheWorkspaceUtils.modificationTimeComparator);
97+
if (recent) {
98+
workspaces.sort(CheWorkspaceUtils.modificationTimeComparator);
99+
100+
if (workspaces.length > 5) {
101+
workspaces = workspaces.slice(0, 5);
102+
}
103+
}
98104

99105
await this.open(workspaces, acceptor);
100106
}

extensions/eclipse-che-theia-workspace/src/browser/che-workspace-contribution.ts

+16
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export namespace CheWorkspaceCommands {
1919
const WORKSPACE_CATEGORY = 'Workspace';
2020
const FILE_CATEGORY = 'File';
2121

22+
export const OPEN_WORKSPACE: Command = {
23+
id: 'che.openWorkspace',
24+
category: FILE_CATEGORY,
25+
label: 'Open Workspace...'
26+
};
2227
export const OPEN_RECENT_WORKSPACE: Command = {
2328
id: 'che.openRecentWorkspace',
2429
category: FILE_CATEGORY,
@@ -37,6 +42,9 @@ export class CheWorkspaceContribution implements CommandContribution, MenuContri
3742
@inject(CheWorkspaceController) protected readonly workspaceController: CheWorkspaceController;
3843

3944
registerCommands(commands: CommandRegistry): void {
45+
commands.registerCommand(CheWorkspaceCommands.OPEN_WORKSPACE, {
46+
execute: () => this.workspaceController.openWorkspace()
47+
});
4048
commands.registerCommand(CheWorkspaceCommands.OPEN_RECENT_WORKSPACE, {
4149
execute: () => this.workspaceController.openRecentWorkspace()
4250
});
@@ -46,13 +54,21 @@ export class CheWorkspaceContribution implements CommandContribution, MenuContri
4654
}
4755

4856
registerMenus(menus: MenuModelRegistry): void {
57+
menus.unregisterMenuAction({
58+
commandId: WorkspaceCommands.OPEN_WORKSPACE.id
59+
}, CommonMenus.FILE_OPEN);
4960
menus.unregisterMenuAction({
5061
commandId: WorkspaceCommands.OPEN_RECENT_WORKSPACE.id
5162
}, CommonMenus.FILE_OPEN);
5263
menus.unregisterMenuAction({
5364
commandId: WorkspaceCommands.CLOSE.id
5465
}, CommonMenus.FILE_CLOSE);
5566

67+
menus.registerMenuAction(CommonMenus.FILE_OPEN, {
68+
commandId: CheWorkspaceCommands.OPEN_WORKSPACE.id,
69+
label: CheWorkspaceCommands.OPEN_WORKSPACE.label,
70+
order: 'a10'
71+
});
5672
menus.registerMenuAction(CommonMenus.FILE_OPEN, {
5773
commandId: CheWorkspaceCommands.OPEN_RECENT_WORKSPACE.id,
5874
label: CheWorkspaceCommands.OPEN_RECENT_WORKSPACE.label,

extensions/eclipse-che-theia-workspace/src/browser/che-workspace-controller.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,16 @@ export class CheWorkspaceController {
7272
@inject(CheApiService) protected readonly cheApi: CheApiService;
7373
@inject(QuickOpenCheWorkspace) protected readonly quickOpenWorkspace: QuickOpenCheWorkspace;
7474

75+
async openWorkspace(): Promise<void> {
76+
await this.doOpenWorkspace(false);
77+
}
78+
7579
async openRecentWorkspace(): Promise<void> {
76-
await this.quickOpenWorkspace.select(async (workspace: che.workspace.Workspace) => {
80+
await this.doOpenWorkspace(true);
81+
}
82+
83+
private doOpenWorkspace(recent: boolean): Promise<void> {
84+
return this.quickOpenWorkspace.select(recent, async (workspace: che.workspace.Workspace) => {
7785
const dialog = new StopWorkspaceDialog();
7886
const result = await dialog.open();
7987
if (typeof result === 'boolean') {

0 commit comments

Comments
 (0)