Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » problems with undo in SourceViewer
problems with undo in SourceViewer [message #313992] Fri, 30 March 2007 10:59 Go to next message
Eclipse UserFriend
Originally posted by: starkom.ngs.ru

Hi, i'm using my own subclass of SourceViewer in my editor. There is suc=
h =

code in it:
protected void handleVisibleDocumentAboutToBeChanged(DocumentEv=
ent =

event) {
if (!isRollback) {
if (isUndesirableChange(event.getOffset(), =

event.getOffset() + event.getLength())) {
oldText =3D getTextWidget().getText();
} else {
super.handleVisibleDocumentAboutToBeChanged(event);=

}
}
}

protected void handleVisibleDocumentChanged(DocumentEvent event=
) {
if (oldText !=3D null && !isRollback) {
isRollback =3D true;
getTextWidget.getContent().setText(oldText);
isRollback =3D false;
oldText =3D null;
} else {
super.handleVisibleDocumentChanged(event);
}
}

This works fine with all undesirable changes of my document. But if =

rollback of undesirable change is occured and then client call "undo" =

operation,
exception occured:
org.eclipse.core.commands.ExecutionException: While undoing the operatio=
n, =

an exception occurred
at =

org.eclipse.core.commands.operations.DefaultOperationHistory .doUndo(Defa=
ultOperationHistory.java:429)
at =

org.eclipse.core.commands.operations.DefaultOperationHistory .undo(Defaul=
tOperationHistory.java:1244)
at =

org.eclipse.ui.operations.UndoActionHandler.runCommand(UndoA ctionHandler=
..java:66)
at =

org.eclipse.ui.operations.OperationHistoryActionHandler$4.ru n(OperationH=
istoryActionHandler.java:279)
....
at org.eclipse.core.launcher.Main.main(Main.java:952)
Caused by: org.eclipse.jface.util.Assert$AssertionFailedException: =

Assertion failed:
at org.eclipse.jface.util.Assert.isTrue(Assert.java:182)
at org.eclipse.jface.util.Assert.isTrue(Assert.java:167)
at =

org.eclipse.ui.internal.texteditor.quickdiff.compare.rangedi fferencer.Ra=
ngeDifferencer.findDifferencesUkkonen(RangeDifferencer.java: 169)
....
at =

org.eclipse.core.commands.operations.DefaultOperationHistory .doUndo(Defa=
ultOperationHistory.java:413)

What is wrong in my code? And what is right concept of implementing =

untouchable text in SourceViewer?
Re: problems with undo in SourceViewer [message #314000 is a reply to message #313992] Fri, 30 March 2007 14:31 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Azargaev Evgeniy wrote:

> Hi, i'm using my own subclass of SourceViewer in my editor. There is
> such code in it:
> protected void
> handleVisibleDocumentAboutToBeChanged(DocumentEvent event) {
> if (!isRollback) {
> if (isUndesirableChange(event.getOffset(),
> event.getOffset() + event.getLength())) {
> oldText = getTextWidget().getText();
> } else {
> super.handleVisibleDocumentAboutToBeChanged(event);
> }
> }
> }
>
> protected void handleVisibleDocumentChanged(DocumentEvent
> event) {
> if (oldText != null && !isRollback) {
> isRollback = true;
> getTextWidget.getContent().setText(oldText);
> isRollback = false;
> oldText = null;
> } else {
> super.handleVisibleDocumentChanged(event);
> }
> }
>
> This works fine with all undesirable changes of my document.

Well, only for those entered into the viewer. If the underlying document
gets changed this approach will fail. As I don't see all code but I can
say that the code as posted is not supported by the source viewer.

Dani

> But if rollback of undesirable change is occured and then client call
> "undo" operation,
> exception occured:
> org.eclipse.core.commands.ExecutionException: While undoing the
> operation, an exception occurred
> at
> org.eclipse.core.commands.operations.DefaultOperationHistory .doUndo(DefaultOperationHistory.java:429)
>
> at
> org.eclipse.core.commands.operations.DefaultOperationHistory .undo(DefaultOperationHistory.java:1244)
>
> at
> org.eclipse.ui.operations.UndoActionHandler.runCommand(UndoA ctionHandler.java:66)
>
> at
> org.eclipse.ui.operations.OperationHistoryActionHandler$4.ru n(OperationHistoryActionHandler.java:279)
>
> ...
> at org.eclipse.core.launcher.Main.main(Main.java:952)
> Caused by: org.eclipse.jface.util.Assert$AssertionFailedException:
> Assertion failed:
> at org.eclipse.jface.util.Assert.isTrue(Assert.java:182)
> at org.eclipse.jface.util.Assert.isTrue(Assert.java:167)
> at
> org.eclipse.ui.internal.texteditor.quickdiff.compare.rangedi fferencer.RangeDifferencer.findDifferencesUkkonen(RangeDiffe rencer.java:169)
>
> ...
> at
> org.eclipse.core.commands.operations.DefaultOperationHistory .doUndo(DefaultOperationHistory.java:413)
>
>
> What is wrong in my code? And what is right concept of implementing
> untouchable text in SourceViewer?
Re: problems with undo in SourceViewer [message #314025 is a reply to message #314000] Mon, 02 April 2007 05:51 Go to previous message
Eclipse UserFriend
Originally posted by: starkom.ngs.ru

On Fri, 30 Mar 2007 21:31:43 +0700, Daniel Megert =

<daniel_megert@ch.ibm.com> wrote:

> Well, only for those entered into the viewer. If the underlying docume=
nt =

> gets changed this approach will fail. As I don't see all code but I ca=
n =

> say that the code as posted is not supported by the source viewer.
>
> Dani

I's all code:
private class InternalProjectionViewer extends SourceViewer {
private String oldText =3D null;
private boolean isRollback =3D false;

public InternalProjectionViewer(Composite parent, IVerticalRule=
r =

ruler, IOverviewRuler overviewRuler, boolean showsAnnotationOverview, in=
t =

styles) {
super(parent, ruler, overviewRuler, showsAnnotationOverview=
, =

styles);
}

protected void handleVisibleDocumentAboutToBeChanged(DocumentEv=
ent =

event) {
if (!isRollback) {
if (isHeader(event.getOffset(), event.getOffset() =

+ event.getLength())) {
oldText =3D getTextWidget().getText();
} else {
super.handleVisibleDocumentAboutToBeChanged(event);=

}
}
}

protected void handleVisibleDocumentChanged(DocumentEvent event=
) {
if (oldText !=3D null && !isRollback) {
isRollback =3D true;
getTextWidget.getContent().setText(oldText);
isRollback =3D false;
oldText =3D null;
} else {
super.handleVisibleDocumentChanged(event);
}
}
}
....
protected ISourceViewer createSourceViewer(Composite parent, =

IVerticalRuler ruler, int styles) {
ISourceViewer viewer =3D new InternalProjectionViewer(parent, r=
uler, =

getOverviewRuler(), isOverviewRulerVisible(), styles);
return viewer;
}

But how can I restore text correctly after undesirable change of it? I =

tried use getUndoManager().undo(), but it modifies undo-redo history and=
I =

can't handle that history directly. I tried save getDocument() in =

aboutToBeChanged event dipatcher and restore it with setDocument(). I =

tried getDocument.set(oldText). But all these workarounds works =

incorrectly.
The problem is that I can't deny any text-change actions. Keyboards' =

changes denies by such listener added to TextWidget:

private class InternalVerifyListener implements VerifyListener {
public void verifyText(VerifyEvent e) {
if (isHeader(e.start, e.end)) {
e.doit =3D false;
return;
}
}
}

But actions send aboutToBeChanged event and work anyway :(
Previous Topic:Re: not getting IFile
Next Topic:Several questions regarding extension points
Goto Forum:
  


Current Time: Fri Jan 03 01:09:17 GMT 2025

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

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

Back to the top