Skip to content

Commit

Permalink
fix: removed undesired editor context menu items
Browse files Browse the repository at this point in the history
Closes #1394

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
  • Loading branch information
Akos Kitta committed May 8, 2023
1 parent 4454666 commit 7534d8a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
);
});
24 changes: 24 additions & 0 deletions arduino-ide-extension/src/browser/theia/monaco/monaco-menu.ts
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 7534d8a

Please sign in to comment.