Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Undo not working from keyboard in custom view but working using mouse shortcut
Undo not working from keyboard in custom view but working using mouse shortcut [message #1843436] Thu, 29 July 2021 09:24 Go to next message
Eclipse UserFriend
I have a custom view extending jdt, undo is working good when using mouse right click shortcut, but when I use undo from keyboard (CTRL + Z) it undo in another opened file and not the file I'm editing in.

anyone has solution for this?

Thanks in advance

[Updated on: Thu, 29 July 2021 11:00] by Moderator

Re: Undo not working from keyboard in custom view but working using mouse shortcut [message #1843449 is a reply to message #1843436] Fri, 30 July 2021 02:46 Go to previous messageGo to next message
Eclipse UserFriend
You might have run in a similar issue as Bug 571513, the undo handler is registered two times. Probably the keyboard shortcut calls the global handler, that you did not register in your own code. The right click calls the local handler, which you did install correctly.

Probably you need to add a call like
getActionBars().setGlobalActionHandler("undo", editor.getAction("undo"))
in the actionbar contributor.
Re: Undo not working from keyboard in custom view but working using mouse shortcut [message #1843455 is a reply to message #1843449] Fri, 30 July 2021 08:04 Go to previous messageGo to next message
Eclipse UserFriend
The weird thing that keyboard shortcut used to work until eclipse 2020-3, when switching to eclipse 2020-6 it stopped working

[Updated on: Fri, 30 July 2021 08:04] by Moderator

Re: Undo not working from keyboard in custom view but working using mouse shortcut [message #1843456 is a reply to message #1843455] Fri, 30 July 2021 08:36 Go to previous messageGo to next message
Eclipse UserFriend
Then it is for sure Bug 571513.
Re: Undo not working from keyboard in custom view but working using mouse shortcut [message #1843457 is a reply to message #1843456] Fri, 30 July 2021 08:53 Go to previous messageGo to next message
Eclipse UserFriend
Sorry but I don't know exactly where to add the suggested line, in the class that I made that extends org.eclipse.ui.editors?, when I try to get TestElementJavaEditor .getAction("undo") it returns null


public class TestElementEditor extends FormEditor implements IResourceChangeListener { // NOSONAR

private static final Logger log = LoggerFactory.getLogger(TestElementEditor.class);

private TestElementJavaEditor fTestElementJavaEditor;

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
if (!(input instanceof IFileEditorInput))
throw new PartInitException("Invalid Input: Must be IFileEditorInput");
super.init(site, input);
ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
}

@Override
public boolean isSaveAsAllowed() {
return false;
}

@Override
protected void addPages() {
try {
IEditorInput editorInput = getEditorInput();

setPartName(editorInput.getName());
setTitleToolTip(editorInput.getToolTipText());

fTestElementJavaEditor = new TestElementJavaEditor();
int index = addPage(fTestElementJavaEditor, editorInput);
setPageText(index, "Source");

} catch (PartInitException e) {
log.error("Failed to create test case editor", e);
}
}

@Override
public void dispose() {
super.dispose();
ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
}

@Override
public void resourceChanged(IResourceChangeEvent arg0) {
// TODO Auto-generated method stub

}

@Override
public void doSave(IProgressMonitor monitor) {
// TODO Auto-generated method stub

}

@Override
public void doSaveAs() {
// TODO Auto-generated method stub

}
}

-------------------------------------------------------------------------------------

@SuppressWarnings("restriction")
public class TestElementJavaEditor extends CompilationUnitEditor { // NOSONAR

@Override
public void doSave(IProgressMonitor progressMonitor) { // NOSONAR, inhereted to avoid restricted access
super.doSave(progressMonitor);
}

@Override
public void doSaveAs() { // NOSONAR, inhereted to avoid restricted access
super.doSaveAs();
}
}

[Updated on: Fri, 30 July 2021 10:17] by Moderator

Re: Undo not working from keyboard in custom view but working using mouse shortcut [message #1843482 is a reply to message #1843457] Mon, 02 August 2021 03:29 Go to previous messageGo to next message
Eclipse UserFriend
Alright, I never made a custom editor like this myself, my instructions were not helpful is see. It seems that the global actions are managed in the IEditorActionBarContributor. This one is registered in the extension-point org.eclipse.ui.editors, the 'contributorClass' attribute, in the plugin.xml.

If you have a custom class here, make sure that the registrations are correct (can be a matter of subclassing the BasicTextEditorActionContributor or a subclass hereof).
If you don't have the attribute set, try adding one (if this is the case, then bug 571513 is even more nasty).

Please let it know what your progress is, so it could also be used as input for Bug 571513.
Re: Undo not working from keyboard in custom view but working using mouse shortcut [message #1843605 is a reply to message #1843482] Tue, 10 August 2021 08:20 Go to previous message
Eclipse UserFriend
Hello,

I have managed to fix it by adding com.valeo.sdk.castle.internal.ui.editors.MultiPageEditorContributor as a contributorClass in plugin.xml for the editor I created

import org.eclipse.jface.action.*;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.ide.IDEActionFactory;
import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;

/**
 * Manages the installation/deinstallation of global actions for multi-page
 * editors. Responsible for the redirection of global actions to the active
 * editor. Multi-page contributor replaces the contributors for the individual
 * editors in the multi-page editor.
 */
public class MultiPageEditorContributor extends MultiPageEditorActionBarContributor {
	private IEditorPart activeEditorPart;

	/**
	 * Creates a multi-page contributor.
	 */
	public MultiPageEditorContributor() {
		super();
	}

	/**
	 * Returns the action registered with the given text editor.
	 * 
	 * @return IAction or null if editor is null.
	 */
	protected IAction getAction(ITextEditor editor, String actionID) {
		return (editor == null ? null : editor.getAction(actionID));
	}
	/*
	 * (non-JavaDoc) Method declared in AbstractMultiPageEditorActionBarContributor.
	 */

	public void setActivePage(IEditorPart part) {
		if (activeEditorPart == part)
			return;

		activeEditorPart = part;

		IActionBars actionBars = getActionBars();
		if (actionBars != null) {

			ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part : null;

			actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(),
					getAction(editor, ITextEditorActionConstants.DELETE));
			actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(),
					getAction(editor, ITextEditorActionConstants.UNDO));
			actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(),
					getAction(editor, ITextEditorActionConstants.REDO));
			actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(),
					getAction(editor, ITextEditorActionConstants.CUT));
			actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(),
					getAction(editor, ITextEditorActionConstants.COPY));
			actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(),
					getAction(editor, ITextEditorActionConstants.PASTE));
			actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(),
					getAction(editor, ITextEditorActionConstants.SELECT_ALL));
			actionBars.setGlobalActionHandler(ActionFactory.FIND.getId(),
					getAction(editor, ITextEditorActionConstants.FIND));
			actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(),
					getAction(editor, IDEActionFactory.BOOKMARK.getId()));
			actionBars.updateActionBars();
		}
	}
}


Previous Topic:Plugin/Feature not loaded
Next Topic:Bundle lib uses getSystemResource
Goto Forum:
  


Current Time: Sat Apr 19 05:28:36 EDT 2025

Powered by FUDForum. Page generated in 0.03154 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top