@theia/toolbar 1.45.0 → 1.46.0-next.72

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 (53) hide show
  1. package/README.md +32 -32
  2. package/lib/browser/abstract-toolbar-contribution.d.ts +16 -16
  3. package/lib/browser/abstract-toolbar-contribution.js +68 -68
  4. package/lib/browser/application-shell-with-toolbar-override.d.ts +15 -15
  5. package/lib/browser/application-shell-with-toolbar-override.js +101 -101
  6. package/lib/browser/codicons.d.ts +1 -1
  7. package/lib/browser/codicons.js +20 -20
  8. package/lib/browser/font-awesome-icons.d.ts +1 -1
  9. package/lib/browser/font-awesome-icons.js +20 -20
  10. package/lib/browser/package.spec.js +18 -18
  11. package/lib/browser/toolbar-command-contribution.d.ts +25 -25
  12. package/lib/browser/toolbar-command-contribution.js +211 -211
  13. package/lib/browser/toolbar-command-quick-input-service.d.ts +19 -19
  14. package/lib/browser/toolbar-command-quick-input-service.js +112 -112
  15. package/lib/browser/toolbar-constants.d.ts +23 -23
  16. package/lib/browser/toolbar-constants.js +75 -75
  17. package/lib/browser/toolbar-controller.d.ts +34 -34
  18. package/lib/browser/toolbar-controller.js +186 -186
  19. package/lib/browser/toolbar-defaults.d.ts +3 -3
  20. package/lib/browser/toolbar-defaults.js +60 -60
  21. package/lib/browser/toolbar-frontend-module.d.ts +4 -4
  22. package/lib/browser/toolbar-frontend-module.js +25 -25
  23. package/lib/browser/toolbar-icon-selector-dialog.d.ts +65 -65
  24. package/lib/browser/toolbar-icon-selector-dialog.js +235 -235
  25. package/lib/browser/toolbar-interfaces.d.ts +45 -45
  26. package/lib/browser/toolbar-interfaces.js +42 -42
  27. package/lib/browser/toolbar-preference-contribution.d.ts +9 -9
  28. package/lib/browser/toolbar-preference-contribution.js +34 -34
  29. package/lib/browser/toolbar-preference-schema.d.ts +5 -5
  30. package/lib/browser/toolbar-preference-schema.js +73 -73
  31. package/lib/browser/toolbar-storage-provider.d.ts +47 -47
  32. package/lib/browser/toolbar-storage-provider.js +357 -357
  33. package/lib/browser/toolbar.d.ts +56 -56
  34. package/lib/browser/toolbar.js +380 -380
  35. package/package.json +11 -11
  36. package/src/browser/abstract-toolbar-contribution.tsx +53 -53
  37. package/src/browser/application-shell-with-toolbar-override.ts +98 -98
  38. package/src/browser/codicons.ts +18 -18
  39. package/src/browser/font-awesome-icons.ts +18 -18
  40. package/src/browser/package.spec.ts +19 -19
  41. package/src/browser/style/toolbar.css +255 -255
  42. package/src/browser/toolbar-command-contribution.ts +211 -211
  43. package/src/browser/toolbar-command-quick-input-service.ts +86 -86
  44. package/src/browser/toolbar-constants.ts +79 -79
  45. package/src/browser/toolbar-controller.ts +185 -185
  46. package/src/browser/toolbar-defaults.ts +58 -58
  47. package/src/browser/toolbar-frontend-module.ts +30 -30
  48. package/src/browser/toolbar-icon-selector-dialog.tsx +296 -296
  49. package/src/browser/toolbar-interfaces.ts +76 -76
  50. package/src/browser/toolbar-preference-contribution.ts +38 -38
  51. package/src/browser/toolbar-preference-schema.ts +75 -75
  52. package/src/browser/toolbar-storage-provider.ts +352 -352
  53. package/src/browser/toolbar.tsx +424 -424
@@ -1,79 +1,79 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2022 Ericsson and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { Command, isObject, MenuPath, nls } from '@theia/core';
18
- import { CommonCommands } from '@theia/core/lib/browser';
19
- import URI from '@theia/core/lib/common/uri';
20
- import { UserStorageUri } from '@theia/userstorage/lib/browser';
21
-
22
- export namespace ToolbarCommands {
23
- export const TOGGLE_TOOLBAR = Command.toLocalizedCommand({
24
- id: 'toolbar.view.toggle',
25
- category: CommonCommands.VIEW_CATEGORY,
26
- label: 'Toggle Toolbar',
27
- }, 'theia/toolbar/toggleToolbar', nls.getDefaultKey(CommonCommands.VIEW_CATEGORY));
28
-
29
- export const REMOVE_COMMAND_FROM_TOOLBAR = Command.toLocalizedCommand({
30
- id: 'toolbar.remove.command',
31
- category: 'Toolbar',
32
- label: 'Remove Command From Toolbar',
33
- }, 'theia/toolbar/removeCommand');
34
-
35
- export const INSERT_GROUP_LEFT = Command.toLocalizedCommand({
36
- id: 'toolbar.insert.group.left',
37
- category: 'Toolbar',
38
- label: 'Insert Group Separator (Left)',
39
- }, 'theia/toolbar/insertGroupLeft');
40
-
41
- export const INSERT_GROUP_RIGHT = Command.toLocalizedCommand({
42
- id: 'toolbar.insert.group.right',
43
- category: 'Toolbar',
44
- label: 'Insert Group Separator (Right)',
45
- }, 'theia/toolbar/insertGroupRight');
46
-
47
- export const ADD_COMMAND_TO_TOOLBAR = Command.toLocalizedCommand({
48
- id: 'toolbar.add.command',
49
- category: 'Toolbar',
50
- label: 'Add Command to Toolbar',
51
- }, 'theia/toolbar/addCommand');
52
-
53
- export const RESET_TOOLBAR = Command.toLocalizedCommand({
54
- id: 'toolbar.restore.defaults',
55
- category: 'Toolbar',
56
- label: 'Restore Toolbar Defaults',
57
- }, 'theia/toolbar/restoreDefaults');
58
-
59
- export const CUSTOMIZE_TOOLBAR = Command.toLocalizedCommand({
60
- id: 'toolbar.customize',
61
- category: 'Toolbar',
62
- label: 'Customize Toolbar (Open JSON)',
63
- }, 'theia/toolbar/openJSON');
64
- }
65
-
66
- export const UserToolbarURI = Symbol('UserToolbarURI');
67
- export const USER_TOOLBAR_URI = new URI().withScheme(UserStorageUri.scheme).withPath('/user/toolbar.json');
68
- export namespace ToolbarMenus {
69
- export const TOOLBAR_ITEM_CONTEXT_MENU: MenuPath = ['toolbar:toolbarItemContextMenu'];
70
- export const TOOLBAR_BACKGROUND_CONTEXT_MENU: MenuPath = ['toolbar:backgroundContextMenu'];
71
- export const SEARCH_WIDGET_DROPDOWN_MENU: MenuPath = ['searchToolbar:dropdown'];
72
- }
73
-
74
- export type ReactInteraction<T = Element, U = MouseEvent> = React.MouseEvent<T, U> | React.KeyboardEvent<T>;
75
- export namespace ReactKeyboardEvent {
76
- export function is(obj: unknown): obj is React.KeyboardEvent {
77
- return isObject(obj) && 'key' in obj;
78
- }
79
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 Ericsson and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { Command, isObject, MenuPath, nls } from '@theia/core';
18
+ import { CommonCommands } from '@theia/core/lib/browser';
19
+ import URI from '@theia/core/lib/common/uri';
20
+ import { UserStorageUri } from '@theia/userstorage/lib/browser';
21
+
22
+ export namespace ToolbarCommands {
23
+ export const TOGGLE_TOOLBAR = Command.toLocalizedCommand({
24
+ id: 'toolbar.view.toggle',
25
+ category: CommonCommands.VIEW_CATEGORY,
26
+ label: 'Toggle Toolbar',
27
+ }, 'theia/toolbar/toggleToolbar', nls.getDefaultKey(CommonCommands.VIEW_CATEGORY));
28
+
29
+ export const REMOVE_COMMAND_FROM_TOOLBAR = Command.toLocalizedCommand({
30
+ id: 'toolbar.remove.command',
31
+ category: 'Toolbar',
32
+ label: 'Remove Command From Toolbar',
33
+ }, 'theia/toolbar/removeCommand');
34
+
35
+ export const INSERT_GROUP_LEFT = Command.toLocalizedCommand({
36
+ id: 'toolbar.insert.group.left',
37
+ category: 'Toolbar',
38
+ label: 'Insert Group Separator (Left)',
39
+ }, 'theia/toolbar/insertGroupLeft');
40
+
41
+ export const INSERT_GROUP_RIGHT = Command.toLocalizedCommand({
42
+ id: 'toolbar.insert.group.right',
43
+ category: 'Toolbar',
44
+ label: 'Insert Group Separator (Right)',
45
+ }, 'theia/toolbar/insertGroupRight');
46
+
47
+ export const ADD_COMMAND_TO_TOOLBAR = Command.toLocalizedCommand({
48
+ id: 'toolbar.add.command',
49
+ category: 'Toolbar',
50
+ label: 'Add Command to Toolbar',
51
+ }, 'theia/toolbar/addCommand');
52
+
53
+ export const RESET_TOOLBAR = Command.toLocalizedCommand({
54
+ id: 'toolbar.restore.defaults',
55
+ category: 'Toolbar',
56
+ label: 'Restore Toolbar Defaults',
57
+ }, 'theia/toolbar/restoreDefaults');
58
+
59
+ export const CUSTOMIZE_TOOLBAR = Command.toLocalizedCommand({
60
+ id: 'toolbar.customize',
61
+ category: 'Toolbar',
62
+ label: 'Customize Toolbar (Open JSON)',
63
+ }, 'theia/toolbar/openJSON');
64
+ }
65
+
66
+ export const UserToolbarURI = Symbol('UserToolbarURI');
67
+ export const USER_TOOLBAR_URI = new URI().withScheme(UserStorageUri.scheme).withPath('/user/toolbar.json');
68
+ export namespace ToolbarMenus {
69
+ export const TOOLBAR_ITEM_CONTEXT_MENU: MenuPath = ['toolbar:toolbarItemContextMenu'];
70
+ export const TOOLBAR_BACKGROUND_CONTEXT_MENU: MenuPath = ['toolbar:backgroundContextMenu'];
71
+ export const SEARCH_WIDGET_DROPDOWN_MENU: MenuPath = ['searchToolbar:dropdown'];
72
+ }
73
+
74
+ export type ReactInteraction<T = Element, U = MouseEvent> = React.MouseEvent<T, U> | React.KeyboardEvent<T>;
75
+ export namespace ReactKeyboardEvent {
76
+ export function is(obj: unknown): obj is React.KeyboardEvent {
77
+ return isObject(obj) && 'key' in obj;
78
+ }
79
+ }
@@ -1,185 +1,185 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2022 Ericsson and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { Command, ContributionProvider, Emitter, MaybePromise, MessageService } from '@theia/core';
18
- import { Widget } from '@theia/core/lib/browser';
19
- import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
20
- import { TabBarToolbarItem } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
21
- import { Deferred } from '@theia/core/lib/common/promise-util';
22
- import { injectable, inject, postConstruct, named } from '@theia/core/shared/inversify';
23
- import { ToolbarDefaultsFactory } from './toolbar-defaults';
24
- import {
25
- DeflatedToolbarTree,
26
- ToolbarContribution,
27
- ToolbarTreeSchema,
28
- ToolbarItem,
29
- ToolbarAlignment,
30
- ToolbarItemPosition,
31
- } from './toolbar-interfaces';
32
- import { ToolbarStorageProvider, TOOLBAR_BAD_JSON_ERROR_MESSAGE } from './toolbar-storage-provider';
33
-
34
- @injectable()
35
- export class ToolbarController {
36
- @inject(ToolbarStorageProvider) protected readonly storageProvider: ToolbarStorageProvider;
37
- @inject(FrontendApplicationStateService) protected readonly appState: FrontendApplicationStateService;
38
- @inject(MessageService) protected readonly messageService: MessageService;
39
- @inject(ToolbarDefaultsFactory) protected readonly defaultsFactory: () => DeflatedToolbarTree;
40
- @inject(ContributionProvider) @named(ToolbarContribution)
41
- protected widgetContributions: ContributionProvider<ToolbarContribution>;
42
-
43
- protected toolbarModelDidUpdateEmitter = new Emitter<void>();
44
- readonly onToolbarModelDidUpdate = this.toolbarModelDidUpdateEmitter.event;
45
-
46
- protected toolbarProviderBusyEmitter = new Emitter<boolean>();
47
- readonly onToolbarDidChangeBusyState = this.toolbarProviderBusyEmitter.event;
48
-
49
- readonly ready = new Deferred<void>();
50
-
51
- protected _toolbarItems: ToolbarTreeSchema;
52
- get toolbarItems(): ToolbarTreeSchema {
53
- return this._toolbarItems;
54
- }
55
-
56
- set toolbarItems(newTree: ToolbarTreeSchema) {
57
- this._toolbarItems = newTree;
58
- this.toolbarModelDidUpdateEmitter.fire();
59
- }
60
-
61
- protected inflateItems(schema: DeflatedToolbarTree): ToolbarTreeSchema {
62
- const newTree: ToolbarTreeSchema = {
63
- items: {
64
- [ToolbarAlignment.LEFT]: [],
65
- [ToolbarAlignment.CENTER]: [],
66
- [ToolbarAlignment.RIGHT]: [],
67
- },
68
- };
69
- for (const column of Object.keys(schema.items)) {
70
- const currentColumn = schema.items[column as ToolbarAlignment];
71
- for (const group of currentColumn) {
72
- const newGroup: ToolbarItem[] = [];
73
- for (const item of group) {
74
- if (item.group === 'contributed') {
75
- const contribution = this.getContributionByID(item.id);
76
- if (contribution) {
77
- newGroup.push(contribution);
78
- }
79
- } else if (TabBarToolbarItem.is(item)) {
80
- newGroup.push({ ...item });
81
- }
82
- }
83
- if (newGroup.length) {
84
- newTree.items[column as ToolbarAlignment].push(newGroup);
85
- }
86
- }
87
- }
88
- return newTree;
89
- }
90
-
91
- getContributionByID(id: string): ToolbarContribution | undefined {
92
- return this.widgetContributions.getContributions().find(contribution => contribution.id === id);
93
- }
94
-
95
- @postConstruct()
96
- protected init(): void {
97
- this.doInit();
98
- }
99
-
100
- protected async doInit(): Promise<void> {
101
- await this.appState.reachedState('ready');
102
- await this.storageProvider.ready;
103
- this.toolbarItems = await this.resolveToolbarItems();
104
- this.storageProvider.onToolbarItemsChanged(async () => {
105
- this.toolbarItems = await this.resolveToolbarItems();
106
- });
107
- this.ready.resolve();
108
- this.widgetContributions.getContributions().forEach(contribution => {
109
- if (contribution.onDidChange) {
110
- contribution.onDidChange(() => this.toolbarModelDidUpdateEmitter.fire());
111
- }
112
- });
113
- }
114
-
115
- protected async resolveToolbarItems(): Promise<ToolbarTreeSchema> {
116
- await this.storageProvider.ready;
117
-
118
- if (this.storageProvider.toolbarItems) {
119
- try {
120
- return this.inflateItems(this.storageProvider.toolbarItems);
121
- } catch (e) {
122
- this.messageService.error(TOOLBAR_BAD_JSON_ERROR_MESSAGE);
123
- }
124
- }
125
- return this.inflateItems(this.defaultsFactory());
126
- }
127
-
128
- async swapValues(
129
- oldPosition: ToolbarItemPosition,
130
- newPosition: ToolbarItemPosition,
131
- direction: 'location-left' | 'location-right',
132
- ): Promise<boolean> {
133
- return this.withBusy<boolean>(async () => {
134
- await this.openOrCreateJSONFile(false);
135
- return this.storageProvider.swapValues(oldPosition, newPosition, direction);
136
- });
137
- }
138
-
139
- async clearAll(): Promise<boolean> {
140
- return this.withBusy<boolean>(() => this.storageProvider.clearAll());
141
- }
142
-
143
- async openOrCreateJSONFile(doOpen = false): Promise<Widget | undefined> {
144
- return this.storageProvider.openOrCreateJSONFile(this.toolbarItems, doOpen);
145
- }
146
-
147
- async addItem(command: Command, area: ToolbarAlignment): Promise<boolean> {
148
- return this.withBusy<boolean>(async () => {
149
- await this.openOrCreateJSONFile(false);
150
- return this.storageProvider.addItem(command, area);
151
- });
152
- }
153
-
154
- async removeItem(position: ToolbarItemPosition, id?: string): Promise<boolean> {
155
- return this.withBusy<boolean>(async () => {
156
- await this.openOrCreateJSONFile(false);
157
- return this.storageProvider.removeItem(position);
158
- });
159
- }
160
-
161
- async moveItemToEmptySpace(
162
- draggedItemPosition: ToolbarItemPosition,
163
- column: ToolbarAlignment,
164
- centerPosition?: 'left' | 'right',
165
- ): Promise<boolean> {
166
- return this.withBusy<boolean>(async () => {
167
- await this.openOrCreateJSONFile(false);
168
- return this.storageProvider.moveItemToEmptySpace(draggedItemPosition, column, centerPosition);
169
- });
170
- }
171
-
172
- async insertGroup(position: ToolbarItemPosition, insertDirection: 'left' | 'right'): Promise<boolean> {
173
- return this.withBusy<boolean>(async () => {
174
- await this.openOrCreateJSONFile(false);
175
- return this.storageProvider.insertGroup(position, insertDirection);
176
- });
177
- }
178
-
179
- async withBusy<T = unknown>(action: () => MaybePromise<T>): Promise<T> {
180
- this.toolbarProviderBusyEmitter.fire(true);
181
- const toReturn = await action();
182
- this.toolbarProviderBusyEmitter.fire(false);
183
- return toReturn;
184
- }
185
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 Ericsson and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { Command, ContributionProvider, Emitter, MaybePromise, MessageService } from '@theia/core';
18
+ import { Widget } from '@theia/core/lib/browser';
19
+ import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
20
+ import { TabBarToolbarItem } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
21
+ import { Deferred } from '@theia/core/lib/common/promise-util';
22
+ import { injectable, inject, postConstruct, named } from '@theia/core/shared/inversify';
23
+ import { ToolbarDefaultsFactory } from './toolbar-defaults';
24
+ import {
25
+ DeflatedToolbarTree,
26
+ ToolbarContribution,
27
+ ToolbarTreeSchema,
28
+ ToolbarItem,
29
+ ToolbarAlignment,
30
+ ToolbarItemPosition,
31
+ } from './toolbar-interfaces';
32
+ import { ToolbarStorageProvider, TOOLBAR_BAD_JSON_ERROR_MESSAGE } from './toolbar-storage-provider';
33
+
34
+ @injectable()
35
+ export class ToolbarController {
36
+ @inject(ToolbarStorageProvider) protected readonly storageProvider: ToolbarStorageProvider;
37
+ @inject(FrontendApplicationStateService) protected readonly appState: FrontendApplicationStateService;
38
+ @inject(MessageService) protected readonly messageService: MessageService;
39
+ @inject(ToolbarDefaultsFactory) protected readonly defaultsFactory: () => DeflatedToolbarTree;
40
+ @inject(ContributionProvider) @named(ToolbarContribution)
41
+ protected widgetContributions: ContributionProvider<ToolbarContribution>;
42
+
43
+ protected toolbarModelDidUpdateEmitter = new Emitter<void>();
44
+ readonly onToolbarModelDidUpdate = this.toolbarModelDidUpdateEmitter.event;
45
+
46
+ protected toolbarProviderBusyEmitter = new Emitter<boolean>();
47
+ readonly onToolbarDidChangeBusyState = this.toolbarProviderBusyEmitter.event;
48
+
49
+ readonly ready = new Deferred<void>();
50
+
51
+ protected _toolbarItems: ToolbarTreeSchema;
52
+ get toolbarItems(): ToolbarTreeSchema {
53
+ return this._toolbarItems;
54
+ }
55
+
56
+ set toolbarItems(newTree: ToolbarTreeSchema) {
57
+ this._toolbarItems = newTree;
58
+ this.toolbarModelDidUpdateEmitter.fire();
59
+ }
60
+
61
+ protected inflateItems(schema: DeflatedToolbarTree): ToolbarTreeSchema {
62
+ const newTree: ToolbarTreeSchema = {
63
+ items: {
64
+ [ToolbarAlignment.LEFT]: [],
65
+ [ToolbarAlignment.CENTER]: [],
66
+ [ToolbarAlignment.RIGHT]: [],
67
+ },
68
+ };
69
+ for (const column of Object.keys(schema.items)) {
70
+ const currentColumn = schema.items[column as ToolbarAlignment];
71
+ for (const group of currentColumn) {
72
+ const newGroup: ToolbarItem[] = [];
73
+ for (const item of group) {
74
+ if (item.group === 'contributed') {
75
+ const contribution = this.getContributionByID(item.id);
76
+ if (contribution) {
77
+ newGroup.push(contribution);
78
+ }
79
+ } else if (TabBarToolbarItem.is(item)) {
80
+ newGroup.push({ ...item });
81
+ }
82
+ }
83
+ if (newGroup.length) {
84
+ newTree.items[column as ToolbarAlignment].push(newGroup);
85
+ }
86
+ }
87
+ }
88
+ return newTree;
89
+ }
90
+
91
+ getContributionByID(id: string): ToolbarContribution | undefined {
92
+ return this.widgetContributions.getContributions().find(contribution => contribution.id === id);
93
+ }
94
+
95
+ @postConstruct()
96
+ protected init(): void {
97
+ this.doInit();
98
+ }
99
+
100
+ protected async doInit(): Promise<void> {
101
+ await this.appState.reachedState('ready');
102
+ await this.storageProvider.ready;
103
+ this.toolbarItems = await this.resolveToolbarItems();
104
+ this.storageProvider.onToolbarItemsChanged(async () => {
105
+ this.toolbarItems = await this.resolveToolbarItems();
106
+ });
107
+ this.ready.resolve();
108
+ this.widgetContributions.getContributions().forEach(contribution => {
109
+ if (contribution.onDidChange) {
110
+ contribution.onDidChange(() => this.toolbarModelDidUpdateEmitter.fire());
111
+ }
112
+ });
113
+ }
114
+
115
+ protected async resolveToolbarItems(): Promise<ToolbarTreeSchema> {
116
+ await this.storageProvider.ready;
117
+
118
+ if (this.storageProvider.toolbarItems) {
119
+ try {
120
+ return this.inflateItems(this.storageProvider.toolbarItems);
121
+ } catch (e) {
122
+ this.messageService.error(TOOLBAR_BAD_JSON_ERROR_MESSAGE);
123
+ }
124
+ }
125
+ return this.inflateItems(this.defaultsFactory());
126
+ }
127
+
128
+ async swapValues(
129
+ oldPosition: ToolbarItemPosition,
130
+ newPosition: ToolbarItemPosition,
131
+ direction: 'location-left' | 'location-right',
132
+ ): Promise<boolean> {
133
+ return this.withBusy<boolean>(async () => {
134
+ await this.openOrCreateJSONFile(false);
135
+ return this.storageProvider.swapValues(oldPosition, newPosition, direction);
136
+ });
137
+ }
138
+
139
+ async clearAll(): Promise<boolean> {
140
+ return this.withBusy<boolean>(() => this.storageProvider.clearAll());
141
+ }
142
+
143
+ async openOrCreateJSONFile(doOpen = false): Promise<Widget | undefined> {
144
+ return this.storageProvider.openOrCreateJSONFile(this.toolbarItems, doOpen);
145
+ }
146
+
147
+ async addItem(command: Command, area: ToolbarAlignment): Promise<boolean> {
148
+ return this.withBusy<boolean>(async () => {
149
+ await this.openOrCreateJSONFile(false);
150
+ return this.storageProvider.addItem(command, area);
151
+ });
152
+ }
153
+
154
+ async removeItem(position: ToolbarItemPosition, id?: string): Promise<boolean> {
155
+ return this.withBusy<boolean>(async () => {
156
+ await this.openOrCreateJSONFile(false);
157
+ return this.storageProvider.removeItem(position);
158
+ });
159
+ }
160
+
161
+ async moveItemToEmptySpace(
162
+ draggedItemPosition: ToolbarItemPosition,
163
+ column: ToolbarAlignment,
164
+ centerPosition?: 'left' | 'right',
165
+ ): Promise<boolean> {
166
+ return this.withBusy<boolean>(async () => {
167
+ await this.openOrCreateJSONFile(false);
168
+ return this.storageProvider.moveItemToEmptySpace(draggedItemPosition, column, centerPosition);
169
+ });
170
+ }
171
+
172
+ async insertGroup(position: ToolbarItemPosition, insertDirection: 'left' | 'right'): Promise<boolean> {
173
+ return this.withBusy<boolean>(async () => {
174
+ await this.openOrCreateJSONFile(false);
175
+ return this.storageProvider.insertGroup(position, insertDirection);
176
+ });
177
+ }
178
+
179
+ async withBusy<T = unknown>(action: () => MaybePromise<T>): Promise<T> {
180
+ this.toolbarProviderBusyEmitter.fire(true);
181
+ const toReturn = await action();
182
+ this.toolbarProviderBusyEmitter.fire(false);
183
+ return toReturn;
184
+ }
185
+ }
@@ -1,58 +1,58 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2022 Ericsson and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { nls } from '@theia/core';
18
- import { DeflatedToolbarTree, ToolbarAlignment } from './toolbar-interfaces';
19
-
20
- // This file specifies the default layout of the toolbar. This binding should be overridden for extenders.
21
- // Both Toolbar Command Items and Toolbar Contributions can be specified here.
22
- export const ToolbarDefaultsFactory = Symbol('ToolbarDefaultsFactory');
23
- export const ToolbarDefaults: () => DeflatedToolbarTree = () => ({
24
- items: {
25
- [ToolbarAlignment.LEFT]: [
26
- [
27
- {
28
- id: 'textEditor.commands.go.back',
29
- command: 'textEditor.commands.go.back',
30
- icon: 'codicon codicon-arrow-left',
31
- },
32
- {
33
- id: 'textEditor.commands.go.forward',
34
- command: 'textEditor.commands.go.forward',
35
- icon: 'codicon codicon-arrow-right',
36
- },
37
- ],
38
- [
39
- {
40
- id: 'workbench.action.splitEditorRight',
41
- command: 'workbench.action.splitEditorRight',
42
- icon: 'codicon codicon-split-horizontal',
43
- },
44
- ],
45
- ],
46
- [ToolbarAlignment.CENTER]: [[]],
47
- [ToolbarAlignment.RIGHT]: [
48
- [
49
- {
50
- id: 'workbench.action.showCommands',
51
- command: 'workbench.action.showCommands',
52
- icon: 'codicon codicon-terminal',
53
- tooltip: nls.localizeByDefault('Command Palette'),
54
- },
55
- ]
56
- ]
57
- },
58
- });
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 Ericsson and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { nls } from '@theia/core';
18
+ import { DeflatedToolbarTree, ToolbarAlignment } from './toolbar-interfaces';
19
+
20
+ // This file specifies the default layout of the toolbar. This binding should be overridden for extenders.
21
+ // Both Toolbar Command Items and Toolbar Contributions can be specified here.
22
+ export const ToolbarDefaultsFactory = Symbol('ToolbarDefaultsFactory');
23
+ export const ToolbarDefaults: () => DeflatedToolbarTree = () => ({
24
+ items: {
25
+ [ToolbarAlignment.LEFT]: [
26
+ [
27
+ {
28
+ id: 'textEditor.commands.go.back',
29
+ command: 'textEditor.commands.go.back',
30
+ icon: 'codicon codicon-arrow-left',
31
+ },
32
+ {
33
+ id: 'textEditor.commands.go.forward',
34
+ command: 'textEditor.commands.go.forward',
35
+ icon: 'codicon codicon-arrow-right',
36
+ },
37
+ ],
38
+ [
39
+ {
40
+ id: 'workbench.action.splitEditorRight',
41
+ command: 'workbench.action.splitEditorRight',
42
+ icon: 'codicon codicon-split-horizontal',
43
+ },
44
+ ],
45
+ ],
46
+ [ToolbarAlignment.CENTER]: [[]],
47
+ [ToolbarAlignment.RIGHT]: [
48
+ [
49
+ {
50
+ id: 'workbench.action.showCommands',
51
+ command: 'workbench.action.showCommands',
52
+ icon: 'codicon codicon-terminal',
53
+ tooltip: nls.localizeByDefault('Command Palette'),
54
+ },
55
+ ]
56
+ ]
57
+ },
58
+ });