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

Commit

Permalink
Open workspace from Che Theia
Browse files Browse the repository at this point in the history
Signed-off-by: Vladyslav Zhukovskyi <vzhukovs@redhat.com>
  • Loading branch information
vzhukovs committed Jul 29, 2020
1 parent 05bfef1 commit 6e6c493
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class QuickOpenCheWorkspace implements QuickOpenModel {
acceptor(this.items);
}

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

const token = await this.oAuthUtils.getUserToken();
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
});
Expand All @@ -46,13 +54,21 @@ 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);
menus.unregisterMenuAction({
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,16 @@ export class CheWorkspaceController {
@inject(CheApiService) protected readonly cheApi: CheApiService;
@inject(QuickOpenCheWorkspace) protected readonly quickOpenWorkspace: QuickOpenCheWorkspace;

async openWorkspace(): Promise<void> {
await this.doOpenWorkspace(false);
}

async openRecentWorkspace(): Promise<void> {
await this.quickOpenWorkspace.select(async (workspace: che.workspace.Workspace) => {
await this.doOpenWorkspace(true);
}

private doOpenWorkspace(recent: boolean): Promise<void> {
return this.quickOpenWorkspace.select(recent, async (workspace: che.workspace.Workspace) => {
const dialog = new StopWorkspaceDialog();
const result = await dialog.open();
if (typeof result === 'boolean') {
Expand Down

0 comments on commit 6e6c493

Please sign in to comment.