Skip to content

Commit

Permalink
Preferences: Additional Open Preferences Commands
Browse files Browse the repository at this point in the history
What it does
- Adds `Preferences: Open User Preferences` command, which opens the
  _preferences-view_ with `User` scope.
- Adds `Preferences: Open Workspace Preferences` command, which opens
  the _preferences-view_ with `Workspace` scope.
- Modifies `Settings: Open Preferences` command to be able to accept an
  optional `query` parameter. Pre-populates the search with this query
upon opening the _preferences-view_.

How to test
1. Open the command palette and search `Preferences: Open User
Preferences` or `Preferences: Open Workspace Preferences`.
2. Execute either command and confirm that the _preferences-view_ is
opened with the correct scope.

Signed-off-by: seantan22 <[email protected]>
Signed-off-by: Colin Grant <[email protected]>

Co-authored-by: seantan22 <[email protected]>
Co-authored-by: Colin Grant <[email protected]>
  • Loading branch information
colin-grant-work and seantan22 committed Jul 28, 2021
1 parent 402a8d9 commit 3716c07
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export class PluginVscodeCommandsContribution implements CommandContribution {
execute: (prefix?: unknown) => this.quickInput.open(typeof prefix === 'string' ? prefix : '')
});
commands.registerCommand({ id: 'workbench.action.openSettings' }, {
execute: () => commands.executeCommand(CommonCommands.OPEN_PREFERENCES.id)
execute: (query?: string) => commands.executeCommand(CommonCommands.OPEN_PREFERENCES.id, query)
});
commands.registerCommand({ id: 'workbench.files.action.refreshFilesExplorer' }, {
execute: () => commands.executeCommand(FileNavigatorCommands.REFRESH_NAVIGATOR.id)
Expand Down
23 changes: 22 additions & 1 deletion packages/preferences/src/browser/preferences-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { WorkspacePreferenceProvider } from './workspace-preference-provider';
import { Preference, PreferencesCommands, PreferenceMenus } from './util/preference-types';
import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';
import { FileService } from '@theia/filesystem/lib/browser/file-service';
import { WorkspaceService } from '@theia/workspace/lib/browser';

@injectable()
export class PreferencesContribution extends AbstractViewContribution<PreferencesWidget> {
Expand All @@ -46,6 +47,7 @@ export class PreferencesContribution extends AbstractViewContribution<Preference
@inject(PreferenceService) protected readonly preferenceService: PreferenceService;
@inject(ClipboardService) protected readonly clipboardService: ClipboardService;
@inject(PreferencesWidget) protected readonly scopeTracker: PreferencesWidget;
@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService;

constructor() {
super({
Expand All @@ -59,7 +61,12 @@ export class PreferencesContribution extends AbstractViewContribution<Preference

registerCommands(commands: CommandRegistry): void {
commands.registerCommand(CommonCommands.OPEN_PREFERENCES, {
execute: () => this.openView({ activate: true }),
execute: async (query?: string) => {
const widget = await this.openView({ activate: true });
if (query) {
widget.setSearchTerm(query);
}
},
});
commands.registerCommand(PreferencesCommands.OPEN_PREFERENCES_JSON_TOOLBAR, {
isEnabled: () => true,
Expand Down Expand Up @@ -90,6 +97,20 @@ export class PreferencesContribution extends AbstractViewContribution<Preference
this.preferenceService.set(id, undefined, Number(this.scopeTracker.currentScope.scope), this.scopeTracker.currentScope.uri);
}
});
commands.registerCommand(PreferencesCommands.OPEN_USER_PREFERENCES, {
execute: async () => {
const widget = await this.openView({ activate: true });
widget.setScope(PreferenceScope.User);
}
});
commands.registerCommand(PreferencesCommands.OPEN_WORKSPACE_PREFERENCES, {
isEnabled: () => !!this.workspaceService.workspace,
isVisible: () => !!this.workspaceService.workspace,
execute: async () => {
const widget = await this.openView({ activate: true });
widget.setScope(PreferenceScope.Workspace);
}
});
}

registerMenus(menus: MenuModelRegistry): void {
Expand Down
12 changes: 12 additions & 0 deletions packages/preferences/src/browser/util/preference-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ export namespace PreferencesCommands {
id: 'preferences:copyJson.value',
label: 'Copy Setting as JSON',
};

export const OPEN_USER_PREFERENCES: Command = {
id: 'workbench.action.openGlobalSettings',
category: 'Preferences',
label: 'Open User Preferences',
};

export const OPEN_WORKSPACE_PREFERENCES: Command = {
id: 'workbench.action.openWorkspaceSettings',
category: 'Preferences',
label: 'Open Workspace Preferences',
};
}

export namespace PreferenceMenus {
Expand Down
10 changes: 9 additions & 1 deletion packages/preferences/src/browser/views/preference-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
********************************************************************************/

import { postConstruct, injectable, inject } from '@theia/core/shared/inversify';
import { Panel, Widget, Message, StatefulWidget } from '@theia/core/lib/browser';
import { Panel, Widget, Message, StatefulWidget, PreferenceScope } from '@theia/core/lib/browser';
import { PreferencesEditorState, PreferencesEditorWidget } from './preference-editor-widget';
import { PreferencesTreeWidget } from './preference-tree-widget';
import { PreferencesSearchbarState, PreferencesSearchbarWidget } from './preference-searchbar-widget';
Expand Down Expand Up @@ -48,6 +48,14 @@ export class PreferencesWidget extends Panel implements StatefulWidget {
return this.tabBarWidget.currentScope;
}

setSearchTerm(query: string): void {
this.searchbarWidget.updateSearchTerm(query);
}

setScope(scope: PreferenceScope.User | PreferenceScope.Workspace): void {
this.tabBarWidget.setScope(scope);
}

protected onResize(msg: Widget.ResizeMessage): void {
super.onResize(msg);
if (msg.width < 600 && this.treeWidget && !this.treeWidget.isHidden) {
Expand Down

0 comments on commit 3716c07

Please sign in to comment.