Add hyperlinks to DiffViewer
commitdf38739c2961914202372451ffc5196d0991afc7
authorThomas Wolf <thomas.wolf@paranor.ch>
Fri, 25 Nov 2016 19:28:04 +0000 (25 20:28 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Sat, 3 Dec 2016 23:44:48 +0000 (4 00:44 +0100)
treebedf8de47f967fc3865815dc1988fe8da261095a
parent6d01c2caccaa282fc700599bb48e3cbf2bc1edc9
Add hyperlinks to DiffViewer

Provide links on file headlines and hunk headers to open files in
editors.

Provides links to:
* Open the previous version in an editor
* Open the workspace version (if it exists) in an editor
* Open "this" version (i.e., the “current” one of the diff) in an
  editor
* Open a two-way diff between the previous and this version in a
  compare editor

Hyperlinks were chosen instead of a context menu because:
* A context menu sensitive to the location in the text would have
  needed to be based on the location of the current selection, which
  is cumbersome.
* A context menu based on click coordinates is not a good idea because
  * one has no immediate access to the coordinates of the mouse event
    triggering the context menu (and if one had, it would need to be
    converted to a text location), and
  * when the context menu is triggered via the keyboard (Shift-F10),
    there is no reasonable coordinate to use anyway.

Add a hyperlink detector to create links to open files (and reveal the
affected lines if on a hunk).

As it turned out, simply adding a hyperlink detector worked already,
but had a few problems:
* Background and foreground colors got messed up when mousing over
  the hyperlinks because the JFace hyperlink infrastructure didn’t
  interact well with the purely SWT-based coloring done in the viewer.
* The hyperlink pop-up giving access to the different open "commands"
  when there are multiple hyperlinks at the same location took longer
  to appear the further down in the diff the hyperlink was. No idea
  why; the hyperlink detector itself is fast.

Therefore rewrite the DiffViewer to use the JFace infrastructure for
syntax coloring. The hand-crafted SWT coloring is a dead-end and makes
adding new features very hard.

Added a document partitioner, plus a presentation reconciler. The line
background listener was kept to get backgrounds extending over the
whole width of the viewer (syntax coloring alone would only set the
background on actual content).

This solves the color problems, and interestingly also makes the
hyperlink pop-ups appear speedily, even at the bottom of a lengthy
diff.

Also move all the "open file (version)" methods to DiffViewer and use
them in StagingView, CommitFileDiffViewer, and CompareTreeView instead
of duplicating code all around.

Change-Id: I84332f8e07d9f9928a66a91799dec7650de6b44c
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
14 files changed:
org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/EgitUiEditorUtils.java
org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/blame/BlameInformationControl.java
org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffDocument.java [new file with mode: 0644]
org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorPage.java
org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffStyleRangeFormatter.java
org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java
org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CompareTreeView.java
org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/HyperlinkSourceViewer.java
org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitFileDiffViewer.java
org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/revision/GitCompareFileRevisionEditorInput.java
org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties