Search in sources :

Example 6 with ILineDiffInfo

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

the class RestoreAction 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.getRemovedLinesAbove() <= 0 && info.getRemovedLinesBelow() <= 0))
        return false;
    if (info.getRemovedLinesBelow() == 0) {
        fLine--;
    } else if (info.getRemovedLinesAbove() != 0) {
    // take the line below
    }
    info = differ.getLineInfo(fLine);
    if (info == null)
        return false;
    if (info.getRemovedLinesBelow() == 1)
        setText(QuickDiffMessages.RestoreAction_label);
    else
        setText(NLSUtility.format(QuickDiffMessages.RestoreAction_multiple_label, String.valueOf(info.getRemovedLinesBelow())));
    return true;
}
Also used : ILineDiffer(org.eclipse.jface.text.source.ILineDiffer) ILineDiffInfo(org.eclipse.jface.text.source.ILineDiffInfo)

Example 7 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)
        setText(QuickDiffMessages.RevertLineAction_delete_label);
    else
        setText(QuickDiffMessages.RevertLineAction_label);
    return true;
}
Also used : ILineDiffer(org.eclipse.jface.text.source.ILineDiffer) ILineDiffInfo(org.eclipse.jface.text.source.ILineDiffInfo)

Example 8 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 9 with ILineDiffInfo

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

the class RestoreAction 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.getRemovedLinesAbove() <= 0 && info.getRemovedLinesBelow() <= 0))
        return false;
    if (info.getRemovedLinesBelow() == 0) {
        fLine--;
    } else if (info.getRemovedLinesAbove() != 0) {
    // take the line below
    }
    info = differ.getLineInfo(fLine);
    if (info == null)
        return false;
    if (info.getRemovedLinesBelow() == 1)
        // $NON-NLS-1$
        setText(QuickDiffMessages.getString("RestoreAction.label"));
    else
        // $NON-NLS-1$
        setText(NLSUtility.format(QuickDiffMessages.getString("RestoreAction.multiple.label"), String.valueOf(info.getRemovedLinesBelow())));
    return true;
}
Also used : ILineDiffer(org.eclipse.jface.text.source.ILineDiffer) ILineDiffInfo(org.eclipse.jface.text.source.ILineDiffInfo)

Example 10 with ILineDiffInfo

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

the class HunkComputer method computeHunks.

/**
 * Converts the line-based information of {@link ILineDiffer} into {@link Hunk}s, grouping
 * contiguous blocks of lines that are changed (added, deleted).
 *
 * @param differ the line differ to query
 * @param lines the number of lines to query
 * @return the corresponding {@link Hunk} information
 */
public static Hunk[] computeHunks(ILineDiffer differ, int lines) {
    List<Hunk> hunks = new ArrayList<>(lines);
    int added = 0;
    int changed = 0;
    ILineDiffInfo info = null;
    for (int line = 0; line < lines; line++) {
        info = differ.getLineInfo(line);
        if (info == null)
            continue;
        int changeType = info.getChangeType();
        switch(changeType) {
            case ILineDiffInfo.ADDED:
                added++;
                continue;
            case ILineDiffInfo.CHANGED:
                changed++;
                continue;
            case ILineDiffInfo.UNCHANGED:
                added -= info.getRemovedLinesAbove();
                if (added != 0 || changed != 0) {
                    hunks.add(new Hunk(line - changed - Math.max(0, added), added, changed));
                    added = 0;
                    changed = 0;
                }
        }
    }
    // last hunk
    if (info != null) {
        added -= info.getRemovedLinesBelow();
        if (added != 0 || changed != 0) {
            hunks.add(new Hunk(lines - changed, added, changed));
            added = 0;
            changed = 0;
        }
    }
    return hunks.toArray(new Hunk[hunks.size()]);
}
Also used : ILineDiffInfo(org.eclipse.jface.text.source.ILineDiffInfo) ArrayList(java.util.ArrayList)

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