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

Open workspace from Che Theia #816

Merged
merged 1 commit into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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