Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-ui-dev] intercept copy/paste in console

On 30-Mar-2016, at 8:24 AM, Martin Lippert <mlippert@xxxxxxxxx> wrote:
> The only thing that bothers me is that this causes my action handler to be called for keystrokes and the global menu entries, but not for the context menu “copy” action. Any idea what I need to do additionally to hook into that as well?

Normally you wouldn’t be able to do anything about that: the context menu looks like it adds an action with a command id (aka definition id).  The command/definition id is used to determine keybindings, but it doesn’t allow overriding the action.

But IOConsolePage/TextConsolePage seems to pull its content from its global actions, and these global actions are configured using a protected method setGlobalActions().  So with a bit of reflection, it looks like you might be able to replace the ‘copy’ command with your own action.  Something like the following (completely untested, and may break at any moment).

	public void init(IPageBookViewPage page, IConsole console) {
		// …
		Method setGlobalActionMethod = …;
		setGlobalActionMethod.setAccessible(true);
		setGlobalActionMethod.invoke(page, new Object[] {
			page.getSite().getActionBars(),
			ActionFactory.COPY.getId(),
			new AnsiConsoleCopyIconAction() });
	}

Brian.

Back to the top