From e8f6d8c476a1f53b26d74e956dae9f06080d357b Mon Sep 17 00:00:00 2001 From: Vlad Arama Date: Tue, 8 Aug 2023 08:17:18 -0400 Subject: [PATCH 1/5] implement workbench: startup editor preference This commit introduces 5 new startup editor preferences: - none: no editor will be shown on startup - welcomePage: the default welcome page will be shown on startup - readme: it will open the folder's readme in preview mode - newUntitledFile: opens an untitled file on startup - welcomePageInEmptyWorkbench: only opens the welcome page when opening empty workbench --- packages/core/src/browser/core-preferences.ts | 14 +++ packages/getting-started/package.json | 3 + .../browser/getting-started-contribution.ts | 90 ++++++++++++++++--- packages/getting-started/tsconfig.json | 9 ++ 4 files changed, 102 insertions(+), 14 deletions(-) diff --git a/packages/core/src/browser/core-preferences.ts b/packages/core/src/browser/core-preferences.ts index 1ebc24b172011..770f96cf2f1a5 100644 --- a/packages/core/src/browser/core-preferences.ts +++ b/packages/core/src/browser/core-preferences.ts @@ -225,6 +225,19 @@ export const corePreferenceSchema: PreferenceSchema = { default: isOSX ? 1500 : 500, description: nls.localizeByDefault('Controls the delay in milliseconds after which the hover is shown.') }, + 'workbench.startupEditor': { + type: 'string', + enum: ['none', 'welcomePage', 'readme', 'newUntitledFile', 'welcomePageInEmptyWorkbench'], + enumDescriptions: [ + nls.localizeByDefault('Start without an editor.'), + nls.localize('theia/getting-started/startup-editor/welcomePage', 'Open the Welcome page, with content to aid in getting started with {0} and extensions.', FrontendApplicationConfigProvider.get().applicationName), + nls.localizeByDefault('Open the README when opening a folder that contains one, fallback to \'welcomePage\' otherwise. Note: This is only observed as a global configuration, it will be ignored if set in a workspace or folder configuration.'), + nls.localizeByDefault('Open a new untitled text file (only applies when opening an empty window).'), + nls.localizeByDefault('Open the Welcome page when opening an empty workbench.'), + ], + default: 'welcomePage', + description: nls.localizeByDefault('Controls which editor is shown at startup, if none are restored from the previous session.') + }, 'workbench.sash.hoverDelay': { type: 'number', default: 300, @@ -285,6 +298,7 @@ export interface CoreConfiguration { 'workbench.statusBar.visible': boolean; 'workbench.tree.renderIndentGuides': 'onHover' | 'none' | 'always'; 'workbench.hover.delay': number; + 'workbench.startupEditor': string; 'workbench.sash.hoverDelay': number; 'workbench.sash.size': number; 'workbench.tab.maximize': boolean; diff --git a/packages/getting-started/package.json b/packages/getting-started/package.json index 89c48b9f8f318..b568750714cdc 100644 --- a/packages/getting-started/package.json +++ b/packages/getting-started/package.json @@ -4,7 +4,10 @@ "description": "Theia - GettingStarted Extension", "dependencies": { "@theia/core": "1.40.0", + "@theia/editor": "1.40.0", + "@theia/filesystem": "1.40.0", "@theia/keymaps": "1.40.0", + "@theia/preview": "1.40.0", "@theia/workspace": "1.40.0" }, "publishConfig": { diff --git a/packages/getting-started/src/browser/getting-started-contribution.ts b/packages/getting-started/src/browser/getting-started-contribution.ts index 6f3d70cf1eb4f..815b668ef2db2 100644 --- a/packages/getting-started/src/browser/getting-started-contribution.ts +++ b/packages/getting-started/src/browser/getting-started-contribution.ts @@ -14,11 +14,17 @@ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 // ***************************************************************************** +import * as path from 'path'; import { injectable, inject } from '@theia/core/shared/inversify'; -import { CommandRegistry, MenuModelRegistry } from '@theia/core/lib/common'; -import { CommonMenus, AbstractViewContribution, FrontendApplicationContribution, FrontendApplication, NavigatableWidget, PreferenceService } from '@theia/core/lib/browser'; +import { ArrayUtils, CommandRegistry, MenuModelRegistry, URI, UntitledResourceResolver } from '@theia/core/lib/common'; +import { CommonMenus, AbstractViewContribution, FrontendApplicationContribution, FrontendApplication, PreferenceService } from '@theia/core/lib/browser'; +import { EditorManager } from '@theia/editor/lib/browser/editor-manager'; import { GettingStartedWidget } from './getting-started-widget'; +import { FileService } from '@theia/filesystem/lib/browser/file-service'; import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state'; +import { OpenerService, open } from '@theia/core/lib/browser/opener-service'; +import { PreviewContribution } from '@theia/preview/lib/browser/preview-contribution'; +import { UserWorkingDirectoryProvider } from '@theia/core/lib/browser/user-working-directory-provider'; import { WorkspaceService } from '@theia/workspace/lib/browser'; /** @@ -32,15 +38,33 @@ export const GettingStartedCommand = { @injectable() export class GettingStartedContribution extends AbstractViewContribution implements FrontendApplicationContribution { + @inject(EditorManager) + protected readonly editorManager: EditorManager; + + @inject(FileService) + protected readonly fileService: FileService; + + @inject(OpenerService) + protected readonly openerService: OpenerService; + + @inject(PreferenceService) + protected readonly preferenceService: PreferenceService; + + @inject(PreviewContribution) + protected readonly previewContributon: PreviewContribution; + @inject(FrontendApplicationStateService) protected readonly stateService: FrontendApplicationStateService; + @inject(UntitledResourceResolver) + protected readonly untitledResourceResolver: UntitledResourceResolver; + + @inject(UserWorkingDirectoryProvider) + protected readonly workingDirProvider: UserWorkingDirectoryProvider; + @inject(WorkspaceService) protected readonly workspaceService: WorkspaceService; - @inject(PreferenceService) - protected readonly preferenceService: PreferenceService; - constructor() { super({ widgetId: GettingStartedWidget.ID, @@ -52,19 +76,57 @@ export class GettingStartedContribution extends AbstractViewContribution { - this.stateService.reachedState('ready').then(() => { - const editors = this.shell.widgets.filter((widget): widget is NavigatableWidget => NavigatableWidget.is(widget)); - if (editors.length === 0) { - this.preferenceService.ready.then(() => { - const showWelcomePage: boolean = this.preferenceService.get('welcome.alwaysShowWelcomePage', true); - if (showWelcomePage) { - this.openView({ reveal: true, activate: true }); - } - }); + this.stateService.reachedState('ready').then(async () => { + if (this.editorManager.all.length === 0) { + const startupEditor = this.preferenceService.get('workbench.startupEditor'); + switch (startupEditor) { + case 'welcomePage': + return this.openWelcomePage(); + case 'welcomePageInEmptyWorkbench': + if (!this.workspaceService.opened) { + return this.openWelcomePage(); + } + break; + case 'newUntitledFile': + const untitledUri = this.untitledResourceResolver.createUntitledURI('', await this.workingDirProvider.getUserWorkingDir()); + this.untitledResourceResolver.resolve(untitledUri); + return open(this.openerService, untitledUri); + case 'readme': + return this.openReadme(); + } } }); } + protected openWelcomePage(): void { + this.preferenceService.ready.then(() => { + const showWelcomePage: boolean = this.preferenceService.get('welcome.alwaysShowWelcomePage', true); + if (showWelcomePage) { + this.openView({ reveal: true, activate: true }); + } + }); + } + + protected async openReadme(): Promise { + const readmes = await Promise.all(this.workspaceService.tryGetRoots().map(async folder => { + const folderUri = folder.resource; + const folderStat = await this.fileService.resolve(folderUri); + const fileArr = folderStat?.children?.map(child => child.name).sort() || []; + const filePath = fileArr.find(file => file.toLowerCase() === 'readme.md') || fileArr.find(file => file.toLowerCase().startsWith('readme')); + return filePath ? path.join(folderUri.toString(), filePath) : undefined; + })); + const validReadmes = ArrayUtils.coalesce(readmes); + if (validReadmes.length) { + for (const readme of validReadmes) { + const fileURI = new URI(readme); + await this.previewContributon.open(fileURI); + } + } else { + // If no readme is found, show the welcome page. + this.openWelcomePage(); + } + } + override registerCommands(registry: CommandRegistry): void { registry.registerCommand(GettingStartedCommand, { execute: () => this.openView({ reveal: true, activate: true }), diff --git a/packages/getting-started/tsconfig.json b/packages/getting-started/tsconfig.json index ba31f57815a43..26df745bdd0c6 100644 --- a/packages/getting-started/tsconfig.json +++ b/packages/getting-started/tsconfig.json @@ -12,9 +12,18 @@ { "path": "../core" }, + { + "path": "../editor" + }, + { + "path": "../filesystem" + }, { "path": "../keymaps" }, + { + "path": "../preview" + }, { "path": "../workspace" } From 5557a2d60d1d0f6da36f702ba7d6e951d80e88bf Mon Sep 17 00:00:00 2001 From: Vlad Arama Date: Thu, 17 Aug 2023 14:43:49 -0400 Subject: [PATCH 2/5] address review comments This commit aims to address and fix various comments received on the PR: - This includes waiting for the `preferenceService` and the `workspaceService` to be ready before actually using them. - It also includes a minor refactoring of the `openReadme` method to avoid the conversion from URI -> string -> URI. Signed-Off-By: Vlad Arama --- .../browser/getting-started-contribution.ts | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/packages/getting-started/src/browser/getting-started-contribution.ts b/packages/getting-started/src/browser/getting-started-contribution.ts index 815b668ef2db2..bfbc43e76a9c2 100644 --- a/packages/getting-started/src/browser/getting-started-contribution.ts +++ b/packages/getting-started/src/browser/getting-started-contribution.ts @@ -14,9 +14,8 @@ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 // ***************************************************************************** -import * as path from 'path'; import { injectable, inject } from '@theia/core/shared/inversify'; -import { ArrayUtils, CommandRegistry, MenuModelRegistry, URI, UntitledResourceResolver } from '@theia/core/lib/common'; +import { ArrayUtils, CommandRegistry, MenuModelRegistry, UntitledResourceResolver } from '@theia/core/lib/common'; import { CommonMenus, AbstractViewContribution, FrontendApplicationContribution, FrontendApplication, PreferenceService } from '@theia/core/lib/browser'; import { EditorManager } from '@theia/editor/lib/browser/editor-manager'; import { GettingStartedWidget } from './getting-started-widget'; @@ -78,48 +77,49 @@ export class GettingStartedContribution extends AbstractViewContribution { this.stateService.reachedState('ready').then(async () => { if (this.editorManager.all.length === 0) { + await this.preferenceService.ready; const startupEditor = this.preferenceService.get('workbench.startupEditor'); switch (startupEditor) { case 'welcomePage': - return this.openWelcomePage(); + this.openWelcomePage(); + break; case 'welcomePageInEmptyWorkbench': if (!this.workspaceService.opened) { - return this.openWelcomePage(); + this.openWelcomePage(); } break; case 'newUntitledFile': const untitledUri = this.untitledResourceResolver.createUntitledURI('', await this.workingDirProvider.getUserWorkingDir()); this.untitledResourceResolver.resolve(untitledUri); - return open(this.openerService, untitledUri); + await open(this.openerService, untitledUri); + break; case 'readme': - return this.openReadme(); + await this.openReadme(); + break; } } }); } protected openWelcomePage(): void { - this.preferenceService.ready.then(() => { - const showWelcomePage: boolean = this.preferenceService.get('welcome.alwaysShowWelcomePage', true); - if (showWelcomePage) { - this.openView({ reveal: true, activate: true }); - } - }); + const showWelcomePage: boolean = this.preferenceService.get('welcome.alwaysShowWelcomePage', true); + if (showWelcomePage) { + this.openView({ reveal: true, activate: true }); + } } protected async openReadme(): Promise { - const readmes = await Promise.all(this.workspaceService.tryGetRoots().map(async folder => { - const folderUri = folder.resource; - const folderStat = await this.fileService.resolve(folderUri); - const fileArr = folderStat?.children?.map(child => child.name).sort() || []; - const filePath = fileArr.find(file => file.toLowerCase() === 'readme.md') || fileArr.find(file => file.toLowerCase().startsWith('readme')); - return filePath ? path.join(folderUri.toString(), filePath) : undefined; + const roots = await this.workspaceService.roots; + const readmes = await Promise.all(roots.map(async folder => { + const folderStat = await this.fileService.resolve(folder.resource); + const fileArr = folderStat?.children?.sort((a, b) => a.name.localeCompare(b.name)) || []; + const filePath = fileArr.find(file => file.name.toLowerCase() === 'readme.md') || fileArr.find(file => file.name.toLowerCase().startsWith('readme')); + return filePath?.resource; })); const validReadmes = ArrayUtils.coalesce(readmes); if (validReadmes.length) { for (const readme of validReadmes) { - const fileURI = new URI(readme); - await this.previewContributon.open(fileURI); + await this.previewContributon.open(readme); } } else { // If no readme is found, show the welcome page. From 2846c6c4cbc6d1145f770a1aaf6fe424bcec8ca2 Mon Sep 17 00:00:00 2001 From: Vlad Arama Date: Mon, 21 Aug 2023 15:34:21 -0400 Subject: [PATCH 3/5] remove `alwaysShowWelcomePage` preference This commit removes the `alwaysShowWelcomePage` preference to allow the checkbox to toggle between the `welcomePage` (checked) and `none` (unchecked) states. This is the behavior currently present in vscode. Signed-off-by: Vlad Arama --- .../browser/getting-started-contribution.ts | 13 +---- .../getting-started-frontend-module.ts | 2 - .../browser/getting-started-preferences.ts | 58 ------------------- .../src/browser/getting-started-widget.tsx | 18 +++--- 4 files changed, 12 insertions(+), 79 deletions(-) delete mode 100644 packages/getting-started/src/browser/getting-started-preferences.ts diff --git a/packages/getting-started/src/browser/getting-started-contribution.ts b/packages/getting-started/src/browser/getting-started-contribution.ts index bfbc43e76a9c2..d97d4173b5524 100644 --- a/packages/getting-started/src/browser/getting-started-contribution.ts +++ b/packages/getting-started/src/browser/getting-started-contribution.ts @@ -81,11 +81,11 @@ export class GettingStartedContribution extends AbstractViewContribution { const roots = await this.workspaceService.roots; const readmes = await Promise.all(roots.map(async folder => { @@ -123,7 +116,7 @@ export class GettingStartedContribution extends AbstractViewContribution { @@ -29,5 +28,4 @@ export default new ContainerModule((bind: interfaces.Bind) => { id: GettingStartedWidget.ID, createWidget: () => context.container.get(GettingStartedWidget), })).inSingletonScope(); - bindGettingStartedPreferences(bind); }); diff --git a/packages/getting-started/src/browser/getting-started-preferences.ts b/packages/getting-started/src/browser/getting-started-preferences.ts deleted file mode 100644 index 18d1cc64e2cc3..0000000000000 --- a/packages/getting-started/src/browser/getting-started-preferences.ts +++ /dev/null @@ -1,58 +0,0 @@ -// ***************************************************************************** -// Copyright (C) 2023 Ericsson 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-only WITH Classpath-exception-2.0 -// ***************************************************************************** - -import { interfaces } from '@theia/core/shared/inversify'; -import { - createPreferenceProxy, - PreferenceProxy, - PreferenceService, - PreferenceSchema, - PreferenceContribution -} from '@theia/core/lib/browser/preferences'; -import { nls } from '@theia/core/lib/common/nls'; - -export const GettingStartedPreferenceSchema: PreferenceSchema = { - 'type': 'object', - properties: { - 'welcome.alwaysShowWelcomePage': { - type: 'boolean', - description: nls.localizeByDefault('Show welcome page on startup'), - default: true - } - } -}; - -export interface GettingStartedConfiguration { - 'welcome.alwaysShowWelcomePage': boolean; -} - -export const GettingStartedPreferenceContribution = Symbol('GettingStartedPreferenceContribution'); -export const GettingStartedPreferences = Symbol('GettingStartedPreferences'); -export type GettingStartedPreferences = PreferenceProxy; - -export function createGettingStartedPreferences(preferences: PreferenceService, schema: PreferenceSchema = GettingStartedPreferenceSchema): GettingStartedPreferences { - return createPreferenceProxy(preferences, schema); -} - -export function bindGettingStartedPreferences(bind: interfaces.Bind): void { - bind(GettingStartedPreferences).toDynamicValue(ctx => { - const preferences = ctx.container.get(PreferenceService); - const contribution = ctx.container.get(GettingStartedPreferenceContribution); - return createGettingStartedPreferences(preferences, contribution.schema); - }).inSingletonScope(); - bind(GettingStartedPreferenceContribution).toConstantValue({ schema: GettingStartedPreferenceSchema }); - bind(PreferenceContribution).toService(GettingStartedPreferenceContribution); -} diff --git a/packages/getting-started/src/browser/getting-started-widget.tsx b/packages/getting-started/src/browser/getting-started-widget.tsx index 4da274562f0e8..72053273f2fd9 100644 --- a/packages/getting-started/src/browser/getting-started-widget.tsx +++ b/packages/getting-started/src/browser/getting-started-widget.tsx @@ -496,32 +496,32 @@ export interface PreferencesProps { } function WelcomePreferences(props: PreferencesProps): JSX.Element { - const [alwaysShowWelcomePage, setAlwaysShowWelcomePage] = React.useState( - props.preferenceService.get('welcome.alwaysShowWelcomePage', true) + const [startupEditor, setStartupEditor] = React.useState( + props.preferenceService.get('workbench.startupEditor', 'welcomePage') ); React.useEffect(() => { const prefListener = props.preferenceService.onPreferenceChanged(change => { - if (change.preferenceName === 'welcome.alwaysShowWelcomePage') { + if (change.preferenceName === 'workbench.startupEditor') { const prefValue = change.newValue; - setAlwaysShowWelcomePage(prefValue); + setStartupEditor(prefValue); } }); return () => prefListener.dispose(); }, [props.preferenceService]); const handleChange = (e: React.ChangeEvent) => { - const newChecked = e.target.checked; - props.preferenceService.updateValue('welcome.alwaysShowWelcomePage', newChecked); + const newValue = e.target.checked ? 'welcomePage' : 'none'; + props.preferenceService.updateValue('workbench.startupEditor', newValue); }; return (
-
From 151e7df67522043bbb077fe279dda26ce1a4f501 Mon Sep 17 00:00:00 2001 From: Vlad Arama Date: Tue, 22 Aug 2023 09:25:51 -0400 Subject: [PATCH 4/5] move preferences from `core` to `getting-started` This commit addresses a few comments: - Move preferences from `@theia/core` to `@theia/getting-started` - Simplify `newUntitledFile` code to reuse the command Signed-off-by: Vlad Arama --- packages/core/src/browser/core-preferences.ts | 14 ---- .../browser/getting-started-contribution.ts | 13 ++-- .../getting-started-frontend-module.ts | 2 + .../browser/getting-started-preferences.ts | 69 +++++++++++++++++++ .../src/browser/getting-started-widget.tsx | 6 +- 5 files changed, 81 insertions(+), 23 deletions(-) create mode 100644 packages/getting-started/src/browser/getting-started-preferences.ts diff --git a/packages/core/src/browser/core-preferences.ts b/packages/core/src/browser/core-preferences.ts index 770f96cf2f1a5..1ebc24b172011 100644 --- a/packages/core/src/browser/core-preferences.ts +++ b/packages/core/src/browser/core-preferences.ts @@ -225,19 +225,6 @@ export const corePreferenceSchema: PreferenceSchema = { default: isOSX ? 1500 : 500, description: nls.localizeByDefault('Controls the delay in milliseconds after which the hover is shown.') }, - 'workbench.startupEditor': { - type: 'string', - enum: ['none', 'welcomePage', 'readme', 'newUntitledFile', 'welcomePageInEmptyWorkbench'], - enumDescriptions: [ - nls.localizeByDefault('Start without an editor.'), - nls.localize('theia/getting-started/startup-editor/welcomePage', 'Open the Welcome page, with content to aid in getting started with {0} and extensions.', FrontendApplicationConfigProvider.get().applicationName), - nls.localizeByDefault('Open the README when opening a folder that contains one, fallback to \'welcomePage\' otherwise. Note: This is only observed as a global configuration, it will be ignored if set in a workspace or folder configuration.'), - nls.localizeByDefault('Open a new untitled text file (only applies when opening an empty window).'), - nls.localizeByDefault('Open the Welcome page when opening an empty workbench.'), - ], - default: 'welcomePage', - description: nls.localizeByDefault('Controls which editor is shown at startup, if none are restored from the previous session.') - }, 'workbench.sash.hoverDelay': { type: 'number', default: 300, @@ -298,7 +285,6 @@ export interface CoreConfiguration { 'workbench.statusBar.visible': boolean; 'workbench.tree.renderIndentGuides': 'onHover' | 'none' | 'always'; 'workbench.hover.delay': number; - 'workbench.startupEditor': string; 'workbench.sash.hoverDelay': number; 'workbench.sash.size': number; 'workbench.tab.maximize': boolean; diff --git a/packages/getting-started/src/browser/getting-started-contribution.ts b/packages/getting-started/src/browser/getting-started-contribution.ts index d97d4173b5524..01f58f5020620 100644 --- a/packages/getting-started/src/browser/getting-started-contribution.ts +++ b/packages/getting-started/src/browser/getting-started-contribution.ts @@ -16,12 +16,12 @@ import { injectable, inject } from '@theia/core/shared/inversify'; import { ArrayUtils, CommandRegistry, MenuModelRegistry, UntitledResourceResolver } from '@theia/core/lib/common'; -import { CommonMenus, AbstractViewContribution, FrontendApplicationContribution, FrontendApplication, PreferenceService } from '@theia/core/lib/browser'; +import { CommonCommands, CommonMenus, AbstractViewContribution, FrontendApplicationContribution, FrontendApplication, PreferenceService } from '@theia/core/lib/browser'; import { EditorManager } from '@theia/editor/lib/browser/editor-manager'; import { GettingStartedWidget } from './getting-started-widget'; import { FileService } from '@theia/filesystem/lib/browser/file-service'; import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state'; -import { OpenerService, open } from '@theia/core/lib/browser/opener-service'; +import { OpenerService } from '@theia/core/lib/browser/opener-service'; import { PreviewContribution } from '@theia/preview/lib/browser/preview-contribution'; import { UserWorkingDirectoryProvider } from '@theia/core/lib/browser/user-working-directory-provider'; import { WorkspaceService } from '@theia/workspace/lib/browser'; @@ -37,6 +37,9 @@ export const GettingStartedCommand = { @injectable() export class GettingStartedContribution extends AbstractViewContribution implements FrontendApplicationContribution { + @inject(CommandRegistry) + protected readonly commandRegistry: CommandRegistry; + @inject(EditorManager) protected readonly editorManager: EditorManager; @@ -78,7 +81,7 @@ export class GettingStartedContribution extends AbstractViewContribution { if (this.editorManager.all.length === 0) { await this.preferenceService.ready; - const startupEditor = this.preferenceService.get('workbench.startupEditor'); + const startupEditor = this.preferenceService.get('welcome.startupEditor'); switch (startupEditor) { case 'welcomePage': this.openView({ reveal: true, activate: true }); @@ -89,9 +92,7 @@ export class GettingStartedContribution extends AbstractViewContribution { @@ -28,4 +29,5 @@ export default new ContainerModule((bind: interfaces.Bind) => { id: GettingStartedWidget.ID, createWidget: () => context.container.get(GettingStartedWidget), })).inSingletonScope(); + bindGettingStartedPreferences(bind); }); diff --git a/packages/getting-started/src/browser/getting-started-preferences.ts b/packages/getting-started/src/browser/getting-started-preferences.ts new file mode 100644 index 0000000000000..265be500c43b9 --- /dev/null +++ b/packages/getting-started/src/browser/getting-started-preferences.ts @@ -0,0 +1,69 @@ +// ***************************************************************************** +// Copyright (C) 2023 Ericsson 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-only WITH Classpath-exception-2.0 +// ***************************************************************************** + +import { interfaces } from '@theia/core/shared/inversify'; +import { + createPreferenceProxy, + PreferenceProxy, + PreferenceService, + PreferenceSchema, + PreferenceContribution +} from '@theia/core/lib/browser/preferences'; +import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider'; +import { nls } from '@theia/core/lib/common/nls'; + +export const GettingStartedPreferenceSchema: PreferenceSchema = { + 'type': 'object', + properties: { + 'welcome.startupEditor': { + type: 'string', + enum: ['none', 'welcomePage', 'readme', 'newUntitledFile', 'welcomePageInEmptyWorkbench'], + enumDescriptions: [ + nls.localizeByDefault('Start without an editor.'), + nls.localize('theia/getting-started/startup-editor/welcomePage', 'Open the Welcome page, with content to aid in getting started with {0} and extensions.', + FrontendApplicationConfigProvider.get().applicationName), + nls.localizeByDefault(`Open the README when opening a folder that contains one, fallback to \'welcomePage\' otherwise. + Note: This is only observed as a global configuration, it will be ignored if set in a workspace or folder configuration.`), + nls.localizeByDefault('Open a new untitled text file (only applies when opening an empty window).'), + nls.localizeByDefault('Open the Welcome page when opening an empty workbench.'), + ], + default: 'welcomePage', + description: nls.localizeByDefault('Controls which editor is shown at startup, if none are restored from the previous session.') + }, + } +}; + +export interface GettingStartedConfiguration { + 'welcome.startupEditor': string; +} + +export const GettingStartedPreferenceContribution = Symbol('GettingStartedPreferenceContribution'); +export const GettingStartedPreferences = Symbol('GettingStartedPreferences'); +export type GettingStartedPreferences = PreferenceProxy; + +export function createGettingStartedPreferences(preferences: PreferenceService, schema: PreferenceSchema = GettingStartedPreferenceSchema): GettingStartedPreferences { + return createPreferenceProxy(preferences, schema); +} + +export function bindGettingStartedPreferences(bind: interfaces.Bind): void { + bind(GettingStartedPreferences).toDynamicValue(ctx => { + const preferences = ctx.container.get(PreferenceService); + const contribution = ctx.container.get(GettingStartedPreferenceContribution); + return createGettingStartedPreferences(preferences, contribution.schema); + }).inSingletonScope(); + bind(GettingStartedPreferenceContribution).toConstantValue({ schema: GettingStartedPreferenceSchema }); + bind(PreferenceContribution).toService(GettingStartedPreferenceContribution); +} diff --git a/packages/getting-started/src/browser/getting-started-widget.tsx b/packages/getting-started/src/browser/getting-started-widget.tsx index 72053273f2fd9..b6576d895b7ff 100644 --- a/packages/getting-started/src/browser/getting-started-widget.tsx +++ b/packages/getting-started/src/browser/getting-started-widget.tsx @@ -497,11 +497,11 @@ export interface PreferencesProps { function WelcomePreferences(props: PreferencesProps): JSX.Element { const [startupEditor, setStartupEditor] = React.useState( - props.preferenceService.get('workbench.startupEditor', 'welcomePage') + props.preferenceService.get('welcome.startupEditor', 'welcomePage') ); React.useEffect(() => { const prefListener = props.preferenceService.onPreferenceChanged(change => { - if (change.preferenceName === 'workbench.startupEditor') { + if (change.preferenceName === 'welcome.startupEditor') { const prefValue = change.newValue; setStartupEditor(prefValue); } @@ -510,7 +510,7 @@ function WelcomePreferences(props: PreferencesProps): JSX.Element { }, [props.preferenceService]); const handleChange = (e: React.ChangeEvent) => { const newValue = e.target.checked ? 'welcomePage' : 'none'; - props.preferenceService.updateValue('workbench.startupEditor', newValue); + props.preferenceService.updateValue('welcome.startupEditor', newValue); }; return (
From c5ae16d5dd7a8f75709279b979c7cb3a6f0e2e14 Mon Sep 17 00:00:00 2001 From: Vlad Arama Date: Tue, 22 Aug 2023 14:24:08 -0400 Subject: [PATCH 5/5] address comments This commit addresses review comments by doing the following: - Remove unused injections - Use `NEW_UNTITLED_TEXT_FILE` instead of `NEW_UNTITLED_FILE` - Fix typos and align preference id with VS Code Signed-off-by: Vlad Arama --- CHANGELOG.md | 4 ++++ .../browser/getting-started-contribution.ts | 21 +++++-------------- .../browser/getting-started-preferences.ts | 4 ++-- .../src/browser/getting-started-widget.tsx | 6 +++--- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f821fc0e16a0..9e252ea0291b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ ## v1.41.0 - - [application-package] Quit Electron app when back end fails to start [#12778](https://github.com/eclipse-theia/theia/pull/12778) - Contributed on behalf of STMicroelectronics. +[Breaking Changes:](#breaking_changes_1.41.0) + +- [preferences] removed the `welcome.alwaysShowWelcomePage` preference in favor of `workbench.startupEditor`: [#12813](https://github.com/eclipse-theia/theia/pull/12813) + ## v1.40.0 - 07/27/2023 - [application-package] bumped the default supported VS Code API from `1.78.0` to `1.79.0` [#12764](https://github.com/eclipse-theia/theia/pull/12764) - Contributed on behalf of STMicroelectronics. diff --git a/packages/getting-started/src/browser/getting-started-contribution.ts b/packages/getting-started/src/browser/getting-started-contribution.ts index 01f58f5020620..b31de3b3bc2c6 100644 --- a/packages/getting-started/src/browser/getting-started-contribution.ts +++ b/packages/getting-started/src/browser/getting-started-contribution.ts @@ -15,15 +15,13 @@ // ***************************************************************************** import { injectable, inject } from '@theia/core/shared/inversify'; -import { ArrayUtils, CommandRegistry, MenuModelRegistry, UntitledResourceResolver } from '@theia/core/lib/common'; +import { ArrayUtils, CommandRegistry, MenuModelRegistry } from '@theia/core/lib/common'; import { CommonCommands, CommonMenus, AbstractViewContribution, FrontendApplicationContribution, FrontendApplication, PreferenceService } from '@theia/core/lib/browser'; import { EditorManager } from '@theia/editor/lib/browser/editor-manager'; import { GettingStartedWidget } from './getting-started-widget'; import { FileService } from '@theia/filesystem/lib/browser/file-service'; import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state'; -import { OpenerService } from '@theia/core/lib/browser/opener-service'; import { PreviewContribution } from '@theia/preview/lib/browser/preview-contribution'; -import { UserWorkingDirectoryProvider } from '@theia/core/lib/browser/user-working-directory-provider'; import { WorkspaceService } from '@theia/workspace/lib/browser'; /** @@ -46,24 +44,15 @@ export class GettingStartedContribution extends AbstractViewContribution { if (this.editorManager.all.length === 0) { await this.preferenceService.ready; - const startupEditor = this.preferenceService.get('welcome.startupEditor'); + const startupEditor = this.preferenceService.get('workbench.startupEditor'); switch (startupEditor) { case 'welcomePage': this.openView({ reveal: true, activate: true }); @@ -92,7 +81,7 @@ export class GettingStartedContribution extends AbstractViewContribution( - props.preferenceService.get('welcome.startupEditor', 'welcomePage') + props.preferenceService.get('workbench.startupEditor', 'welcomePage') ); React.useEffect(() => { const prefListener = props.preferenceService.onPreferenceChanged(change => { - if (change.preferenceName === 'welcome.startupEditor') { + if (change.preferenceName === 'workbench.startupEditor') { const prefValue = change.newValue; setStartupEditor(prefValue); } @@ -510,7 +510,7 @@ function WelcomePreferences(props: PreferencesProps): JSX.Element { }, [props.preferenceService]); const handleChange = (e: React.ChangeEvent) => { const newValue = e.target.checked ? 'welcomePage' : 'none'; - props.preferenceService.updateValue('welcome.startupEditor', newValue); + props.preferenceService.updateValue('workbench.startupEditor', newValue); }; return (