From f83dca036a425580739c3d4fd3305f70f8885bde Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Tue, 29 Aug 2017 13:48:00 +0200 Subject: [PATCH] GH-210: Registered `selection` commands, handlers and menu items. Signed-off-by: Akos Kitta --- packages/monaco/src/browser/monaco-command.ts | 76 +++++++++++++++ packages/monaco/src/browser/monaco-menu.ts | 96 +++++++++++++++++++ 2 files changed, 172 insertions(+) diff --git a/packages/monaco/src/browser/monaco-command.ts b/packages/monaco/src/browser/monaco-command.ts index 14bdaeb837493..05d064625ea34 100644 --- a/packages/monaco/src/browser/monaco-command.ts +++ b/packages/monaco/src/browser/monaco-command.ts @@ -13,7 +13,11 @@ import { Position, Location } from "@theia/languages/lib/common"; ======= ======= <<<<<<< HEAD +<<<<<<< Upstream, based on branch 'GH-210' of https://github.com/theia-ide/theia.git >>>>>>> f57136b GH-210: Registered find/replace commands and menu items. +======= +<<<<<<< HEAD +>>>>>>> 7929942 GH-210: Registered `selection` commands, handlers and menu items. import { CommandHandler, CommandContribution, CommandRegistry, SelectionService } from '@theia/core/lib/common'; @@ -27,15 +31,26 @@ import { CommandHandler, CommandContribution, CommandRegistry, CommonCommands, S >>>>>>> f57136b GH-210: Registered find/replace commands and menu items. import { EditorManager, TextEditorSelection, SHOW_REFERENCES } from '@theia/editor/lib/browser'; <<<<<<< Upstream, based on branch 'GH-210' of https://github.com/theia-ide/theia.git +<<<<<<< Upstream, based on branch 'GH-210' of https://github.com/theia-ide/theia.git import { CommandHandler, CommandContribution, CommandRegistry, CommonCommands, SelectionService } from '@theia/core/lib/common'; ======= +======= +======= +>>>>>>> GH-210: Registered `selection` commands, handlers and menu items. +>>>>>>> 7929942 GH-210: Registered `selection` commands, handlers and menu items. import { Position, Location } from "@theia/languages/lib/common"; +<<<<<<< Upstream, based on branch 'GH-210' of https://github.com/theia-ide/theia.git >>>>>>> f57136b GH-210: Registered find/replace commands and menu items. +======= +import { EditorManager, TextEditorSelection, SHOW_REFERENCES } from '@theia/editor/lib/browser'; +import { CommandHandler, CommandContribution, CommandRegistry, CommonCommands, SelectionService } from '@theia/core/lib/common'; +>>>>>>> 7929942 GH-210: Registered `selection` commands, handlers and menu items. import { getCurrent, MonacoEditor } from './monaco-editor'; import MenuRegistry = monaco.actions.MenuRegistry; import MenuId = monaco.actions.MenuId; /** +<<<<<<< Upstream, based on branch 'GH-210' of https://github.com/theia-ide/theia.git * Editor commands (and actions) for the `Selection` menu contribution. */ export namespace MonacoSelectionCommands { @@ -73,6 +88,46 @@ export namespace MonacoSelectionCommands { { id: SELECTION_MOVE_LINE_UP, label: 'Move Line Up' }, { id: SELECTION_MOVE_LINE_DOWN, label: 'Move Line Down' }, +======= + * Editor commands for the `Selection` menu contribution. + */ +export namespace MonacoSelectionCommands { + + export const SELECTION_MENU = '3_selection'; + + export const SELECTION_MENU_SELECTION_GROUP = '1_selection_group'; + export const SELECTION_MENU_COPY_MOVE_GROUP = '2_copy_move_group'; + export const SELECTION_MENU_CURSOR_GROUP = '3_cursor_group'; + + export const SELECTION_SELECT_ALL = 'editor.action.selectAll'; + export const SELECTION_EXPAND_SELECTION = 'editor.action.smartSelect.grow'; + export const SELECTION_SHRINK_SELECTION = 'editor.action.smartSelect.shrink'; + + export const SELECTION_COPY_LINE_UP = 'editor.action.copyLinesUpAction'; + export const SELECTION_COPY_LINE_DOWN = 'editor.action.copyLinesDownAction'; + export const SELECTION_MOVE_LINE_UP = 'editor.action.moveLinesUpAction'; + export const SELECTION_MOVE_LINE_DOWN = 'editor.action.moveLinesDownAction'; + + export const SELECTION_SWITCH_TO_MULTI_CURSOR = 'workbench.action.toggleMultiCursorModifier'; + export const SELECTION_ADD_CURSOR_ABOVE = 'editor.action.insertCursorAbove'; + export const SELECTION_ADD_CURSOR_BELOW = 'editor.action.insertCursorBelow'; + export const SELECTION_ADD_CURSOR_TO_LINE_END = 'editor.action.insertCursorAtEndOfEachLineSelected'; + export const SELECTION_ADD_NEXT_OCCURRENCE = 'editor.action.addSelectionToNextFindMatch'; + export const SELECTION_ADD_PREVIOUS_OCCURRENCE = 'editor.action.addSelectionToPreviousFindMatch'; + export const SELECTION_SELECT_ALL_OCCURRENCES = 'editor.action.selectHighlights'; + + export const ACTIONS: { id: string, label: string }[] = [ + { id: SELECTION_SELECT_ALL, label: 'Select All' }, + { id: SELECTION_EXPAND_SELECTION, label: 'Expand Selection' }, + { id: SELECTION_SHRINK_SELECTION, label: 'Shrink Selection' }, + + { id: SELECTION_COPY_LINE_UP, label: 'Copy Line Up' }, + { id: SELECTION_COPY_LINE_DOWN, label: 'Copy Line Down' }, + { id: SELECTION_MOVE_LINE_UP, label: 'Move Line Up' }, + { id: SELECTION_MOVE_LINE_DOWN, label: 'Move Line Down' }, + + { id: SELECTION_SWITCH_TO_MULTI_CURSOR, label: SELECTION_SWITCH_TO_MULTI_CURSOR }, +>>>>>>> 7929942 GH-210: Registered `selection` commands, handlers and menu items. { id: SELECTION_ADD_CURSOR_ABOVE, label: 'Add Cursor Above' }, { id: SELECTION_ADD_CURSOR_BELOW, label: 'Add Cursor Below' }, { id: SELECTION_ADD_CURSOR_TO_LINE_END, label: 'Add Cursors to Line Ends' }, @@ -124,6 +179,7 @@ export class MonacoEditorCommandHandlers implements CommandContribution { commands.registerHandler(id, handler); }); +<<<<<<< Upstream, based on branch 'GH-210' of https://github.com/theia-ide/theia.git <<<<<<< Upstream, based on branch 'GH-210' of https://github.com/theia-ide/theia.git [CommonCommands.EDIT_FIND, CommonCommands.EDIT_REPLACE, ...MonacoSelectionCommands.ACTIONS.filter(action => !action.delegateId).map(({ id }) => id)].forEach(id => { commands.registerHandler(id, this.newHandler(id)); @@ -154,6 +210,11 @@ export class MonacoEditorCommandHandlers implements CommandContribution { const replaceHandler = new EditorCommandHandler(CommonCommands.EDIT_REPLACE, this.editorManager, this.selectionService); commands.registerHandler(CommonCommands.EDIT_REPLACE, replaceHandler); >>>>>>> f57136b GH-210: Registered find/replace commands and menu items. +======= + [CommonCommands.EDIT_FIND, CommonCommands.EDIT_REPLACE, ...MonacoSelectionCommands.ACTIONS.map(({ id }) => id)].forEach(id => { + commands.registerHandler(id, new EditorCommandHandler(id, this.editorManager, this.selectionService)); + }); +>>>>>>> 7929942 GH-210: Registered `selection` commands, handlers and menu items. for (const menuItem of MenuRegistry.getMenuItems(MenuId.EditorContext)) { const { id, title, iconClass } = menuItem.command; @@ -173,10 +234,25 @@ export class MonacoEditorCommandHandlers implements CommandContribution { const { id, label } = entry; commands.registerCommand({ id, +<<<<<<< Upstream, based on branch 'GH-210' of https://github.com/theia-ide/theia.git label }); }); +======= + iconClass, + label: title + }, this.newHandler(id)); + } + + MonacoSelectionCommands.ACTIONS.forEach(entry => { + const { id, label } = entry; + commands.registerCommand({ + id, + label + }); + }); +>>>>>>> 7929942 GH-210: Registered `selection` commands, handlers and menu items. } protected newHandler(id: string): CommandHandler { diff --git a/packages/monaco/src/browser/monaco-menu.ts b/packages/monaco/src/browser/monaco-menu.ts index 94c3048c4592b..d15119563c040 100644 --- a/packages/monaco/src/browser/monaco-menu.ts +++ b/packages/monaco/src/browser/monaco-menu.ts @@ -7,11 +7,21 @@ import { injectable } from "inversify"; <<<<<<< Upstream, based on branch 'GH-210' of https://github.com/theia-ide/theia.git +<<<<<<< Upstream, based on branch 'GH-210' of https://github.com/theia-ide/theia.git import { MenuContribution, MenuModelRegistry, CommonCommands, MAIN_MENU_BAR } from "@theia/core/lib/common"; ======= +======= +<<<<<<< HEAD +>>>>>>> 7929942 GH-210: Registered `selection` commands, handlers and menu items. import { MenuContribution, MenuModelRegistry } from "@theia/core/lib/common"; import { CommonCommands } from '@theia/core/lib/browser'; +<<<<<<< Upstream, based on branch 'GH-210' of https://github.com/theia-ide/theia.git >>>>>>> 008c2e4 Merge core-commands with common-frontend-contribution +======= +======= +import { MenuContribution, MenuModelRegistry, CommonCommands, MAIN_MENU_BAR } from "@theia/core/lib/common"; +>>>>>>> GH-210: Registered `selection` commands, handlers and menu items. +>>>>>>> 7929942 GH-210: Registered `selection` commands, handlers and menu items. import { EDITOR_CONTEXT_MENU_ID } from "@theia/editor/lib/browser"; import { MonacoSelectionCommands } from "./monaco-command"; import MenuRegistry = monaco.actions.MenuRegistry; @@ -45,6 +55,7 @@ export class MonacoEditorMenuContribution implements MenuContribution { MAIN_MENU_BAR, MonacoSelectionCommands.SELECTION_MENU, MonacoSelectionCommands.SELECTION_MENU_SELECTION_GROUP], { +<<<<<<< Upstream, based on branch 'GH-210' of https://github.com/theia-ide/theia.git commandId: MonacoSelectionCommands.SELECTION_SELECT_ALL, order: '0' }); @@ -135,6 +146,91 @@ export class MonacoEditorMenuContribution implements MenuContribution { MonacoSelectionCommands.SELECTION_MENU_CURSOR_GROUP], { commandId: MonacoSelectionCommands.SELECTION_SELECT_ALL_OCCURRENCES, order: '5' +======= + commandId: MonacoSelectionCommands.SELECTION_SELECT_ALL + }); + registry.registerMenuAction([ + MAIN_MENU_BAR, + MonacoSelectionCommands.SELECTION_MENU, + MonacoSelectionCommands.SELECTION_MENU_SELECTION_GROUP], { + commandId: MonacoSelectionCommands.SELECTION_EXPAND_SELECTION + }); + registry.registerMenuAction([ + MAIN_MENU_BAR, + MonacoSelectionCommands.SELECTION_MENU, + MonacoSelectionCommands.SELECTION_MENU_SELECTION_GROUP], { + commandId: MonacoSelectionCommands.SELECTION_SHRINK_SELECTION + }); + + // Copy and move group + registry.registerMenuAction([ + MAIN_MENU_BAR, + MonacoSelectionCommands.SELECTION_MENU, + MonacoSelectionCommands.SELECTION_MENU_COPY_MOVE_GROUP], { + commandId: MonacoSelectionCommands.SELECTION_COPY_LINE_UP + }); + registry.registerMenuAction([ + MAIN_MENU_BAR, + MonacoSelectionCommands.SELECTION_MENU, + MonacoSelectionCommands.SELECTION_MENU_COPY_MOVE_GROUP], { + commandId: MonacoSelectionCommands.SELECTION_COPY_LINE_DOWN + }); + registry.registerMenuAction([ + MAIN_MENU_BAR, + MonacoSelectionCommands.SELECTION_MENU, + MonacoSelectionCommands.SELECTION_MENU_COPY_MOVE_GROUP], { + commandId: MonacoSelectionCommands.SELECTION_MOVE_LINE_UP + }); + registry.registerMenuAction([ + MAIN_MENU_BAR, + MonacoSelectionCommands.SELECTION_MENU, + MonacoSelectionCommands.SELECTION_MENU_COPY_MOVE_GROUP], { + commandId: MonacoSelectionCommands.SELECTION_MOVE_LINE_DOWN + }); + + // Cursor group + registry.registerMenuAction([ + MAIN_MENU_BAR, + MonacoSelectionCommands.SELECTION_MENU, + MonacoSelectionCommands.SELECTION_MENU_CURSOR_GROUP], { + commandId: MonacoSelectionCommands.SELECTION_SWITCH_TO_MULTI_CURSOR + }); + registry.registerMenuAction([ + MAIN_MENU_BAR, + MonacoSelectionCommands.SELECTION_MENU, + MonacoSelectionCommands.SELECTION_MENU_CURSOR_GROUP], { + commandId: MonacoSelectionCommands.SELECTION_ADD_CURSOR_ABOVE + }); + registry.registerMenuAction([ + MAIN_MENU_BAR, + MonacoSelectionCommands.SELECTION_MENU, + MonacoSelectionCommands.SELECTION_MENU_CURSOR_GROUP], { + commandId: MonacoSelectionCommands.SELECTION_ADD_CURSOR_BELOW + }); + registry.registerMenuAction([ + MAIN_MENU_BAR, + MonacoSelectionCommands.SELECTION_MENU, + MonacoSelectionCommands.SELECTION_MENU_CURSOR_GROUP], { + commandId: MonacoSelectionCommands.SELECTION_ADD_CURSOR_TO_LINE_END + }); + registry.registerMenuAction([ + MAIN_MENU_BAR, + MonacoSelectionCommands.SELECTION_MENU, + MonacoSelectionCommands.SELECTION_MENU_CURSOR_GROUP], { + commandId: MonacoSelectionCommands.SELECTION_ADD_NEXT_OCCURRENCE + }); + registry.registerMenuAction([ + MAIN_MENU_BAR, + MonacoSelectionCommands.SELECTION_MENU, + MonacoSelectionCommands.SELECTION_MENU_CURSOR_GROUP], { + commandId: MonacoSelectionCommands.SELECTION_ADD_PREVIOUS_OCCURRENCE + }); + registry.registerMenuAction([ + MAIN_MENU_BAR, + MonacoSelectionCommands.SELECTION_MENU, + MonacoSelectionCommands.SELECTION_MENU_CURSOR_GROUP], { + commandId: MonacoSelectionCommands.SELECTION_SELECT_ALL_OCCURRENCES +>>>>>>> 7929942 GH-210: Registered `selection` commands, handlers and menu items. }); } }