Skip to content

Commit

Permalink
GH-210: Registered find/replace commands 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 b4ed54f commit 43a27d5
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 9 deletions.
54 changes: 47 additions & 7 deletions packages/core/src/common/commands-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { CommandContribution, CommandRegistry } from './command';
import { injectable } from "inversify";

export namespace CommonCommands {
<<<<<<< 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

export const EDIT_MENU = "2_edit";
Expand Down Expand Up @@ -107,13 +108,22 @@ export class CommonCommandContribution implements CommandContribution {
export const EDIT_MENU = "2_edit"
export const EDIT_MENU_UNDO_GROUP = "1_undo/redo"
export const EDIT_MENU_COPYPASTE_GROUP = "2_copy"
=======
export const EDIT_MENU = "2_edit";
export const EDIT_MENU_UNDO_GROUP = "1_undo/redo";
export const EDIT_MENU_FIND_REPLACE_GROUP = "2_find/replace";
export const EDIT_MENU_COPYPASTE_GROUP = "2_copy";
>>>>>>> f57136b GH-210: Registered find/replace commands and menu items.

export const EDIT_CUT = 'edit_cut';
export const EDIT_COPY = 'edit_copy';
export const EDIT_PASTE = 'edit_paste';

export const EDIT_UNDO = 'undo';
export const EDIT_REDO = 'redo';

export const EDIT_FIND = 'actions.find';
export const EDIT_REPLACE = 'editor.action.startFindReplaceAction';
}

@injectable()
Expand All @@ -122,15 +132,33 @@ export class CommonMenuContribution implements MenuContribution {
registerMenus(registry: MenuModelRegistry): void {
// Explicitly register the Edit Submenu
registry.registerSubmenu([MAIN_MENU_BAR], CommonCommands.EDIT_MENU, "Edit");
registry.registerMenuAction([MAIN_MENU_BAR, CommonCommands.EDIT_MENU, CommonCommands.EDIT_MENU_UNDO_GROUP], {
commandId: CommonCommands.EDIT_UNDO
});

// Undo/Redo
registry.registerMenuAction([
MAIN_MENU_BAR,
CommonCommands.EDIT_MENU,
CommonCommands.EDIT_MENU_UNDO_GROUP], {
commandId: CommonCommands.EDIT_UNDO
});
registry.registerMenuAction([
MAIN_MENU_BAR,
CommonCommands.EDIT_MENU,
CommonCommands.EDIT_MENU_UNDO_GROUP], {
commandId: CommonCommands.EDIT_REDO
});
// Find/Replace
registry.registerMenuAction([
MAIN_MENU_BAR,
CommonCommands.EDIT_MENU,
CommonCommands.EDIT_MENU_FIND_REPLACE_GROUP], {
commandId: CommonCommands.EDIT_FIND
});
registry.registerMenuAction([
MAIN_MENU_BAR,
CommonCommands.EDIT_MENU,
CommonCommands.EDIT_MENU_FIND_REPLACE_GROUP], {
commandId: CommonCommands.EDIT_REPLACE
});
}

}
Expand All @@ -142,24 +170,36 @@ export class CommonCommandContribution implements CommandContribution {
commandRegistry.registerCommand({
id: CommonCommands.EDIT_CUT,
label: 'Cut'
})
});
commandRegistry.registerCommand({
id: CommonCommands.EDIT_COPY,
label: 'Copy',
})
});
commandRegistry.registerCommand({
id: CommonCommands.EDIT_PASTE,
label: 'Paste'
})
});
commandRegistry.registerCommand({
id: CommonCommands.EDIT_UNDO,
label: 'Undo'
})
});
commandRegistry.registerCommand({
id: CommonCommands.EDIT_REDO,
label: 'Redo'
<<<<<<< Upstream, based on branch 'GH-210' of https://github.com/theia-ide/theia.git
})
>>>>>>> 21b1906 GH-210: Restored undo/redo functionality.
=======
});
commandRegistry.registerCommand({
id: CommonCommands.EDIT_FIND,
label: 'Find'
});
commandRegistry.registerCommand({
id: CommonCommands.EDIT_REPLACE,
label: 'Replace'
});
>>>>>>> f57136b GH-210: Registered find/replace commands and menu items.
}

}
32 changes: 30 additions & 2 deletions packages/monaco/src/browser/monaco-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,29 @@
import { injectable, inject } from "inversify";
import { ProtocolToMonacoConverter } from "monaco-languageclient/lib";
<<<<<<< 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 { Position, Location } from "@theia/languages/lib/common";
=======
=======
<<<<<<< HEAD
>>>>>>> f57136b GH-210: Registered find/replace commands and menu items.
import {
CommandHandler, CommandContribution, CommandRegistry, SelectionService
} 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 { CommandHandler, CommandContribution, CommandRegistry, CommonCommands, SelectionService } from '@theia/core/lib/common';
>>>>>>> GH-210: Registered find/replace commands and menu items.
>>>>>>> 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
import { CommandHandler, CommandContribution, CommandRegistry, CommonCommands, SelectionService } from '@theia/core/lib/common';
=======
import { Position, Location } from "@theia/languages/lib/common";
>>>>>>> f57136b GH-210: Registered find/replace commands and menu items.
import { getCurrent, MonacoEditor } from './monaco-editor';
import MenuRegistry = monaco.actions.MenuRegistry;
import MenuId = monaco.actions.MenuId;
Expand Down Expand Up @@ -95,17 +109,22 @@ export class MonacoEditorCommandHandlers implements CommandContribution {
});

[CommonCommands.EDIT_UNDO, CommonCommands.EDIT_REDO].forEach(id => {
<<<<<<< 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
const doExecute = (editor: MonacoEditor, ...args: any[]): any => editor.getControl().cursor.trigger('keyboard', id, args);
=======
const doExecute = (editor: MonacoEditor, ...args: any[]): any => {
return editor.getControl().cursor.trigger('keyboard', id, args);
};
>>>>>>> 21b1906 GH-210: Restored undo/redo functionality.
=======
const doExecute = (editor: MonacoEditor, ...args: any[]): any => editor.getControl().cursor.trigger('keyboard', id, args);
>>>>>>> f57136b GH-210: Registered find/replace commands and menu items.
const handler = this.newClipboardHandler(id, doExecute);
commands.registerHandler(id, handler);
});

<<<<<<< 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 All @@ -128,6 +147,13 @@ export class MonacoEditorCommandHandlers implements CommandContribution {
});
}
});
=======
const findHandler = new EditorCommandHandler(CommonCommands.EDIT_FIND, this.editorManager, this.selectionService);
commands.registerHandler(CommonCommands.EDIT_FIND, findHandler);

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.

for (const menuItem of MenuRegistry.getMenuItems(MenuId.EditorContext)) {
const { id, title, iconClass } = menuItem.command;
Expand Down Expand Up @@ -182,12 +208,14 @@ export class EditorCommandHandler implements CommandHandler {
}

isVisible(): boolean {
return TextEditorSelection.is(this.selectionService.selection);
const r = TextEditorSelection.is(this.selectionService.selection);
return r;
}

isEnabled(): boolean {
const editor = getCurrent(this.editorManager);
return !!editor && editor.isActionSupported(this.id);
const r = !!editor && editor.isActionSupported(this.id);
return r;
}

}
Expand Down

0 comments on commit 43a27d5

Please sign in to comment.