Search in sources :

Example 1 with ILineDiffInfo

use of org.eclipse.jface.text.source.ILineDiffInfo in project eclipse.platform.text by eclipse.

the class RevertBlockAction method computeEnablement.

@Override
public boolean computeEnablement() {
    if (!super.computeEnablement())
        return false;
    fLine = getLastLine();
    if (fLine == -1)
        return false;
    ILineDiffer differ = getDiffer();
    if (differ == null)
        return false;
    ILineDiffInfo info = differ.getLineInfo(fLine);
    if (info == null || info.getChangeType() == ILineDiffInfo.UNCHANGED)
        return false;
    boolean hasBlock = false;
    if (fLine > 0) {
        info = differ.getLineInfo(fLine - 1);
        hasBlock = info != null && info.hasChanges();
    }
    if (!hasBlock) {
        info = differ.getLineInfo(fLine + 1);
        hasBlock = info != null && info.hasChanges();
    }
    if (hasBlock)
        return true;
    return false;
}
Also used : ILineDiffer(org.eclipse.jface.text.source.ILineDiffer) ILineDiffInfo(org.eclipse.jface.text.source.ILineDiffInfo)

Example 2 with ILineDiffInfo

use of org.eclipse.jface.text.source.ILineDiffInfo in project eclipse.platform.text by eclipse.

the class RevertLineAction method computeEnablement.

@Override
public boolean computeEnablement() {
    if (!super.computeEnablement())
        return false;
    fLine = getLastLine();
    if (fLine == -1)
        return false;
    ILineDiffer differ = getDiffer();
    if (differ == null)
        return false;
    ILineDiffInfo info = differ.getLineInfo(fLine);
    if (info == null || info.getChangeType() == ILineDiffInfo.UNCHANGED)
        return false;
    if (info.getChangeType() == ILineDiffInfo.ADDED)
        // $NON-NLS-1$
        setText(QuickDiffMessages.getString("RevertLineAction.delete.label"));
    else
        // $NON-NLS-1$
        setText(QuickDiffMessages.getString("RevertLineAction.label"));
    return true;
}
Also used : ILineDiffer(org.eclipse.jface.text.source.ILineDiffer) ILineDiffInfo(org.eclipse.jface.text.source.ILineDiffInfo)

Example 3 with ILineDiffInfo

use of org.eclipse.jface.text.source.ILineDiffInfo in project eclipse.platform.text by eclipse.

the class RevertSelectionAction method computeEnablement.

@Override
public boolean computeEnablement() {
    if (!super.computeEnablement())
        return false;
    ITextSelection selection = getSelection();
    if (selection == null)
        return false;
    fStartLine = selection.getStartLine();
    fEndLine = selection.getEndLine();
    // only enable if mouse activity is inside line range
    int activityLine = getLastLine();
    if (activityLine == -1 || activityLine < fStartLine || activityLine > fEndLine + 1)
        // + 1 to cover the case where the selection goes to the offset of the next line
        return false;
    ILineDiffer differ = getDiffer();
    if (differ == null)
        return false;
    // only enable if selection covers at least two lines
    if (fEndLine > fStartLine) {
        for (int i = fStartLine; i <= fEndLine; i++) {
            ILineDiffInfo info = differ.getLineInfo(i);
            if (info != null && info.hasChanges()) {
                return true;
            }
        }
    }
    return false;
}
Also used : ILineDiffer(org.eclipse.jface.text.source.ILineDiffer) ILineDiffInfo(org.eclipse.jface.text.source.ILineDiffInfo) ITextSelection(org.eclipse.jface.text.ITextSelection)

Example 4 with ILineDiffInfo

use of org.eclipse.jface.text.source.ILineDiffInfo in project eclipse.platform.text by eclipse.

the class RevertBlockAction method computeEnablement.

@Override
public boolean computeEnablement() {
    if (!super.computeEnablement())
        return false;
    fLine = getLastLine();
    if (fLine == -1)
        return false;
    ILineDiffer differ = getDiffer();
    if (differ == null)
        return false;
    ILineDiffInfo info = differ.getLineInfo(fLine);
    if (info == null || info.getChangeType() == ILineDiffInfo.UNCHANGED)
        return false;
    boolean hasBlock = false;
    if (fLine > 0) {
        info = differ.getLineInfo(fLine - 1);
        hasBlock = info != null && info.hasChanges();
    }
    if (!hasBlock) {
        info = differ.getLineInfo(fLine + 1);
        hasBlock = info != null && info.hasChanges();
    }
    if (hasBlock)
        return true;
    return false;
}
Also used : ILineDiffer(org.eclipse.jface.text.source.ILineDiffer) ILineDiffInfo(org.eclipse.jface.text.source.ILineDiffInfo)

Example 5 with ILineDiffInfo

use of org.eclipse.jface.text.source.ILineDiffInfo in project eclipse.platform.text by eclipse.

the class DiffPainter method paintLine.

/**
 * Paints a single model line onto <code>gc</code>.
 *
 * @param line the model line to paint
 * @param gc the {@link GC} to paint onto
 * @param width the width of the column
 * @param deletionColor the background color used to indicate deletions
 */
private void paintLine(int line, GC gc, int width, Color deletionColor) {
    int widgetLine = JFaceTextUtil.modelLineToWidgetLine(fViewer, line);
    if (widgetLine == -1)
        return;
    ILineDiffInfo info = getDiffInfo(line);
    if (info != null) {
        int y = fWidget.getLinePixel(widgetLine);
        int lineHeight = JFaceTextUtil.computeLineHeight(fWidget, widgetLine);
        // draw background color if special
        if (hasSpecialColor(info)) {
            gc.setBackground(getColor(info));
            gc.fillRectangle(0, autoScaleUp(y), autoScaleUp(width), autoScaleUp(lineHeight));
        }
        /* Deletion Indicator: Simply a horizontal line */
        int delBefore = info.getRemovedLinesAbove();
        int delBelow = info.getRemovedLinesBelow();
        if (delBefore > 0 || delBelow > 0) {
            gc.setForeground(deletionColor);
            gc.setLineWidth(autoScaleUp(1));
            if (delBefore > 0)
                gc.drawLine(0, autoScaleUp(y), autoScaleUp(width), autoScaleUp(y));
            if (delBelow > 0)
                gc.drawLine(0, autoScaleUp(y + lineHeight - 1), autoScaleUp(width), autoScaleUp(y + lineHeight - 1));
        }
    }
}
Also used : ILineDiffInfo(org.eclipse.jface.text.source.ILineDiffInfo)

Aggregations

ILineDiffInfo (org.eclipse.jface.text.source.ILineDiffInfo)10 ILineDiffer (org.eclipse.jface.text.source.ILineDiffer)8 ITextSelection (org.eclipse.jface.text.ITextSelection)2 ArrayList (java.util.ArrayList)1