Search in sources :

Example 46 with ZyLineContent

use of com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent 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)

Example 47 with ZyLineContent

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

the class CAbstractKeyBehavior method getSelectedText.

protected String getSelectedText() {
    if (!isSelection()) {
        return "";
    }
    final int yStart = Math.min(getCaretMousePressedY(), getCaretMouseReleasedY());
    final int yEnd = Math.max(getCaretMousePressedY(), getCaretMouseReleasedY());
    final int xStart = Math.min(getCaretMousePressedX(), getCaretMouseReleasedX());
    final int xEnd = Math.max(getCaretMousePressedX(), getCaretMouseReleasedX());
    final StringBuilder clipboardText = new StringBuilder();
    for (int lineIndex = yStart; lineIndex <= yEnd; ++lineIndex) {
        final ZyLineContent lineContent = getLineContent(lineIndex);
        final int lineLength = lineContent.getText().length();
        if (xStart < lineLength) {
            int xTempEnd = xEnd;
            if (xEnd > lineLength) {
                xTempEnd = lineLength;
            }
            final String lineText = lineContent.getText();
            String fragment = lineText.substring(xStart, xTempEnd);
            if (!fragment.endsWith("\n") && (lineIndex != yEnd)) {
                fragment += "\n";
            }
            if (fragment.endsWith("\r") || ((lineIndex == yEnd) && fragment.endsWith("\n"))) {
                fragment = fragment.substring(0, fragment.length() - 1);
            }
            clipboardText.append(fragment);
        } else if (lineIndex != yEnd) {
            clipboardText.append("\n");
        }
    }
    return clipboardText.toString();
}
Also used : ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent) Point(java.awt.Point)

Example 48 with ZyLineContent

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

the class CBackspaceKeyBehavior method updateUndoHistory.

@Override
protected void updateUndoHistory() {
    if (!m_wasEditablePosition) {
        return;
    }
    m_wasEditablePosition = false;
    final int x = getCaretEndPosX();
    int y = getCaretMouseReleasedY();
    ZyLineContent lineContent = getLineContent(y);
    String text = "";
    if ((lineContent == null) || (lineContent.getLineObject() == null) || (m_lineModel.getPersistentModel() != lineContent.getLineObject().getPersistentModel())) {
        if (!m_isLabelComment) {
            int offset = 0;
            if ((y + 1) < getLabelContent().getLineCount()) {
                offset = 1;
                lineContent = getLineContent(y + offset);
            }
            if ((m_lineModel.getPersistentModel() != lineContent.getLineObject().getPersistentModel()) && (y > 0)) {
                offset = -1;
                lineContent = getLineContent(y + offset);
            }
            y += offset;
        }
    } else if (isComment(x, y)) {
        text = getMultiLineComment(y);
    }
    udpateUndolist(getLabelContent(), m_lineModel.getPersistentModel(), m_lineModel, text, m_isAboveComment, m_isBehindComment, m_isLabelComment, getCaretStartPosX(), getCaretMousePressedX(), getCaretMousePressedY(), getCaretEndPosX(), getCaretMouseReleasedX(), getCaretMouseReleasedY());
}
Also used : ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent)

Example 49 with ZyLineContent

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

the class CBackspaceKeyBehavior method initUndoHistory.

@Override
protected void initUndoHistory() {
    final int x = getCaretEndPosX();
    final int y = getCaretMouseReleasedY();
    final ZyLineContent lineContent = getLineContent(y);
    m_editableObject = lineContent.getLineFragmentObjectAt(x);
    m_lineModel = lineContent.getLineObject();
    if (m_editableObject != null) {
        // Caret is within an editable object.
        m_wasEditablePosition = true;
        String text = lineContent.getText().substring(m_editableObject.getStart(), m_editableObject.getEnd());
        m_isAboveComment = isAboveLineComment(y);
        m_isBehindComment = isBehindLineComment(x, y);
        m_isLabelComment = isLabelComment(y);
        if (isComment(x, y)) {
            text = getMultiLineComment(y);
        }
        udpateUndolist(getLabelContent(), m_lineModel.getPersistentModel(), m_editableObject, text, m_isAboveComment, m_isBehindComment, m_isLabelComment, getCaretStartPosX(), getCaretMousePressedX(), getCaretMousePressedY(), getCaretEndPosX(), getCaretMouseReleasedX(), getCaretMouseReleasedY());
    }
}
Also used : ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent)

Example 50 with ZyLineContent

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

the class GraphSearcherTest method testSearchSelected.

@Test
public void testSearchSelected() {
    final ZyNodeRealizer<NaviNode> r = new ZyNormalNodeRealizer<NaviNode>(m_content);
    final NaviNode m_node1 = new NaviNode(m_ynode, r, m_codeNode1);
    final GraphSearcher searcher = new GraphSearcher();
    searcher.getSettings().setOnlySelected(true);
    m_content.addLineContent(new ZyLineContent("Hello my Test", null));
    searcher.search(Lists.newArrayList(m_node1), new ArrayList<NaviEdge>(), "my");
    assertNull(searcher.getCursor().current());
    m_node1.getRawNode().setSelected(true);
    searcher.search(Lists.newArrayList(m_node1), new ArrayList<NaviEdge>(), "my");
    assertEquals(m_node1, searcher.getCursor().current().getObject());
    assertEquals(0, searcher.getCursor().current().getLine());
    assertEquals(6, searcher.getCursor().current().getPosition());
    assertEquals(2, searcher.getCursor().current().getLength());
    // TEST: Do not move beyond the last result
    searcher.getCursor().next();
    assertEquals(m_node1, searcher.getCursor().current().getObject());
    assertEquals(0, searcher.getCursor().current().getLine());
    assertEquals(6, searcher.getCursor().current().getPosition());
    assertEquals(2, searcher.getCursor().current().getLength());
}
Also used : ZyNormalNodeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyNormalNodeRealizer) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) GraphSearcher(com.google.security.zynamics.binnavi.yfileswrap.Gui.GraphWindows.Searchers.Text.Model.GraphSearcher) ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge) Test(org.junit.Test)

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