Skip to content

Commit

Permalink
GH-210: Registered selection commands, handlers and menu items.
Browse files Browse the repository at this point in the history
Signed-off-by: Akos Kitta <[email protected]>
  • Loading branch information
kittaakos committed Sep 1, 2017
1 parent 43a27d5 commit f83dca0
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 0 deletions.
76 changes: 76 additions & 0 deletions packages/monaco/src/browser/monaco-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {
Expand Down Expand Up @@ -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' },
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
96 changes: 96 additions & 0 deletions packages/monaco/src/browser/monaco-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'
});
Expand Down Expand Up @@ -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.
});
}
}

0 comments on commit f83dca0

Please sign in to comment.