mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06:01 +02:00
Patch for Devin Steffler re: DOMAST View.
I finally figured out how to refresh the TreeViewer in a manner that will let me determine programmatically what tree nodes to expand. So now after a refresh, if a treenode has the same offset (via getOffset) and toString() then it is expanded.
This commit is contained in:
parent
6c526dff10
commit
0167673957
1 changed files with 22 additions and 3 deletions
|
@ -79,6 +79,8 @@ import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.graphics.Image;
|
import org.eclipse.swt.graphics.Image;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.swt.widgets.Menu;
|
import org.eclipse.swt.widgets.Menu;
|
||||||
|
import org.eclipse.swt.widgets.Tree;
|
||||||
|
import org.eclipse.swt.widgets.TreeItem;
|
||||||
import org.eclipse.ui.IActionBars;
|
import org.eclipse.ui.IActionBars;
|
||||||
import org.eclipse.ui.IEditorPart;
|
import org.eclipse.ui.IEditorPart;
|
||||||
import org.eclipse.ui.IEditorReference;
|
import org.eclipse.ui.IEditorReference;
|
||||||
|
@ -471,14 +473,31 @@ public class DOMAST extends ViewPart {
|
||||||
loadActiveEditorAction.setImageDescriptor(DOMASTPluginImages.DESC_DEFAULT);
|
loadActiveEditorAction.setImageDescriptor(DOMASTPluginImages.DESC_DEFAULT);
|
||||||
|
|
||||||
refreshAction = new Action() {
|
refreshAction = new Action() {
|
||||||
|
private void expandTreeIfNecessary(TreeItem[] tree, Object[] expanded) {
|
||||||
|
for( int i=0; i<tree.length; i++) {
|
||||||
|
for( int j=0; j<expanded.length; j++) {
|
||||||
|
if (expanded[j] instanceof TreeObject &&
|
||||||
|
tree[i].getData() instanceof TreeObject &&
|
||||||
|
((TreeObject)expanded[j]).toString().equals(((TreeObject)tree[i].getData()).toString()) &&
|
||||||
|
((TreeObject)expanded[j]).getOffset() == (((TreeObject)tree[i].getData()).getOffset())) {
|
||||||
|
tree[i].setExpanded(true);
|
||||||
|
viewer.refresh();
|
||||||
|
expandTreeIfNecessary(tree[i].getItems(), expanded);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
// TODO take a snapshot of the tree expansion
|
// take a snapshot of the tree expansion
|
||||||
|
Object[] expanded = viewer.getExpandedElements();
|
||||||
|
|
||||||
// set the new content provider
|
// set the new content provider
|
||||||
setContentProvider(new ViewContentProvider(file));
|
setContentProvider(new ViewContentProvider(file));
|
||||||
|
|
||||||
// TODO set the expansion of the view based on the original snapshot (educated guess)
|
// set the expansion of the view based on the original snapshot (educated guess)
|
||||||
|
Tree tree = viewer.getTree();
|
||||||
|
expandTreeIfNecessary(tree.getItems(), expanded);
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue