diff --git a/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts b/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts index fca4d081f..89d13fd93 100644 --- a/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts +++ b/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts @@ -352,6 +352,8 @@ import { CreateCloudCopy } from './contributions/create-cloud-copy'; import { FileResourceResolver } from './theia/filesystem/file-resource'; import { FileResourceResolver as TheiaFileResourceResolver } from '@theia/filesystem/lib/browser/file-resource'; import { StylingParticipant } from '@theia/core/lib/browser/styling-service'; +import { MonacoEditorMenuContribution } from './theia/monaco/monaco-menu'; +import { MonacoEditorMenuContribution as TheiaMonacoEditorMenuContribution } from '@theia/monaco/lib/browser/monaco-menu'; // Hack to fix copy/cut/paste issue after electron version update in Theia. // https://github.com/eclipse-theia/theia/issues/12487 @@ -1014,4 +1016,12 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => { // https://github.com/arduino/arduino-ide/issues/437 bind(FileResourceResolver).toSelf().inSingletonScope(); rebind(TheiaFileResourceResolver).toService(FileResourceResolver); + + // Full control over the editor context menu to filter undesired menu items contributed by Theia. + // https://github.com/arduino/arduino-ide/issues/1394 + // https://github.com/arduino/arduino-ide/pull/2027#pullrequestreview-1414246614 + bind(MonacoEditorMenuContribution).toSelf().inSingletonScope(); + rebind(TheiaMonacoEditorMenuContribution).toService( + MonacoEditorMenuContribution + ); }); diff --git a/arduino-ide-extension/src/browser/theia/monaco/monaco-menu.ts b/arduino-ide-extension/src/browser/theia/monaco/monaco-menu.ts new file mode 100644 index 000000000..5d8ae055f --- /dev/null +++ b/arduino-ide-extension/src/browser/theia/monaco/monaco-menu.ts @@ -0,0 +1,24 @@ +import type { MenuModelRegistry } from '@theia/core/lib/common/menu/menu-model-registry'; +import { injectable } from '@theia/core/shared/inversify'; +import { MonacoEditorMenuContribution as TheiaMonacoEditorMenuContribution } from '@theia/monaco/lib/browser/monaco-menu'; + +@injectable() +export class MonacoEditorMenuContribution extends TheiaMonacoEditorMenuContribution { + override registerMenus(registry: MenuModelRegistry): void { + super.registerMenus(registry); + // https://github.com/arduino/arduino-ide/issues/1394 + registry.unregisterMenuAction('editor.action.refactor'); // Refactor... + registry.unregisterMenuAction('editor.action.sourceAction'); // Source Action... + // https://github.com/arduino/arduino-ide/pull/2027#pullrequestreview-1414246614 + // Root editor context menu + registry.unregisterMenuAction('editor.action.revealDeclaration'); // Go to Declaration + registry.unregisterMenuAction('editor.action.goToTypeDefinition'); // Go to Type Definition + registry.unregisterMenuAction('editor.action.goToImplementation'); // Go to Implementations + registry.unregisterMenuAction('editor.action.goToReferences'); // Go to References + // Peek submenu + registry.unregisterMenuAction('editor.action.peekDeclaration'); // Peek Declaration + registry.unregisterMenuAction('editor.action.peekTypeDefinition'); // Peek Type Definition + registry.unregisterMenuAction('editor.action.peekImplementation'); // Peek Implementation + registry.unregisterMenuAction('editor.action.referenceSearch.trigger'); // Peek References + } +}