Search in sources :

Example 11 with ZyLineContent

use of com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent in project binnavi by google.

the class CCharKeyBehavior method updateLabelContent.

@Override
protected void updateLabelContent() {
    if (m_wasUneditableSelection) {
        m_caretX = getCaretEndPosX();
        return;
    }
    final int x = getCaretEndPosX();
    final int y = getCaretMouseReleasedY();
    m_caretX = x;
    if (isComment(x, y)) {
        // Cursor is within an existing comment
        m_caretX += 1;
        final ZyLineContent lineContent = getLineContent(y);
        final IZyEditableObject editableObject = lineContent.getLineFragmentObjectAt(x);
        if ((editableObject == null) || editableObject.isCommentDelimiter()) {
            return;
        }
        final int textCursor = x - editableObject.getStart();
        final String text = lineContent.getText().substring(editableObject.getStart(), editableObject.getEnd());
        final String chr = String.valueOf(getEvent().getKeyChar());
        String changedText = String.format("%s%s%s", text.substring(0, textCursor), chr, text.substring(textCursor));
        if (isComment(x, y)) {
            changedText = getMultilineComment(y, changedText);
        }
        editableObject.update(changedText);
        getLabelContent().getLineEditor().recreateLabelLines(getLabelContent(), editableObject.getPersistentModel());
    } else if (isEditable(x, y)) {
        throw new RuntimeException("Not implemented yet.");
    } else {
        // Underlying object is NOT editable
        final ZyLineContent lineContent = getLineContent(y);
        if ((x == lineContent.getText().length()) && (lineContent.getLineObject() != null)) {
            // Create new behind line comment
            lineContent.getLineObject().updateComment(Character.toString(getEvent().getKeyChar()), ECommentPlacement.BEHIND_LINE);
            getLabelContent().getLineEditor().recreateLabelLines(getLabelContent(), lineContent.getLineObject().getPersistentModel());
            m_caretX = getLineContent(y).getText().length();
        }
    }
}
Also used : IZyEditableObject(com.google.security.zynamics.zylib.gui.zygraph.realizers.IZyEditableObject) ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent)

Example 12 with ZyLineContent

use of com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent in project binnavi by google.

the class CCharKeyBehavior method updateUndoHistory.

@Override
protected void updateUndoHistory() {
    if (m_editableObject != null) {
        // There was an editable object that has been changed
        final int x = getCaretEndPosX();
        final int y = getCaretMouseReleasedY();
        final ZyLineContent lineContent = getLineContent(y);
        final IZyEditableObject editableObject = lineContent.getLineFragmentObjectAt(x);
        if (editableObject != null) {
            String text = lineContent.getText().substring(editableObject.getStart(), editableObject.getEnd());
            if (isComment(x, y)) {
                text = getMultiLineComment(y);
            }
            udpateUndolist(getLabelContent(), lineContent.getLineObject().getPersistentModel(), editableObject, text, m_isAboveComment, m_isBehindComment, m_isLabelComment, getCaretStartPosX(), getCaretMousePressedX(), getCaretMousePressedY(), getCaretEndPosX(), getCaretMouseReleasedX(), getCaretMouseReleasedY());
        }
    }
}
Also used : IZyEditableObject(com.google.security.zynamics.zylib.gui.zygraph.realizers.IZyEditableObject) ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent)

Example 13 with ZyLineContent

use of com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent in project binnavi by google.

the class CCharKeyBehavior method initUndoHistory.

@Override
protected void initUndoHistory() {
    final int x = getCaretEndPosX();
    final int y = getCaretMouseReleasedY();
    final ZyLineContent lineContent = getLineContent(y);
    IZyEditableObject editableObject = lineContent.getLineFragmentObjectAt(x);
    m_isAboveComment = isAboveLineComment(y);
    m_isBehindComment = isBehindLineComment(x, y);
    m_isLabelComment = isLabelComment(y);
    boolean isNewBehindLineComment = false;
    if ((x == lineContent.getText().length()) && !isComment(x, y)) {
        // a new behind line comment will be created
        m_isBehindComment = true;
        isNewBehindLineComment = true;
        editableObject = lineContent.getLineObject();
    }
    m_editableObject = editableObject;
    String text = "";
    if (editableObject != null) {
        if (!isNewBehindLineComment) {
            text = lineContent.getText().substring(editableObject.getStart(), editableObject.getEnd());
            if (isComment(x, y)) {
                text = getMultiLineComment(y);
            }
        }
        udpateUndolist(getLabelContent(), lineContent.getLineObject().getPersistentModel(), editableObject, text, m_isAboveComment, m_isBehindComment, m_isLabelComment, getCaretStartPosX(), getCaretMousePressedX(), getCaretMousePressedY(), getCaretEndPosX(), getCaretMouseReleasedX(), getCaretMouseReleasedY());
    }
}
Also used : IZyEditableObject(com.google.security.zynamics.zylib.gui.zygraph.realizers.IZyEditableObject) ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent)

Example 14 with ZyLineContent

use of com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent in project binnavi by google.

the class CCursorKeyBehavior method handleNotShiftAndCtrl.

protected void handleNotShiftAndCtrl(final int xdelta, final int ydelta) {
    final ZyLabelContent labelContent = getLabelContent();
    int caretStartPos_X = getCaretStartPosX();
    int mousePressed_X = getCaretMousePressedX();
    final int mousePressed_Y = getCaretMousePressedY();
    int caretEndPos_X = getCaretEndPosX();
    int mouseReleased_X = getCaretMouseReleasedX();
    final int mouseReleased_Y = getCaretMouseReleasedY();
    if (xdelta != 0) {
        final ZyLineContent lineContent = labelContent.getLineContent(mouseReleased_Y);
        final String s = lineContent.getText() + " ";
        if (xdelta > 0) {
            final boolean firstIsSpace = s.charAt(caretEndPos_X) == ' ';
            int endindex = 0;
            for (int i = caretEndPos_X; i < s.length(); ++i) {
                endindex = i;
                if (firstIsSpace) {
                    if (s.charAt(i) != ' ') {
                        break;
                    }
                } else {
                    if (s.charAt(i) == ' ') {
                        break;
                    }
                }
            }
            if ((lineContent.getText().endsWith("\n") || lineContent.getText().endsWith("\r")) && (lineContent.getText().length() == endindex)) {
                endindex -= 1;
            }
            caretStartPos_X = endindex;
            mousePressed_X = endindex;
            mouseReleased_X = endindex;
            caretEndPos_X = endindex;
        } else if (xdelta < 0) {
            if (caretEndPos_X == 0) {
                return;
            }
            final boolean firstIsSpace = s.charAt(caretEndPos_X - 1) == ' ';
            int startindex = caretEndPos_X - 1;
            for (int i = caretEndPos_X - 1; i >= 0; --i) {
                if (firstIsSpace) {
                    if (s.charAt(i) != ' ') {
                        break;
                    }
                } else {
                    if (s.charAt(i) == ' ') {
                        break;
                    }
                }
                startindex = i;
            }
            caretStartPos_X = startindex;
            mousePressed_X = startindex;
            mouseReleased_X = startindex;
            caretEndPos_X = startindex;
        }
        mouseReleased_X = correctMouseReleasedX(mouseReleased_X, mouseReleased_Y, mousePressed_Y);
        setCaret(caretStartPos_X, mousePressed_X, mousePressed_Y, caretEndPos_X, mouseReleased_X, mouseReleased_Y);
    } else if (ydelta != 0) {
        handleNotShiftAndNotCtrl(0, ydelta);
    }
}
Also used : ZyLabelContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent) ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent)

Example 15 with ZyLineContent

use of com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent in project binnavi by google.

the class ClipboardCopier method copyToClipboard.

/**
   * Copies the text content of a node to the clip board.
   * 
   * @param node The node to copy to the clip board.
   */
public static void copyToClipboard(final ZyGraphNode<?> node) {
    Preconditions.checkNotNull(node, "Error: Node argument can not be null");
    final IZyNodeRealizer realizer = node.getRealizer();
    final ZyLabelContent content = realizer.getNodeContent();
    if (content.isSelectable()) {
        final ZyLabelContent zyContent = content;
        final StringBuilder textBuilder = new StringBuilder();
        for (final ZyLineContent zyLineContent : zyContent) {
            textBuilder.append(zyLineContent.getText());
            //$NON-NLS-1$
            textBuilder.append("\n");
        }
        ClipboardHelpers.copyToClipboard(textBuilder.toString());
    }
}
Also used : ZyLabelContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent) IZyNodeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.IZyNodeRealizer) ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent)

Aggregations

ZyLineContent (com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent)56 IZyEditableObject (com.google.security.zynamics.zylib.gui.zygraph.realizers.IZyEditableObject)24 Point (java.awt.Point)15 GraphSearcher (com.google.security.zynamics.binnavi.yfileswrap.Gui.GraphWindows.Searchers.Text.Model.GraphSearcher)8 NaviEdge (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge)8 NaviNode (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode)8 ZyNormalNodeRealizer (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyNormalNodeRealizer)8 Test (org.junit.Test)8 ZyLabelContent (com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent)5 CStyleRunData (com.google.security.zynamics.zylib.gui.zygraph.realizers.CStyleRunData)3 IZyNodeRealizer (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.IZyNodeRealizer)3 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)2 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)2 ArrayList (java.util.ArrayList)2 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)1 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)1 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)1 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)1 DefaultAddressConverter (com.google.security.zynamics.binnavi.debug.debugger.DefaultAddressConverter)1 IDebugger (com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger)1