From 17aab3ae9076b02b2e58dfa960c4ccdf766b1299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=A4der?= Date: Thu, 25 Jul 2019 10:57:12 +0200 Subject: [PATCH 1/8] Add workspaces module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Mäder --- che-theia-init-sources.yml | 1 + .../eclipse-che-theia-workspace/.gitignore | 2 + .../eclipse-che-theia-workspace/package.json | 38 ++++++++ .../workspace-frontend-contribution.ts | 89 +++++++++++++++++++ .../src/browser/workspace-frontend-module.ts | 24 +++++ .../eclipse-che-theia-workspace/tsconfig.json | 14 +++ 6 files changed, 168 insertions(+) create mode 100644 extensions/eclipse-che-theia-workspace/.gitignore create mode 100644 extensions/eclipse-che-theia-workspace/package.json create mode 100644 extensions/eclipse-che-theia-workspace/src/browser/workspace-frontend-contribution.ts create mode 100644 extensions/eclipse-che-theia-workspace/src/browser/workspace-frontend-module.ts create mode 100644 extensions/eclipse-che-theia-workspace/tsconfig.json diff --git a/che-theia-init-sources.yml b/che-theia-init-sources.yml index 4d8c8176f..528770459 100644 --- a/che-theia-init-sources.yml +++ b/che-theia-init-sources.yml @@ -10,6 +10,7 @@ sources: - extensions/eclipse-che-theia-dashboard - extensions/eclipse-che-theia-activity-tracker - extensions/eclipse-che-theia-about + - extensions/eclipse-che-theia-workspace - extensions/eclipse-che-theia-preferences-provider-extension plugins: - plugins/containers-plugin diff --git a/extensions/eclipse-che-theia-workspace/.gitignore b/extensions/eclipse-che-theia-workspace/.gitignore new file mode 100644 index 000000000..c67d30dad --- /dev/null +++ b/extensions/eclipse-che-theia-workspace/.gitignore @@ -0,0 +1,2 @@ +conf +lib diff --git a/extensions/eclipse-che-theia-workspace/package.json b/extensions/eclipse-che-theia-workspace/package.json new file mode 100644 index 000000000..819f04bcd --- /dev/null +++ b/extensions/eclipse-che-theia-workspace/package.json @@ -0,0 +1,38 @@ +{ + "name": "@eclipse-che/theia-workspace", + "keywords": [ + "theia-extension", + "workspace" + ], + "version": "0.0.1", + "description": "Eclipse Che - Workspace Menu", + "dependencies": { + "@theia/core": "next", + "@theia/workspace": "next" + }, + "publishConfig": { + "access": "public" + }, + "theiaExtensions": [ + { + "frontend": "lib/browser/workspace-frontend-module" + } + ], + "license": "EPL-2.0", + "files": [ + "lib", + "src", + "scripts", + "conf" + ], + "scripts": { + "prepare": "yarn run clean && yarn run build", + "clean": "rimraf lib", + "format": "tsfmt -r --useTsfmt ../../configs/tsfmt.json", + "lint": "tslint -c ../../configs/tslint.json --project tsconfig.json", + "compile": "tsc", + "build": "concurrently -n \"format,lint,compile\" -c \"red,green,blue\" \"yarn format\" \"yarn lint\" \"yarn compile\"", + "watch": "tsc -w", + "publish:next": "yarn publish --registry=https://registry.npmjs.org/ --no-git-tag-version --new-version 0.0.1-\"$(date +%s)\"" + } +} diff --git a/extensions/eclipse-che-theia-workspace/src/browser/workspace-frontend-contribution.ts b/extensions/eclipse-che-theia-workspace/src/browser/workspace-frontend-contribution.ts new file mode 100644 index 000000000..38e403959 --- /dev/null +++ b/extensions/eclipse-che-theia-workspace/src/browser/workspace-frontend-contribution.ts @@ -0,0 +1,89 @@ +/******************************************************************************** + * Copyright (C) 2017 TypeFox and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +import { injectable, inject } from 'inversify'; +import { CommandContribution, CommandRegistry, MenuContribution, MenuModelRegistry } from '@theia/core/lib/common'; +import { + CommonMenus, LabelProvider, KeybindingRegistry, KeybindingContribution +} from '@theia/core/lib/browser'; +import { WorkspaceCommands } from '@theia/workspace/lib/browser'; +import { ContextKeyService } from '@theia/core/lib/browser/context-key-service'; + +@injectable() +export class WorkspaceFrontendContribution implements CommandContribution, KeybindingContribution, MenuContribution { + + @inject(LabelProvider) protected readonly labelProvider: LabelProvider; + @inject(CommandRegistry) protected readonly commandRegistry: CommandRegistry; + + @inject(ContextKeyService) + protected readonly contextKeyService: ContextKeyService; + + registerCommands(commands: CommandRegistry): void { + // Not visible/enabled on Windows/Linux in electron. + commands.unregisterCommand(WorkspaceCommands.OPEN); + // Visible/enabled only on Windows/Linux in electron. + commands.unregisterCommand(WorkspaceCommands.OPEN_FILE); + // Visible/enabled only on Windows/Linux in electron. + commands.unregisterCommand(WorkspaceCommands.OPEN_FOLDER); + commands.unregisterCommand(WorkspaceCommands.OPEN_RECENT_WORKSPACE); + commands.unregisterCommand(WorkspaceCommands.CLOSE); + commands.unregisterCommand(WorkspaceCommands.OPEN_RECENT_WORKSPACE); + commands.unregisterCommand(WorkspaceCommands.SAVE_WORKSPACE_AS); + } + + registerMenus(menus: MenuModelRegistry): void { + menus.unregisterMenuAction({ + commandId: WorkspaceCommands.OPEN.id, + }, CommonMenus.FILE_OPEN); + menus.unregisterMenuAction({ + commandId: WorkspaceCommands.OPEN_FILE.id, + }, CommonMenus.FILE_OPEN); + menus.unregisterMenuAction({ + commandId: WorkspaceCommands.OPEN_FOLDER.id + }); + menus.unregisterMenuAction({ + commandId: WorkspaceCommands.OPEN_WORKSPACE.id + }); + menus.unregisterMenuAction({ + commandId: WorkspaceCommands.OPEN_RECENT_WORKSPACE.id + }); + menus.unregisterMenuAction({ + commandId: WorkspaceCommands.SAVE_WORKSPACE_AS.id + }); + menus.unregisterMenuAction({ + commandId: WorkspaceCommands.CLOSE.id + }); + } + + registerKeybindings(keybindings: KeybindingRegistry): void { + keybindings.unregisterKeybinding({ + command: WorkspaceCommands.OPEN.id, + keybinding: 'ctrlcmd+alt+o', + }); + keybindings.unregisterKeybinding({ + command: WorkspaceCommands.OPEN_FOLDER.id, + keybinding: 'ctrl+k ctrl+o', + }); + keybindings.unregisterKeybinding({ + command: WorkspaceCommands.OPEN_WORKSPACE.id, + keybinding: 'ctrlcmd+alt+w', + }); + keybindings.unregisterKeybinding({ + command: WorkspaceCommands.OPEN_RECENT_WORKSPACE.id, + keybinding: 'ctrlcmd+alt+r', + }); + } +} diff --git a/extensions/eclipse-che-theia-workspace/src/browser/workspace-frontend-module.ts b/extensions/eclipse-che-theia-workspace/src/browser/workspace-frontend-module.ts new file mode 100644 index 000000000..10748550a --- /dev/null +++ b/extensions/eclipse-che-theia-workspace/src/browser/workspace-frontend-module.ts @@ -0,0 +1,24 @@ +/********************************************************************* + * Copyright (c) 2019 Red Hat, Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + **********************************************************************/ + +import { ContainerModule } from 'inversify'; +import { WorkspaceFrontendContribution } from './workspace-frontend-contribution'; +import { CommandContribution } from '@theia/core/lib/common/command'; +import { KeybindingContribution } from '@theia/core/lib/browser/keybinding'; +import { MenuContribution } from '@theia/core/lib/common/menu'; + +export default new ContainerModule((bind, unbind, isBound, rebind) => { + + bind(WorkspaceFrontendContribution).toSelf().inSingletonScope(); + for (const identifier of [CommandContribution, KeybindingContribution, MenuContribution]) { + bind(identifier).toService(WorkspaceFrontendContribution); + } + +}); diff --git a/extensions/eclipse-che-theia-workspace/tsconfig.json b/extensions/eclipse-che-theia-workspace/tsconfig.json new file mode 100644 index 000000000..a6a832536 --- /dev/null +++ b/extensions/eclipse-che-theia-workspace/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": "../../configs/base.tsconfig.json", + "compilerOptions": { + "lib": [ + "es6", + "dom" + ], + "rootDir": "src", + "outDir": "lib" + }, + "include": [ + "src" + ] +} From d182e37ba51702fc8a9990d520b1030efe751405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=A4der?= Date: Fri, 26 Jul 2019 09:28:21 +0000 Subject: [PATCH 2/8] fix version --- extensions/eclipse-che-theia-workspace/package.json | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/extensions/eclipse-che-theia-workspace/package.json b/extensions/eclipse-che-theia-workspace/package.json index 819f04bcd..e9ba512cb 100644 --- a/extensions/eclipse-che-theia-workspace/package.json +++ b/extensions/eclipse-che-theia-workspace/package.json @@ -7,8 +7,8 @@ "version": "0.0.1", "description": "Eclipse Che - Workspace Menu", "dependencies": { - "@theia/core": "next", - "@theia/workspace": "next" + "@theia/core": "^0.8.0", + "@theia/workspace": "^0.8.0" }, "publishConfig": { "access": "public" @@ -34,5 +34,6 @@ "build": "concurrently -n \"format,lint,compile\" -c \"red,green,blue\" \"yarn format\" \"yarn lint\" \"yarn compile\"", "watch": "tsc -w", "publish:next": "yarn publish --registry=https://registry.npmjs.org/ --no-git-tag-version --new-version 0.0.1-\"$(date +%s)\"" - } -} + }, + "devDependencies": {} +} \ No newline at end of file From 78f8d2c444f8af33ef799c6eb337903efb6de69f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=A4der?= Date: Tue, 30 Jul 2019 15:57:15 +0000 Subject: [PATCH 3/8] Register update workspace command --- .../src/browser/workspace-frontend-contribution.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/extensions/eclipse-che-theia-workspace/src/browser/workspace-frontend-contribution.ts b/extensions/eclipse-che-theia-workspace/src/browser/workspace-frontend-contribution.ts index 38e403959..0153fb308 100644 --- a/extensions/eclipse-che-theia-workspace/src/browser/workspace-frontend-contribution.ts +++ b/extensions/eclipse-che-theia-workspace/src/browser/workspace-frontend-contribution.ts @@ -19,14 +19,16 @@ import { CommandContribution, CommandRegistry, MenuContribution, MenuModelRegist import { CommonMenus, LabelProvider, KeybindingRegistry, KeybindingContribution } from '@theia/core/lib/browser'; -import { WorkspaceCommands } from '@theia/workspace/lib/browser'; +import { WorkspaceCommands, WorkspaceService } from '@theia/workspace/lib/browser'; import { ContextKeyService } from '@theia/core/lib/browser/context-key-service'; +import URI from '@theia/core/lib/common/uri'; @injectable() export class WorkspaceFrontendContribution implements CommandContribution, KeybindingContribution, MenuContribution { @inject(LabelProvider) protected readonly labelProvider: LabelProvider; @inject(CommandRegistry) protected readonly commandRegistry: CommandRegistry; + @inject(WorkspaceService) protected readonly workspaceService: WorkspaceService; @inject(ContextKeyService) protected readonly contextKeyService: ContextKeyService; @@ -42,6 +44,12 @@ export class WorkspaceFrontendContribution implements CommandContribution, Keybi commands.unregisterCommand(WorkspaceCommands.CLOSE); commands.unregisterCommand(WorkspaceCommands.OPEN_RECENT_WORKSPACE); commands.unregisterCommand(WorkspaceCommands.SAVE_WORKSPACE_AS); + + commands.registerCommand({ + id: 'che.workspace.addFolder' + }, { + execute: async (uri: URI) => await this.workspaceService.addRoot(uri) + }); } registerMenus(menus: MenuModelRegistry): void { From df83e2f1c9bec2e28235e0c511508a15d9bbcddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=A4der?= Date: Tue, 30 Jul 2019 16:20:53 +0000 Subject: [PATCH 4/8] Add to workspace on clone --- .../factory-plugin/src/factory-initializer.ts | 8 ++++- plugins/factory-plugin/src/theia-commands.ts | 32 ++++++++++++++++--- .../src/workspace-projects-manager.ts | 20 ++++-------- 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/plugins/factory-plugin/src/factory-initializer.ts b/plugins/factory-plugin/src/factory-initializer.ts index 14a71d508..d784183bc 100644 --- a/plugins/factory-plugin/src/factory-initializer.ts +++ b/plugins/factory-plugin/src/factory-initializer.ts @@ -92,9 +92,15 @@ export class FactoryInitializer { return; } + let workspaceUpdate = Promise.resolve(); await Promise.all( - cloneCommands.map(command => command.execute()) + cloneCommands.map(cloneCommand => { + cloneCommand.clone().then(() => { + workspaceUpdate = workspaceUpdate.then(() => cloneCommand.updateWorkpace()); + }); + }) ); + await workspaceUpdate; theia.window.showInformationMessage('Che Factory: Finished cloning projects.'); } diff --git a/plugins/factory-plugin/src/theia-commands.ts b/plugins/factory-plugin/src/theia-commands.ts index 7e1890d60..5395556a1 100644 --- a/plugins/factory-plugin/src/theia-commands.ts +++ b/plugins/factory-plugin/src/theia-commands.ts @@ -13,6 +13,7 @@ import * as theia from '@theia/plugin'; import { che as cheApi } from '@eclipse-che/api'; import * as fileuri from './file-uri'; import * as git from './git'; +import * as fs from 'fs'; const CHE_TASK_TYPE = 'che'; @@ -68,7 +69,7 @@ export class TheiaCloneCommand { this.projectsRoot = projectsRoot; } - execute(): PromiseLike { + clone(): PromiseLike { if (!this.locationURI) { return new Promise(() => { }); } @@ -109,10 +110,31 @@ export class TheiaCloneCommand { } }; - return theia.window.withProgress({ - location: theia.ProgressLocation.Notification, - title: `Cloning ${this.locationURI} ...` - }, (progress, token) => clone(progress, token)); + if (!fs.existsSync(this.folder)) { + return theia.window.withProgress({ + location: theia.ProgressLocation.Notification, + title: `Cloning ${this.locationURI} ...` + }, (progress, token) => clone(progress, token)); + } + return Promise.resolve(); + } + + updateWorkpace(): PromiseLike { + if (!this.isInTheiaWorkspace()) { + return theia.commands.executeCommand('che.workspace.addFolder', theia.Uri.file(this.folder)).then(() => { }); + } + return Promise.resolve(); + } + + private isInTheiaWorkspace(): boolean { + for (let i = 0; i < theia.workspace.workspaceFolders.length; i++) { + const wsFolder = theia.workspace.workspaceFolders[i]; + + if (wsFolder && fs.realpathSync(wsFolder.uri.fsPath) === fs.realpathSync(this.folder)) { + return true; + } + } + return false; } } diff --git a/plugins/factory-plugin/src/workspace-projects-manager.ts b/plugins/factory-plugin/src/workspace-projects-manager.ts index 1cacf5018..b2d8e1d2d 100644 --- a/plugins/factory-plugin/src/workspace-projects-manager.ts +++ b/plugins/factory-plugin/src/workspace-projects-manager.ts @@ -8,8 +8,6 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ -import * as path from 'path'; -import * as fs from 'fs'; import { TheiaCloneCommand } from './theia-commands'; import * as git from './git'; import * as projectsHelper from './projects'; @@ -41,11 +39,6 @@ abstract class WorkspaceProjectsManager { abstract deleteProject(workspace: cheApi.workspace.Workspace, projectFolderURI: string): void; async run(workspace?: cheApi.workspace.Workspace) { - if (!theia.workspace.name) { - // no workspace opened, so nothing to clone / watch - return; - } - if (!workspace) { workspace = await che.workspace.getCurrentWorkspace(); } @@ -61,9 +54,15 @@ abstract class WorkspaceProjectsManager { } theia.window.showInformationMessage('Che Workspace: Starting cloning projects.'); + let workspaceUpdate = Promise.resolve(); await Promise.all( - cloneCommandList.map(cloneCommand => cloneCommand.execute()) + cloneCommandList.map(cloneCommand => { + cloneCommand.clone().then(() => { + workspaceUpdate = workspaceUpdate.then(() => cloneCommand.updateWorkpace()); + }); + }) ); + await workspaceUpdate; theia.window.showInformationMessage('Che Workspace: Finished cloning projects.'); } @@ -126,10 +125,6 @@ export class DevfileProjectsManager extends WorkspaceProjectsManager { } return projects - .filter(project => { - const projectPath = project.clonePath ? path.join(instance.projectsRoot, project.clonePath) : path.join(instance.projectsRoot, project.name); - return !fs.existsSync(projectPath); - }) .map(project => new TheiaCloneCommand(project, instance.projectsRoot)); } @@ -170,7 +165,6 @@ export class WorkspaceConfigProjectsManager extends WorkspaceProjectsManager { } return projects - .filter(project => !fs.existsSync(instance.projectsRoot + project.path)) .map(project => new TheiaCloneCommand(project, instance.projectsRoot)); } From 8bba0e8c6207904366e16a325bed6696b89bdde4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=A4der?= Date: Wed, 31 Jul 2019 09:21:02 +0000 Subject: [PATCH 5/8] Make add folder command handle multiple uris --- .../src/browser/workspace-frontend-contribution.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/eclipse-che-theia-workspace/src/browser/workspace-frontend-contribution.ts b/extensions/eclipse-che-theia-workspace/src/browser/workspace-frontend-contribution.ts index 0153fb308..24e2e5e0d 100644 --- a/extensions/eclipse-che-theia-workspace/src/browser/workspace-frontend-contribution.ts +++ b/extensions/eclipse-che-theia-workspace/src/browser/workspace-frontend-contribution.ts @@ -48,7 +48,7 @@ export class WorkspaceFrontendContribution implements CommandContribution, Keybi commands.registerCommand({ id: 'che.workspace.addFolder' }, { - execute: async (uri: URI) => await this.workspaceService.addRoot(uri) + execute: async (uris: URI[]) => await this.workspaceService.spliceRoots(0, 0, ...uris) }); } From ce917409f656a5474cd753f5f28e4e4aef231498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=A4der?= Date: Wed, 31 Jul 2019 09:22:17 +0000 Subject: [PATCH 6/8] Use single command to update workspace --- .../factory-plugin/src/factory-initializer.ts | 11 +++---- plugins/factory-plugin/src/theia-commands.ts | 30 ++++++++----------- .../src/workspace-projects-manager.ts | 11 +++---- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/plugins/factory-plugin/src/factory-initializer.ts b/plugins/factory-plugin/src/factory-initializer.ts index d784183bc..49f93e6b6 100644 --- a/plugins/factory-plugin/src/factory-initializer.ts +++ b/plugins/factory-plugin/src/factory-initializer.ts @@ -92,15 +92,16 @@ export class FactoryInitializer { return; } - let workspaceUpdate = Promise.resolve(); + const workspaceFolders: theia.Uri[] = []; await Promise.all( cloneCommands.map(cloneCommand => { - cloneCommand.clone().then(() => { - workspaceUpdate = workspaceUpdate.then(() => cloneCommand.updateWorkpace()); - }); + if (cloneCommand.isInTheiaWorkspace()) { + workspaceFolders.push(theia.Uri.file(cloneCommand.folder)); + } + cloneCommand.clone(); }) ); - await workspaceUpdate; + await theia.commands.executeCommand('che.workspace.addFolder', workspaceFolders); theia.window.showInformationMessage('Che Factory: Finished cloning projects.'); } diff --git a/plugins/factory-plugin/src/theia-commands.ts b/plugins/factory-plugin/src/theia-commands.ts index 5395556a1..7a73117a7 100644 --- a/plugins/factory-plugin/src/theia-commands.ts +++ b/plugins/factory-plugin/src/theia-commands.ts @@ -32,7 +32,7 @@ function isDevfileProjectConfig(project: cheApi.workspace.ProjectConfig | cheApi export class TheiaCloneCommand { private locationURI: string | undefined; - private folder: string; + private _folder: string; private checkoutBranch?: string | undefined; private checkoutTag?: string | undefined; private checkoutStartPoint?: string | undefined; @@ -47,7 +47,7 @@ export class TheiaCloneCommand { } this.locationURI = source.location; - this.folder = project.clonePath ? path.join(projectsRoot, project.clonePath) : path.join(projectsRoot, project.name); + this._folder = project.clonePath ? path.join(projectsRoot, project.clonePath) : path.join(projectsRoot, project.name); this.checkoutBranch = source.branch; this.checkoutStartPoint = source.startPoint; this.checkoutTag = source.tag; @@ -60,7 +60,7 @@ export class TheiaCloneCommand { const parameters = project.source.parameters; this.locationURI = project.source.location; - this.folder = projectsRoot + project.path; + this._folder = projectsRoot + project.path; this.checkoutBranch = parameters['branch']; this.checkoutStartPoint = parameters['startPoint']; this.checkoutTag = project.source.parameters['tag']; @@ -75,7 +75,7 @@ export class TheiaCloneCommand { } const clone = async (progress: theia.Progress<{ message?: string; increment?: number }>, token: theia.CancellationToken): Promise => { - const args: string[] = ['clone', this.locationURI, this.folder]; + const args: string[] = ['clone', this.locationURI, this._folder]; if (this.checkoutBranch) { args.push('--branch'); args.push(this.checkoutBranch); @@ -91,15 +91,15 @@ export class TheiaCloneCommand { : (this.checkoutTag ? this.checkoutTag : this.checkoutCommitId); const branch = this.checkoutBranch ? this.checkoutBranch : 'default branch'; - const messageStart = `Project ${this.locationURI} cloned to ${this.folder} and checked out ${branch}`; + const messageStart = `Project ${this.locationURI} cloned to ${this._folder} and checked out ${branch}`; if (treeish) { - git.execGit(this.folder, 'reset', '--hard', treeish) + git.execGit(this._folder, 'reset', '--hard', treeish) .then(_ => { theia.window.showInformationMessage(`${messageStart} which has been reset to ${treeish}.`); }, e => { theia.window.showErrorMessage(`${messageStart} but resetting to ${treeish} failed with ${e.message}.`); - console.log(`Couldn't reset to ${treeish} of ${this.folder} cloned from ${this.locationURI} and checked out to ${branch}.`, e); + console.log(`Couldn't reset to ${treeish} of ${this._folder} cloned from ${this.locationURI} and checked out to ${branch}.`, e); }); } else { theia.window.showInformationMessage(`${messageStart}.`); @@ -110,7 +110,7 @@ export class TheiaCloneCommand { } }; - if (!fs.existsSync(this.folder)) { + if (!fs.existsSync(this._folder)) { return theia.window.withProgress({ location: theia.ProgressLocation.Notification, title: `Cloning ${this.locationURI} ...` @@ -119,24 +119,20 @@ export class TheiaCloneCommand { return Promise.resolve(); } - updateWorkpace(): PromiseLike { - if (!this.isInTheiaWorkspace()) { - return theia.commands.executeCommand('che.workspace.addFolder', theia.Uri.file(this.folder)).then(() => { }); - } - return Promise.resolve(); - } - - private isInTheiaWorkspace(): boolean { + isInTheiaWorkspace(): boolean { for (let i = 0; i < theia.workspace.workspaceFolders.length; i++) { const wsFolder = theia.workspace.workspaceFolders[i]; - if (wsFolder && fs.realpathSync(wsFolder.uri.fsPath) === fs.realpathSync(this.folder)) { + if (wsFolder && fs.realpathSync(wsFolder.uri.fsPath) === fs.realpathSync(this._folder)) { return true; } } return false; } + get folder(): string { + return this._folder; + } } export class TheiaCommand { diff --git a/plugins/factory-plugin/src/workspace-projects-manager.ts b/plugins/factory-plugin/src/workspace-projects-manager.ts index b2d8e1d2d..c5242bf4c 100644 --- a/plugins/factory-plugin/src/workspace-projects-manager.ts +++ b/plugins/factory-plugin/src/workspace-projects-manager.ts @@ -54,15 +54,16 @@ abstract class WorkspaceProjectsManager { } theia.window.showInformationMessage('Che Workspace: Starting cloning projects.'); - let workspaceUpdate = Promise.resolve(); + const workspaceFolders: theia.Uri[] = []; await Promise.all( cloneCommandList.map(cloneCommand => { - cloneCommand.clone().then(() => { - workspaceUpdate = workspaceUpdate.then(() => cloneCommand.updateWorkpace()); - }); + if (!cloneCommand.isInTheiaWorkspace()) { + workspaceFolders.push(theia.Uri.file(cloneCommand.folder)); + } + return cloneCommand.clone(); }) ); - await workspaceUpdate; + await theia.commands.executeCommand('che.workspace.addFolder', workspaceFolders); theia.window.showInformationMessage('Che Workspace: Finished cloning projects.'); } From 2eb142d1da8b474e328f8df1a75a9bee9a446874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=A4der?= Date: Wed, 31 Jul 2019 14:12:21 +0000 Subject: [PATCH 7/8] Ensure open file is visible --- .../src/browser/workspace-frontend-contribution.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/extensions/eclipse-che-theia-workspace/src/browser/workspace-frontend-contribution.ts b/extensions/eclipse-che-theia-workspace/src/browser/workspace-frontend-contribution.ts index 24e2e5e0d..96504fb3d 100644 --- a/extensions/eclipse-che-theia-workspace/src/browser/workspace-frontend-contribution.ts +++ b/extensions/eclipse-che-theia-workspace/src/browser/workspace-frontend-contribution.ts @@ -37,8 +37,6 @@ export class WorkspaceFrontendContribution implements CommandContribution, Keybi // Not visible/enabled on Windows/Linux in electron. commands.unregisterCommand(WorkspaceCommands.OPEN); // Visible/enabled only on Windows/Linux in electron. - commands.unregisterCommand(WorkspaceCommands.OPEN_FILE); - // Visible/enabled only on Windows/Linux in electron. commands.unregisterCommand(WorkspaceCommands.OPEN_FOLDER); commands.unregisterCommand(WorkspaceCommands.OPEN_RECENT_WORKSPACE); commands.unregisterCommand(WorkspaceCommands.CLOSE); @@ -56,9 +54,6 @@ export class WorkspaceFrontendContribution implements CommandContribution, Keybi menus.unregisterMenuAction({ commandId: WorkspaceCommands.OPEN.id, }, CommonMenus.FILE_OPEN); - menus.unregisterMenuAction({ - commandId: WorkspaceCommands.OPEN_FILE.id, - }, CommonMenus.FILE_OPEN); menus.unregisterMenuAction({ commandId: WorkspaceCommands.OPEN_FOLDER.id }); @@ -74,6 +69,11 @@ export class WorkspaceFrontendContribution implements CommandContribution, Keybi menus.unregisterMenuAction({ commandId: WorkspaceCommands.CLOSE.id }); + menus.registerMenuAction(CommonMenus.FILE_OPEN, { + commandId: WorkspaceCommands.OPEN_FILE.id, + label: `${WorkspaceCommands.OPEN_FILE.dialogLabel}...`, + order: 'a01' + }); } registerKeybindings(keybindings: KeybindingRegistry): void { From f5379062d76765faa9ac46b1956d5685a68a978e Mon Sep 17 00:00:00 2001 From: Josh Pinkney Date: Wed, 7 Aug 2019 12:48:44 -0400 Subject: [PATCH 8/8] Start theia using projects.theia-workspace --- dockerfiles/theia/Dockerfile | 2 ++ dockerfiles/theia/projects.theia-workspace | 4 ++++ dockerfiles/theia/src/entrypoint.sh | 2 +- extensions/eclipse-che-theia-workspace/package.json | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 dockerfiles/theia/projects.theia-workspace diff --git a/dockerfiles/theia/Dockerfile b/dockerfiles/theia/Dockerfile index de0144594..16bbf8c46 100644 --- a/dockerfiles/theia/Dockerfile +++ b/dockerfiles/theia/Dockerfile @@ -143,6 +143,8 @@ RUN adduser -D -S -u 1001 -G root -h ${HOME} -s /bin/sh theia \ && find ${HOME} -exec sh -c "chgrp 0 {}; chmod g+rwX {}" \; COPY --chown=theia:root --from=builder /home/theia-dev/theia-source-code/production /home/theia +RUN mkdir -p ${HOME}/.theia && chmod -R 777 ${HOME}/.theia +COPY ["./projects.theia-workspace", "/home/theia/.theia"] USER theia WORKDIR /projects ADD src/entrypoint.sh /entrypoint.sh diff --git a/dockerfiles/theia/projects.theia-workspace b/dockerfiles/theia/projects.theia-workspace new file mode 100644 index 000000000..7500b91a3 --- /dev/null +++ b/dockerfiles/theia/projects.theia-workspace @@ -0,0 +1,4 @@ +{ + "folders": [], + "settings": {} +} diff --git a/dockerfiles/theia/src/entrypoint.sh b/dockerfiles/theia/src/entrypoint.sh index 99c92a1b2..6ad6ea38e 100755 --- a/dockerfiles/theia/src/entrypoint.sh +++ b/dockerfiles/theia/src/entrypoint.sh @@ -77,7 +77,7 @@ fi shopt -u nocasematch # run che -node src-gen/backend/main.js /projects --hostname=0.0.0.0 --port=${THEIA_PORT} & +node src-gen/backend/main.js /home/theia/.theia/projects.theia-workspace --hostname=0.0.0.0 --port=${THEIA_PORT} & PID=$! diff --git a/extensions/eclipse-che-theia-workspace/package.json b/extensions/eclipse-che-theia-workspace/package.json index e9ba512cb..ab62d1eba 100644 --- a/extensions/eclipse-che-theia-workspace/package.json +++ b/extensions/eclipse-che-theia-workspace/package.json @@ -36,4 +36,4 @@ "publish:next": "yarn publish --registry=https://registry.npmjs.org/ --no-git-tag-version --new-version 0.0.1-\"$(date +%s)\"" }, "devDependencies": {} -} \ No newline at end of file +}