Path: blob/main/src/vs/workbench/contrib/preferences/browser/settingsSearchMenu.ts
5270 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { IActionViewItemOptions } from '../../../../base/browser/ui/actionbar/actionViewItems.js';6import { AnchorAlignment } from '../../../../base/browser/ui/contextview/contextview.js';7import { DropdownMenuActionViewItem } from '../../../../base/browser/ui/dropdown/dropdownActionViewItem.js';8import { IAction, IActionRunner, Separator } from '../../../../base/common/actions.js';9import { SuggestController } from '../../../../editor/contrib/suggest/browser/suggestController.js';10import { localize } from '../../../../nls.js';11import { IContextMenuService } from '../../../../platform/contextview/browser/contextView.js';12import { SuggestEnabledInput } from '../../codeEditor/browser/suggestEnabledInput/suggestEnabledInput.js';13import { ADVANCED_SETTING_TAG, EXTENSION_SETTING_TAG, FEATURE_SETTING_TAG, GENERAL_TAG_SETTING_TAG, ID_SETTING_TAG, LANGUAGE_SETTING_TAG, MODIFIED_SETTING_TAG, POLICY_SETTING_TAG } from '../common/preferences.js';1415export class SettingsSearchFilterDropdownMenuActionViewItem extends DropdownMenuActionViewItem {16private readonly suggestController: SuggestController | null;1718constructor(19action: IAction,20options: IActionViewItemOptions,21actionRunner: IActionRunner | undefined,22private readonly searchWidget: SuggestEnabledInput,23@IContextMenuService contextMenuService: IContextMenuService24) {25super(action,26{ getActions: () => this.getActions() },27contextMenuService,28{29...options,30actionRunner,31classNames: action.class,32anchorAlignmentProvider: () => AnchorAlignment.RIGHT,33menuAsChild: true34}35);3637this.suggestController = SuggestController.get(this.searchWidget.inputWidget);38}3940override render(container: HTMLElement): void {41super.render(container);42}4344private doSearchWidgetAction(queryToAppend: string, triggerSuggest: boolean) {45this.searchWidget.setValue(this.searchWidget.getValue().trimEnd() + ' ' + queryToAppend);46this.searchWidget.focus();47if (triggerSuggest && this.suggestController) {48this.suggestController.triggerSuggest();49}50}5152/**53* The created action appends a query to the search widget search string. It optionally triggers suggestions.54*/55private createAction(id: string, label: string, tooltip: string, queryToAppend: string, triggerSuggest: boolean): IAction {56return {57id,58label,59tooltip,60class: undefined,61enabled: true,62run: () => { this.doSearchWidgetAction(queryToAppend, triggerSuggest); }63};64}6566/**67* The created action appends a query to the search widget search string, if the query does not exist.68* Otherwise, it removes the query from the search widget search string.69* The action does not trigger suggestions after adding or removing the query.70*/71private createToggleAction(id: string, label: string, tooltip: string, queryToAppend: string): IAction {72const splitCurrentQuery = this.searchWidget.getValue().split(' ');73const queryContainsQueryToAppend = splitCurrentQuery.includes(queryToAppend);74return {75id,76label,77tooltip,78class: undefined,79enabled: true,80checked: queryContainsQueryToAppend,81run: () => {82if (!queryContainsQueryToAppend) {83const trimmedCurrentQuery = this.searchWidget.getValue().trimEnd();84const newQuery = trimmedCurrentQuery ? trimmedCurrentQuery + ' ' + queryToAppend : queryToAppend;85this.searchWidget.setValue(newQuery);86} else {87const queryWithRemovedTags = this.searchWidget.getValue().split(' ')88.filter(word => word !== queryToAppend).join(' ');89this.searchWidget.setValue(queryWithRemovedTags);90}91this.searchWidget.focus();92}93};94}9596private createMutuallyExclusiveToggleAction(id: string, label: string, tooltip: string, filter: string, excludeFilters: string[]): IAction {97const isFilterEnabled = this.searchWidget.getValue().split(' ').includes(filter);98return {99id,100label,101tooltip,102class: undefined,103enabled: true,104checked: isFilterEnabled,105run: () => {106if (isFilterEnabled) {107const queryWithRemovedTags = this.searchWidget.getValue().split(' ')108.filter(word => word !== filter).join(' ');109this.searchWidget.setValue(queryWithRemovedTags);110} else {111let newQuery = this.searchWidget.getValue().split(' ')112.filter(word => !excludeFilters.includes(word) && word !== filter)113.join(' ')114.trimEnd();115newQuery = newQuery ? newQuery + ' ' + filter : filter;116this.searchWidget.setValue(newQuery);117}118this.searchWidget.focus();119}120};121}122123getActions(): IAction[] {124return [125this.createToggleAction(126'modifiedSettingsSearch',127localize('modifiedSettingsSearch', "Modified"),128localize('modifiedSettingsSearchTooltip', "Add or remove modified settings filter"),129`@${MODIFIED_SETTING_TAG}`130),131new Separator(),132this.createAction(133'extSettingsSearch',134localize('extSettingsSearch', "Extension ID..."),135localize('extSettingsSearchTooltip', "Add extension ID filter"),136`@${EXTENSION_SETTING_TAG}`,137true138),139this.createAction(140'featuresSettingsSearch',141localize('featureSettingsSearch', "Feature..."),142localize('featureSettingsSearchTooltip', "Add feature filter"),143`@${FEATURE_SETTING_TAG}`,144true145),146this.createAction(147'tagSettingsSearch',148localize('tagSettingsSearch', "Tag..."),149localize('tagSettingsSearchTooltip', "Add tag filter"),150`@${GENERAL_TAG_SETTING_TAG}`,151true152),153this.createAction(154'langSettingsSearch',155localize('langSettingsSearch', "Language..."),156localize('langSettingsSearchTooltip', "Add language ID filter"),157`@${LANGUAGE_SETTING_TAG}`,158true159),160this.createAction(161'idSettingsSearch',162localize('idSettingsSearch', "Setting ID..."),163localize('idSettingsSearchTooltip', "Add Setting ID filter"),164`@${ID_SETTING_TAG}`,165false166),167new Separator(),168this.createToggleAction(169'onlineSettingsSearch',170localize('onlineSettingsSearch', "Online services"),171localize('onlineSettingsSearchTooltip', "Show settings for online services"),172'@tag:usesOnlineServices'173),174this.createToggleAction(175'policySettingsSearch',176localize('policySettingsSearch', "Organization policies"),177localize('policySettingsSearchTooltip', "Show organization policy settings"),178`@${POLICY_SETTING_TAG}`179),180new Separator(),181this.createMutuallyExclusiveToggleAction(182'stableSettingsSearch',183localize('stableSettings', "Stable"),184localize('stableSettingsSearchTooltip', "Show stable settings"),185`@stable`,186['@tag:preview', '@tag:experimental']187),188this.createMutuallyExclusiveToggleAction(189'previewSettingsSearch',190localize('previewSettings', "Preview"),191localize('previewSettingsSearchTooltip', "Show preview settings"),192`@tag:preview`,193['@stable', '@tag:experimental']194),195this.createMutuallyExclusiveToggleAction(196'experimentalSettingsSearch',197localize('experimental', "Experimental"),198localize('experimentalSettingsSearchTooltip', "Show experimental settings"),199`@tag:experimental`,200['@stable', '@tag:preview']201),202new Separator(),203this.createToggleAction(204'advancedSettingsSearch',205localize('advancedSettingsSearch', "Advanced"),206localize('advancedSettingsSearchTooltip', "Show advanced settings"),207`@tag:${ADVANCED_SETTING_TAG}`,208),209];210}211}212213214