Search in sources :

Example 1 with FileDiffRegion

use of org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion in project egit by eclipse.

the class DiffEditorPage method doSetSelection.

@Override
protected void doSetSelection(ISelection selection) {
    if (!selection.isEmpty() && selection instanceof StructuredSelection) {
        Object selected = ((StructuredSelection) selection).getFirstElement();
        if (selected instanceof FileDiffRegion) {
            FileDiffRegion newRange = (FileDiffRegion) selected;
            if (!newRange.equals(currentFileDiffRange)) {
                currentFileDiffRange = newRange;
                selectAndReveal(newRange.getOffset(), 0);
            }
            return;
        }
    }
    super.doSetSelection(selection);
}
Also used : FileDiffRegion(org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 2 with FileDiffRegion

use of org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion in project egit by eclipse.

the class DiffEditorPage method doSetInput.

@Override
protected void doSetInput(IEditorInput input) throws CoreException {
    super.doSetInput(input);
    if (input instanceof DiffEditorInput) {
        setFolding();
        FileDiffRegion region = getFileDiffRange(0);
        currentFileDiffRange = region;
        setOverviewAnnotations();
    } else if (input instanceof CommitEditorInput) {
        formatDiff();
        currentFileDiffRange = null;
    }
    if (outlinePage != null) {
        outlinePage.setInput(getDocumentProvider().getDocument(input));
        if (currentFileDiffRange != null) {
            outlinePage.setSelection(new StructuredSelection(currentFileDiffRange));
        }
    }
}
Also used : FileDiffRegion(org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 3 with FileDiffRegion

use of org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion in project egit by eclipse.

the class DiffDocument method connect.

/**
 * Sets up the document to use information from the given
 * {@link DiffRegionFormatter} for partitioning the document into
 * partitions for file headlines, hunk headers, and added or removed lines.
 * It is assumed that the given formatter has been used to generate content
 * into the document.
 *
 * @param formatter
 *            to obtain information from
 */
public void connect(DiffRegionFormatter formatter) {
    regions = formatter.getRegions();
    fileRegions = formatter.getFileRegions();
    if ((fileRegions == null || fileRegions.length == 0) && defaultRepository != null && defaultFileDiff != null) {
        fileRegions = new FileDiffRegion[] { new FileDiffRegion(defaultRepository, defaultFileDiff, 0, getLength()) };
    }
    newPathPattern = Pattern.compile(// $NON-NLS-1$
    Pattern.quote(formatter.getNewPrefix()) + "\\S+");
    oldPathPattern = Pattern.compile(// $NON-NLS-1$
    Pattern.quote(formatter.getOldPrefix()) + "\\S+");
    maximumLineNumbers = formatter.getMaximumLineNumbers();
    // Connect a new partitioner.
    IDocumentPartitioner partitioner = new FastPartitioner(new DiffPartitionTokenScanner(), new String[] { IDocument.DEFAULT_CONTENT_TYPE, HEADLINE_CONTENT_TYPE, HUNK_CONTENT_TYPE, ADDED_CONTENT_TYPE, REMOVED_CONTENT_TYPE });
    IDocumentPartitioner oldPartitioner = getDocumentPartitioner();
    if (oldPartitioner != null) {
        oldPartitioner.disconnect();
    }
    partitioner.connect(this);
    setDocumentPartitioner(partitioner);
}
Also used : IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) FileDiffRegion(org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion) FastPartitioner(org.eclipse.jface.text.rules.FastPartitioner)

Example 4 with FileDiffRegion

use of org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion in project egit by eclipse.

the class DiffDocument method findFileRegion.

FileDiffRegion findFileRegion(int offset) {
    FileDiffRegion key = new FileDiffRegion(null, null, offset, 0);
    int i = Arrays.binarySearch(fileRegions, key, (a, b) -> {
        if (!TextUtilities.overlaps(a, b)) {
            return a.getOffset() - b.getOffset();
        }
        return 0;
    });
    return i >= 0 ? fileRegions[i] : null;
}
Also used : FileDiffRegion(org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion)

Example 5 with FileDiffRegion

use of org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion in project egit by eclipse.

the class DiffEditorOutlinePage method getSelectedFileDiffs.

private Collection<FileDiffRegion> getSelectedFileDiffs() {
    ISelection currentSelection = getSelection();
    List<FileDiffRegion> result = new ArrayList<>();
    if (!currentSelection.isEmpty() && currentSelection instanceof StructuredSelection) {
        for (Object selected : ((StructuredSelection) currentSelection).toList()) {
            if (selected instanceof FileDiffRegion && !((FileDiffRegion) selected).getDiff().isSubmodule()) {
                result.add((FileDiffRegion) selected);
            }
        }
    }
    return result;
}
Also used : FileDiffRegion(org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

FileDiffRegion (org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion)8 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)5 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 IDocument (org.eclipse.jface.text.IDocument)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 File (java.io.File)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Path (org.eclipse.core.runtime.Path)1 UIText (org.eclipse.egit.ui.internal.UIText)1 FileDiff (org.eclipse.egit.ui.internal.history.FileDiff)1 Action (org.eclipse.jface.action.Action)1 MenuManager (org.eclipse.jface.action.MenuManager)1 Separator (org.eclipse.jface.action.Separator)1