From 0149146f973e0f739facdf61cc7ef6a72190d155 Mon Sep 17 00:00:00 2001 From: Vlad Arama Date: Wed, 12 Jul 2023 08:36:15 -0400 Subject: [PATCH 1/9] search next/prev result commands and keybindings --- ...arch-in-workspace-frontend-contribution.ts | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/packages/search-in-workspace/src/browser/search-in-workspace-frontend-contribution.ts b/packages/search-in-workspace/src/browser/search-in-workspace-frontend-contribution.ts index 754c2020e434f..ed990039993bb 100644 --- a/packages/search-in-workspace/src/browser/search-in-workspace-frontend-contribution.ts +++ b/packages/search-in-workspace/src/browser/search-in-workspace-frontend-contribution.ts @@ -57,6 +57,16 @@ export namespace SearchInWorkspaceCommands { category: SEARCH_CATEGORY, label: 'Find in Folder...' }); + export const FOCUS_NEXT_RESULT = Command.toDefaultLocalizedCommand({ + id: 'search-in-workspace.next-result', + category: SEARCH_CATEGORY, + label: 'Focus Next Search Result' + }); + export const FOCUS_PREV_RESULT = Command.toDefaultLocalizedCommand({ + id: 'search-in-workspace.prev-result', + category: SEARCH_CATEGORY, + label: 'Focus Previous Search Result' + }); export const REFRESH_RESULTS = Command.toDefaultLocalizedCommand({ id: 'search-in-workspace.refresh', category: SEARCH_CATEGORY, @@ -169,6 +179,20 @@ export class SearchInWorkspaceFrontendContribution extends AbstractViewContribut } }); + commands.registerCommand(SearchInWorkspaceCommands.FOCUS_NEXT_RESULT, { + execute: async () => { + const widget = await this.openView({ activate: true }); + widget.resultTreeWidget.model.selectNextNode(); + } + }); + + commands.registerCommand(SearchInWorkspaceCommands.FOCUS_PREV_RESULT, { + execute: async () => { + const widget = await this.openView({ activate: true }); + widget.resultTreeWidget.model.selectPrevNode(); + } + }); + commands.registerCommand(SearchInWorkspaceCommands.FIND_IN_FOLDER, this.newMultiUriAwareCommandHandler({ execute: async uris => { const resources: string[] = []; @@ -343,6 +367,14 @@ export class SearchInWorkspaceFrontendContribution extends AbstractViewContribut keybinding: 'shift+alt+f', when: 'explorerResourceIsFolder' }); + keybindings.registerKeybinding({ + command: SearchInWorkspaceCommands.FOCUS_NEXT_RESULT.id, + keybinding: 'f4', + }); + keybindings.registerKeybinding({ + command: SearchInWorkspaceCommands.FOCUS_PREV_RESULT.id, + keybinding: 'shift+f4', + }); keybindings.registerKeybinding({ command: SearchInWorkspaceCommands.DISMISS_RESULT.id, keybinding: isOSX ? 'cmd+backspace' : 'del', @@ -376,9 +408,17 @@ export class SearchInWorkspaceFrontendContribution extends AbstractViewContribut order: '2' }); menus.registerMenuAction(CommonMenus.EDIT_FIND, { - commandId: SearchInWorkspaceCommands.REPLACE_IN_FILES.id, + commandId: SearchInWorkspaceCommands.FOCUS_NEXT_RESULT.id, order: '3' }); + menus.registerMenuAction(CommonMenus.EDIT_FIND, { + commandId: SearchInWorkspaceCommands.FOCUS_PREV_RESULT.id, + order: '4' + }); + menus.registerMenuAction(CommonMenus.EDIT_FIND, { + commandId: SearchInWorkspaceCommands.REPLACE_IN_FILES.id, + order: '5' + }); menus.registerMenuAction(SearchInWorkspaceResultTreeWidget.Menus.INTERNAL, { commandId: SearchInWorkspaceCommands.REPLACE_RESULT.id, label: nls.localizeByDefault('Replace'), From 67840a94f4f44ad4bcbf66e510fa4ba5d720dc1e Mon Sep 17 00:00:00 2001 From: Vlad Arama Date: Wed, 12 Jul 2023 11:20:23 -0400 Subject: [PATCH 2/9] Fix review comments and remove menu --- .../search-in-workspace-frontend-contribution.ts | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/search-in-workspace/src/browser/search-in-workspace-frontend-contribution.ts b/packages/search-in-workspace/src/browser/search-in-workspace-frontend-contribution.ts index ed990039993bb..8207e90061633 100644 --- a/packages/search-in-workspace/src/browser/search-in-workspace-frontend-contribution.ts +++ b/packages/search-in-workspace/src/browser/search-in-workspace-frontend-contribution.ts @@ -58,12 +58,12 @@ export namespace SearchInWorkspaceCommands { label: 'Find in Folder...' }); export const FOCUS_NEXT_RESULT = Command.toDefaultLocalizedCommand({ - id: 'search-in-workspace.next-result', + id: 'search-in-workspace.focusNextSearchResult', category: SEARCH_CATEGORY, label: 'Focus Next Search Result' }); export const FOCUS_PREV_RESULT = Command.toDefaultLocalizedCommand({ - id: 'search-in-workspace.prev-result', + id: 'search-in-workspace.focusPreviousSearchResult', category: SEARCH_CATEGORY, label: 'Focus Previous Search Result' }); @@ -407,17 +407,9 @@ export class SearchInWorkspaceFrontendContribution extends AbstractViewContribut commandId: SearchInWorkspaceCommands.OPEN_SIW_WIDGET.id, order: '2' }); - menus.registerMenuAction(CommonMenus.EDIT_FIND, { - commandId: SearchInWorkspaceCommands.FOCUS_NEXT_RESULT.id, - order: '3' - }); - menus.registerMenuAction(CommonMenus.EDIT_FIND, { - commandId: SearchInWorkspaceCommands.FOCUS_PREV_RESULT.id, - order: '4' - }); menus.registerMenuAction(CommonMenus.EDIT_FIND, { commandId: SearchInWorkspaceCommands.REPLACE_IN_FILES.id, - order: '5' + order: '3' }); menus.registerMenuAction(SearchInWorkspaceResultTreeWidget.Menus.INTERNAL, { commandId: SearchInWorkspaceCommands.REPLACE_RESULT.id, From abe5ff29f1d0e525effd6cd69ebcc7a8d459de58 Mon Sep 17 00:00:00 2001 From: Vlad Arama Date: Mon, 24 Jul 2023 09:41:21 -0400 Subject: [PATCH 3/9] getting-started: add welcome page preference --- .../browser/getting-started-contribution.ts | 19 ++++--- .../getting-started-frontend-module.ts | 5 +- .../browser/getting-started-preferences.ts | 32 +++++++++++ .../src/browser/getting-started-widget.tsx | 54 ++++++++++++++++++- .../src/browser/style/index.css | 13 +++++ 5 files changed, 113 insertions(+), 10 deletions(-) create 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 f3a21ca099347..bf9ec69249f89 100644 --- a/packages/getting-started/src/browser/getting-started-contribution.ts +++ b/packages/getting-started/src/browser/getting-started-contribution.ts @@ -16,10 +16,11 @@ import { injectable, inject } from '@theia/core/shared/inversify'; import { CommandRegistry, MenuModelRegistry } from '@theia/core/lib/common'; -import { CommonMenus, AbstractViewContribution, FrontendApplicationContribution, FrontendApplication } from '@theia/core/lib/browser'; +import { CommonMenus, AbstractViewContribution, FrontendApplicationContribution, FrontendApplication, PreferenceService } from '@theia/core/lib/browser'; import { GettingStartedWidget } from './getting-started-widget'; import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state'; import { WorkspaceService } from '@theia/workspace/lib/browser'; +import { WelcomePagePreferences } from './getting-started-preferences'; /** * Triggers opening the `GettingStartedWidget`. @@ -38,6 +39,9 @@ export class GettingStartedContribution extends AbstractViewContribution { - if (!this.workspaceService.opened) { - this.stateService.reachedState('ready').then( - () => this.openView({ reveal: true, activate: true }) - ); - } + this.stateService.reachedState('ready').then( + () => this.preferenceService.ready.then(() => { + const showWelcomePage: boolean = this.preferenceService.get(WelcomePagePreferences.alwaysShowWelcomePage, true); + if (showWelcomePage) { + this.openView({ reveal: true, activate: true }); + } + }) + ); } override registerCommands(registry: CommandRegistry): void { diff --git a/packages/getting-started/src/browser/getting-started-frontend-module.ts b/packages/getting-started/src/browser/getting-started-frontend-module.ts index a51e8b627f19c..4ab534c149cca 100644 --- a/packages/getting-started/src/browser/getting-started-frontend-module.ts +++ b/packages/getting-started/src/browser/getting-started-frontend-module.ts @@ -17,8 +17,8 @@ import { GettingStartedContribution } from './getting-started-contribution'; import { ContainerModule, interfaces } from '@theia/core/shared/inversify'; import { GettingStartedWidget } from './getting-started-widget'; -import { WidgetFactory, FrontendApplicationContribution, bindViewContribution } from '@theia/core/lib/browser'; - +import { WidgetFactory, FrontendApplicationContribution, bindViewContribution, PreferenceContribution } from '@theia/core/lib/browser'; +import { welcomePreferenceSchema } from './getting-started-preferences'; import '../../src/browser/style/index.css'; export default new ContainerModule((bind: interfaces.Bind) => { @@ -29,4 +29,5 @@ export default new ContainerModule((bind: interfaces.Bind) => { id: GettingStartedWidget.ID, createWidget: () => context.container.get(GettingStartedWidget), })).inSingletonScope(); + bind(PreferenceContribution).toConstantValue({ schema: welcomePreferenceSchema }); }); 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..2d1779b26ffe8 --- /dev/null +++ b/packages/getting-started/src/browser/getting-started-preferences.ts @@ -0,0 +1,32 @@ +// ***************************************************************************** +// 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 { PreferenceSchema } from '@theia/core/lib/common/preferences/preference-schema'; + +export namespace WelcomePagePreferences { + export const alwaysShowWelcomePage = 'welcome.alwaysShowWelcomePage'; +} + +export const welcomePreferenceSchema: PreferenceSchema = { + 'type': 'object', + 'properties': { + 'welcome.alwaysShowWelcomePage': { + type: 'boolean', + description: 'Show Welcome Page after every start of the application.', + default: true + } + } +}; diff --git a/packages/getting-started/src/browser/getting-started-widget.tsx b/packages/getting-started/src/browser/getting-started-widget.tsx index d468240e7db2e..15055250ccc6b 100644 --- a/packages/getting-started/src/browser/getting-started-widget.tsx +++ b/packages/getting-started/src/browser/getting-started-widget.tsx @@ -20,12 +20,13 @@ import { injectable, inject, postConstruct } from '@theia/core/shared/inversify' import { CommandRegistry, isOSX, environment, Path } from '@theia/core/lib/common'; import { WorkspaceCommands, WorkspaceService } from '@theia/workspace/lib/browser'; import { KeymapsCommands } from '@theia/keymaps/lib/browser'; -import { Message, ReactWidget, CommonCommands, LabelProvider, Key, KeyCode, codicon } from '@theia/core/lib/browser'; +import { Message, ReactWidget, CommonCommands, LabelProvider, Key, KeyCode, codicon, PreferenceService } from '@theia/core/lib/browser'; import { ApplicationInfo, ApplicationServer } from '@theia/core/lib/common/application-protocol'; import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider'; import { EnvVariablesServer } from '@theia/core/lib/common/env-variables'; import { WindowService } from '@theia/core/lib/browser/window/window-service'; import { nls } from '@theia/core/lib/common/nls'; +import { WelcomePagePreferences } from './getting-started-preferences'; /** * Default implementation of the `GettingStartedWidget`. @@ -47,7 +48,7 @@ export class GettingStartedWidget extends ReactWidget { /** * The widget `label` which is used for display purposes. */ - static readonly LABEL = nls.localizeByDefault('Get Started'); + static readonly LABEL = nls.localizeByDefault('Welcome'); /** * The `ApplicationInfo` for the application if available. @@ -97,6 +98,9 @@ export class GettingStartedWidget extends ReactWidget { @inject(WorkspaceService) protected readonly workspaceService: WorkspaceService; + @inject(PreferenceService) + protected readonly preferenceService: PreferenceService; + @postConstruct() protected init(): void { this.doInit(); @@ -154,6 +158,9 @@ export class GettingStartedWidget extends ReactWidget { {this.renderVersion()} +
+ {this.renderPreferences()} +
; } @@ -364,6 +371,10 @@ export class GettingStartedWidget extends ReactWidget { ; } + protected renderPreferences(): React.ReactNode { + return ; + } + /** * Build the list of workspace paths. * @param workspaces {string[]} the list of workspaces. @@ -478,3 +489,42 @@ export class GettingStartedWidget extends ReactWidget { return Key.ENTER.keyCode === KeyCode.createKeyCode(e.nativeEvent).key?.keyCode; } } + +export interface PreferencesProps { + preferenceService: PreferenceService; +} + +function WelcomePreferences(props: PreferencesProps): JSX.Element { + const [alwaysShowWelcomePage, setAlwaysShowWelcomePage] = React.useState( + props.preferenceService.get(WelcomePagePreferences.alwaysShowWelcomePage, true) + ); + React.useEffect(() => { + const prefListener = props.preferenceService.onPreferenceChanged(change => { + if (change.preferenceName === WelcomePagePreferences.alwaysShowWelcomePage) { + const prefValue = change.newValue; + console.info(`Set welcome.alwaysShowWelcomePage checkbox state to ${prefValue}`); + setAlwaysShowWelcomePage(prefValue); + } + }); + return () => prefListener.dispose(); + }, [props.preferenceService]); + const handleChange = (e: React.ChangeEvent) => { + const newChecked = e.target.checked; + console.info(`Set welcome.alwaysShowWelcomePage pref to ${newChecked}`); + props.preferenceService.updateValue(WelcomePagePreferences.alwaysShowWelcomePage, newChecked); + }; + return ( +
+ + +
+ ); +} diff --git a/packages/getting-started/src/browser/style/index.css b/packages/getting-started/src/browser/style/index.css index 2a23b097fdd32..a54cfbe7d0ff6 100644 --- a/packages/getting-started/src/browser/style/index.css +++ b/packages/getting-started/src/browser/style/index.css @@ -29,6 +29,10 @@ body { display: flex; } +.text-bold { + font-weight: 600; +} + .gs-action-container { line-height: 20px; } @@ -89,3 +93,12 @@ body { text-transform: capitalize; font-weight: 400; } + +.gs-preference-container { + margin-top: 20px; +} + +.gs-preference { + align-items: center; + display: flex; +} From cf3c83b45ad773043e05296a388caa85d7e6e0ef Mon Sep 17 00:00:00 2001 From: Vlad Arama Date: Mon, 24 Jul 2023 09:45:38 -0400 Subject: [PATCH 4/9] Revert "Fix review comments and remove menu" This reverts commit 67840a94f4f44ad4bcbf66e510fa4ba5d720dc1e. --- .../search-in-workspace-frontend-contribution.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/search-in-workspace/src/browser/search-in-workspace-frontend-contribution.ts b/packages/search-in-workspace/src/browser/search-in-workspace-frontend-contribution.ts index 8207e90061633..ed990039993bb 100644 --- a/packages/search-in-workspace/src/browser/search-in-workspace-frontend-contribution.ts +++ b/packages/search-in-workspace/src/browser/search-in-workspace-frontend-contribution.ts @@ -58,12 +58,12 @@ export namespace SearchInWorkspaceCommands { label: 'Find in Folder...' }); export const FOCUS_NEXT_RESULT = Command.toDefaultLocalizedCommand({ - id: 'search-in-workspace.focusNextSearchResult', + id: 'search-in-workspace.next-result', category: SEARCH_CATEGORY, label: 'Focus Next Search Result' }); export const FOCUS_PREV_RESULT = Command.toDefaultLocalizedCommand({ - id: 'search-in-workspace.focusPreviousSearchResult', + id: 'search-in-workspace.prev-result', category: SEARCH_CATEGORY, label: 'Focus Previous Search Result' }); @@ -408,9 +408,17 @@ export class SearchInWorkspaceFrontendContribution extends AbstractViewContribut order: '2' }); menus.registerMenuAction(CommonMenus.EDIT_FIND, { - commandId: SearchInWorkspaceCommands.REPLACE_IN_FILES.id, + commandId: SearchInWorkspaceCommands.FOCUS_NEXT_RESULT.id, order: '3' }); + menus.registerMenuAction(CommonMenus.EDIT_FIND, { + commandId: SearchInWorkspaceCommands.FOCUS_PREV_RESULT.id, + order: '4' + }); + menus.registerMenuAction(CommonMenus.EDIT_FIND, { + commandId: SearchInWorkspaceCommands.REPLACE_IN_FILES.id, + order: '5' + }); menus.registerMenuAction(SearchInWorkspaceResultTreeWidget.Menus.INTERNAL, { commandId: SearchInWorkspaceCommands.REPLACE_RESULT.id, label: nls.localizeByDefault('Replace'), From c9acdba6e2f4b5c53b4e8038d3607625ea108edf Mon Sep 17 00:00:00 2001 From: Vlad Arama Date: Mon, 24 Jul 2023 09:48:00 -0400 Subject: [PATCH 5/9] Revert "search next/prev result commands " This reverts commit 0149146f973e0f739facdf61cc7ef6a72190d155. --- ...arch-in-workspace-frontend-contribution.ts | 42 +------------------ 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/packages/search-in-workspace/src/browser/search-in-workspace-frontend-contribution.ts b/packages/search-in-workspace/src/browser/search-in-workspace-frontend-contribution.ts index ed990039993bb..754c2020e434f 100644 --- a/packages/search-in-workspace/src/browser/search-in-workspace-frontend-contribution.ts +++ b/packages/search-in-workspace/src/browser/search-in-workspace-frontend-contribution.ts @@ -57,16 +57,6 @@ export namespace SearchInWorkspaceCommands { category: SEARCH_CATEGORY, label: 'Find in Folder...' }); - export const FOCUS_NEXT_RESULT = Command.toDefaultLocalizedCommand({ - id: 'search-in-workspace.next-result', - category: SEARCH_CATEGORY, - label: 'Focus Next Search Result' - }); - export const FOCUS_PREV_RESULT = Command.toDefaultLocalizedCommand({ - id: 'search-in-workspace.prev-result', - category: SEARCH_CATEGORY, - label: 'Focus Previous Search Result' - }); export const REFRESH_RESULTS = Command.toDefaultLocalizedCommand({ id: 'search-in-workspace.refresh', category: SEARCH_CATEGORY, @@ -179,20 +169,6 @@ export class SearchInWorkspaceFrontendContribution extends AbstractViewContribut } }); - commands.registerCommand(SearchInWorkspaceCommands.FOCUS_NEXT_RESULT, { - execute: async () => { - const widget = await this.openView({ activate: true }); - widget.resultTreeWidget.model.selectNextNode(); - } - }); - - commands.registerCommand(SearchInWorkspaceCommands.FOCUS_PREV_RESULT, { - execute: async () => { - const widget = await this.openView({ activate: true }); - widget.resultTreeWidget.model.selectPrevNode(); - } - }); - commands.registerCommand(SearchInWorkspaceCommands.FIND_IN_FOLDER, this.newMultiUriAwareCommandHandler({ execute: async uris => { const resources: string[] = []; @@ -367,14 +343,6 @@ export class SearchInWorkspaceFrontendContribution extends AbstractViewContribut keybinding: 'shift+alt+f', when: 'explorerResourceIsFolder' }); - keybindings.registerKeybinding({ - command: SearchInWorkspaceCommands.FOCUS_NEXT_RESULT.id, - keybinding: 'f4', - }); - keybindings.registerKeybinding({ - command: SearchInWorkspaceCommands.FOCUS_PREV_RESULT.id, - keybinding: 'shift+f4', - }); keybindings.registerKeybinding({ command: SearchInWorkspaceCommands.DISMISS_RESULT.id, keybinding: isOSX ? 'cmd+backspace' : 'del', @@ -407,17 +375,9 @@ export class SearchInWorkspaceFrontendContribution extends AbstractViewContribut commandId: SearchInWorkspaceCommands.OPEN_SIW_WIDGET.id, order: '2' }); - menus.registerMenuAction(CommonMenus.EDIT_FIND, { - commandId: SearchInWorkspaceCommands.FOCUS_NEXT_RESULT.id, - order: '3' - }); - menus.registerMenuAction(CommonMenus.EDIT_FIND, { - commandId: SearchInWorkspaceCommands.FOCUS_PREV_RESULT.id, - order: '4' - }); menus.registerMenuAction(CommonMenus.EDIT_FIND, { commandId: SearchInWorkspaceCommands.REPLACE_IN_FILES.id, - order: '5' + order: '3' }); menus.registerMenuAction(SearchInWorkspaceResultTreeWidget.Menus.INTERNAL, { commandId: SearchInWorkspaceCommands.REPLACE_RESULT.id, From d1f455a1418dda0c1b477c34c5be97a92b7a206d Mon Sep 17 00:00:00 2001 From: Vlad Arama Date: Tue, 25 Jul 2023 10:41:40 -0400 Subject: [PATCH 6/9] Fix review comments and improve ui --- .../browser/getting-started-contribution.ts | 4 +- .../getting-started-frontend-module.ts | 6 +- .../browser/getting-started-preferences.ts | 11 +++- .../src/browser/getting-started-widget.tsx | 58 +++++++++---------- .../src/browser/style/index.css | 11 +++- 5 files changed, 51 insertions(+), 39 deletions(-) diff --git a/packages/getting-started/src/browser/getting-started-contribution.ts b/packages/getting-started/src/browser/getting-started-contribution.ts index bf9ec69249f89..fe433dd7584c0 100644 --- a/packages/getting-started/src/browser/getting-started-contribution.ts +++ b/packages/getting-started/src/browser/getting-started-contribution.ts @@ -20,7 +20,7 @@ import { CommonMenus, AbstractViewContribution, FrontendApplicationContribution, import { GettingStartedWidget } from './getting-started-widget'; import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state'; import { WorkspaceService } from '@theia/workspace/lib/browser'; -import { WelcomePagePreferences } from './getting-started-preferences'; +import { GettingStartedPreferences } from './getting-started-preferences'; /** * Triggers opening the `GettingStartedWidget`. @@ -55,7 +55,7 @@ export class GettingStartedContribution extends AbstractViewContribution { this.stateService.reachedState('ready').then( () => this.preferenceService.ready.then(() => { - const showWelcomePage: boolean = this.preferenceService.get(WelcomePagePreferences.alwaysShowWelcomePage, true); + const showWelcomePage: boolean = this.preferenceService.get(GettingStartedPreferences.alwaysShowWelcomePage, true); if (showWelcomePage) { this.openView({ reveal: true, activate: true }); } diff --git a/packages/getting-started/src/browser/getting-started-frontend-module.ts b/packages/getting-started/src/browser/getting-started-frontend-module.ts index 4ab534c149cca..03902723a7348 100644 --- a/packages/getting-started/src/browser/getting-started-frontend-module.ts +++ b/packages/getting-started/src/browser/getting-started-frontend-module.ts @@ -17,8 +17,8 @@ import { GettingStartedContribution } from './getting-started-contribution'; import { ContainerModule, interfaces } from '@theia/core/shared/inversify'; import { GettingStartedWidget } from './getting-started-widget'; -import { WidgetFactory, FrontendApplicationContribution, bindViewContribution, PreferenceContribution } from '@theia/core/lib/browser'; -import { welcomePreferenceSchema } from './getting-started-preferences'; +import { WidgetFactory, FrontendApplicationContribution, bindViewContribution } from '@theia/core/lib/browser'; +import { bindWelcomePreference } from './getting-started-preferences'; import '../../src/browser/style/index.css'; export default new ContainerModule((bind: interfaces.Bind) => { @@ -29,5 +29,5 @@ export default new ContainerModule((bind: interfaces.Bind) => { id: GettingStartedWidget.ID, createWidget: () => context.container.get(GettingStartedWidget), })).inSingletonScope(); - bind(PreferenceContribution).toConstantValue({ schema: welcomePreferenceSchema }); + bindWelcomePreference(bind); }); diff --git a/packages/getting-started/src/browser/getting-started-preferences.ts b/packages/getting-started/src/browser/getting-started-preferences.ts index 2d1779b26ffe8..4535a39858ca4 100644 --- a/packages/getting-started/src/browser/getting-started-preferences.ts +++ b/packages/getting-started/src/browser/getting-started-preferences.ts @@ -14,9 +14,12 @@ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 // ***************************************************************************** +import { interfaces } from '@theia/core/shared/inversify'; +import { nls } from '@theia/core/lib/common/nls'; import { PreferenceSchema } from '@theia/core/lib/common/preferences/preference-schema'; +import { PreferenceContribution } from '@theia/core/lib/browser'; -export namespace WelcomePagePreferences { +export namespace GettingStartedPreferences { export const alwaysShowWelcomePage = 'welcome.alwaysShowWelcomePage'; } @@ -25,8 +28,12 @@ export const welcomePreferenceSchema: PreferenceSchema = { 'properties': { 'welcome.alwaysShowWelcomePage': { type: 'boolean', - description: 'Show Welcome Page after every start of the application.', + description: nls.localizeByDefault('Show welcome page on startup'), default: true } } }; + +export function bindWelcomePreference(bind: interfaces.Bind): void { + bind(PreferenceContribution).toConstantValue({ schema: welcomePreferenceSchema }); +} diff --git a/packages/getting-started/src/browser/getting-started-widget.tsx b/packages/getting-started/src/browser/getting-started-widget.tsx index 15055250ccc6b..994e312b3a40e 100644 --- a/packages/getting-started/src/browser/getting-started-widget.tsx +++ b/packages/getting-started/src/browser/getting-started-widget.tsx @@ -26,7 +26,7 @@ import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/front import { EnvVariablesServer } from '@theia/core/lib/common/env-variables'; import { WindowService } from '@theia/core/lib/browser/window/window-service'; import { nls } from '@theia/core/lib/common/nls'; -import { WelcomePagePreferences } from './getting-started-preferences'; +import { GettingStartedPreferences } from './getting-started-preferences'; /** * Default implementation of the `GettingStartedWidget`. @@ -130,32 +130,34 @@ export class GettingStartedWidget extends ReactWidget { * Render the content of the widget. */ protected render(): React.ReactNode { - return
- {this.renderHeader()} -
-
-
- {this.renderOpen()} + return
+
+ {this.renderHeader()} +
+
+
+ {this.renderOpen()} +
-
-
-
- {this.renderRecentWorkspaces()} +
+
+ {this.renderRecentWorkspaces()} +
-
-
-
- {this.renderSettings()} +
+
+ {this.renderSettings()} +
-
-
-
- {this.renderHelp()} +
+
+ {this.renderHelp()} +
-
-
-
- {this.renderVersion()} +
+
+ {this.renderVersion()} +
@@ -496,13 +498,12 @@ export interface PreferencesProps { function WelcomePreferences(props: PreferencesProps): JSX.Element { const [alwaysShowWelcomePage, setAlwaysShowWelcomePage] = React.useState( - props.preferenceService.get(WelcomePagePreferences.alwaysShowWelcomePage, true) + props.preferenceService.get(GettingStartedPreferences.alwaysShowWelcomePage, true) ); React.useEffect(() => { const prefListener = props.preferenceService.onPreferenceChanged(change => { - if (change.preferenceName === WelcomePagePreferences.alwaysShowWelcomePage) { + if (change.preferenceName === GettingStartedPreferences.alwaysShowWelcomePage) { const prefValue = change.newValue; - console.info(`Set welcome.alwaysShowWelcomePage checkbox state to ${prefValue}`); setAlwaysShowWelcomePage(prefValue); } }); @@ -510,8 +511,7 @@ function WelcomePreferences(props: PreferencesProps): JSX.Element { }, [props.preferenceService]); const handleChange = (e: React.ChangeEvent) => { const newChecked = e.target.checked; - console.info(`Set welcome.alwaysShowWelcomePage pref to ${newChecked}`); - props.preferenceService.updateValue(WelcomePagePreferences.alwaysShowWelcomePage, newChecked); + props.preferenceService.updateValue(GettingStartedPreferences.alwaysShowWelcomePage, newChecked); }; return (
@@ -523,7 +523,7 @@ function WelcomePreferences(props: PreferencesProps): JSX.Element { checked={alwaysShowWelcomePage} />
); diff --git a/packages/getting-started/src/browser/style/index.css b/packages/getting-started/src/browser/style/index.css index a54cfbe7d0ff6..1cdd9e3acd93c 100644 --- a/packages/getting-started/src/browser/style/index.css +++ b/packages/getting-started/src/browser/style/index.css @@ -95,10 +95,15 @@ body { } .gs-preference-container { - margin-top: 20px; + display: flex; + position: absolute; + bottom: 0; + width: 100%; + justify-content: center; } - .gs-preference { - align-items: center; + margin-top: 20px; + margin-bottom: 20px; display: flex; + align-items: center; } From 39c3e376851dade2b649022f7203f284a0e3d468 Mon Sep 17 00:00:00 2001 From: Vlad Arama Date: Wed, 26 Jul 2023 12:41:33 -0400 Subject: [PATCH 7/9] add condition for open-editor --- .../browser/getting-started-contribution.ts | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/getting-started/src/browser/getting-started-contribution.ts b/packages/getting-started/src/browser/getting-started-contribution.ts index fe433dd7584c0..8efdc932b608c 100644 --- a/packages/getting-started/src/browser/getting-started-contribution.ts +++ b/packages/getting-started/src/browser/getting-started-contribution.ts @@ -17,10 +17,11 @@ import { injectable, inject } from '@theia/core/shared/inversify'; import { CommandRegistry, MenuModelRegistry } from '@theia/core/lib/common'; import { CommonMenus, AbstractViewContribution, FrontendApplicationContribution, FrontendApplication, PreferenceService } from '@theia/core/lib/browser'; +import { EditorManager } from '../../../editor/lib/browser'; import { GettingStartedWidget } from './getting-started-widget'; +import { GettingStartedPreferences } from './getting-started-preferences'; import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state'; import { WorkspaceService } from '@theia/workspace/lib/browser'; -import { GettingStartedPreferences } from './getting-started-preferences'; /** * Triggers opening the `GettingStartedWidget`. @@ -39,6 +40,9 @@ export class GettingStartedContribution extends AbstractViewContribution { - this.stateService.reachedState('ready').then( - () => this.preferenceService.ready.then(() => { - const showWelcomePage: boolean = this.preferenceService.get(GettingStartedPreferences.alwaysShowWelcomePage, true); - if (showWelcomePage) { - this.openView({ reveal: true, activate: true }); - } - }) - ); + this.stateService.reachedState('ready').then(() => { + const lastOpenedEditors = this.editorManager.all; + if (lastOpenedEditors.length === 0) { + this.preferenceService.ready.then(() => { + const showWelcomePage: boolean = this.preferenceService.get(GettingStartedPreferences.alwaysShowWelcomePage, true); + if (showWelcomePage) { + this.openView({ reveal: true, activate: true }); + } + }); + } + }); } override registerCommands(registry: CommandRegistry): void { From c976f1c25c081dec42ca565c3c3f29b2daad3b1d Mon Sep 17 00:00:00 2001 From: Vlad Arama Date: Wed, 26 Jul 2023 14:00:18 -0400 Subject: [PATCH 8/9] remove text bolding --- .../getting-started/src/browser/getting-started-widget.tsx | 2 +- packages/getting-started/src/browser/style/index.css | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/getting-started/src/browser/getting-started-widget.tsx b/packages/getting-started/src/browser/getting-started-widget.tsx index 994e312b3a40e..f707db5564ce5 100644 --- a/packages/getting-started/src/browser/getting-started-widget.tsx +++ b/packages/getting-started/src/browser/getting-started-widget.tsx @@ -522,7 +522,7 @@ function WelcomePreferences(props: PreferencesProps): JSX.Element { onChange={handleChange} checked={alwaysShowWelcomePage} /> -
diff --git a/packages/getting-started/src/browser/style/index.css b/packages/getting-started/src/browser/style/index.css index 1cdd9e3acd93c..9d6769163e14c 100644 --- a/packages/getting-started/src/browser/style/index.css +++ b/packages/getting-started/src/browser/style/index.css @@ -29,10 +29,6 @@ body { display: flex; } -.text-bold { - font-weight: 600; -} - .gs-action-container { line-height: 20px; } From 2e27a220baf71f41a6830797c9737968440c44a1 Mon Sep 17 00:00:00 2001 From: Vlad Arama Date: Fri, 28 Jul 2023 14:24:04 -0400 Subject: [PATCH 9/9] address comments and make schema extensible --- .../browser/getting-started-contribution.ts | 13 ++----- .../getting-started-frontend-module.ts | 4 +- .../browser/getting-started-preferences.ts | 39 ++++++++++++++----- .../src/browser/getting-started-widget.tsx | 7 ++-- .../src/browser/style/index.css | 1 + 5 files changed, 39 insertions(+), 25 deletions(-) diff --git a/packages/getting-started/src/browser/getting-started-contribution.ts b/packages/getting-started/src/browser/getting-started-contribution.ts index 8efdc932b608c..6f3d70cf1eb4f 100644 --- a/packages/getting-started/src/browser/getting-started-contribution.ts +++ b/packages/getting-started/src/browser/getting-started-contribution.ts @@ -16,10 +16,8 @@ import { injectable, inject } from '@theia/core/shared/inversify'; import { CommandRegistry, MenuModelRegistry } from '@theia/core/lib/common'; -import { CommonMenus, AbstractViewContribution, FrontendApplicationContribution, FrontendApplication, PreferenceService } from '@theia/core/lib/browser'; -import { EditorManager } from '../../../editor/lib/browser'; +import { CommonMenus, AbstractViewContribution, FrontendApplicationContribution, FrontendApplication, NavigatableWidget, PreferenceService } from '@theia/core/lib/browser'; import { GettingStartedWidget } from './getting-started-widget'; -import { GettingStartedPreferences } from './getting-started-preferences'; import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state'; import { WorkspaceService } from '@theia/workspace/lib/browser'; @@ -40,9 +38,6 @@ export class GettingStartedContribution extends AbstractViewContribution { this.stateService.reachedState('ready').then(() => { - const lastOpenedEditors = this.editorManager.all; - if (lastOpenedEditors.length === 0) { + 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(GettingStartedPreferences.alwaysShowWelcomePage, true); + const showWelcomePage: boolean = this.preferenceService.get('welcome.alwaysShowWelcomePage', true); if (showWelcomePage) { this.openView({ reveal: true, activate: true }); } diff --git a/packages/getting-started/src/browser/getting-started-frontend-module.ts b/packages/getting-started/src/browser/getting-started-frontend-module.ts index 03902723a7348..fbcc828646f02 100644 --- a/packages/getting-started/src/browser/getting-started-frontend-module.ts +++ b/packages/getting-started/src/browser/getting-started-frontend-module.ts @@ -18,7 +18,7 @@ import { GettingStartedContribution } from './getting-started-contribution'; import { ContainerModule, interfaces } from '@theia/core/shared/inversify'; import { GettingStartedWidget } from './getting-started-widget'; import { WidgetFactory, FrontendApplicationContribution, bindViewContribution } from '@theia/core/lib/browser'; -import { bindWelcomePreference } from './getting-started-preferences'; +import { bindGettingStartedPreferences } from './getting-started-preferences'; import '../../src/browser/style/index.css'; export default new ContainerModule((bind: interfaces.Bind) => { @@ -29,5 +29,5 @@ export default new ContainerModule((bind: interfaces.Bind) => { id: GettingStartedWidget.ID, createWidget: () => context.container.get(GettingStartedWidget), })).inSingletonScope(); - bindWelcomePreference(bind); + bindGettingStartedPreferences(bind); }); diff --git a/packages/getting-started/src/browser/getting-started-preferences.ts b/packages/getting-started/src/browser/getting-started-preferences.ts index 4535a39858ca4..18d1cc64e2cc3 100644 --- a/packages/getting-started/src/browser/getting-started-preferences.ts +++ b/packages/getting-started/src/browser/getting-started-preferences.ts @@ -15,17 +15,18 @@ // ***************************************************************************** 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'; -import { PreferenceSchema } from '@theia/core/lib/common/preferences/preference-schema'; -import { PreferenceContribution } from '@theia/core/lib/browser'; -export namespace GettingStartedPreferences { - export const alwaysShowWelcomePage = 'welcome.alwaysShowWelcomePage'; -} - -export const welcomePreferenceSchema: PreferenceSchema = { +export const GettingStartedPreferenceSchema: PreferenceSchema = { 'type': 'object', - 'properties': { + properties: { 'welcome.alwaysShowWelcomePage': { type: 'boolean', description: nls.localizeByDefault('Show welcome page on startup'), @@ -34,6 +35,24 @@ export const welcomePreferenceSchema: PreferenceSchema = { } }; -export function bindWelcomePreference(bind: interfaces.Bind): void { - bind(PreferenceContribution).toConstantValue({ schema: welcomePreferenceSchema }); +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 f707db5564ce5..c833471122e8e 100644 --- a/packages/getting-started/src/browser/getting-started-widget.tsx +++ b/packages/getting-started/src/browser/getting-started-widget.tsx @@ -26,7 +26,6 @@ import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/front import { EnvVariablesServer } from '@theia/core/lib/common/env-variables'; import { WindowService } from '@theia/core/lib/browser/window/window-service'; import { nls } from '@theia/core/lib/common/nls'; -import { GettingStartedPreferences } from './getting-started-preferences'; /** * Default implementation of the `GettingStartedWidget`. @@ -498,11 +497,11 @@ export interface PreferencesProps { function WelcomePreferences(props: PreferencesProps): JSX.Element { const [alwaysShowWelcomePage, setAlwaysShowWelcomePage] = React.useState( - props.preferenceService.get(GettingStartedPreferences.alwaysShowWelcomePage, true) + props.preferenceService.get('welcome.alwaysShowWelcomePage', true) ); React.useEffect(() => { const prefListener = props.preferenceService.onPreferenceChanged(change => { - if (change.preferenceName === GettingStartedPreferences.alwaysShowWelcomePage) { + if (change.preferenceName === 'welcome.alwaysShowWelcomePage') { const prefValue = change.newValue; setAlwaysShowWelcomePage(prefValue); } @@ -511,7 +510,7 @@ function WelcomePreferences(props: PreferencesProps): JSX.Element { }, [props.preferenceService]); const handleChange = (e: React.ChangeEvent) => { const newChecked = e.target.checked; - props.preferenceService.updateValue(GettingStartedPreferences.alwaysShowWelcomePage, newChecked); + props.preferenceService.updateValue('welcome.alwaysShowWelcomePage', newChecked); }; return (
diff --git a/packages/getting-started/src/browser/style/index.css b/packages/getting-started/src/browser/style/index.css index 9d6769163e14c..ba828730c4c0a 100644 --- a/packages/getting-started/src/browser/style/index.css +++ b/packages/getting-started/src/browser/style/index.css @@ -97,6 +97,7 @@ body { width: 100%; justify-content: center; } + .gs-preference { margin-top: 20px; margin-bottom: 20px;