From 6e6c49358de50f4b61f4925bea7fc86f65e07740 Mon Sep 17 00:00:00 2001 From: Vladyslav Zhukovskyi Date: Wed, 29 Jul 2020 13:59:53 +0300 Subject: [PATCH] Open workspace from Che Theia Signed-off-by: Vladyslav Zhukovskyi --- .../src/browser/che-quick-open-workspace.ts | 12 +++++++++--- .../src/browser/che-workspace-contribution.ts | 16 ++++++++++++++++ .../src/browser/che-workspace-controller.ts | 10 +++++++++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/extensions/eclipse-che-theia-workspace/src/browser/che-quick-open-workspace.ts b/extensions/eclipse-che-theia-workspace/src/browser/che-quick-open-workspace.ts index b66fce0f9..ec11f1eb0 100644 --- a/extensions/eclipse-che-theia-workspace/src/browser/che-quick-open-workspace.ts +++ b/extensions/eclipse-che-theia-workspace/src/browser/che-quick-open-workspace.ts @@ -79,7 +79,7 @@ export class QuickOpenCheWorkspace implements QuickOpenModel { acceptor(this.items); } - async select(acceptor: (workspace: che.workspace.Workspace) => void): Promise { + async select(recent: boolean, acceptor: (workspace: che.workspace.Workspace) => void): Promise { this.items = []; const token = await this.oAuthUtils.getUserToken(); @@ -92,9 +92,15 @@ export class QuickOpenCheWorkspace implements QuickOpenModel { return; } - const workspaces = await this.cheApi.getAllByNamespace(this.currentWorkspace.namespace, token); + let workspaces = await this.cheApi.getAllByNamespace(this.currentWorkspace.namespace, token); - workspaces.sort(CheWorkspaceUtils.modificationTimeComparator); + if (recent) { + workspaces.sort(CheWorkspaceUtils.modificationTimeComparator); + + if (workspaces.length > 5) { + workspaces = workspaces.slice(0, 5); + } + } await this.open(workspaces, acceptor); } diff --git a/extensions/eclipse-che-theia-workspace/src/browser/che-workspace-contribution.ts b/extensions/eclipse-che-theia-workspace/src/browser/che-workspace-contribution.ts index 381ca3be3..9b4ea3901 100644 --- a/extensions/eclipse-che-theia-workspace/src/browser/che-workspace-contribution.ts +++ b/extensions/eclipse-che-theia-workspace/src/browser/che-workspace-contribution.ts @@ -19,6 +19,11 @@ export namespace CheWorkspaceCommands { const WORKSPACE_CATEGORY = 'Workspace'; const FILE_CATEGORY = 'File'; + export const OPEN_WORKSPACE: Command = { + id: 'che.openWorkspace', + category: FILE_CATEGORY, + label: 'Open Workspace...' + }; export const OPEN_RECENT_WORKSPACE: Command = { id: 'che.openRecentWorkspace', category: FILE_CATEGORY, @@ -37,6 +42,9 @@ export class CheWorkspaceContribution implements CommandContribution, MenuContri @inject(CheWorkspaceController) protected readonly workspaceController: CheWorkspaceController; registerCommands(commands: CommandRegistry): void { + commands.registerCommand(CheWorkspaceCommands.OPEN_WORKSPACE, { + execute: () => this.workspaceController.openWorkspace() + }); commands.registerCommand(CheWorkspaceCommands.OPEN_RECENT_WORKSPACE, { execute: () => this.workspaceController.openRecentWorkspace() }); @@ -46,6 +54,9 @@ export class CheWorkspaceContribution implements CommandContribution, MenuContri } registerMenus(menus: MenuModelRegistry): void { + menus.unregisterMenuAction({ + commandId: WorkspaceCommands.OPEN_WORKSPACE.id + }, CommonMenus.FILE_OPEN); menus.unregisterMenuAction({ commandId: WorkspaceCommands.OPEN_RECENT_WORKSPACE.id }, CommonMenus.FILE_OPEN); @@ -53,6 +64,11 @@ export class CheWorkspaceContribution implements CommandContribution, MenuContri commandId: WorkspaceCommands.CLOSE.id }, CommonMenus.FILE_CLOSE); + menus.registerMenuAction(CommonMenus.FILE_OPEN, { + commandId: CheWorkspaceCommands.OPEN_WORKSPACE.id, + label: CheWorkspaceCommands.OPEN_WORKSPACE.label, + order: 'a10' + }); menus.registerMenuAction(CommonMenus.FILE_OPEN, { commandId: CheWorkspaceCommands.OPEN_RECENT_WORKSPACE.id, label: CheWorkspaceCommands.OPEN_RECENT_WORKSPACE.label, diff --git a/extensions/eclipse-che-theia-workspace/src/browser/che-workspace-controller.ts b/extensions/eclipse-che-theia-workspace/src/browser/che-workspace-controller.ts index 993a057d3..b981221cb 100644 --- a/extensions/eclipse-che-theia-workspace/src/browser/che-workspace-controller.ts +++ b/extensions/eclipse-che-theia-workspace/src/browser/che-workspace-controller.ts @@ -72,8 +72,16 @@ export class CheWorkspaceController { @inject(CheApiService) protected readonly cheApi: CheApiService; @inject(QuickOpenCheWorkspace) protected readonly quickOpenWorkspace: QuickOpenCheWorkspace; + async openWorkspace(): Promise { + await this.doOpenWorkspace(false); + } + async openRecentWorkspace(): Promise { - await this.quickOpenWorkspace.select(async (workspace: che.workspace.Workspace) => { + await this.doOpenWorkspace(true); + } + + private doOpenWorkspace(recent: boolean): Promise { + return this.quickOpenWorkspace.select(recent, async (workspace: che.workspace.Workspace) => { const dialog = new StopWorkspaceDialog(); const result = await dialog.open(); if (typeof result === 'boolean') {