How to Differentiate The Type of Change (i.e., normal, or undo) using IUndoManagerListener [message #658028] |
Sat, 05 March 2011 08:48 |
Kivanc Muslu Messages: 153 Registered: November 2010 |
Senior Member |
|
|
Hi all,
I am trying to use IUndoListener to get notified of the changes and undoes applied workspace wide. It generally works as it should, however I need to somehow match a change that is performed to an undo that is performed (if any) if they represent the same action.
i.e., I have a compilation error because my file in stays in default package however, in the .java file I have package foo; declaration. I click on the quick fix and choose 'move ... to package 'foo''. This creates an aboutToPerformChange(...) action and a changePerformed(...) action. Let's say that after this point I clicked undo (cmd+z), this also creates 2 actions (of course different). How can I understand that the first action is a normal change and the second one represents an undo?
My current implementation of the listener (to better understand what is going on is:
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.CompositeChange;
import org.eclipse.ltk.core.refactoring.IUndoManager;
import org.eclipse.ltk.core.refactoring.IUndoManagerListener;
public class QFUsageUndoManagerListener implements IUndoManagerListener
{
@Override
public void undoStackChanged(IUndoManager manager)
{}
@Override
public void redoStackChanged(IUndoManager manager)
{}
@Override
public void aboutToPerformChange(IUndoManager manager, Change change)
{
System.out.println("=== About to perform change ===");
printChange(change);
System.out.println("===============================");
System.out.println();
}
@Override
public void changePerformed(IUndoManager manager, Change change)
{
System.out.println("=== Change performed ===");
printChange(change);
System.out.println("========================");
System.out.println();
}
private void printChange(Change change)
{
if (change instanceof CompositeChange)
{
for (Change child: ((CompositeChange) change).getChildren())
printChange(child);
}
else
{
System.out.println("Change performed class = " + change.getClass());
System.out.println("Change performed = " + change.getName());
}
}
}
and for the above scenario, I get the following print-outs:
// Represents the first change, since composite there are 2 changes.
=== About to perform change ===
Change performed class = class org.eclipse.jdt.internal.corext.refactoring.changes.CreatePackageChange
Change performed = Create package
Change performed class = class org.eclipse.jdt.internal.corext.refactoring.changes.MoveCompilationUnitChange
Change performed = Move compilation unit 'All.java' to 'foo'
===============================
// I have no idea why there is nothing in this?
=== Change performed ===
========================
// Represents the undo, since composite, there are multiple.
=== About to perform change ===
Change performed class = class org.eclipse.jdt.internal.corext.refactoring.changes.MoveCompilationUnitChange
Change performed = Move compilation unit 'All.java' to '(default package)'
Change performed class = class org.eclipse.ltk.core.refactoring.resource.DeleteResourceChange
Change performed = Delete 'Quickfixes/src/foo'
===============================
// I have no idea why this is different that aboutToPerformChange(...)
=== Change performed ===
Change performed class = class org.eclipse.ltk.internal.core.refactoring.resource.UndoDeleteResourceChange
Change performed = Restore 'foo'
Change performed class = class org.eclipse.jdt.internal.corext.refactoring.changes.MoveCompilationUnitChange
Change performed = Move compilation unit 'All.java' to 'foo'
========================
Some internal questions:
1- Why I get an empty CompositeChange for the actual change in changePerformed(...) action?
2- Why the aboutToPerformChange(...) and changePerformed(...) actions are quite different than each other for the undo?
Other suggestions, solutions are always appreciated.
Thanks in advance, best regards,
|
|
|
Powered by
FUDForum. Page generated in 0.02826 seconds