Search in sources :

Example 26 with IZyEditableObject

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

the class CAbstractKeyBehavior method getNextModelLineContent.

protected ZyLineContent getNextModelLineContent(final int lineYPos) {
    final ZyLineContent lineContent = m_labelContent.getLineContent(lineYPos);
    final IZyEditableObject lineObject = lineContent.getLineObject();
    for (int index = lineYPos + 1; index < m_labelContent.getLineCount(); ++index) {
        final ZyLineContent nextLineContent = m_labelContent.getLineContent(index);
        if (nextLineContent == null) {
            return null;
        }
        final IZyEditableObject nextLineObject = nextLineContent.getLineObject();
        if ((lineObject != nextLineObject) && !nextLineObject.isPlaceholder()) {
            return nextLineContent;
        }
    }
    return null;
}
Also used : IZyEditableObject(com.google.security.zynamics.zylib.gui.zygraph.realizers.IZyEditableObject) ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent) Point(java.awt.Point)

Example 27 with IZyEditableObject

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

the class CAbstractKeyBehavior method pasteClipboardText.

protected Point pasteClipboardText() {
    int caretX = getCaretEndPosX();
    int caretY = getCaretMouseReleasedY();
    boolean isNewComment = false;
    final ZyLineContent lineContent = getLineContent(caretY);
    IZyEditableObject editObject = lineContent.getLineFragmentObjectAt(caretX);
    if ((editObject == null) && (caretX == lineContent.getText().length())) {
        final int nonModelLineY = getLabelContent().getNonPureCommentLineIndexOfModelAt(caretY);
        if ((nonModelLineY != -1) && (nonModelLineY == caretY)) {
            editObject = lineContent.getLineObject();
            isNewComment = true;
        }
    }
    if (editObject != null) {
        String insertText = ClipboardHelpers.getClipboardString();
        if (editObject.isCommentDelimiter()) {
            caretX = editObject.getEnd();
            editObject = lineContent.getLineFragmentObjectAt(caretX);
            if (editObject == null) {
                return null;
            }
        }
        if (isComment(caretX, caretY)) {
            // Insert into existing comment
            final int insertedLineCount = StringHelper.count(insertText, '\n');
            final int lastLineBreak = insertText.lastIndexOf("\n");
            final int textCursor = caretX - editObject.getStart();
            final String lineText = lineContent.getText().substring(editObject.getStart(), editObject.getEnd());
            String changedText = String.format("%s%s%s", lineText.substring(0, textCursor), insertText, lineText.substring(textCursor));
            changedText = getMultilineComment(caretY, changedText);
            editObject.update(changedText);
            getLabelContent().getLineEditor().recreateLabelLines(getLabelContent(), editObject.getPersistentModel());
            caretX += insertText.length() - lastLineBreak - 1;
            caretY += insertedLineCount;
        } else if (isNewComment) {
            // Create new comment
            editObject.updateComment(insertText, ECommentPlacement.BEHIND_LINE);
            if (!isLabelComment(caretY)) {
                getLabelContent().getLineEditor().recreateLabelLines(getLabelContent(), editObject.getPersistentModel());
                final int insertedLineCount = StringHelper.count(insertText, '\n');
                caretY += insertedLineCount;
                final ZyLineContent lastInsertedLineContent = getLineContent(caretY);
                caretX += lastInsertedLineContent.getText().length() - 1;
            }
        } else {
            // Insert into non comment editable object
            insertText = insertText.replace("\n", "");
            insertText = insertText.replace("\r", "");
            final int tempCaretX = caretX;
            caretX = caretX + insertText.length();
            final String lineText = lineContent.getText();
            String changedText = lineText.substring(editObject.getStart(), editObject.getEnd());
            final int insertXpos = tempCaretX - editObject.getStart();
            changedText = String.format("%s%s%s", lineText.substring(editObject.getStart(), insertXpos), insertText, lineText.substring(caretX, editObject.getEnd()));
            editObject.update(changedText);
        }
    }
    return new Point(caretX, caretY);
}
Also used : IZyEditableObject(com.google.security.zynamics.zylib.gui.zygraph.realizers.IZyEditableObject) Point(java.awt.Point) ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent) Point(java.awt.Point)

Aggregations

IZyEditableObject (com.google.security.zynamics.zylib.gui.zygraph.realizers.IZyEditableObject)27 ZyLineContent (com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent)24 Point (java.awt.Point)12 ZyLabelContent (com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent)2 ECommentPlacement (com.google.security.zynamics.zylib.gui.zygraph.realizers.ECommentPlacement)1