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 Aug 29, 2017
1 parent 87c72be commit 16da2cc
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 26 deletions.
52 changes: 41 additions & 11 deletions packages/core/src/common/commands-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ import { CommandContribution, CommandRegistry } from './command';
import { injectable } from "inversify";

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

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 @@ -28,15 +32,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 @@ -48,23 +70,31 @@ 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'
})
});
commandRegistry.registerCommand({
id: CommonCommands.EDIT_FIND,
label: 'Find'
});
commandRegistry.registerCommand({
id: CommonCommands.EDIT_REPLACE,
label: 'Replace'
});
}

}
7 changes: 3 additions & 4 deletions packages/editor/src/browser/editor-keybinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
*/

import { injectable, inject } from "inversify";
import {
KeybindingContext, Keybinding, KeybindingContribution, KeybindingRegistry, KeyCode, Key, Modifier
} from "@theia/core/lib/common";
import { EditorManager } from "./editor-manager";
import { KeyCode, Key, Modifier } from "@theia/core/lib/common/keys";
import { KeybindingContext, Keybinding, KeybindingContribution, KeybindingRegistry } from "@theia/core/lib/common/keybinding";

@injectable()
export class EditorKeybindingContext implements KeybindingContext {
Expand Down Expand Up @@ -49,4 +48,4 @@ export class EditorKeybindingContribution implements KeybindingContribution {

}

}
}
22 changes: 13 additions & 9 deletions packages/monaco/src/browser/monaco-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@

import { injectable, inject } from "inversify";
import { ProtocolToMonacoConverter } from "monaco-languageclient/lib";
import {
CommandHandler, CommandContribution, CommandRegistry, CommonCommands, SelectionService
} from '@theia/core/lib/common';
import { CommandHandler, CommandContribution, CommandRegistry, CommonCommands, SelectionService } from '@theia/core/lib/common';
import { EditorManager, TextEditorSelection, SHOW_REFERENCES } from '@theia/editor/lib/browser';
import { Position, Location } from "@theia/languages/lib/common"
import { Position, Location } from "@theia/languages/lib/common";
import { getCurrent, MonacoEditor } from './monaco-editor';
import MenuRegistry = monaco.actions.MenuRegistry;
import MenuId = monaco.actions.MenuId;
Expand Down Expand Up @@ -41,13 +39,17 @@ export class MonacoEditorCommandHandlers implements CommandContribution {
});

[CommonCommands.EDIT_UNDO, CommonCommands.EDIT_REDO].forEach(id => {
const doExecute = (editor: MonacoEditor, ...args: any[]): any => {
return editor.getControl().cursor.trigger('keyboard', id, args);
};
const doExecute = (editor: MonacoEditor, ...args: any[]): any => editor.getControl().cursor.trigger('keyboard', id, args);
const handler = this.newClipboardHandler(id, doExecute);
commands.registerHandler(id, handler);
});

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

for (const menuItem of MenuRegistry.getMenuItems(MenuId.EditorContext)) {
const { id, title, iconClass } = menuItem.command;
commands.registerCommand({
Expand Down Expand Up @@ -86,12 +88,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
4 changes: 2 additions & 2 deletions packages/monaco/src/browser/monaco-model-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class MonacoModelResolver implements ITextModelResolverService {
object: model,
dispose: () =>
removeReference.dispose()
}
};
removeReference = references.push(reference);
return reference;
}
Expand Down Expand Up @@ -81,6 +81,6 @@ export class MonacoModelResolver implements ITextModelResolverService {
dispose(): void {
// no-op
}
}
};
}
}

0 comments on commit 16da2cc

Please sign in to comment.