Search in sources :

Example 1 with ILineDiffer

use of org.eclipse.jface.text.source.ILineDiffer 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 ILineDiffer

use of org.eclipse.jface.text.source.ILineDiffer 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 ILineDiffer

use of org.eclipse.jface.text.source.ILineDiffer 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 ILineDiffer

use of org.eclipse.jface.text.source.ILineDiffer 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 ILineDiffer

use of org.eclipse.jface.text.source.ILineDiffer 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)

Aggregations

ILineDiffInfo (org.eclipse.jface.text.source.ILineDiffInfo)8 ILineDiffer (org.eclipse.jface.text.source.ILineDiffer)8 ITextSelection (org.eclipse.jface.text.ITextSelection)2