Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 13:24 Go to next message
Aly El-Kerdany is currently offline Aly El-KerdanyFriend
Messages: 10
Registered: February 2021
Junior Member
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 15:00]

Report message to a 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 06:46 Go to previous messageGo to next message
Rolf Theunissen is currently offline Rolf TheunissenFriend
Messages: 260
Registered: April 2012
Senior Member
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 12:04 Go to previous messageGo to next message
Aly El-Kerdany is currently offline Aly El-KerdanyFriend
Messages: 10
Registered: February 2021
Junior Member
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 12:04]

Report message to a 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 12:36 Go to previous messageGo to next message
Rolf Theunissen is currently offline Rolf TheunissenFriend
Messages: 260
Registered: April 2012
Senior Member
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 12:53 Go to previous messageGo to next message
Aly El-Kerdany is currently offline Aly El-KerdanyFriend
Messages: 10
Registered: February 2021
Junior Member
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 14:17]

Report message to a 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 07:29 Go to previous messageGo to next message
Rolf Theunissen is currently offline Rolf TheunissenFriend
Messages: 260
Registered: April 2012
Senior Member
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 12:20 Go to previous message
Aly El-Kerdany is currently offline Aly El-KerdanyFriend
Messages: 10
Registered: February 2021
Junior Member
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: Thu Apr 25 12:51:25 GMT 2024

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

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

Back to the top