Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e994ea7

Browse files
author
Akos Kitta
committed
fix: menu item enablement issues
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent 7c86f1f commit e994ea7

File tree

11 files changed

+64
-128
lines changed

11 files changed

+64
-128
lines changed

‎arduino-ide-extension/src/browser/contributions/contribution.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import { BoardsDataStore } from '../boards/boards-data-store';
6161
import { NotificationManager } from '../theia/messages/notifications-manager';
6262
import { MessageType } from '@theia/core/lib/common/message-service-protocol';
6363
import { WorkspaceService } from '../theia/workspace/workspace-service';
64+
import { MainMenuManager } from '../../common/main-menu-manager';
6465

6566
export {
6667
Command,
@@ -106,6 +107,9 @@ export abstract class Contribution
106107
@inject(FrontendApplicationStateService)
107108
protected readonly appStateService: FrontendApplicationStateService;
108109

110+
@inject(MainMenuManager)
111+
protected readonly menuManager: MainMenuManager;
112+
109113
@postConstruct()
110114
protected init(): void {
111115
this.appStateService.reachedState('ready').then(() => this.onReady());

‎arduino-ide-extension/src/browser/contributions/examples.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
} from '@theia/core/lib/common/disposable';
1313
import { OpenSketch } from './open-sketch';
1414
import { ArduinoMenus, PlaceholderMenuNode } from '../menu/arduino-menus';
15-
import { MainMenuManager } from '../../common/main-menu-manager';
1615
import { BoardsServiceProvider } from '../boards/boards-service-provider';
1716
import { ExamplesService } from '../../common/protocol/examples-service';
1817
import {
@@ -39,9 +38,6 @@ export abstract class Examples extends SketchContribution {
3938
@inject(MenuModelRegistry)
4039
private readonly menuRegistry: MenuModelRegistry;
4140

42-
@inject(MainMenuManager)
43-
protected readonly menuManager: MainMenuManager;
44-
4541
@inject(ExamplesService)
4642
protected readonly examplesService: ExamplesService;
4743

‎arduino-ide-extension/src/browser/contributions/interface-scale.ts‎

Lines changed: 8 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,17 @@
1-
import { inject,injectable } from '@theia/core/shared/inversify';
1+
import { injectable } from '@theia/core/shared/inversify';
22
import {
33
Contribution,
44
Command,
55
MenuModelRegistry,
66
KeybindingRegistry,
77
} from './contribution';
8-
import { ArduinoMenus, PlaceholderMenuNode } from '../menu/arduino-menus';
9-
import {
10-
CommandRegistry,
11-
DisposableCollection,
12-
MaybePromise,
13-
nls,
14-
} from '@theia/core/lib/common';
15-
8+
import { ArduinoMenus } from '../menu/arduino-menus';
9+
import { CommandRegistry, MaybePromise, nls } from '@theia/core/lib/common';
1610
import { Settings } from '../dialogs/settings/settings';
17-
import { MainMenuManager } from '../../common/main-menu-manager';
1811
import debounce = require('lodash.debounce');
1912

2013
@injectable()
2114
export class InterfaceScale extends Contribution {
22-
@inject(MenuModelRegistry)
23-
private readonly menuRegistry: MenuModelRegistry;
24-
25-
@inject(MainMenuManager)
26-
private readonly mainMenuManager: MainMenuManager;
27-
28-
private readonly menuActionsDisposables = new DisposableCollection();
2915
private fontScalingEnabled: InterfaceScale.FontScalingEnabled = {
3016
increase: true,
3117
decrease: true,
@@ -62,63 +48,22 @@ export class InterfaceScale extends Contribution {
6248
}
6349

6450
override registerMenus(registry: MenuModelRegistry): void {
65-
this.menuActionsDisposables.dispose();
66-
const increaseFontSizeMenuAction = {
51+
registry.registerMenuAction(ArduinoMenus.EDIT__FONT_CONTROL_GROUP, {
6752
commandId: InterfaceScale.Commands.INCREASE_FONT_SIZE.id,
6853
label: nls.localize(
6954
'arduino/editor/increaseFontSize',
7055
'Increase Font Size'
7156
),
7257
order: '0',
73-
};
74-
constdecreaseFontSizeMenuAction= {
58+
});
59+
registry.registerMenuAction(ArduinoMenus.EDIT__FONT_CONTROL_GROUP, {
7560
commandId: InterfaceScale.Commands.DECREASE_FONT_SIZE.id,
7661
label: nls.localize(
7762
'arduino/editor/decreaseFontSize',
7863
'Decrease Font Size'
7964
),
8065
order: '1',
81-
};
82-
83-
if (this.fontScalingEnabled.increase) {
84-
this.menuActionsDisposables.push(
85-
registry.registerMenuAction(
86-
ArduinoMenus.EDIT__FONT_CONTROL_GROUP,
87-
increaseFontSizeMenuAction
88-
)
89-
);
90-
} else {
91-
this.menuActionsDisposables.push(
92-
registry.registerMenuNode(
93-
ArduinoMenus.EDIT__FONT_CONTROL_GROUP,
94-
new PlaceholderMenuNode(
95-
ArduinoMenus.EDIT__FONT_CONTROL_GROUP,
96-
increaseFontSizeMenuAction.label,
97-
{ order: increaseFontSizeMenuAction.order }
98-
)
99-
)
100-
);
101-
}
102-
if (this.fontScalingEnabled.decrease) {
103-
this.menuActionsDisposables.push(
104-
this.menuRegistry.registerMenuAction(
105-
ArduinoMenus.EDIT__FONT_CONTROL_GROUP,
106-
decreaseFontSizeMenuAction
107-
)
108-
);
109-
} else {
110-
this.menuActionsDisposables.push(
111-
this.menuRegistry.registerMenuNode(
112-
ArduinoMenus.EDIT__FONT_CONTROL_GROUP,
113-
new PlaceholderMenuNode(
114-
ArduinoMenus.EDIT__FONT_CONTROL_GROUP,
115-
decreaseFontSizeMenuAction.label,
116-
{ order: decreaseFontSizeMenuAction.order }
117-
)
118-
)
119-
);
120-
}
121-
this.mainMenuManager.update();
66+
});
12267
}
12368

12469
private updateFontScalingEnabled(): void {
@@ -153,7 +98,7 @@ export class InterfaceScale extends Contribution {
15398
);
15499
if (isChanged) {
155100
this.fontScalingEnabled = fontScalingEnabled;
156-
this.registerMenus(this.menuRegistry);
101+
this.menuManager.update();
157102
}
158103
}
159104

‎arduino-ide-extension/src/browser/contributions/new-cloud-sketch.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { nls } from '@theia/core/lib/common/nls';
1717
import { inject, injectable } from '@theia/core/shared/inversify';
1818
import { WorkspaceInputDialogProps } from '@theia/workspace/lib/browser/workspace-input-dialog';
1919
import { v4 } from 'uuid';
20-
import { MainMenuManager } from '../../common/main-menu-manager';
2120
import type { AuthenticationSession } from '../../node/auth/types';
2221
import { AuthenticationClientService } from '../auth/authentication-client-service';
2322
import { CreateApi } from '../create/create-api';
@@ -41,8 +40,6 @@ export class NewCloudSketch extends Contribution {
4140
private readonly widgetContribution: SketchbookWidgetContribution;
4241
@inject(AuthenticationClientService)
4342
private readonly authenticationService: AuthenticationClientService;
44-
@inject(MainMenuManager)
45-
private readonly mainMenuManager: MainMenuManager;
4643

4744
private readonly toDispose = new DisposableCollection();
4845
private _session: AuthenticationSession | undefined;
@@ -54,23 +51,23 @@ export class NewCloudSketch extends Contribution {
5451
const oldSession = this._session;
5552
this._session = session;
5653
if (!!oldSession !== !!this._session) {
57-
this.mainMenuManager.update();
54+
this.menuManager.update();
5855
}
5956
}),
6057
this.preferences.onPreferenceChanged(({ preferenceName, newValue }) => {
6158
if (preferenceName === 'arduino.cloud.enabled') {
6259
const oldEnabled = this._enabled;
6360
this._enabled = Boolean(newValue);
6461
if (this._enabled !== oldEnabled) {
65-
this.mainMenuManager.update();
62+
this.menuManager.update();
6663
}
6764
}
6865
}),
6966
]);
7067
this._enabled = this.preferences['arduino.cloud.enabled'];
7168
this._session = this.authenticationService.session;
7269
if (this._session) {
73-
this.mainMenuManager.update();
70+
this.menuManager.update();
7471
}
7572
}
7673

‎arduino-ide-extension/src/browser/contributions/open-settings.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { nls } from '@theia/core/lib/common/nls';
22
import { inject, injectable } from '@theia/core/shared/inversify';
3-
import { MainMenuManager } from '../../common/main-menu-manager';
43
import type { Settings } from '../dialogs/settings/settings';
54
import { SettingsDialog } from '../dialogs/settings/settings-dialog';
65
import { ArduinoMenus } from '../menu/arduino-menus';
@@ -16,8 +15,6 @@ import {
1615
export class OpenSettings extends SketchContribution {
1716
@inject(SettingsDialog)
1817
private readonly settingsDialog: SettingsDialog;
19-
@inject(MainMenuManager)
20-
private readonly menuManager: MainMenuManager;
2118

2219
private settingsOpened = false;
2320

‎arduino-ide-extension/src/browser/contributions/upload-certificate.ts‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
PreferenceScope,
1313
PreferenceService,
1414
} from '@theia/core/lib/browser/preferences/preference-service';
15-
import { ArduinoPreferences } from '../arduino-preferences';
1615
import {
1716
arduinoCert,
1817
certificateList,
@@ -31,30 +30,37 @@ export class UploadCertificate extends Contribution {
3130
@inject(PreferenceService)
3231
protected readonly preferenceService: PreferenceService;
3332

34-
@inject(ArduinoPreferences)
35-
protected readonly arduinoPreferences: ArduinoPreferences;
36-
3733
@inject(ArduinoFirmwareUploader)
3834
protected readonly arduinoFirmwareUploader: ArduinoFirmwareUploader;
3935

4036
protected dialogOpened = false;
4137

38+
override onStart(): void {
39+
this.preferences.onPreferenceChanged(({ preferenceName }) => {
40+
if (preferenceName === 'arduino.board.certificates') {
41+
this.menuManager.update();
42+
}
43+
});
44+
}
45+
4246
override registerCommands(registry: CommandRegistry): void {
4347
registry.registerCommand(UploadCertificate.Commands.OPEN, {
4448
execute: async () => {
4549
try {
4650
this.dialogOpened = true;
51+
this.menuManager.update();
4752
await this.dialog.open();
4853
} finally {
4954
this.dialogOpened = false;
55+
this.menuManager.update();
5056
}
5157
},
5258
isEnabled: () => !this.dialogOpened,
5359
});
5460

5561
registry.registerCommand(UploadCertificate.Commands.REMOVE_CERT, {
5662
execute: async (certToRemove) => {
57-
const certs = this.arduinoPreferences.get('arduino.board.certificates');
63+
const certs = this.preferences.get('arduino.board.certificates');
5864

5965
this.preferenceService.set(
6066
'arduino.board.certificates',
@@ -75,7 +81,6 @@ export class UploadCertificate extends Contribution {
7581
.join(' ')}`
7682
);
7783
},
78-
isEnabled: () => true,
7984
});
8085

8186
registry.registerCommand(UploadCertificate.Commands.OPEN_CERT_CONTEXT, {
@@ -89,7 +94,6 @@ export class UploadCertificate extends Contribution {
8994
args: [args.cert],
9095
});
9196
},
92-
isEnabled: () => true,
9397
});
9498
}
9599

‎arduino-ide-extension/src/browser/contributions/upload-firmware.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ export class UploadFirmware extends Contribution {
2121
execute: async () => {
2222
try {
2323
this.dialogOpened = true;
24+
this.menuManager.update();
2425
await this.dialog.open();
2526
} finally {
2627
this.dialogOpened = false;
28+
this.menuManager.update();
2729
}
2830
},
2931
isEnabled: () => !this.dialogOpened,

‎arduino-ide-extension/src/browser/contributions/upload-sketch.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export class UploadSketch extends CoreServiceContribution {
106106
// toggle the toolbar button and menu item state.
107107
// uploadInProgress will be set to false whether the upload fails or not
108108
this.uploadInProgress = true;
109+
this.menuManager.update();
109110
this.boardsServiceProvider.snapshotBoardDiscoveryOnUpload();
110111
this.onDidChangeEmitter.fire();
111112
this.clearVisibleNotification();
@@ -150,6 +151,7 @@ export class UploadSketch extends CoreServiceContribution {
150151
this.handleError(e);
151152
} finally {
152153
this.uploadInProgress = false;
154+
this.menuManager.update();
153155
this.boardsServiceProvider.attemptPostUploadAutoSelect();
154156
this.onDidChangeEmitter.fire();
155157
}

‎arduino-ide-extension/src/browser/contributions/user-fields.ts‎

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { inject, injectable } from '@theia/core/shared/inversify';
2-
import { DisposableCollection,nls } from '@theia/core/lib/common';
2+
import { nls } from '@theia/core/lib/common';
33
import { BoardUserField, CoreError } from '../../common/protocol';
44
import { BoardsServiceProvider } from '../boards/boards-service-provider';
55
import { UserFieldsDialog } from '../dialogs/user-fields/user-fields-dialog';
6-
import { ArduinoMenus,PlaceholderMenuNode } from '../menu/arduino-menus';
6+
import { ArduinoMenus } from '../menu/arduino-menus';
77
import { MenuModelRegistry, Contribution } from './contribution';
88
import { UploadSketch } from './upload-sketch';
99

@@ -12,50 +12,29 @@ export class UserFields extends Contribution {
1212
private boardRequiresUserFields = false;
1313
private userFieldsSet = false;
1414
private readonly cachedUserFields: Map<string, BoardUserField[]> = new Map();
15-
private readonly menuActionsDisposables = new DisposableCollection();
1615

1716
@inject(UserFieldsDialog)
1817
private readonly userFieldsDialog: UserFieldsDialog;
1918

2019
@inject(BoardsServiceProvider)
2120
private readonly boardsServiceProvider: BoardsServiceProvider;
2221

23-
@inject(MenuModelRegistry)
24-
private readonly menuRegistry: MenuModelRegistry;
25-
2622
protected override init(): void {
2723
super.init();
2824
this.boardsServiceProvider.onBoardsConfigChanged(async () => {
2925
const userFields =
3026
await this.boardsServiceProvider.selectedBoardUserFields();
3127
this.boardRequiresUserFields = userFields.length > 0;
32-
this.registerMenus(this.menuRegistry);
28+
this.menuManager.update();
3329
});
3430
}
3531

3632
override registerMenus(registry: MenuModelRegistry): void {
37-
this.menuActionsDisposables.dispose();
38-
if (this.boardRequiresUserFields) {
39-
this.menuActionsDisposables.push(
40-
registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, {
41-
commandId: UploadSketch.Commands.UPLOAD_WITH_CONFIGURATION.id,
42-
label: UploadSketch.Commands.UPLOAD_WITH_CONFIGURATION.label,
43-
order: '2',
44-
})
45-
);
46-
} else {
47-
this.menuActionsDisposables.push(
48-
registry.registerMenuNode(
49-
ArduinoMenus.SKETCH__MAIN_GROUP,
50-
new PlaceholderMenuNode(
51-
ArduinoMenus.SKETCH__MAIN_GROUP,
52-
// commandId: UploadSketch.Commands.UPLOAD_WITH_CONFIGURATION.id,
53-
UploadSketch.Commands.UPLOAD_WITH_CONFIGURATION.label,
54-
{ order: '2' }
55-
)
56-
)
57-
);
58-
}
33+
registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, {
34+
commandId: UploadSketch.Commands.UPLOAD_WITH_CONFIGURATION.id,
35+
label: UploadSketch.Commands.UPLOAD_WITH_CONFIGURATION.label,
36+
order: '2',
37+
});
5938
}
6039

6140
private selectedFqbnAddress(): string | undefined {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /