From 42d5a08c3b0fd7ed05f3e351c7103ce722b088f8 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Sat, 18 Jul 2020 17:30:54 +0200 Subject: [PATCH] cloned the editor menu. Signed-off-by: Akos Kitta --- .../contributions/edit-contributions.ts | 100 ++++++++++++++++-- .../core/common-frontend-contribution.ts | 14 ++- ...arch-in-workspace-frontend-contribution.ts | 8 +- .../src/browser/menu/arduino-menus.ts | 8 +- 4 files changed, 113 insertions(+), 17 deletions(-) diff --git a/arduino-ide-extension/src/browser/contributions/edit-contributions.ts b/arduino-ide-extension/src/browser/contributions/edit-contributions.ts index b803b2b4..91815fc3 100644 --- a/arduino-ide-extension/src/browser/contributions/edit-contributions.ts +++ b/arduino-ide-extension/src/browser/contributions/edit-contributions.ts @@ -4,21 +4,28 @@ import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor'; import { Contribution, Command, MenuModelRegistry, KeybindingRegistry, CommandRegistry } from './contribution'; import { ArduinoMenus } from '../menu/arduino-menus'; import { ClipboardService } from '@theia/core/lib/browser/clipboard-service'; +import { CommonCommands } from '@theia/core/lib/browser'; +// TODO: [macOS]: to remove `Start Dictation...` and `Emoji & Symbol` see this thread: https://github.com/electron/electron/issues/8283#issuecomment-269522072 +// Depends on https://github.com/eclipse-theia/theia/pull/7964 @injectable() export class EditContributions extends Contribution { - @inject(ClipboardService) - protected readonly clipboardService: ClipboardService; - @inject(EditorManager) protected readonly editorManager: EditorManager; + @inject(ClipboardService) + protected readonly clipboardService: ClipboardService; + registerCommands(registry: CommandRegistry): void { registry.registerCommand(EditContributions.Commands.GO_TO_LINE, { execute: () => this.run('editor.action.gotoLine') }); registry.registerCommand(EditContributions.Commands.TOGGLE_COMMENT, { execute: () => this.run('editor.action.commentLine') }); registry.registerCommand(EditContributions.Commands.INDENT_LINES, { execute: () => this.run('editor.action.indentLines') }); registry.registerCommand(EditContributions.Commands.OUTDENT_LINES, { execute: () => this.run('editor.action.outdentLines') }); + registry.registerCommand(EditContributions.Commands.FIND, { execute: () => this.run('actions.find') }); + registry.registerCommand(EditContributions.Commands.FIND_NEXT, { execute: () => this.run('actions.findWithSelection') }); + registry.registerCommand(EditContributions.Commands.FIND_PREVIOUS, { execute: () => this.run('editor.action.nextMatchFindAction') }); + registry.registerCommand(EditContributions.Commands.USE_FOR_FIND, { execute: () => this.run('editor.action.previousSelectionMatchFindAction') }); registry.registerCommand(EditContributions.Commands.COPY_FOR_FORUM, { execute: async () => { const value = await this.currentValue(); @@ -29,7 +36,7 @@ ${value} } } }); - registry.registerCommand(EditContributions.Commands.COPY_FOR_MARKDOWN, { + registry.registerCommand(EditContributions.Commands.COPY_FOR_GITHUB, { execute: async () => { const value = await this.currentValue(); if (value !== undefined) { @@ -43,16 +50,35 @@ ${value} registerMenus(registry: MenuModelRegistry): void { registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, { - commandId: EditContributions.Commands.COPY_FOR_FORUM.id, - label: 'Copy for Forum', + commandId: CommonCommands.CUT.id, + order: '0' }); registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, { - commandId: EditContributions.Commands.COPY_FOR_MARKDOWN.id, - label: 'Copy for GitHub [Markdown]', + commandId: CommonCommands.COPY.id, + order: '1' + }); + registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, { + commandId: EditContributions.Commands.COPY_FOR_FORUM.id, + label: 'Copy for Forum', + order: '2' + }); + registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, { + commandId: EditContributions.Commands.COPY_FOR_GITHUB.id, + label: 'Copy for GitHub', + order: '3' + }); + registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, { + commandId: CommonCommands.PASTE.id, + order: '4' + }); + registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, { + commandId: CommonCommands.SELECT_ALL.id, + order: '5' }); registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, { commandId: EditContributions.Commands.GO_TO_LINE.id, label: 'Go to Line...', + order: '6' }); registry.registerMenuAction(ArduinoMenus.EDIT__CODE_CONTROL_GROUP, { @@ -70,6 +96,27 @@ ${value} label: 'Decrease Indent', order: '2' }); + + registry.registerMenuAction(ArduinoMenus.EDIT__FIND_GROUP, { + commandId: EditContributions.Commands.FIND.id, + label: 'Find', + order: '0' + }); + registry.registerMenuAction(ArduinoMenus.EDIT__FIND_GROUP, { + commandId: EditContributions.Commands.FIND_NEXT.id, + label: 'Find Next', + order: '1' + }); + registry.registerMenuAction(ArduinoMenus.EDIT__FIND_GROUP, { + commandId: EditContributions.Commands.FIND_PREVIOUS.id, + label: 'Find Previous', + order: '2' + }); + registry.registerMenuAction(ArduinoMenus.EDIT__FIND_GROUP, { + commandId: EditContributions.Commands.USE_FOR_FIND.id, + label: 'Use Selection for Find', // XXX: The Java IDE uses `Use Selection For Find`. + order: '3' + }); } registerKeybindings(registry: KeybindingRegistry): void { @@ -77,6 +124,10 @@ ${value} command: EditContributions.Commands.COPY_FOR_FORUM.id, keybinding: 'CtrlCmd+Shift+C' }); + registry.registerKeybinding({ + command: EditContributions.Commands.COPY_FOR_GITHUB.id, + keybinding: 'CtrlCmd+Alt+C' + }); registry.registerKeybinding({ command: EditContributions.Commands.GO_TO_LINE.id, keybinding: 'CtrlCmd+L' @@ -94,6 +145,23 @@ ${value} command: EditContributions.Commands.OUTDENT_LINES.id, keybinding: 'Shift+Tab' }); + + registry.registerKeybinding({ + command: EditContributions.Commands.FIND.id, + keybinding: 'CtrlCmd+F' + }); + registry.registerKeybinding({ + command: EditContributions.Commands.FIND_NEXT.id, + keybinding: 'CtrlCmd+G' + }); + registry.registerKeybinding({ + command: EditContributions.Commands.FIND_PREVIOUS.id, + keybinding: 'CtrlCmd+Shift+G' + }); + registry.registerKeybinding({ + command: EditContributions.Commands.USE_FOR_FIND.id, + keybinding: 'CtrlCmd+E' + }); } protected async current(): Promise { @@ -122,8 +190,8 @@ export namespace EditContributions { export const COPY_FOR_FORUM: Command = { id: 'arduino-copy-for-forum' }; - export const COPY_FOR_MARKDOWN: Command = { - id: 'arduino-copy-for-markdown' + export const COPY_FOR_GITHUB: Command = { + id: 'arduino-copy-for-github' }; export const GO_TO_LINE: Command = { id: 'arduino-go-to-line' @@ -137,5 +205,17 @@ export namespace EditContributions { export const OUTDENT_LINES: Command = { id: 'arduino-outdent-lines' }; + export const FIND: Command = { + id: 'arduino-find' + }; + export const FIND_NEXT: Command = { + id: 'arduino-find-next' + }; + export const FIND_PREVIOUS: Command = { + id: 'arduino-find-previous' + }; + export const USE_FOR_FIND: Command = { + id: 'arduino-for-find' + }; } } diff --git a/arduino-ide-extension/src/browser/customization/core/common-frontend-contribution.ts b/arduino-ide-extension/src/browser/customization/core/common-frontend-contribution.ts index 04940f72..adbd140d 100644 --- a/arduino-ide-extension/src/browser/customization/core/common-frontend-contribution.ts +++ b/arduino-ide-extension/src/browser/customization/core/common-frontend-contribution.ts @@ -7,8 +7,18 @@ export class CommonFrontendContribution extends TheiaCommonFrontendContribution registerMenus(registry: MenuModelRegistry): void { super.registerMenus(registry); - registry.unregisterMenuAction(CommonCommands.SAVE); - registry.unregisterMenuAction(CommonCommands.SAVE_ALL); + for (const command of [ + CommonCommands.SAVE, + CommonCommands.SAVE_ALL, + CommonCommands.CUT, + CommonCommands.COPY, + CommonCommands.PASTE, + CommonCommands.COPY_PATH, + CommonCommands.FIND, + CommonCommands.REPLACE + ]) { + registry.unregisterMenuAction(command); + } } } diff --git a/arduino-ide-extension/src/browser/customization/search-in-workspace/search-in-workspace-frontend-contribution.ts b/arduino-ide-extension/src/browser/customization/search-in-workspace/search-in-workspace-frontend-contribution.ts index c26aa07d..00738e5e 100644 --- a/arduino-ide-extension/src/browser/customization/search-in-workspace/search-in-workspace-frontend-contribution.ts +++ b/arduino-ide-extension/src/browser/customization/search-in-workspace/search-in-workspace-frontend-contribution.ts @@ -1,7 +1,8 @@ import { inject, injectable } from 'inversify'; import { FrontendApplication } from '@theia/core/lib/browser/frontend-application'; -import { SearchInWorkspaceFrontendContribution as TheiaSearchInWorkspaceFrontendContribution } from '@theia/search-in-workspace/lib/browser/search-in-workspace-frontend-contribution'; +import { SearchInWorkspaceFrontendContribution as TheiaSearchInWorkspaceFrontendContribution, SearchInWorkspaceCommands } from '@theia/search-in-workspace/lib/browser/search-in-workspace-frontend-contribution'; import { EditorMode } from '../../editor-mode'; +import { MenuModelRegistry } from '@theia/core'; @injectable() export class SearchInWorkspaceFrontendContribution extends TheiaSearchInWorkspaceFrontendContribution { @@ -15,4 +16,9 @@ export class SearchInWorkspaceFrontendContribution extends TheiaSearchInWorkspac } } + registerMenus(registry: MenuModelRegistry): void { + super.registerMenus(registry); + registry.unregisterMenuAction(SearchInWorkspaceCommands.OPEN_SIW_WIDGET); + } + } diff --git a/arduino-ide-extension/src/browser/menu/arduino-menus.ts b/arduino-ide-extension/src/browser/menu/arduino-menus.ts index 840b8ac5..200eb05a 100644 --- a/arduino-ide-extension/src/browser/menu/arduino-menus.ts +++ b/arduino-ide-extension/src/browser/menu/arduino-menus.ts @@ -9,10 +9,10 @@ export namespace ArduinoMenus { export const FILE__PRINT_GROUP = [...CommonMenus.FILE, '1_print']; // Edit - export const EDIT__TEXT_CONTROL_GROUP = [...CommonMenus.EDIT, '1_text_control']; // `Copy`, `Copy to Forum`, `Paste`, etc. - export const EDIT__CODE_CONTROL_GROUP = [...CommonMenus.EDIT, '2_code_control']; // `Comment/Uncomment`, etc. - export const EDIT__FONT_CONTROL_GROUP = [...CommonMenus.EDIT, '3_font_control']; - export const EDIT__FIND_GROUP = [...CommonMenus.EDIT, '4_find']; + export const EDIT__TEXT_CONTROL_GROUP = [...CommonMenus.EDIT, '2_text_control']; // `Copy`, `Copy to Forum`, `Paste`, etc. Note: `1_undo` is the first group from Theia + export const EDIT__CODE_CONTROL_GROUP = [...CommonMenus.EDIT, '3_code_control']; // `Comment/Uncomment`, etc. + export const EDIT__FONT_CONTROL_GROUP = [...CommonMenus.EDIT, '4_font_control']; + export const EDIT__FIND_GROUP = [...CommonMenus.EDIT, '5_find']; // Sketch export const SKETCH = [...MAIN_MENU_BAR, '3_sketch'];