mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-09 04:16:38 +00:00
fix: menu item enablement issues
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
parent
7c86f1f9d3
commit
908ec4c544
@ -61,6 +61,7 @@ import { BoardsDataStore } from '../boards/boards-data-store';
|
|||||||
import { NotificationManager } from '../theia/messages/notifications-manager';
|
import { NotificationManager } from '../theia/messages/notifications-manager';
|
||||||
import { MessageType } from '@theia/core/lib/common/message-service-protocol';
|
import { MessageType } from '@theia/core/lib/common/message-service-protocol';
|
||||||
import { WorkspaceService } from '../theia/workspace/workspace-service';
|
import { WorkspaceService } from '../theia/workspace/workspace-service';
|
||||||
|
import { MainMenuManager } from '../../common/main-menu-manager';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Command,
|
Command,
|
||||||
@ -106,6 +107,9 @@ export abstract class Contribution
|
|||||||
@inject(FrontendApplicationStateService)
|
@inject(FrontendApplicationStateService)
|
||||||
protected readonly appStateService: FrontendApplicationStateService;
|
protected readonly appStateService: FrontendApplicationStateService;
|
||||||
|
|
||||||
|
@inject(MainMenuManager)
|
||||||
|
protected readonly menuManager: MainMenuManager;
|
||||||
|
|
||||||
@postConstruct()
|
@postConstruct()
|
||||||
protected init(): void {
|
protected init(): void {
|
||||||
this.appStateService.reachedState('ready').then(() => this.onReady());
|
this.appStateService.reachedState('ready').then(() => this.onReady());
|
||||||
|
@ -12,7 +12,6 @@ import {
|
|||||||
} from '@theia/core/lib/common/disposable';
|
} from '@theia/core/lib/common/disposable';
|
||||||
import { OpenSketch } from './open-sketch';
|
import { OpenSketch } from './open-sketch';
|
||||||
import { ArduinoMenus, PlaceholderMenuNode } from '../menu/arduino-menus';
|
import { ArduinoMenus, PlaceholderMenuNode } from '../menu/arduino-menus';
|
||||||
import { MainMenuManager } from '../../common/main-menu-manager';
|
|
||||||
import { BoardsServiceProvider } from '../boards/boards-service-provider';
|
import { BoardsServiceProvider } from '../boards/boards-service-provider';
|
||||||
import { ExamplesService } from '../../common/protocol/examples-service';
|
import { ExamplesService } from '../../common/protocol/examples-service';
|
||||||
import {
|
import {
|
||||||
@ -39,9 +38,6 @@ export abstract class Examples extends SketchContribution {
|
|||||||
@inject(MenuModelRegistry)
|
@inject(MenuModelRegistry)
|
||||||
private readonly menuRegistry: MenuModelRegistry;
|
private readonly menuRegistry: MenuModelRegistry;
|
||||||
|
|
||||||
@inject(MainMenuManager)
|
|
||||||
protected readonly menuManager: MainMenuManager;
|
|
||||||
|
|
||||||
@inject(ExamplesService)
|
@inject(ExamplesService)
|
||||||
protected readonly examplesService: ExamplesService;
|
protected readonly examplesService: ExamplesService;
|
||||||
|
|
||||||
|
@ -1,31 +1,17 @@
|
|||||||
import { inject, injectable } from '@theia/core/shared/inversify';
|
import { injectable } from '@theia/core/shared/inversify';
|
||||||
import {
|
import {
|
||||||
Contribution,
|
Contribution,
|
||||||
Command,
|
Command,
|
||||||
MenuModelRegistry,
|
MenuModelRegistry,
|
||||||
KeybindingRegistry,
|
KeybindingRegistry,
|
||||||
} from './contribution';
|
} from './contribution';
|
||||||
import { ArduinoMenus, PlaceholderMenuNode } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
import {
|
import { CommandRegistry, MaybePromise, nls } from '@theia/core/lib/common';
|
||||||
CommandRegistry,
|
|
||||||
DisposableCollection,
|
|
||||||
MaybePromise,
|
|
||||||
nls,
|
|
||||||
} from '@theia/core/lib/common';
|
|
||||||
|
|
||||||
import { Settings } from '../dialogs/settings/settings';
|
import { Settings } from '../dialogs/settings/settings';
|
||||||
import { MainMenuManager } from '../../common/main-menu-manager';
|
|
||||||
import debounce = require('lodash.debounce');
|
import debounce = require('lodash.debounce');
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class InterfaceScale extends Contribution {
|
export class InterfaceScale extends Contribution {
|
||||||
@inject(MenuModelRegistry)
|
|
||||||
private readonly menuRegistry: MenuModelRegistry;
|
|
||||||
|
|
||||||
@inject(MainMenuManager)
|
|
||||||
private readonly mainMenuManager: MainMenuManager;
|
|
||||||
|
|
||||||
private readonly menuActionsDisposables = new DisposableCollection();
|
|
||||||
private fontScalingEnabled: InterfaceScale.FontScalingEnabled = {
|
private fontScalingEnabled: InterfaceScale.FontScalingEnabled = {
|
||||||
increase: true,
|
increase: true,
|
||||||
decrease: true,
|
decrease: true,
|
||||||
@ -62,63 +48,22 @@ export class InterfaceScale extends Contribution {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override registerMenus(registry: MenuModelRegistry): void {
|
override registerMenus(registry: MenuModelRegistry): void {
|
||||||
this.menuActionsDisposables.dispose();
|
registry.registerMenuAction(ArduinoMenus.EDIT__FONT_CONTROL_GROUP, {
|
||||||
const increaseFontSizeMenuAction = {
|
|
||||||
commandId: InterfaceScale.Commands.INCREASE_FONT_SIZE.id,
|
commandId: InterfaceScale.Commands.INCREASE_FONT_SIZE.id,
|
||||||
label: nls.localize(
|
label: nls.localize(
|
||||||
'arduino/editor/increaseFontSize',
|
'arduino/editor/increaseFontSize',
|
||||||
'Increase Font Size'
|
'Increase Font Size'
|
||||||
),
|
),
|
||||||
order: '0',
|
order: '0',
|
||||||
};
|
});
|
||||||
const decreaseFontSizeMenuAction = {
|
registry.registerMenuAction(ArduinoMenus.EDIT__FONT_CONTROL_GROUP, {
|
||||||
commandId: InterfaceScale.Commands.DECREASE_FONT_SIZE.id,
|
commandId: InterfaceScale.Commands.DECREASE_FONT_SIZE.id,
|
||||||
label: nls.localize(
|
label: nls.localize(
|
||||||
'arduino/editor/decreaseFontSize',
|
'arduino/editor/decreaseFontSize',
|
||||||
'Decrease Font Size'
|
'Decrease Font Size'
|
||||||
),
|
),
|
||||||
order: '1',
|
order: '1',
|
||||||
};
|
});
|
||||||
|
|
||||||
if (this.fontScalingEnabled.increase) {
|
|
||||||
this.menuActionsDisposables.push(
|
|
||||||
registry.registerMenuAction(
|
|
||||||
ArduinoMenus.EDIT__FONT_CONTROL_GROUP,
|
|
||||||
increaseFontSizeMenuAction
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
this.menuActionsDisposables.push(
|
|
||||||
registry.registerMenuNode(
|
|
||||||
ArduinoMenus.EDIT__FONT_CONTROL_GROUP,
|
|
||||||
new PlaceholderMenuNode(
|
|
||||||
ArduinoMenus.EDIT__FONT_CONTROL_GROUP,
|
|
||||||
increaseFontSizeMenuAction.label,
|
|
||||||
{ order: increaseFontSizeMenuAction.order }
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (this.fontScalingEnabled.decrease) {
|
|
||||||
this.menuActionsDisposables.push(
|
|
||||||
this.menuRegistry.registerMenuAction(
|
|
||||||
ArduinoMenus.EDIT__FONT_CONTROL_GROUP,
|
|
||||||
decreaseFontSizeMenuAction
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
this.menuActionsDisposables.push(
|
|
||||||
this.menuRegistry.registerMenuNode(
|
|
||||||
ArduinoMenus.EDIT__FONT_CONTROL_GROUP,
|
|
||||||
new PlaceholderMenuNode(
|
|
||||||
ArduinoMenus.EDIT__FONT_CONTROL_GROUP,
|
|
||||||
decreaseFontSizeMenuAction.label,
|
|
||||||
{ order: decreaseFontSizeMenuAction.order }
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
this.mainMenuManager.update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateFontScalingEnabled(): void {
|
private updateFontScalingEnabled(): void {
|
||||||
@ -153,7 +98,7 @@ export class InterfaceScale extends Contribution {
|
|||||||
);
|
);
|
||||||
if (isChanged) {
|
if (isChanged) {
|
||||||
this.fontScalingEnabled = fontScalingEnabled;
|
this.fontScalingEnabled = fontScalingEnabled;
|
||||||
this.registerMenus(this.menuRegistry);
|
this.menuManager.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ import { nls } from '@theia/core/lib/common/nls';
|
|||||||
import { inject, injectable } from '@theia/core/shared/inversify';
|
import { inject, injectable } from '@theia/core/shared/inversify';
|
||||||
import { WorkspaceInputDialogProps } from '@theia/workspace/lib/browser/workspace-input-dialog';
|
import { WorkspaceInputDialogProps } from '@theia/workspace/lib/browser/workspace-input-dialog';
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
import { MainMenuManager } from '../../common/main-menu-manager';
|
|
||||||
import type { AuthenticationSession } from '../../node/auth/types';
|
import type { AuthenticationSession } from '../../node/auth/types';
|
||||||
import { AuthenticationClientService } from '../auth/authentication-client-service';
|
import { AuthenticationClientService } from '../auth/authentication-client-service';
|
||||||
import { CreateApi } from '../create/create-api';
|
import { CreateApi } from '../create/create-api';
|
||||||
@ -41,8 +40,6 @@ export class NewCloudSketch extends Contribution {
|
|||||||
private readonly widgetContribution: SketchbookWidgetContribution;
|
private readonly widgetContribution: SketchbookWidgetContribution;
|
||||||
@inject(AuthenticationClientService)
|
@inject(AuthenticationClientService)
|
||||||
private readonly authenticationService: AuthenticationClientService;
|
private readonly authenticationService: AuthenticationClientService;
|
||||||
@inject(MainMenuManager)
|
|
||||||
private readonly mainMenuManager: MainMenuManager;
|
|
||||||
|
|
||||||
private readonly toDispose = new DisposableCollection();
|
private readonly toDispose = new DisposableCollection();
|
||||||
private _session: AuthenticationSession | undefined;
|
private _session: AuthenticationSession | undefined;
|
||||||
@ -54,7 +51,7 @@ export class NewCloudSketch extends Contribution {
|
|||||||
const oldSession = this._session;
|
const oldSession = this._session;
|
||||||
this._session = session;
|
this._session = session;
|
||||||
if (!!oldSession !== !!this._session) {
|
if (!!oldSession !== !!this._session) {
|
||||||
this.mainMenuManager.update();
|
this.menuManager.update();
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
this.preferences.onPreferenceChanged(({ preferenceName, newValue }) => {
|
this.preferences.onPreferenceChanged(({ preferenceName, newValue }) => {
|
||||||
@ -62,7 +59,7 @@ export class NewCloudSketch extends Contribution {
|
|||||||
const oldEnabled = this._enabled;
|
const oldEnabled = this._enabled;
|
||||||
this._enabled = Boolean(newValue);
|
this._enabled = Boolean(newValue);
|
||||||
if (this._enabled !== oldEnabled) {
|
if (this._enabled !== oldEnabled) {
|
||||||
this.mainMenuManager.update();
|
this.menuManager.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@ -70,7 +67,7 @@ export class NewCloudSketch extends Contribution {
|
|||||||
this._enabled = this.preferences['arduino.cloud.enabled'];
|
this._enabled = this.preferences['arduino.cloud.enabled'];
|
||||||
this._session = this.authenticationService.session;
|
this._session = this.authenticationService.session;
|
||||||
if (this._session) {
|
if (this._session) {
|
||||||
this.mainMenuManager.update();
|
this.menuManager.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { nls } from '@theia/core/lib/common/nls';
|
import { nls } from '@theia/core/lib/common/nls';
|
||||||
import { inject, injectable } from '@theia/core/shared/inversify';
|
import { inject, injectable } from '@theia/core/shared/inversify';
|
||||||
import { MainMenuManager } from '../../common/main-menu-manager';
|
|
||||||
import type { Settings } from '../dialogs/settings/settings';
|
import type { Settings } from '../dialogs/settings/settings';
|
||||||
import { SettingsDialog } from '../dialogs/settings/settings-dialog';
|
import { SettingsDialog } from '../dialogs/settings/settings-dialog';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
@ -16,8 +15,6 @@ import {
|
|||||||
export class OpenSettings extends SketchContribution {
|
export class OpenSettings extends SketchContribution {
|
||||||
@inject(SettingsDialog)
|
@inject(SettingsDialog)
|
||||||
private readonly settingsDialog: SettingsDialog;
|
private readonly settingsDialog: SettingsDialog;
|
||||||
@inject(MainMenuManager)
|
|
||||||
private readonly menuManager: MainMenuManager;
|
|
||||||
|
|
||||||
private settingsOpened = false;
|
private settingsOpened = false;
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ import {
|
|||||||
PreferenceScope,
|
PreferenceScope,
|
||||||
PreferenceService,
|
PreferenceService,
|
||||||
} from '@theia/core/lib/browser/preferences/preference-service';
|
} from '@theia/core/lib/browser/preferences/preference-service';
|
||||||
import { ArduinoPreferences } from '../arduino-preferences';
|
|
||||||
import {
|
import {
|
||||||
arduinoCert,
|
arduinoCert,
|
||||||
certificateList,
|
certificateList,
|
||||||
@ -31,22 +30,29 @@ export class UploadCertificate extends Contribution {
|
|||||||
@inject(PreferenceService)
|
@inject(PreferenceService)
|
||||||
protected readonly preferenceService: PreferenceService;
|
protected readonly preferenceService: PreferenceService;
|
||||||
|
|
||||||
@inject(ArduinoPreferences)
|
|
||||||
protected readonly arduinoPreferences: ArduinoPreferences;
|
|
||||||
|
|
||||||
@inject(ArduinoFirmwareUploader)
|
@inject(ArduinoFirmwareUploader)
|
||||||
protected readonly arduinoFirmwareUploader: ArduinoFirmwareUploader;
|
protected readonly arduinoFirmwareUploader: ArduinoFirmwareUploader;
|
||||||
|
|
||||||
protected dialogOpened = false;
|
protected dialogOpened = false;
|
||||||
|
|
||||||
|
override onStart(): void {
|
||||||
|
this.preferences.onPreferenceChanged(({ preferenceName }) => {
|
||||||
|
if (preferenceName === 'arduino.board.certificates') {
|
||||||
|
this.menuManager.update();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
override registerCommands(registry: CommandRegistry): void {
|
override registerCommands(registry: CommandRegistry): void {
|
||||||
registry.registerCommand(UploadCertificate.Commands.OPEN, {
|
registry.registerCommand(UploadCertificate.Commands.OPEN, {
|
||||||
execute: async () => {
|
execute: async () => {
|
||||||
try {
|
try {
|
||||||
this.dialogOpened = true;
|
this.dialogOpened = true;
|
||||||
|
this.menuManager.update();
|
||||||
await this.dialog.open();
|
await this.dialog.open();
|
||||||
} finally {
|
} finally {
|
||||||
this.dialogOpened = false;
|
this.dialogOpened = false;
|
||||||
|
this.menuManager.update();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
isEnabled: () => !this.dialogOpened,
|
isEnabled: () => !this.dialogOpened,
|
||||||
@ -54,7 +60,7 @@ export class UploadCertificate extends Contribution {
|
|||||||
|
|
||||||
registry.registerCommand(UploadCertificate.Commands.REMOVE_CERT, {
|
registry.registerCommand(UploadCertificate.Commands.REMOVE_CERT, {
|
||||||
execute: async (certToRemove) => {
|
execute: async (certToRemove) => {
|
||||||
const certs = this.arduinoPreferences.get('arduino.board.certificates');
|
const certs = this.preferences.get('arduino.board.certificates');
|
||||||
|
|
||||||
this.preferenceService.set(
|
this.preferenceService.set(
|
||||||
'arduino.board.certificates',
|
'arduino.board.certificates',
|
||||||
@ -75,7 +81,6 @@ export class UploadCertificate extends Contribution {
|
|||||||
.join(' ')}`
|
.join(' ')}`
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
isEnabled: () => true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
registry.registerCommand(UploadCertificate.Commands.OPEN_CERT_CONTEXT, {
|
registry.registerCommand(UploadCertificate.Commands.OPEN_CERT_CONTEXT, {
|
||||||
@ -89,7 +94,6 @@ export class UploadCertificate extends Contribution {
|
|||||||
args: [args.cert],
|
args: [args.cert],
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
isEnabled: () => true,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,9 +21,11 @@ export class UploadFirmware extends Contribution {
|
|||||||
execute: async () => {
|
execute: async () => {
|
||||||
try {
|
try {
|
||||||
this.dialogOpened = true;
|
this.dialogOpened = true;
|
||||||
|
this.menuManager.update();
|
||||||
await this.dialog.open();
|
await this.dialog.open();
|
||||||
} finally {
|
} finally {
|
||||||
this.dialogOpened = false;
|
this.dialogOpened = false;
|
||||||
|
this.menuManager.update();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
isEnabled: () => !this.dialogOpened,
|
isEnabled: () => !this.dialogOpened,
|
||||||
|
@ -106,6 +106,7 @@ export class UploadSketch extends CoreServiceContribution {
|
|||||||
// toggle the toolbar button and menu item state.
|
// toggle the toolbar button and menu item state.
|
||||||
// uploadInProgress will be set to false whether the upload fails or not
|
// uploadInProgress will be set to false whether the upload fails or not
|
||||||
this.uploadInProgress = true;
|
this.uploadInProgress = true;
|
||||||
|
this.menuManager.update();
|
||||||
this.boardsServiceProvider.snapshotBoardDiscoveryOnUpload();
|
this.boardsServiceProvider.snapshotBoardDiscoveryOnUpload();
|
||||||
this.onDidChangeEmitter.fire();
|
this.onDidChangeEmitter.fire();
|
||||||
this.clearVisibleNotification();
|
this.clearVisibleNotification();
|
||||||
@ -150,6 +151,7 @@ export class UploadSketch extends CoreServiceContribution {
|
|||||||
this.handleError(e);
|
this.handleError(e);
|
||||||
} finally {
|
} finally {
|
||||||
this.uploadInProgress = false;
|
this.uploadInProgress = false;
|
||||||
|
this.menuManager.update();
|
||||||
this.boardsServiceProvider.attemptPostUploadAutoSelect();
|
this.boardsServiceProvider.attemptPostUploadAutoSelect();
|
||||||
this.onDidChangeEmitter.fire();
|
this.onDidChangeEmitter.fire();
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { inject, injectable } from '@theia/core/shared/inversify';
|
import { inject, injectable } from '@theia/core/shared/inversify';
|
||||||
import { DisposableCollection, nls } from '@theia/core/lib/common';
|
import { nls } from '@theia/core/lib/common';
|
||||||
import { BoardUserField, CoreError } from '../../common/protocol';
|
import { BoardUserField, CoreError } from '../../common/protocol';
|
||||||
import { BoardsServiceProvider } from '../boards/boards-service-provider';
|
import { BoardsServiceProvider } from '../boards/boards-service-provider';
|
||||||
import { UserFieldsDialog } from '../dialogs/user-fields/user-fields-dialog';
|
import { UserFieldsDialog } from '../dialogs/user-fields/user-fields-dialog';
|
||||||
import { ArduinoMenus, PlaceholderMenuNode } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
import { MenuModelRegistry, Contribution } from './contribution';
|
import { MenuModelRegistry, Contribution } from './contribution';
|
||||||
import { UploadSketch } from './upload-sketch';
|
import { UploadSketch } from './upload-sketch';
|
||||||
|
|
||||||
@ -12,7 +12,6 @@ export class UserFields extends Contribution {
|
|||||||
private boardRequiresUserFields = false;
|
private boardRequiresUserFields = false;
|
||||||
private userFieldsSet = false;
|
private userFieldsSet = false;
|
||||||
private readonly cachedUserFields: Map<string, BoardUserField[]> = new Map();
|
private readonly cachedUserFields: Map<string, BoardUserField[]> = new Map();
|
||||||
private readonly menuActionsDisposables = new DisposableCollection();
|
|
||||||
|
|
||||||
@inject(UserFieldsDialog)
|
@inject(UserFieldsDialog)
|
||||||
private readonly userFieldsDialog: UserFieldsDialog;
|
private readonly userFieldsDialog: UserFieldsDialog;
|
||||||
@ -20,42 +19,22 @@ export class UserFields extends Contribution {
|
|||||||
@inject(BoardsServiceProvider)
|
@inject(BoardsServiceProvider)
|
||||||
private readonly boardsServiceProvider: BoardsServiceProvider;
|
private readonly boardsServiceProvider: BoardsServiceProvider;
|
||||||
|
|
||||||
@inject(MenuModelRegistry)
|
|
||||||
private readonly menuRegistry: MenuModelRegistry;
|
|
||||||
|
|
||||||
protected override init(): void {
|
protected override init(): void {
|
||||||
super.init();
|
super.init();
|
||||||
this.boardsServiceProvider.onBoardsConfigChanged(async () => {
|
this.boardsServiceProvider.onBoardsConfigChanged(async () => {
|
||||||
const userFields =
|
const userFields =
|
||||||
await this.boardsServiceProvider.selectedBoardUserFields();
|
await this.boardsServiceProvider.selectedBoardUserFields();
|
||||||
this.boardRequiresUserFields = userFields.length > 0;
|
this.boardRequiresUserFields = userFields.length > 0;
|
||||||
this.registerMenus(this.menuRegistry);
|
this.menuManager.update();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
override registerMenus(registry: MenuModelRegistry): void {
|
override registerMenus(registry: MenuModelRegistry): void {
|
||||||
this.menuActionsDisposables.dispose();
|
|
||||||
if (this.boardRequiresUserFields) {
|
|
||||||
this.menuActionsDisposables.push(
|
|
||||||
registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, {
|
registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, {
|
||||||
commandId: UploadSketch.Commands.UPLOAD_WITH_CONFIGURATION.id,
|
commandId: UploadSketch.Commands.UPLOAD_WITH_CONFIGURATION.id,
|
||||||
label: UploadSketch.Commands.UPLOAD_WITH_CONFIGURATION.label,
|
label: UploadSketch.Commands.UPLOAD_WITH_CONFIGURATION.label,
|
||||||
order: '2',
|
order: '2',
|
||||||
})
|
});
|
||||||
);
|
|
||||||
} else {
|
|
||||||
this.menuActionsDisposables.push(
|
|
||||||
registry.registerMenuNode(
|
|
||||||
ArduinoMenus.SKETCH__MAIN_GROUP,
|
|
||||||
new PlaceholderMenuNode(
|
|
||||||
ArduinoMenus.SKETCH__MAIN_GROUP,
|
|
||||||
// commandId: UploadSketch.Commands.UPLOAD_WITH_CONFIGURATION.id,
|
|
||||||
UploadSketch.Commands.UPLOAD_WITH_CONFIGURATION.label,
|
|
||||||
{ order: '2' }
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private selectedFqbnAddress(): string | undefined {
|
private selectedFqbnAddress(): string | undefined {
|
||||||
|
@ -21,11 +21,18 @@ export interface VerifySketchParams {
|
|||||||
*/
|
*/
|
||||||
readonly exportBinaries?: boolean;
|
readonly exportBinaries?: boolean;
|
||||||
/**
|
/**
|
||||||
* If `true`, there won't be any UI indication of the verify command. It's `false` by default.
|
* If `true`, there won't be any UI indication of the verify command in the toolbar. It's `false` by default.
|
||||||
*/
|
*/
|
||||||
readonly silent?: boolean;
|
readonly silent?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* - `"idle"` when neither verify, not upload is running,
|
||||||
|
* - `"explicit-verify"` when only verify is running triggered by the user, and
|
||||||
|
* - `"automatic-verify"` is when the automatic verify phase is running as part of an upload triggered by the user.
|
||||||
|
*/
|
||||||
|
type VerifyProgress = 'idle' | 'explicit-verify' | 'automatic-verify';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class VerifySketch extends CoreServiceContribution {
|
export class VerifySketch extends CoreServiceContribution {
|
||||||
@inject(CoreErrorHandler)
|
@inject(CoreErrorHandler)
|
||||||
@ -33,22 +40,24 @@ export class VerifySketch extends CoreServiceContribution {
|
|||||||
|
|
||||||
private readonly onDidChangeEmitter = new Emitter<void>();
|
private readonly onDidChangeEmitter = new Emitter<void>();
|
||||||
private readonly onDidChange = this.onDidChangeEmitter.event;
|
private readonly onDidChange = this.onDidChangeEmitter.event;
|
||||||
private verifyInProgress = false;
|
private verifyProgress: VerifyProgress = 'idle';
|
||||||
|
|
||||||
override registerCommands(registry: CommandRegistry): void {
|
override registerCommands(registry: CommandRegistry): void {
|
||||||
registry.registerCommand(VerifySketch.Commands.VERIFY_SKETCH, {
|
registry.registerCommand(VerifySketch.Commands.VERIFY_SKETCH, {
|
||||||
execute: (params?: VerifySketchParams) => this.verifySketch(params),
|
execute: (params?: VerifySketchParams) => this.verifySketch(params),
|
||||||
isEnabled: () => !this.verifyInProgress,
|
isEnabled: () => this.verifyProgress === 'idle',
|
||||||
});
|
});
|
||||||
registry.registerCommand(VerifySketch.Commands.EXPORT_BINARIES, {
|
registry.registerCommand(VerifySketch.Commands.EXPORT_BINARIES, {
|
||||||
execute: () => this.verifySketch({ exportBinaries: true }),
|
execute: () => this.verifySketch({ exportBinaries: true }),
|
||||||
isEnabled: () => !this.verifyInProgress,
|
isEnabled: () => this.verifyProgress === 'idle',
|
||||||
});
|
});
|
||||||
registry.registerCommand(VerifySketch.Commands.VERIFY_SKETCH_TOOLBAR, {
|
registry.registerCommand(VerifySketch.Commands.VERIFY_SKETCH_TOOLBAR, {
|
||||||
isVisible: (widget) =>
|
isVisible: (widget) =>
|
||||||
ArduinoToolbar.is(widget) && widget.side === 'left',
|
ArduinoToolbar.is(widget) && widget.side === 'left',
|
||||||
isEnabled: () => !this.verifyInProgress,
|
isEnabled: () => this.verifyProgress !== 'explicit-verify',
|
||||||
isToggled: () => this.verifyInProgress,
|
// toggled only when verify is running, but not toggled when automatic verify is running before the upload
|
||||||
|
// https://github.com/arduino/arduino-ide/pull/1750#pullrequestreview-1214762975
|
||||||
|
isToggled: () => this.verifyProgress === 'explicit-verify',
|
||||||
execute: () =>
|
execute: () =>
|
||||||
registry.executeCommand(VerifySketch.Commands.VERIFY_SKETCH.id),
|
registry.executeCommand(VerifySketch.Commands.VERIFY_SKETCH.id),
|
||||||
});
|
});
|
||||||
@ -99,15 +108,16 @@ export class VerifySketch extends CoreServiceContribution {
|
|||||||
private async verifySketch(
|
private async verifySketch(
|
||||||
params?: VerifySketchParams
|
params?: VerifySketchParams
|
||||||
): Promise<CoreService.Options.Compile | undefined> {
|
): Promise<CoreService.Options.Compile | undefined> {
|
||||||
if (this.verifyInProgress) {
|
if (this.verifyProgress !== 'idle') {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!params?.silent) {
|
this.verifyProgress = params?.silent
|
||||||
this.verifyInProgress = true;
|
? 'automatic-verify'
|
||||||
|
: 'explicit-verify';
|
||||||
this.onDidChangeEmitter.fire();
|
this.onDidChangeEmitter.fire();
|
||||||
}
|
this.menuManager.update();
|
||||||
this.clearVisibleNotification();
|
this.clearVisibleNotification();
|
||||||
this.coreErrorHandler.reset();
|
this.coreErrorHandler.reset();
|
||||||
|
|
||||||
@ -139,10 +149,9 @@ export class VerifySketch extends CoreServiceContribution {
|
|||||||
this.handleError(e);
|
this.handleError(e);
|
||||||
return undefined;
|
return undefined;
|
||||||
} finally {
|
} finally {
|
||||||
this.verifyInProgress = false;
|
this.verifyProgress = 'idle';
|
||||||
if (!params?.silent) {
|
|
||||||
this.onDidChangeEmitter.fire();
|
this.onDidChangeEmitter.fire();
|
||||||
}
|
this.menuManager.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,8 @@ export class CommonFrontendContribution extends TheiaCommonFrontendContribution
|
|||||||
CommonCommands.SELECT_ICON_THEME,
|
CommonCommands.SELECT_ICON_THEME,
|
||||||
CommonCommands.SELECT_COLOR_THEME,
|
CommonCommands.SELECT_COLOR_THEME,
|
||||||
CommonCommands.ABOUT_COMMAND,
|
CommonCommands.ABOUT_COMMAND,
|
||||||
CommonCommands.SAVE_WITHOUT_FORMATTING, // Patched for https://github.com/eclipse-theia/theia/pull/8877
|
CommonCommands.SAVE_WITHOUT_FORMATTING, // Patched for https://github.com/eclipse-theia/theia/pull/8877,
|
||||||
|
CommonCommands.NEW_UNTITLED_FILE,
|
||||||
]) {
|
]) {
|
||||||
registry.unregisterMenuAction(command);
|
registry.unregisterMenuAction(command);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user