cloned the editor menu.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta 2020-07-18 17:30:54 +02:00
parent 88631a318b
commit 42d5a08c3b
4 changed files with 113 additions and 17 deletions

View File

@ -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<MonacoEditor | undefined> {
@ -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'
};
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}

View File

@ -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'];