1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Patch for Devin Steffler.

Further updates to DOM AST View.
This commit is contained in:
John Camelon 2005-01-27 16:31:58 +00:00
parent e6868902c5
commit 493b29d4e4
5 changed files with 62 additions and 22 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 B

View file

@ -98,20 +98,24 @@ import org.eclipse.ui.part.ViewPart;
*/ */
public class DOMAST extends ViewPart { public class DOMAST extends ViewPart {
private static final String REFRESH_DOM_AST = "Refresh DOM AST"; //$NON-NLS-1$ private static final String COLLAPSE_ALL = "Collapse ALL"; //$NON-NLS-1$
private static final String EXPAND_ALL = "Expand All"; //$NON-NLS-1$
private static final String REFRESH_DOM_AST = "Refresh DOM AST"; //$NON-NLS-1$
private static final String VIEW_NAME = "DOM View"; //$NON-NLS-1$ private static final String VIEW_NAME = "DOM View"; //$NON-NLS-1$
private static final String POPUPMENU = "#PopupMenu"; //$NON-NLS-1$ private static final String POPUPMENU = "#PopupMenu"; //$NON-NLS-1$
private static final String OPEN_DECLARATIONS = "Open Declarations"; //$NON-NLS-1$ private static final String OPEN_DECLARATIONS = "Open Declarations"; //$NON-NLS-1$
private static final String OPEN_REFERENCES = "Open References"; //$NON-NLS-1$ private static final String OPEN_REFERENCES = "Open References"; //$NON-NLS-1$
TreeViewer viewer; TreeViewer viewer;
private DrillDownAdapter drillDownAdapter; private DrillDownAdapter drillDownAdapter;
private Action action1; private Action openDeclarationsAction;
private Action action2; private Action openReferencesAction;
Action singleClickAction; private Action singleClickAction;
private Action refreshAction; private Action refreshAction;
IFile file = null; private Action expandAllAction;
private Action collapseAllAction;
private IFile file = null;
private IEditorPart part = null; private IEditorPart part = null;
ParserLanguage lang = null; private ParserLanguage lang = null;
/* /*
* The content provider class is responsible for providing objects to the * The content provider class is responsible for providing objects to the
@ -363,8 +367,8 @@ public class DOMAST extends ViewPart {
} }
void fillContextMenu(IMenuManager manager) { void fillContextMenu(IMenuManager manager) {
manager.add(action1); manager.add(openDeclarationsAction);
manager.add(action2); manager.add(openReferencesAction);
manager.add(new Separator()); manager.add(new Separator());
drillDownAdapter.addNavigationActions(manager); drillDownAdapter.addNavigationActions(manager);
// Other plug-ins can contribute there actions here // Other plug-ins can contribute there actions here
@ -372,6 +376,8 @@ public class DOMAST extends ViewPart {
} }
private void fillLocalToolBar(IToolBarManager manager) { private void fillLocalToolBar(IToolBarManager manager) {
manager.add(expandAllAction);
manager.add(collapseAllAction);
manager.add(refreshAction); manager.add(refreshAction);
manager.add(new Separator()); manager.add(new Separator());
drillDownAdapter.addNavigationActions(manager); drillDownAdapter.addNavigationActions(manager);
@ -380,31 +386,56 @@ public class DOMAST extends ViewPart {
private void makeActions() { private void makeActions() {
refreshAction = new Action() { refreshAction = new Action() {
public void run() { public void run() {
// TODO take a snapshot of the tree expansion
// 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)
} }
}; };
refreshAction.setText(REFRESH_DOM_AST); refreshAction.setText(REFRESH_DOM_AST);
refreshAction.setToolTipText(REFRESH_DOM_AST); refreshAction.setToolTipText(REFRESH_DOM_AST);
refreshAction.setImageDescriptor(DOMASTPluginImages.DESC_IASTInitializer); refreshAction.setImageDescriptor(DOMASTPluginImages.DESC_IASTInitializer);
action1 = new Action() { expandAllAction = new Action() {
public void run() {
viewer.expandAll();
}
};
expandAllAction.setText(EXPAND_ALL);
expandAllAction.setToolTipText(EXPAND_ALL);
expandAllAction.setImageDescriptor(DOMASTPluginImages.DESC_EXPAND_ALL);
collapseAllAction = new Action() {
public void run() {
viewer.collapseAll();
}
};
collapseAllAction.setText(COLLAPSE_ALL);
collapseAllAction.setToolTipText(COLLAPSE_ALL);
collapseAllAction.setImageDescriptor(DOMASTPluginImages.DESC_COLLAPSE_ALL);
openDeclarationsAction = new Action() {
public void run() { public void run() {
showMessage("Action 1 executed"); // TODO open declarations action //$NON-NLS-1$ showMessage("Action 1 executed"); // TODO open declarations action //$NON-NLS-1$
// ... use annotations // ... use annotations
} }
}; };
action1.setText(OPEN_DECLARATIONS); openDeclarationsAction.setText(OPEN_DECLARATIONS);
action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() openDeclarationsAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
.getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
action2 = new Action() { openReferencesAction = new Action() {
public void run() { public void run() {
showMessage("Action 2 executed"); // TODO open references action ... //$NON-NLS-1$ showMessage("Action 2 executed"); // TODO open references action ... //$NON-NLS-1$
// use annotations // use annotations
} }
}; };
action2.setText(OPEN_REFERENCES); openReferencesAction.setText(OPEN_REFERENCES);
action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() openReferencesAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
.getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
singleClickAction = new ASTHighlighterAction(part); singleClickAction = new ASTHighlighterAction(part);
@ -441,6 +472,10 @@ public class DOMAST extends ViewPart {
Object obj = ((IStructuredSelection) selection).getFirstElement(); Object obj = ((IStructuredSelection) selection).getFirstElement();
if (aPart instanceof CEditor && obj instanceof TreeObject) { if (aPart instanceof CEditor && obj instanceof TreeObject) {
String filename = ((TreeObject) obj).getFilename(); String filename = ((TreeObject) obj).getFilename();
if (filename.equals(TreeObject.BLANK_FILENAME))
return;
IResource r = ParserUtil.getResourceForFilename(filename); IResource r = ParserUtil.getResourceForFilename(filename);
if (r != null) { if (r != null) {
try { try {

View file

@ -72,6 +72,8 @@ public class DOMASTPluginImages {
public static final String IMG_ICPPASTConstructorChainInitializer = NAME_PREFIX + "jump_co.gif"; //$NON-NLS-1$ public static final String IMG_ICPPASTConstructorChainInitializer = NAME_PREFIX + "jump_co.gif"; //$NON-NLS-1$
public static final String IMG_ICPPASTTemplateParameter = NAME_PREFIX + "disassembly.gif"; //$NON-NLS-1$ public static final String IMG_ICPPASTTemplateParameter = NAME_PREFIX + "disassembly.gif"; //$NON-NLS-1$
public static final String IMG_DEFAULT = NAME_PREFIX + "brkpd_obj.gif"; //$NON-NLS-1$ public static final String IMG_DEFAULT = NAME_PREFIX + "brkpd_obj.gif"; //$NON-NLS-1$
public static final String IMG_EXPAND_ALL = NAME_PREFIX + "expandall.gif"; //$NON-NLS-1$
public static final String IMG_COLLAPSE_ALL = NAME_PREFIX + "collapseall.gif"; //$NON-NLS-1$
public static final ImageDescriptor DESC_IASTArrayModifier= createManaged(ICON_PREFIX, IMG_IASTArrayModifier); public static final ImageDescriptor DESC_IASTArrayModifier= createManaged(ICON_PREFIX, IMG_IASTArrayModifier);
public static final ImageDescriptor DESC_IASTDeclaration= createManaged(ICON_PREFIX, IMG_IASTDeclaration); public static final ImageDescriptor DESC_IASTDeclaration= createManaged(ICON_PREFIX, IMG_IASTDeclaration);
@ -93,6 +95,8 @@ public class DOMASTPluginImages {
public static final ImageDescriptor DESC_ICPPASTConstructorChainInitializer= createManaged(ICON_PREFIX, IMG_ICPPASTConstructorChainInitializer); public static final ImageDescriptor DESC_ICPPASTConstructorChainInitializer= createManaged(ICON_PREFIX, IMG_ICPPASTConstructorChainInitializer);
public static final ImageDescriptor DESC_ICPPASTTemplateParameter= createManaged(ICON_PREFIX, IMG_ICPPASTTemplateParameter); public static final ImageDescriptor DESC_ICPPASTTemplateParameter= createManaged(ICON_PREFIX, IMG_ICPPASTTemplateParameter);
public static final ImageDescriptor DESC_DEFAULT= createManaged(ICON_PREFIX, IMG_DEFAULT); public static final ImageDescriptor DESC_DEFAULT= createManaged(ICON_PREFIX, IMG_DEFAULT);
public static final ImageDescriptor DESC_EXPAND_ALL= createManaged(ICON_PREFIX, IMG_EXPAND_ALL);
public static final ImageDescriptor DESC_COLLAPSE_ALL= createManaged(ICON_PREFIX, IMG_COLLAPSE_ALL);
private static ImageDescriptor createManaged(String prefix, String name) { private static ImageDescriptor createManaged(String prefix, String name) {
return createManaged(imageRegistry, prefix, name); return createManaged(imageRegistry, prefix, name);

View file

@ -21,6 +21,7 @@ import org.eclipse.core.runtime.IAdaptable;
* @author dsteffle * @author dsteffle
*/ */
public class TreeObject implements IAdaptable { public class TreeObject implements IAdaptable {
public static final String BLANK_FILENAME = ""; //$NON-NLS-1$
private static final String IGCCAST_PREFIX = "IGCCAST"; //$NON-NLS-1$ private static final String IGCCAST_PREFIX = "IGCCAST"; //$NON-NLS-1$
private static final String IGNUAST_PREFIX = "IGNUAST"; //$NON-NLS-1$ private static final String IGNUAST_PREFIX = "IGNUAST"; //$NON-NLS-1$
private static final String IGPPAST_PREFIX = "IGPPAST"; //$NON-NLS-1$ private static final String IGPPAST_PREFIX = "IGPPAST"; //$NON-NLS-1$
@ -59,7 +60,7 @@ public class TreeObject implements IAdaptable {
} }
public String toString() { public String toString() {
if( node == null ) return ""; //$NON-NLS-1$ //TODO Devin is this the best way??? if( node == null ) return BLANK_FILENAME; //$NON-NLS-1$ //TODO Devin is this the best way???
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
Class[] classes = node.getClass().getInterfaces(); Class[] classes = node.getClass().getInterfaces();
@ -85,11 +86,11 @@ public class TreeObject implements IAdaptable {
public String getFilename() public String getFilename()
{ {
if ( node == null ) return ""; //$NON-NLS-1$ if ( node == null ) return BLANK_FILENAME;
IASTNodeLocation [] location = node.getNodeLocations(); IASTNodeLocation [] location = node.getNodeLocations();
if( location[0] instanceof IASTFileLocation ) if( location.length > 0 && location[0] instanceof IASTFileLocation )
return ((IASTFileLocation)location[0]).getFileName(); return ((IASTFileLocation)location[0]).getFileName();
return ""; //$NON-NLS-1$ return BLANK_FILENAME; //$NON-NLS-1$
} }
public int getOffset() { public int getOffset() {