@theia/preferences 1.34.1 → 1.34.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/LICENSE +641 -641
  2. package/README.md +81 -81
  3. package/lib/browser/abstract-resource-preference-provider.d.ts +46 -46
  4. package/lib/browser/abstract-resource-preference-provider.js +237 -237
  5. package/lib/browser/abstract-resource-preference-provider.spec.d.ts +1 -1
  6. package/lib/browser/abstract-resource-preference-provider.spec.js +83 -83
  7. package/lib/browser/folder-preference-provider.d.ts +20 -20
  8. package/lib/browser/folder-preference-provider.js +59 -59
  9. package/lib/browser/folders-preferences-provider.d.ts +25 -25
  10. package/lib/browser/folders-preferences-provider.js +239 -239
  11. package/lib/browser/index.d.ts +7 -7
  12. package/lib/browser/index.js +34 -34
  13. package/lib/browser/monaco-jsonc-editor.d.ts +9 -9
  14. package/lib/browser/monaco-jsonc-editor.js +80 -80
  15. package/lib/browser/package.spec.js +25 -25
  16. package/lib/browser/preference-bindings.d.ts +4 -4
  17. package/lib/browser/preference-bindings.js +63 -63
  18. package/lib/browser/preference-frontend-module.d.ts +6 -6
  19. package/lib/browser/preference-frontend-module.js +52 -52
  20. package/lib/browser/preference-open-handler.d.ts +9 -9
  21. package/lib/browser/preference-open-handler.js +64 -64
  22. package/lib/browser/preference-transaction-manager.d.ts +98 -98
  23. package/lib/browser/preference-transaction-manager.js +295 -295
  24. package/lib/browser/preference-tree-model.d.ts +59 -59
  25. package/lib/browser/preference-tree-model.js +240 -240
  26. package/lib/browser/preferences-contribution.d.ts +37 -37
  27. package/lib/browser/preferences-contribution.js +279 -279
  28. package/lib/browser/preferences-json-schema-contribution.d.ts +17 -17
  29. package/lib/browser/preferences-json-schema-contribution.js +91 -91
  30. package/lib/browser/preferences-monaco-contribution.d.ts +1 -1
  31. package/lib/browser/preferences-monaco-contribution.js +30 -30
  32. package/lib/browser/section-preference-provider.d.ts +21 -21
  33. package/lib/browser/section-preference-provider.js +96 -96
  34. package/lib/browser/user-configs-preference-provider.d.ts +21 -21
  35. package/lib/browser/user-configs-preference-provider.js +134 -134
  36. package/lib/browser/user-preference-provider.d.ts +13 -13
  37. package/lib/browser/user-preference-provider.js +41 -41
  38. package/lib/browser/util/preference-scope-command-manager.d.ts +17 -17
  39. package/lib/browser/util/preference-scope-command-manager.js +87 -87
  40. package/lib/browser/util/preference-tree-generator.d.ts +30 -30
  41. package/lib/browser/util/preference-tree-generator.js +234 -234
  42. package/lib/browser/util/preference-tree-label-provider.d.ts +11 -11
  43. package/lib/browser/util/preference-tree-label-provider.js +77 -77
  44. package/lib/browser/util/preference-tree-label-provider.spec.d.ts +1 -1
  45. package/lib/browser/util/preference-tree-label-provider.spec.js +87 -87
  46. package/lib/browser/util/preference-types.d.ts +62 -62
  47. package/lib/browser/util/preference-types.js +128 -128
  48. package/lib/browser/views/components/preference-array-input.d.ts +28 -28
  49. package/lib/browser/views/components/preference-array-input.js +180 -180
  50. package/lib/browser/views/components/preference-boolean-input.d.ts +17 -17
  51. package/lib/browser/views/components/preference-boolean-input.js +79 -79
  52. package/lib/browser/views/components/preference-file-input.d.ts +29 -29
  53. package/lib/browser/views/components/preference-file-input.js +110 -110
  54. package/lib/browser/views/components/preference-json-input.d.ts +19 -19
  55. package/lib/browser/views/components/preference-json-input.js +93 -93
  56. package/lib/browser/views/components/preference-node-renderer-creator.d.ts +48 -48
  57. package/lib/browser/views/components/preference-node-renderer-creator.js +132 -132
  58. package/lib/browser/views/components/preference-node-renderer.d.ts +111 -111
  59. package/lib/browser/views/components/preference-node-renderer.js +460 -460
  60. package/lib/browser/views/components/preference-number-input.d.ts +34 -34
  61. package/lib/browser/views/components/preference-number-input.js +142 -142
  62. package/lib/browser/views/components/preference-select-input.d.ts +27 -27
  63. package/lib/browser/views/components/preference-select-input.js +135 -135
  64. package/lib/browser/views/components/preference-string-input.d.ts +17 -17
  65. package/lib/browser/views/components/preference-string-input.js +89 -89
  66. package/lib/browser/views/preference-editor-widget.d.ts +67 -67
  67. package/lib/browser/views/preference-editor-widget.js +376 -376
  68. package/lib/browser/views/preference-scope-tabbar-widget.d.ts +54 -54
  69. package/lib/browser/views/preference-scope-tabbar-widget.js +343 -343
  70. package/lib/browser/views/preference-searchbar-widget.d.ts +53 -53
  71. package/lib/browser/views/preference-searchbar-widget.js +173 -173
  72. package/lib/browser/views/preference-tree-widget.d.ts +17 -17
  73. package/lib/browser/views/preference-tree-widget.js +104 -104
  74. package/lib/browser/views/preference-widget-bindings.d.ts +3 -3
  75. package/lib/browser/views/preference-widget-bindings.js +85 -85
  76. package/lib/browser/views/preference-widget.d.ts +35 -35
  77. package/lib/browser/views/preference-widget.js +123 -123
  78. package/lib/browser/workspace-file-preference-provider.d.ts +23 -23
  79. package/lib/browser/workspace-file-preference-provider.js +110 -110
  80. package/lib/browser/workspace-preference-provider.d.ts +28 -28
  81. package/lib/browser/workspace-preference-provider.js +142 -142
  82. package/package.json +9 -9
  83. package/src/browser/abstract-resource-preference-provider.spec.ts +95 -95
  84. package/src/browser/abstract-resource-preference-provider.ts +228 -228
  85. package/src/browser/folder-preference-provider.ts +58 -58
  86. package/src/browser/folders-preferences-provider.ts +236 -236
  87. package/src/browser/index.ts +23 -23
  88. package/src/browser/monaco-jsonc-editor.ts +67 -67
  89. package/src/browser/package.spec.ts +28 -28
  90. package/src/browser/preference-bindings.ts +65 -65
  91. package/src/browser/preference-frontend-module.ts +57 -57
  92. package/src/browser/preference-open-handler.ts +53 -53
  93. package/src/browser/preference-transaction-manager.ts +283 -283
  94. package/src/browser/preference-tree-model.ts +246 -246
  95. package/src/browser/preferences-contribution.ts +263 -263
  96. package/src/browser/preferences-json-schema-contribution.ts +86 -86
  97. package/src/browser/preferences-monaco-contribution.ts +30 -30
  98. package/src/browser/section-preference-provider.ts +83 -83
  99. package/src/browser/style/index.css +456 -456
  100. package/src/browser/style/preference-array.css +90 -90
  101. package/src/browser/style/preference-context-menu.css +74 -74
  102. package/src/browser/style/preference-file.css +32 -32
  103. package/src/browser/style/preference-object.css +49 -49
  104. package/src/browser/style/search-input.css +66 -66
  105. package/src/browser/user-configs-preference-provider.ts +123 -123
  106. package/src/browser/user-preference-provider.ts +35 -35
  107. package/src/browser/util/preference-scope-command-manager.ts +75 -75
  108. package/src/browser/util/preference-tree-generator.ts +222 -222
  109. package/src/browser/util/preference-tree-label-provider.spec.ts +108 -108
  110. package/src/browser/util/preference-tree-label-provider.ts +64 -64
  111. package/src/browser/util/preference-types.ts +169 -169
  112. package/src/browser/views/components/preference-array-input.ts +174 -174
  113. package/src/browser/views/components/preference-boolean-input.ts +69 -69
  114. package/src/browser/views/components/preference-file-input.ts +104 -104
  115. package/src/browser/views/components/preference-json-input.ts +78 -78
  116. package/src/browser/views/components/preference-node-renderer-creator.ts +141 -141
  117. package/src/browser/views/components/preference-node-renderer.ts +499 -499
  118. package/src/browser/views/components/preference-number-input.ts +147 -147
  119. package/src/browser/views/components/preference-select-input.ts +127 -127
  120. package/src/browser/views/components/preference-string-input.ts +76 -76
  121. package/src/browser/views/preference-editor-widget.ts +361 -361
  122. package/src/browser/views/preference-scope-tabbar-widget.tsx +344 -344
  123. package/src/browser/views/preference-searchbar-widget.tsx +183 -183
  124. package/src/browser/views/preference-tree-widget.tsx +93 -93
  125. package/src/browser/views/preference-widget-bindings.ts +99 -99
  126. package/src/browser/views/preference-widget.tsx +113 -113
  127. package/src/browser/workspace-file-preference-provider.ts +100 -100
  128. package/src/browser/workspace-preference-provider.ts +134 -134
@@ -1,38 +1,38 @@
1
- import { MenuModelRegistry, CommandRegistry } from '@theia/core';
2
- import { AbstractViewContribution, KeybindingRegistry, Widget, PreferenceScope, PreferenceService, QuickInputService, PreferenceSchemaProvider } from '@theia/core/lib/browser';
3
- import { TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
4
- import { EditorManager } from '@theia/editor/lib/browser';
5
- import { PreferencesWidget } from './views/preference-widget';
6
- import { WorkspacePreferenceProvider } from './workspace-preference-provider';
7
- import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';
8
- import { FileService } from '@theia/filesystem/lib/browser/file-service';
9
- import { WorkspaceService } from '@theia/workspace/lib/browser';
10
- import { FileStat } from '@theia/filesystem/lib/common/files';
11
- export declare class PreferencesContribution extends AbstractViewContribution<PreferencesWidget> {
12
- protected readonly fileService: FileService;
13
- protected readonly workspacePreferenceProvider: WorkspacePreferenceProvider;
14
- protected readonly editorManager: EditorManager;
15
- protected readonly preferenceService: PreferenceService;
16
- protected readonly clipboardService: ClipboardService;
17
- protected readonly scopeTracker: PreferencesWidget;
18
- protected readonly workspaceService: WorkspaceService;
19
- protected readonly quickInputService: QuickInputService;
20
- protected readonly schema: PreferenceSchemaProvider;
21
- constructor();
22
- registerCommands(commands: CommandRegistry): void;
23
- registerMenus(menus: MenuModelRegistry): void;
24
- registerKeybindings(keybindings: KeybindingRegistry): void;
25
- registerToolbarItems(toolbar: TabBarToolbarRegistry): void;
26
- protected openPreferencesJSON(opener: string | PreferencesWidget): Promise<void>;
27
- protected openJson(scope: PreferenceScope, resource?: string): Promise<void>;
28
- /**
29
- * Prompts which workspace root folder to open the JSON settings.
30
- */
31
- protected openFolderPreferences(callback: (root: FileStat) => unknown): Promise<void>;
32
- private obtainConfigUri;
33
- /**
34
- * Determine if the current widget is the PreferencesWidget.
35
- */
36
- protected withWidget<T>(widget: Widget | undefined, fn: (widget: PreferencesWidget) => T): T | false;
37
- }
1
+ import { MenuModelRegistry, CommandRegistry } from '@theia/core';
2
+ import { AbstractViewContribution, KeybindingRegistry, Widget, PreferenceScope, PreferenceService, QuickInputService, PreferenceSchemaProvider } from '@theia/core/lib/browser';
3
+ import { TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
4
+ import { EditorManager } from '@theia/editor/lib/browser';
5
+ import { PreferencesWidget } from './views/preference-widget';
6
+ import { WorkspacePreferenceProvider } from './workspace-preference-provider';
7
+ import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';
8
+ import { FileService } from '@theia/filesystem/lib/browser/file-service';
9
+ import { WorkspaceService } from '@theia/workspace/lib/browser';
10
+ import { FileStat } from '@theia/filesystem/lib/common/files';
11
+ export declare class PreferencesContribution extends AbstractViewContribution<PreferencesWidget> {
12
+ protected readonly fileService: FileService;
13
+ protected readonly workspacePreferenceProvider: WorkspacePreferenceProvider;
14
+ protected readonly editorManager: EditorManager;
15
+ protected readonly preferenceService: PreferenceService;
16
+ protected readonly clipboardService: ClipboardService;
17
+ protected readonly scopeTracker: PreferencesWidget;
18
+ protected readonly workspaceService: WorkspaceService;
19
+ protected readonly quickInputService: QuickInputService;
20
+ protected readonly schema: PreferenceSchemaProvider;
21
+ constructor();
22
+ registerCommands(commands: CommandRegistry): void;
23
+ registerMenus(menus: MenuModelRegistry): void;
24
+ registerKeybindings(keybindings: KeybindingRegistry): void;
25
+ registerToolbarItems(toolbar: TabBarToolbarRegistry): void;
26
+ protected openPreferencesJSON(opener: string | PreferencesWidget): Promise<void>;
27
+ protected openJson(scope: PreferenceScope, resource?: string): Promise<void>;
28
+ /**
29
+ * Prompts which workspace root folder to open the JSON settings.
30
+ */
31
+ protected openFolderPreferences(callback: (root: FileStat) => unknown): Promise<void>;
32
+ private obtainConfigUri;
33
+ /**
34
+ * Determine if the current widget is the PreferencesWidget.
35
+ */
36
+ protected withWidget<T>(widget: Widget | undefined, fn: (widget: PreferencesWidget) => T): T | false;
37
+ }
38
38
  //# sourceMappingURL=preferences-contribution.d.ts.map
@@ -1,280 +1,280 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2018 Ericsson and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
- return c > 3 && r && Object.defineProperty(target, key, r), r;
22
- };
23
- var __metadata = (this && this.__metadata) || function (k, v) {
24
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
- };
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.PreferencesContribution = void 0;
28
- const inversify_1 = require("@theia/core/shared/inversify");
29
- const browser_1 = require("@theia/core/lib/browser");
30
- const os_1 = require("@theia/core/lib/common/os");
31
- const browser_2 = require("@theia/editor/lib/browser");
32
- const preference_widget_1 = require("./views/preference-widget");
33
- const workspace_preference_provider_1 = require("./workspace-preference-provider");
34
- const preference_types_1 = require("./util/preference-types");
35
- const clipboard_service_1 = require("@theia/core/lib/browser/clipboard-service");
36
- const file_service_1 = require("@theia/filesystem/lib/browser/file-service");
37
- const browser_3 = require("@theia/workspace/lib/browser");
38
- let PreferencesContribution = class PreferencesContribution extends browser_1.AbstractViewContribution {
39
- constructor() {
40
- super({
41
- widgetId: preference_widget_1.PreferencesWidget.ID,
42
- widgetName: preference_widget_1.PreferencesWidget.LABEL,
43
- defaultWidgetOptions: {
44
- area: 'main',
45
- },
46
- });
47
- }
48
- registerCommands(commands) {
49
- commands.registerCommand(browser_1.CommonCommands.OPEN_PREFERENCES, {
50
- execute: async (query) => {
51
- const widget = await this.openView({ activate: true });
52
- if (typeof query === 'string') {
53
- widget.setSearchTerm(query);
54
- }
55
- },
56
- });
57
- commands.registerCommand(preference_types_1.PreferencesCommands.OPEN_PREFERENCES_JSON_TOOLBAR, {
58
- isEnabled: () => true,
59
- isVisible: w => this.withWidget(w, () => true),
60
- execute: (preferenceId) => {
61
- this.openPreferencesJSON(preferenceId);
62
- }
63
- });
64
- commands.registerCommand(preference_types_1.PreferencesCommands.COPY_JSON_NAME, {
65
- isEnabled: preference_types_1.Preference.EditorCommandArgs.is,
66
- isVisible: preference_types_1.Preference.EditorCommandArgs.is,
67
- execute: ({ id, value }) => {
68
- this.clipboardService.writeText(id);
69
- }
70
- });
71
- commands.registerCommand(preference_types_1.PreferencesCommands.COPY_JSON_VALUE, {
72
- isEnabled: preference_types_1.Preference.EditorCommandArgs.is,
73
- isVisible: preference_types_1.Preference.EditorCommandArgs.is,
74
- execute: ({ id, value }) => {
75
- const jsonString = `"${id}": ${JSON.stringify(value)}`;
76
- this.clipboardService.writeText(jsonString);
77
- }
78
- });
79
- commands.registerCommand(preference_types_1.PreferencesCommands.RESET_PREFERENCE, {
80
- isEnabled: preference_types_1.Preference.EditorCommandArgs.is,
81
- isVisible: preference_types_1.Preference.EditorCommandArgs.is,
82
- execute: ({ id }) => {
83
- this.preferenceService.set(id, undefined, Number(this.scopeTracker.currentScope.scope), this.scopeTracker.currentScope.uri);
84
- }
85
- });
86
- commands.registerCommand(preference_types_1.PreferencesCommands.OPEN_USER_PREFERENCES, {
87
- execute: async () => {
88
- const widget = await this.openView({ activate: true });
89
- widget.setScope(browser_1.PreferenceScope.User);
90
- }
91
- });
92
- commands.registerCommand(preference_types_1.PreferencesCommands.OPEN_WORKSPACE_PREFERENCES, {
93
- isEnabled: () => !!this.workspaceService.workspace,
94
- isVisible: () => !!this.workspaceService.workspace,
95
- execute: async () => {
96
- const widget = await this.openView({ activate: true });
97
- widget.setScope(browser_1.PreferenceScope.Workspace);
98
- }
99
- });
100
- commands.registerCommand(preference_types_1.PreferencesCommands.OPEN_FOLDER_PREFERENCES, {
101
- isEnabled: () => !!this.workspaceService.isMultiRootWorkspaceOpened && this.workspaceService.tryGetRoots().length > 0,
102
- isVisible: () => !!this.workspaceService.isMultiRootWorkspaceOpened && this.workspaceService.tryGetRoots().length > 0,
103
- execute: () => this.openFolderPreferences(root => {
104
- this.openView({ activate: true });
105
- this.scopeTracker.setScope(root.resource);
106
- })
107
- });
108
- commands.registerCommand(preference_types_1.PreferencesCommands.OPEN_USER_PREFERENCES_JSON, {
109
- execute: async () => this.openJson(browser_1.PreferenceScope.User)
110
- });
111
- commands.registerCommand(preference_types_1.PreferencesCommands.OPEN_WORKSPACE_PREFERENCES_JSON, {
112
- isEnabled: () => !!this.workspaceService.workspace,
113
- isVisible: () => !!this.workspaceService.workspace,
114
- execute: async () => this.openJson(browser_1.PreferenceScope.Workspace)
115
- });
116
- commands.registerCommand(preference_types_1.PreferencesCommands.OPEN_FOLDER_PREFERENCES_JSON, {
117
- isEnabled: () => !!this.workspaceService.isMultiRootWorkspaceOpened && this.workspaceService.tryGetRoots().length > 0,
118
- isVisible: () => !!this.workspaceService.isMultiRootWorkspaceOpened && this.workspaceService.tryGetRoots().length > 0,
119
- execute: () => this.openFolderPreferences(root => this.openJson(browser_1.PreferenceScope.Folder, root.resource.toString()))
120
- });
121
- }
122
- registerMenus(menus) {
123
- menus.registerMenuAction(browser_1.CommonMenus.FILE_SETTINGS_SUBMENU_OPEN, {
124
- commandId: browser_1.CommonCommands.OPEN_PREFERENCES.id,
125
- label: browser_1.CommonCommands.OPEN_PREFERENCES.label,
126
- order: 'a10',
127
- });
128
- menus.registerMenuAction(browser_1.CommonMenus.SETTINGS_OPEN, {
129
- commandId: browser_1.CommonCommands.OPEN_PREFERENCES.id,
130
- label: browser_1.CommonCommands.OPEN_PREFERENCES.label,
131
- order: 'a10',
132
- });
133
- menus.registerMenuAction(preference_types_1.PreferenceMenus.PREFERENCE_EDITOR_CONTEXT_MENU, {
134
- commandId: preference_types_1.PreferencesCommands.RESET_PREFERENCE.id,
135
- label: preference_types_1.PreferencesCommands.RESET_PREFERENCE.label,
136
- order: 'a'
137
- });
138
- menus.registerMenuAction(preference_types_1.PreferenceMenus.PREFERENCE_EDITOR_COPY_ACTIONS, {
139
- commandId: preference_types_1.PreferencesCommands.COPY_JSON_VALUE.id,
140
- label: preference_types_1.PreferencesCommands.COPY_JSON_VALUE.label,
141
- order: 'b'
142
- });
143
- menus.registerMenuAction(preference_types_1.PreferenceMenus.PREFERENCE_EDITOR_COPY_ACTIONS, {
144
- commandId: preference_types_1.PreferencesCommands.COPY_JSON_NAME.id,
145
- label: preference_types_1.PreferencesCommands.COPY_JSON_NAME.label,
146
- order: 'c'
147
- });
148
- }
149
- registerKeybindings(keybindings) {
150
- keybindings.registerKeybinding({
151
- command: browser_1.CommonCommands.OPEN_PREFERENCES.id,
152
- keybinding: (os_1.isOSX && !browser_1.isFirefox) ? 'cmd+,' : 'ctrl+,'
153
- });
154
- }
155
- registerToolbarItems(toolbar) {
156
- toolbar.registerItem({
157
- id: preference_types_1.PreferencesCommands.OPEN_PREFERENCES_JSON_TOOLBAR.id,
158
- command: preference_types_1.PreferencesCommands.OPEN_PREFERENCES_JSON_TOOLBAR.id,
159
- tooltip: preference_types_1.PreferencesCommands.OPEN_USER_PREFERENCES_JSON.label,
160
- priority: 0,
161
- });
162
- }
163
- async openPreferencesJSON(opener) {
164
- var _a;
165
- const { scope, activeScopeIsFolder, uri } = this.scopeTracker.currentScope;
166
- const scopeID = Number(scope);
167
- let preferenceId = '';
168
- if (typeof opener === 'string') {
169
- preferenceId = opener;
170
- const currentPreferenceValue = this.preferenceService.inspect(preferenceId, uri);
171
- const valueInCurrentScope = (_a = preference_types_1.Preference.getValueInScope(currentPreferenceValue, scopeID)) !== null && _a !== void 0 ? _a : currentPreferenceValue === null || currentPreferenceValue === void 0 ? void 0 : currentPreferenceValue.defaultValue;
172
- this.preferenceService.set(preferenceId, valueInCurrentScope, scopeID, uri);
173
- }
174
- let jsonEditorWidget;
175
- const jsonUriToOpen = await this.obtainConfigUri(scopeID, activeScopeIsFolder, uri);
176
- if (jsonUriToOpen) {
177
- jsonEditorWidget = await this.editorManager.open(jsonUriToOpen);
178
- if (preferenceId) {
179
- const text = jsonEditorWidget.editor.document.getText();
180
- if (preferenceId) {
181
- const { index } = text.match(preferenceId);
182
- const numReturns = text.slice(0, index).match(new RegExp('\n', 'g')).length;
183
- jsonEditorWidget.editor.cursor = { line: numReturns, character: 4 + preferenceId.length + 4 };
184
- }
185
- }
186
- }
187
- }
188
- async openJson(scope, resource) {
189
- const jsonUriToOpen = await this.obtainConfigUri(scope, false, resource);
190
- if (jsonUriToOpen) {
191
- await this.editorManager.open(jsonUriToOpen);
192
- }
193
- }
194
- /**
195
- * Prompts which workspace root folder to open the JSON settings.
196
- */
197
- async openFolderPreferences(callback) {
198
- var _a;
199
- const roots = this.workspaceService.tryGetRoots();
200
- if (roots.length === 1) {
201
- callback(roots[0]);
202
- }
203
- else {
204
- const items = roots.map(root => ({
205
- label: root.name,
206
- description: root.resource.path.fsPath(),
207
- execute: () => callback(root)
208
- }));
209
- (_a = this.quickInputService) === null || _a === void 0 ? void 0 : _a.showQuickPick(items, { placeholder: 'Select workspace folder' });
210
- }
211
- }
212
- async obtainConfigUri(serializedScope, activeScopeIsFolder, resource) {
213
- let scope = serializedScope;
214
- if (activeScopeIsFolder) {
215
- scope = browser_1.PreferenceScope.Folder;
216
- }
217
- const resourceUri = !!resource ? resource : undefined;
218
- const configUri = this.preferenceService.getConfigUri(scope, resourceUri);
219
- if (!configUri) {
220
- return undefined;
221
- }
222
- if (configUri && !await this.fileService.exists(configUri)) {
223
- await this.fileService.create(configUri);
224
- }
225
- return configUri;
226
- }
227
- /**
228
- * Determine if the current widget is the PreferencesWidget.
229
- */
230
- withWidget(widget = this.tryGetWidget(), fn) {
231
- if (widget instanceof preference_widget_1.PreferencesWidget && widget.id === preference_widget_1.PreferencesWidget.ID) {
232
- return fn(widget);
233
- }
234
- return false;
235
- }
236
- };
237
- __decorate([
238
- (0, inversify_1.inject)(file_service_1.FileService),
239
- __metadata("design:type", file_service_1.FileService)
240
- ], PreferencesContribution.prototype, "fileService", void 0);
241
- __decorate([
242
- (0, inversify_1.inject)(browser_1.PreferenceProvider),
243
- (0, inversify_1.named)(browser_1.PreferenceScope.Workspace),
244
- __metadata("design:type", workspace_preference_provider_1.WorkspacePreferenceProvider)
245
- ], PreferencesContribution.prototype, "workspacePreferenceProvider", void 0);
246
- __decorate([
247
- (0, inversify_1.inject)(browser_2.EditorManager),
248
- __metadata("design:type", browser_2.EditorManager)
249
- ], PreferencesContribution.prototype, "editorManager", void 0);
250
- __decorate([
251
- (0, inversify_1.inject)(browser_1.PreferenceService),
252
- __metadata("design:type", Object)
253
- ], PreferencesContribution.prototype, "preferenceService", void 0);
254
- __decorate([
255
- (0, inversify_1.inject)(clipboard_service_1.ClipboardService),
256
- __metadata("design:type", Object)
257
- ], PreferencesContribution.prototype, "clipboardService", void 0);
258
- __decorate([
259
- (0, inversify_1.inject)(preference_widget_1.PreferencesWidget),
260
- __metadata("design:type", preference_widget_1.PreferencesWidget)
261
- ], PreferencesContribution.prototype, "scopeTracker", void 0);
262
- __decorate([
263
- (0, inversify_1.inject)(browser_3.WorkspaceService),
264
- __metadata("design:type", browser_3.WorkspaceService)
265
- ], PreferencesContribution.prototype, "workspaceService", void 0);
266
- __decorate([
267
- (0, inversify_1.inject)(browser_1.QuickInputService),
268
- (0, inversify_1.optional)(),
269
- __metadata("design:type", Object)
270
- ], PreferencesContribution.prototype, "quickInputService", void 0);
271
- __decorate([
272
- (0, inversify_1.inject)(browser_1.PreferenceSchemaProvider),
273
- __metadata("design:type", browser_1.PreferenceSchemaProvider)
274
- ], PreferencesContribution.prototype, "schema", void 0);
275
- PreferencesContribution = __decorate([
276
- (0, inversify_1.injectable)(),
277
- __metadata("design:paramtypes", [])
278
- ], PreferencesContribution);
279
- exports.PreferencesContribution = PreferencesContribution;
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2018 Ericsson and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
23
+ var __metadata = (this && this.__metadata) || function (k, v) {
24
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.PreferencesContribution = void 0;
28
+ const inversify_1 = require("@theia/core/shared/inversify");
29
+ const browser_1 = require("@theia/core/lib/browser");
30
+ const os_1 = require("@theia/core/lib/common/os");
31
+ const browser_2 = require("@theia/editor/lib/browser");
32
+ const preference_widget_1 = require("./views/preference-widget");
33
+ const workspace_preference_provider_1 = require("./workspace-preference-provider");
34
+ const preference_types_1 = require("./util/preference-types");
35
+ const clipboard_service_1 = require("@theia/core/lib/browser/clipboard-service");
36
+ const file_service_1 = require("@theia/filesystem/lib/browser/file-service");
37
+ const browser_3 = require("@theia/workspace/lib/browser");
38
+ let PreferencesContribution = class PreferencesContribution extends browser_1.AbstractViewContribution {
39
+ constructor() {
40
+ super({
41
+ widgetId: preference_widget_1.PreferencesWidget.ID,
42
+ widgetName: preference_widget_1.PreferencesWidget.LABEL,
43
+ defaultWidgetOptions: {
44
+ area: 'main',
45
+ },
46
+ });
47
+ }
48
+ registerCommands(commands) {
49
+ commands.registerCommand(browser_1.CommonCommands.OPEN_PREFERENCES, {
50
+ execute: async (query) => {
51
+ const widget = await this.openView({ activate: true });
52
+ if (typeof query === 'string') {
53
+ widget.setSearchTerm(query);
54
+ }
55
+ },
56
+ });
57
+ commands.registerCommand(preference_types_1.PreferencesCommands.OPEN_PREFERENCES_JSON_TOOLBAR, {
58
+ isEnabled: () => true,
59
+ isVisible: w => this.withWidget(w, () => true),
60
+ execute: (preferenceId) => {
61
+ this.openPreferencesJSON(preferenceId);
62
+ }
63
+ });
64
+ commands.registerCommand(preference_types_1.PreferencesCommands.COPY_JSON_NAME, {
65
+ isEnabled: preference_types_1.Preference.EditorCommandArgs.is,
66
+ isVisible: preference_types_1.Preference.EditorCommandArgs.is,
67
+ execute: ({ id, value }) => {
68
+ this.clipboardService.writeText(id);
69
+ }
70
+ });
71
+ commands.registerCommand(preference_types_1.PreferencesCommands.COPY_JSON_VALUE, {
72
+ isEnabled: preference_types_1.Preference.EditorCommandArgs.is,
73
+ isVisible: preference_types_1.Preference.EditorCommandArgs.is,
74
+ execute: ({ id, value }) => {
75
+ const jsonString = `"${id}": ${JSON.stringify(value)}`;
76
+ this.clipboardService.writeText(jsonString);
77
+ }
78
+ });
79
+ commands.registerCommand(preference_types_1.PreferencesCommands.RESET_PREFERENCE, {
80
+ isEnabled: preference_types_1.Preference.EditorCommandArgs.is,
81
+ isVisible: preference_types_1.Preference.EditorCommandArgs.is,
82
+ execute: ({ id }) => {
83
+ this.preferenceService.set(id, undefined, Number(this.scopeTracker.currentScope.scope), this.scopeTracker.currentScope.uri);
84
+ }
85
+ });
86
+ commands.registerCommand(preference_types_1.PreferencesCommands.OPEN_USER_PREFERENCES, {
87
+ execute: async () => {
88
+ const widget = await this.openView({ activate: true });
89
+ widget.setScope(browser_1.PreferenceScope.User);
90
+ }
91
+ });
92
+ commands.registerCommand(preference_types_1.PreferencesCommands.OPEN_WORKSPACE_PREFERENCES, {
93
+ isEnabled: () => !!this.workspaceService.workspace,
94
+ isVisible: () => !!this.workspaceService.workspace,
95
+ execute: async () => {
96
+ const widget = await this.openView({ activate: true });
97
+ widget.setScope(browser_1.PreferenceScope.Workspace);
98
+ }
99
+ });
100
+ commands.registerCommand(preference_types_1.PreferencesCommands.OPEN_FOLDER_PREFERENCES, {
101
+ isEnabled: () => !!this.workspaceService.isMultiRootWorkspaceOpened && this.workspaceService.tryGetRoots().length > 0,
102
+ isVisible: () => !!this.workspaceService.isMultiRootWorkspaceOpened && this.workspaceService.tryGetRoots().length > 0,
103
+ execute: () => this.openFolderPreferences(root => {
104
+ this.openView({ activate: true });
105
+ this.scopeTracker.setScope(root.resource);
106
+ })
107
+ });
108
+ commands.registerCommand(preference_types_1.PreferencesCommands.OPEN_USER_PREFERENCES_JSON, {
109
+ execute: async () => this.openJson(browser_1.PreferenceScope.User)
110
+ });
111
+ commands.registerCommand(preference_types_1.PreferencesCommands.OPEN_WORKSPACE_PREFERENCES_JSON, {
112
+ isEnabled: () => !!this.workspaceService.workspace,
113
+ isVisible: () => !!this.workspaceService.workspace,
114
+ execute: async () => this.openJson(browser_1.PreferenceScope.Workspace)
115
+ });
116
+ commands.registerCommand(preference_types_1.PreferencesCommands.OPEN_FOLDER_PREFERENCES_JSON, {
117
+ isEnabled: () => !!this.workspaceService.isMultiRootWorkspaceOpened && this.workspaceService.tryGetRoots().length > 0,
118
+ isVisible: () => !!this.workspaceService.isMultiRootWorkspaceOpened && this.workspaceService.tryGetRoots().length > 0,
119
+ execute: () => this.openFolderPreferences(root => this.openJson(browser_1.PreferenceScope.Folder, root.resource.toString()))
120
+ });
121
+ }
122
+ registerMenus(menus) {
123
+ menus.registerMenuAction(browser_1.CommonMenus.FILE_SETTINGS_SUBMENU_OPEN, {
124
+ commandId: browser_1.CommonCommands.OPEN_PREFERENCES.id,
125
+ label: browser_1.CommonCommands.OPEN_PREFERENCES.label,
126
+ order: 'a10',
127
+ });
128
+ menus.registerMenuAction(browser_1.CommonMenus.SETTINGS_OPEN, {
129
+ commandId: browser_1.CommonCommands.OPEN_PREFERENCES.id,
130
+ label: browser_1.CommonCommands.OPEN_PREFERENCES.label,
131
+ order: 'a10',
132
+ });
133
+ menus.registerMenuAction(preference_types_1.PreferenceMenus.PREFERENCE_EDITOR_CONTEXT_MENU, {
134
+ commandId: preference_types_1.PreferencesCommands.RESET_PREFERENCE.id,
135
+ label: preference_types_1.PreferencesCommands.RESET_PREFERENCE.label,
136
+ order: 'a'
137
+ });
138
+ menus.registerMenuAction(preference_types_1.PreferenceMenus.PREFERENCE_EDITOR_COPY_ACTIONS, {
139
+ commandId: preference_types_1.PreferencesCommands.COPY_JSON_VALUE.id,
140
+ label: preference_types_1.PreferencesCommands.COPY_JSON_VALUE.label,
141
+ order: 'b'
142
+ });
143
+ menus.registerMenuAction(preference_types_1.PreferenceMenus.PREFERENCE_EDITOR_COPY_ACTIONS, {
144
+ commandId: preference_types_1.PreferencesCommands.COPY_JSON_NAME.id,
145
+ label: preference_types_1.PreferencesCommands.COPY_JSON_NAME.label,
146
+ order: 'c'
147
+ });
148
+ }
149
+ registerKeybindings(keybindings) {
150
+ keybindings.registerKeybinding({
151
+ command: browser_1.CommonCommands.OPEN_PREFERENCES.id,
152
+ keybinding: (os_1.isOSX && !browser_1.isFirefox) ? 'cmd+,' : 'ctrl+,'
153
+ });
154
+ }
155
+ registerToolbarItems(toolbar) {
156
+ toolbar.registerItem({
157
+ id: preference_types_1.PreferencesCommands.OPEN_PREFERENCES_JSON_TOOLBAR.id,
158
+ command: preference_types_1.PreferencesCommands.OPEN_PREFERENCES_JSON_TOOLBAR.id,
159
+ tooltip: preference_types_1.PreferencesCommands.OPEN_USER_PREFERENCES_JSON.label,
160
+ priority: 0,
161
+ });
162
+ }
163
+ async openPreferencesJSON(opener) {
164
+ var _a;
165
+ const { scope, activeScopeIsFolder, uri } = this.scopeTracker.currentScope;
166
+ const scopeID = Number(scope);
167
+ let preferenceId = '';
168
+ if (typeof opener === 'string') {
169
+ preferenceId = opener;
170
+ const currentPreferenceValue = this.preferenceService.inspect(preferenceId, uri);
171
+ const valueInCurrentScope = (_a = preference_types_1.Preference.getValueInScope(currentPreferenceValue, scopeID)) !== null && _a !== void 0 ? _a : currentPreferenceValue === null || currentPreferenceValue === void 0 ? void 0 : currentPreferenceValue.defaultValue;
172
+ this.preferenceService.set(preferenceId, valueInCurrentScope, scopeID, uri);
173
+ }
174
+ let jsonEditorWidget;
175
+ const jsonUriToOpen = await this.obtainConfigUri(scopeID, activeScopeIsFolder, uri);
176
+ if (jsonUriToOpen) {
177
+ jsonEditorWidget = await this.editorManager.open(jsonUriToOpen);
178
+ if (preferenceId) {
179
+ const text = jsonEditorWidget.editor.document.getText();
180
+ if (preferenceId) {
181
+ const { index } = text.match(preferenceId);
182
+ const numReturns = text.slice(0, index).match(new RegExp('\n', 'g')).length;
183
+ jsonEditorWidget.editor.cursor = { line: numReturns, character: 4 + preferenceId.length + 4 };
184
+ }
185
+ }
186
+ }
187
+ }
188
+ async openJson(scope, resource) {
189
+ const jsonUriToOpen = await this.obtainConfigUri(scope, false, resource);
190
+ if (jsonUriToOpen) {
191
+ await this.editorManager.open(jsonUriToOpen);
192
+ }
193
+ }
194
+ /**
195
+ * Prompts which workspace root folder to open the JSON settings.
196
+ */
197
+ async openFolderPreferences(callback) {
198
+ var _a;
199
+ const roots = this.workspaceService.tryGetRoots();
200
+ if (roots.length === 1) {
201
+ callback(roots[0]);
202
+ }
203
+ else {
204
+ const items = roots.map(root => ({
205
+ label: root.name,
206
+ description: root.resource.path.fsPath(),
207
+ execute: () => callback(root)
208
+ }));
209
+ (_a = this.quickInputService) === null || _a === void 0 ? void 0 : _a.showQuickPick(items, { placeholder: 'Select workspace folder' });
210
+ }
211
+ }
212
+ async obtainConfigUri(serializedScope, activeScopeIsFolder, resource) {
213
+ let scope = serializedScope;
214
+ if (activeScopeIsFolder) {
215
+ scope = browser_1.PreferenceScope.Folder;
216
+ }
217
+ const resourceUri = !!resource ? resource : undefined;
218
+ const configUri = this.preferenceService.getConfigUri(scope, resourceUri);
219
+ if (!configUri) {
220
+ return undefined;
221
+ }
222
+ if (configUri && !await this.fileService.exists(configUri)) {
223
+ await this.fileService.create(configUri);
224
+ }
225
+ return configUri;
226
+ }
227
+ /**
228
+ * Determine if the current widget is the PreferencesWidget.
229
+ */
230
+ withWidget(widget = this.tryGetWidget(), fn) {
231
+ if (widget instanceof preference_widget_1.PreferencesWidget && widget.id === preference_widget_1.PreferencesWidget.ID) {
232
+ return fn(widget);
233
+ }
234
+ return false;
235
+ }
236
+ };
237
+ __decorate([
238
+ (0, inversify_1.inject)(file_service_1.FileService),
239
+ __metadata("design:type", file_service_1.FileService)
240
+ ], PreferencesContribution.prototype, "fileService", void 0);
241
+ __decorate([
242
+ (0, inversify_1.inject)(browser_1.PreferenceProvider),
243
+ (0, inversify_1.named)(browser_1.PreferenceScope.Workspace),
244
+ __metadata("design:type", workspace_preference_provider_1.WorkspacePreferenceProvider)
245
+ ], PreferencesContribution.prototype, "workspacePreferenceProvider", void 0);
246
+ __decorate([
247
+ (0, inversify_1.inject)(browser_2.EditorManager),
248
+ __metadata("design:type", browser_2.EditorManager)
249
+ ], PreferencesContribution.prototype, "editorManager", void 0);
250
+ __decorate([
251
+ (0, inversify_1.inject)(browser_1.PreferenceService),
252
+ __metadata("design:type", Object)
253
+ ], PreferencesContribution.prototype, "preferenceService", void 0);
254
+ __decorate([
255
+ (0, inversify_1.inject)(clipboard_service_1.ClipboardService),
256
+ __metadata("design:type", Object)
257
+ ], PreferencesContribution.prototype, "clipboardService", void 0);
258
+ __decorate([
259
+ (0, inversify_1.inject)(preference_widget_1.PreferencesWidget),
260
+ __metadata("design:type", preference_widget_1.PreferencesWidget)
261
+ ], PreferencesContribution.prototype, "scopeTracker", void 0);
262
+ __decorate([
263
+ (0, inversify_1.inject)(browser_3.WorkspaceService),
264
+ __metadata("design:type", browser_3.WorkspaceService)
265
+ ], PreferencesContribution.prototype, "workspaceService", void 0);
266
+ __decorate([
267
+ (0, inversify_1.inject)(browser_1.QuickInputService),
268
+ (0, inversify_1.optional)(),
269
+ __metadata("design:type", Object)
270
+ ], PreferencesContribution.prototype, "quickInputService", void 0);
271
+ __decorate([
272
+ (0, inversify_1.inject)(browser_1.PreferenceSchemaProvider),
273
+ __metadata("design:type", browser_1.PreferenceSchemaProvider)
274
+ ], PreferencesContribution.prototype, "schema", void 0);
275
+ PreferencesContribution = __decorate([
276
+ (0, inversify_1.injectable)(),
277
+ __metadata("design:paramtypes", [])
278
+ ], PreferencesContribution);
279
+ exports.PreferencesContribution = PreferencesContribution;
280
280
  //# sourceMappingURL=preferences-contribution.js.map