Better default editor opening for file revisions
commitb5764723c1bef281a3d7d00d6f64af1d016472ca
authorThomas Wolf <thomas.wolf@paranor.ch>
Thu, 5 Jul 2018 20:53:00 +0000 (5 22:53 +0200)
committerThomas Wolf <thomas.wolf@paranor.ch>
Sat, 7 Jul 2018 10:55:56 +0000 (7 12:55 +0200)
treebac154a75282563838785d579cf592957608fa6a
parent96d430a13d0e9210ccf563d42ba94c202d578d18
Better default editor opening for file revisions

EGit tried already to open the configured editor based on content
types or file name associations. On failure, it would fall back to
the default internal text editor.

Unfortunately, opening a default editor failed always for editors
that do require some physical file. Thus opening an external editor
always failed, and EGit showed the file as text. Even if the file
was binary.

Newly, make FileRevisionEditorInput implement IPathEditorInput.
Eclipse uses this to invoke external editors, so when getPath()
is called, we can write the blob to a temporary file, so that the
external editor has something to read from.

This is the same technique as used in InternalClassFileEditorInput
in JDT.

Incidentally this also makes showing a git revision of an HTML page
in the internal web browser work.

The file is created inside a temporary directory; this enables us
to use a simple file name (revision & original file name), which
looks nicer in programs that show the file name than a (partially)
auto-generated name as we'd get from createTempFile().

The file is set as read-only: a user cannot modify a git revision.
We attempt to delete the temporary file and directory when the JVM
terminates to avoid filling the system tmp directory.

Bug: 463906
Change-Id: I355524f46a8ef66745f287adf718dfb8ea197b4a
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
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/revision/FileRevisionEditorInput.java
org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties