Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/preferences/browser/settingsSearchMenu.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { IActionViewItemOptions } from '../../../../base/browser/ui/actionbar/actionViewItems.js';
7
import { AnchorAlignment } from '../../../../base/browser/ui/contextview/contextview.js';
8
import { DropdownMenuActionViewItem } from '../../../../base/browser/ui/dropdown/dropdownActionViewItem.js';
9
import { IAction, IActionRunner } from '../../../../base/common/actions.js';
10
import { SuggestController } from '../../../../editor/contrib/suggest/browser/suggestController.js';
11
import { localize } from '../../../../nls.js';
12
import { IContextMenuService } from '../../../../platform/contextview/browser/contextView.js';
13
import { SuggestEnabledInput } from '../../codeEditor/browser/suggestEnabledInput/suggestEnabledInput.js';
14
import { 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';
15
16
export class SettingsSearchFilterDropdownMenuActionViewItem extends DropdownMenuActionViewItem {
17
private readonly suggestController: SuggestController | null;
18
19
constructor(
20
action: IAction,
21
options: IActionViewItemOptions,
22
actionRunner: IActionRunner | undefined,
23
private readonly searchWidget: SuggestEnabledInput,
24
@IContextMenuService contextMenuService: IContextMenuService
25
) {
26
super(action,
27
{ getActions: () => this.getActions() },
28
contextMenuService,
29
{
30
...options,
31
actionRunner,
32
classNames: action.class,
33
anchorAlignmentProvider: () => AnchorAlignment.RIGHT,
34
menuAsChild: true
35
}
36
);
37
38
this.suggestController = SuggestController.get(this.searchWidget.inputWidget);
39
}
40
41
override render(container: HTMLElement): void {
42
super.render(container);
43
}
44
45
private doSearchWidgetAction(queryToAppend: string, triggerSuggest: boolean) {
46
this.searchWidget.setValue(this.searchWidget.getValue().trimEnd() + ' ' + queryToAppend);
47
this.searchWidget.focus();
48
if (triggerSuggest && this.suggestController) {
49
this.suggestController.triggerSuggest();
50
}
51
}
52
53
/**
54
* The created action appends a query to the search widget search string. It optionally triggers suggestions.
55
*/
56
private createAction(id: string, label: string, tooltip: string, queryToAppend: string, triggerSuggest: boolean): IAction {
57
return {
58
id,
59
label,
60
tooltip,
61
class: undefined,
62
enabled: true,
63
run: () => { this.doSearchWidgetAction(queryToAppend, triggerSuggest); }
64
};
65
}
66
67
/**
68
* The created action appends a query to the search widget search string, if the query does not exist.
69
* Otherwise, it removes the query from the search widget search string.
70
* The action does not trigger suggestions after adding or removing the query.
71
*/
72
private createToggleAction(id: string, label: string, tooltip: string, queryToAppend: string): IAction {
73
const splitCurrentQuery = this.searchWidget.getValue().split(' ');
74
const queryContainsQueryToAppend = splitCurrentQuery.includes(queryToAppend);
75
return {
76
id,
77
label,
78
tooltip,
79
class: undefined,
80
enabled: true,
81
checked: queryContainsQueryToAppend,
82
run: () => {
83
if (!queryContainsQueryToAppend) {
84
const trimmedCurrentQuery = this.searchWidget.getValue().trimEnd();
85
const newQuery = trimmedCurrentQuery ? trimmedCurrentQuery + ' ' + queryToAppend : queryToAppend;
86
this.searchWidget.setValue(newQuery);
87
} else {
88
const queryWithRemovedTags = this.searchWidget.getValue().split(' ')
89
.filter(word => word !== queryToAppend).join(' ');
90
this.searchWidget.setValue(queryWithRemovedTags);
91
}
92
this.searchWidget.focus();
93
}
94
};
95
}
96
97
getActions(): IAction[] {
98
return [
99
this.createToggleAction(
100
'modifiedSettingsSearch',
101
localize('modifiedSettingsSearch', "Modified"),
102
localize('modifiedSettingsSearchTooltip', "Add or remove modified settings filter"),
103
`@${MODIFIED_SETTING_TAG}`
104
),
105
this.createAction(
106
'extSettingsSearch',
107
localize('extSettingsSearch', "Extension ID..."),
108
localize('extSettingsSearchTooltip', "Add extension ID filter"),
109
`@${EXTENSION_SETTING_TAG}`,
110
true
111
),
112
this.createAction(
113
'featuresSettingsSearch',
114
localize('featureSettingsSearch', "Feature..."),
115
localize('featureSettingsSearchTooltip', "Add feature filter"),
116
`@${FEATURE_SETTING_TAG}`,
117
true
118
),
119
this.createAction(
120
'tagSettingsSearch',
121
localize('tagSettingsSearch', "Tag..."),
122
localize('tagSettingsSearchTooltip', "Add tag filter"),
123
`@${GENERAL_TAG_SETTING_TAG}`,
124
true
125
),
126
this.createAction(
127
'langSettingsSearch',
128
localize('langSettingsSearch', "Language..."),
129
localize('langSettingsSearchTooltip', "Add language ID filter"),
130
`@${LANGUAGE_SETTING_TAG}`,
131
true
132
),
133
this.createToggleAction(
134
'onlineSettingsSearch',
135
localize('onlineSettingsSearch', "Online services"),
136
localize('onlineSettingsSearchTooltip', "Show settings for online services"),
137
'@tag:usesOnlineServices'
138
),
139
this.createToggleAction(
140
'policySettingsSearch',
141
localize('policySettingsSearch', "Policy services"),
142
localize('policySettingsSearchTooltip', "Show settings for policy services"),
143
`@${POLICY_SETTING_TAG}`
144
),
145
this.createAction(
146
'idSettingsSearch',
147
localize('idSettingsSearch', "Setting ID"),
148
localize('idSettingsSearchTooltip', "Add Setting ID filter"),
149
`@${ID_SETTING_TAG}`,
150
false
151
)
152
];
153
}
154
}
155
156