Search in sources :

Example 1 with IASTPreprocessorIncludeStatement

use of org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement in project ch.hsr.ifs.cdttesting by IFS-HSR.

the class ASTWidget method createNode.

private Node<Pair<Button, IASTNode>> createNode(final Button button, final IASTNode astNode) {
    final Node<Pair<Button, IASTNode>> node = new Node<>(new Pair<>(button, astNode));
    final Point minButtonSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    nodeHeight = Math.max(nodeHeight, minButtonSize.y);
    node.setWidth(minButtonSize.x);
    node.treatAsLeaf(true);
    if (astNode instanceof ICPPASTTranslationUnit) {
        button.setBackground(GOLDEN_YELLOW);
        button.getFont().getFontData()[0].setStyle(SWT.BOLD);
    }
    button.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(final MouseEvent e) {
            int selectKey = 0;
            if (prefStore.getString(PreferenceConstants.P_HOW_TO_SELECT).equals(PreferenceConstants.P_SELECT_BY_RIGHT_CLICK)) {
                selectKey = 3;
            } else if (prefStore.getString(PreferenceConstants.P_HOW_TO_SELECT).equals(PreferenceConstants.P_SELECT_BY_LEFT_CLICK)) {
                selectKey = 1;
            }
            if (e.button == selectKey) {
                setNodeInNodeView(astNode);
            }
            if (e.button == 1) {
                buildChildrenAndRefresh(node);
            }
        }
    });
    button.addMouseTrackListener(new MouseTrackListener() {

        @Override
        public void mouseHover(final MouseEvent e) {
            if (prefStore.getString(PreferenceConstants.P_HOW_TO_SELECT).equals(PreferenceConstants.P_SELECT_BY_MOUSE_OVER)) {
                setNodeInNodeView(astNode);
            }
            IASTFileLocation fileLocation = astNode.getFileLocation();
            while (fileLocation.getContextInclusionStatement() != null) {
                final IASTPreprocessorIncludeStatement contextInclusionStatement = fileLocation.getContextInclusionStatement();
                fileLocation = contextInclusionStatement.getFileLocation();
            }
            final TextSelection textSelection = new TextSelection(fileLocation.getNodeOffset(), fileLocation.getNodeLength());
            CUIPlugin.getActivePage().getActiveEditor().getEditorSite().getSelectionProvider().setSelection(textSelection);
        }

        @Override
        public void mouseExit(final MouseEvent e) {
        }

        @Override
        public void mouseEnter(final MouseEvent e) {
        }
    });
    return node;
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) TextSelection(org.eclipse.jface.text.TextSelection) IASTNode(org.eclipse.cdt.core.dom.ast.IASTNode) Node(ch.hsr.ifs.pasta.tree.Node) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Point(org.eclipse.swt.graphics.Point) IASTFileLocation(org.eclipse.cdt.core.dom.ast.IASTFileLocation) IASTPreprocessorIncludeStatement(org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement) ICPPASTTranslationUnit(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit)

Aggregations

Node (ch.hsr.ifs.pasta.tree.Node)1 IASTFileLocation (org.eclipse.cdt.core.dom.ast.IASTFileLocation)1 IASTNode (org.eclipse.cdt.core.dom.ast.IASTNode)1 IASTPreprocessorIncludeStatement (org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement)1 ICPPASTTranslationUnit (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit)1 TextSelection (org.eclipse.jface.text.TextSelection)1 MouseAdapter (org.eclipse.swt.events.MouseAdapter)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 MouseTrackListener (org.eclipse.swt.events.MouseTrackListener)1 Point (org.eclipse.swt.graphics.Point)1