|
|
|
|
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   |
Eclipse User |
|
|
|
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 #1843605 is a reply to message #1843482] |
Tue, 10 August 2021 08:20  |
Eclipse User |
|
|
|
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();
}
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.03154 seconds