Search in sources :

Example 16 with ZyLineContent

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

the class CAbstractKeyBehavior method getMultiLineComment.

protected String getMultiLineComment(final int lineYPos) {
    final StringBuilder commentText = new StringBuilder();
    final int nonCommentLine = m_labelContent.getNonPureCommentLineIndexOfModelAt(lineYPos);
    final int firstModelLine = m_labelContent.getFirstLineIndexOfModelAt(lineYPos);
    final int lastModelLine = m_labelContent.getLastLineIndexOfModelAt(lineYPos);
    int startIndex = isAboveLineComment(lineYPos) ? firstModelLine : nonCommentLine;
    int endIndex = isAboveLineComment(lineYPos) ? nonCommentLine - 1 : lastModelLine;
    if (nonCommentLine < 0) {
        startIndex = firstModelLine;
        endIndex = lastModelLine;
    }
    for (int index = startIndex; index <= endIndex; ++index) {
        final ZyLineContent curLineContent = m_labelContent.getLineContent(index);
        final String lineText = getSingleLineCommentText(curLineContent);
        commentText.append(lineText);
    }
    return commentText.toString();
}
Also used : ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent) Point(java.awt.Point)

Example 17 with ZyLineContent

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

the class CReturnKeyBehavior method updateLabelContent.

@Override
protected void updateLabelContent() {
    if (m_wasUneditableSelection) {
        return;
    }
    int x = getCaretEndPosX();
    final int y = getCaretMouseReleasedY();
    m_caretY = y + 1;
    if (isComment(x, y)) {
        // Caret end was within a comment. Insert a new line into the comment.
        final ZyLineContent lineContent = getLineContent(y);
        IZyEditableObject lineObject = lineContent.getLineFragmentObjectAt(x);
        if (lineObject.isCommentDelimiter()) {
            x = lineObject.getEnd();
            lineObject = lineContent.getLineFragmentObjectAt(x);
        }
        int textCursor = x - lineObject.getStart();
        final String text = lineContent.getText().substring(lineObject.getStart(), lineObject.getEnd());
        if (text.endsWith("\r") && (textCursor == text.length())) {
            --textCursor;
        }
        String changedLine = String.format("%s%s%s", text.substring(0, textCursor), "\n", text.substring(textCursor));
        changedLine = getMultilineComment(y, changedLine);
        final IZyEditableObject editableObject = lineContent.getLineObject();
        if (editableObject == null) {
            return;
        }
        if (isAboveLineComment(y)) {
            editableObject.updateComment(changedLine, ECommentPlacement.ABOVE_LINE);
        } else if (isBehindLineComment(x, y)) {
            editableObject.updateComment(changedLine, ECommentPlacement.BEHIND_LINE);
        } else if (isLabelComment(y)) {
            editableObject.update(changedLine);
        }
        getLabelContent().getLineEditor().recreateLabelLines(getLabelContent(), editableObject.getPersistentModel());
    } else {
        // Caret was not within a comment. Create a new comment.
        final ZyLineContent lineContent = getLineContent(y);
        final ZyLineContent nextModelLineContent = getNextModelLineContent(y);
        m_caretY = getNextModelLineIndex(y);
        if ((x == lineContent.getText().length()) && (y != 0)) {
            // Caret is at the end of a non-comment line, but it is NOT the first line. A new behind
            // line comment will be created.
            m_caretY = y;
            final IZyEditableObject editableObject = lineContent.getLineObject();
            if (editableObject != null) {
                editableObject.updateComment("\r", ECommentPlacement.BEHIND_LINE);
                getLabelContent().getLineEditor().recreateLabelLines(getLabelContent(), editableObject.getPersistentModel());
            }
        } else if ((nextModelLineContent != null) && (nextModelLineContent.getLineObject() != null) && !isLabelComment(m_caretY)) {
            // There is a next model line, but it's not the label comment. Add a new comment line to the
            // front.
            String changedComment = "\r";
            if (isComment(0, m_caretY)) {
                // There is already a above line comment
                changedComment = "\n" + getMultiLineComment(m_caretY);
            }
            nextModelLineContent.getLineObject().updateComment(changedComment, ECommentPlacement.ABOVE_LINE);
            getLabelContent().getLineEditor().recreateLabelLines(getLabelContent(), nextModelLineContent.getLineObject().getPersistentModel());
        } else if ((nextModelLineContent != null) && isLabelComment(m_caretY)) {
            // There is a next model line content and it's the label comment. Add a new comment line to
            // the front.
            String changedComment = "\n";
            changedComment += getMultiLineComment(m_caretY);
            getLabelContent().getModel().update(changedComment);
            getLabelContent().getLineEditor().recreateLabelLines(getLabelContent(), getLabelContent().getModel().getPersistentModel());
        } else {
            // There is no next model line content and there is still no label comment appended. Create
            // a new label comment.
            // m_caretY = getLabelContent().getLineCount(); // line count is invalid if other sides
            // label comment has more lines than this one
            m_caretY = y + 1;
            getLabelContent().getModel().update("\r");
            getLabelContent().getLineEditor().recreateLabelLines(getLabelContent(), getLabelContent().getModel().getPersistentModel());
        }
    }
}
Also used : IZyEditableObject(com.google.security.zynamics.zylib.gui.zygraph.realizers.IZyEditableObject) ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent)

Example 18 with ZyLineContent

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

the class CReturnKeyBehavior method updateUndoHistory.

@Override
protected void updateUndoHistory() {
    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, isAboveLineComment(y), isBehindLineComment(x, y), isLabelComment(y), 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 19 with ZyLineContent

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

the class CReturnKeyBehavior method initUndoHistory.

@Override
protected void initUndoHistory() {
    int x = getCaretEndPosX();
    int y = getCaretMouseReleasedY();
    final ZyLineContent lineContent = getLineContent(y);
    if (isComment(x, y)) {
        // Caret end was within a comment, when return was pressed
        IZyEditableObject lineObject = lineContent.getLineFragmentObjectAt(x);
        String text = "";
        if (lineObject.isCommentDelimiter()) {
            x = lineObject.getEnd();
            lineObject = lineContent.getLineFragmentObjectAt(x);
        }
        text = getMultiLineComment(y);
        udpateUndolist(getLabelContent(), lineContent.getLineObject().getPersistentModel(), lineObject, text, isAboveLineComment(y), isBehindLineComment(x, y), isLabelComment(y), getCaretStartPosX(), getCaretMousePressedX(), getCaretMousePressedY(), getCaretEndPosX(), getCaretMouseReleasedX(), getCaretMouseReleasedY());
    } else {
        // Caret was not within a comment. Note: Line fragments are always single lined
        final ZyLineContent nextModelLineContent = getNextModelLineContent(y);
        y = getNextModelLineIndex(y);
        String text = "";
        boolean isAboveLineComment = false;
        boolean isBehindLineComment = false;
        boolean isLabelComment = false;
        IZyEditableObject editableObject = nextModelLineContent == null ? getLabelContent().getModel() : nextModelLineContent.getLineObject();
        if ((x == lineContent.getText().length()) && (getCaretMouseReleasedY() != 0)) {
            // Caret is at the end of a non-comment line. A new behind line comment will be created
            editableObject = lineContent.getLineObject();
            isBehindLineComment = true;
        } else if ((nextModelLineContent != null) && !isLabelComment(y)) {
            if (isComment(0, y)) {
                text = getMultiLineComment(y);
            }
            isAboveLineComment = true;
        } else if ((nextModelLineContent != null) && isLabelComment(y)) {
            // There is a next model line content and it's the label comment
            text += getMultiLineComment(y);
            isLabelComment = true;
        } else {
            // There is no next model line content and there is still no label comment appended
            isLabelComment = true;
        }
        if (editableObject == null) {
            return;
        }
        udpateUndolist(getLabelContent(), editableObject.getPersistentModel(), editableObject, text, isAboveLineComment, isBehindLineComment, 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 20 with ZyLineContent

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

the class CSelectAllKeyBehavior method updateCaret.

@Override
protected void updateCaret() {
    final int lastLineIndex = getLabelContent().getLineCount() - 1;
    int lineMaxX = 0;
    for (final ZyLineContent lineContent : getLabelContent()) {
        lineMaxX = Math.max(lineContent.getText().length(), lineMaxX);
    }
    final ZyLineContent lastLineContent = getLineContent(lastLineIndex);
    final int lastLineLength = lastLineContent.getText().length();
    setCaret(0, 0, 0, lastLineLength, lineMaxX, lastLineIndex);
}
Also used : 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