Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2016-12-03 22:41:38 +0000
committerMatthias Sohn2016-12-07 23:07:31 +0000
commit7a8a09de3dca421abf20ce430cf2e5348381a7f7 (patch)
tree1c11c2e5421d21294d5fe4767d9fd8337fc24a15
parent6cdb692cc5933a00079fcb1f520560e1312194d3 (diff)
downloadegit-7a8a09de3dca421abf20ce430cf2e5348381a7f7.tar.gz
egit-7a8a09de3dca421abf20ce430cf2e5348381a7f7.tar.xz
egit-7a8a09de3dca421abf20ce430cf2e5348381a7f7.zip
Turn the DiffEditorPage into a real TextEditor
This enables many standard text editor actions like "Find" or "Go to line". There should be no visual changes except: * The diff page behaves generally like a real read-only text editor, including global contributions to menus, toolbars, the status line, and so on. The line number ruler is now provided by the text editor and can be toggled. And if the diff show multiple files, there's even folding. * The context menu is now a standard extensible text editor context menu that may get contributions. It also provides access to the text editor preferences. Code changes: * DiffViewer simplified. In particular removed a number of things from the constructor that are now provided by the standard text editor framework. (Line numbers, highlighting current line, configuration). * CommitEditor: give it an IEditorActionBarContributor to manage contributions of nested text editors. * Make HyperlinkSourceViewer a ProjectionViewer to get folding support in the editor. * Rewrite DiffEditorPage to be a TextEditor. * Add "Show In..." support. Change-Id: Ic9f2ad74f50e92d9c93d4cfd04273c12b741b284 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.ui/plugin.xml1
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/blame/BlameInformationControl.java7
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditor.java62
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorActionBarContributor.java87
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java13
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorPage.java416
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffStyleRangeFormatter.java8
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java188
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/HyperlinkSourceViewer.java11
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/SpellcheckableMessageArea.java4
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java5
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java12
12 files changed, 591 insertions, 223 deletions
diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml
index 4ec8080628..63ff44dcb1 100644
--- a/org.eclipse.egit.ui/plugin.xml
+++ b/org.eclipse.egit.ui/plugin.xml
@@ -5981,6 +5981,7 @@
point="org.eclipse.ui.editors">
<editor
class="org.eclipse.egit.ui.internal.commit.CommitEditor"
+ contributorClass="org.eclipse.egit.ui.internal.commit.CommitEditorActionBarContributor"
default="false"
icon="icons/obj16/changelog_obj.gif"
id="org.eclipse.egit.ui.commitEditor"
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/blame/BlameInformationControl.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/blame/BlameInformationControl.java
index c1d1413c78..c69ea2ff3a 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/blame/BlameInformationControl.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/blame/BlameInformationControl.java
@@ -68,6 +68,7 @@ import org.eclipse.team.ui.history.IHistoryView;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.editors.text.EditorsUI;
/**
* Annotation information control
@@ -367,9 +368,9 @@ public class BlameInformationControl extends AbstractInformationControl
showAnnotationsLink
.addSelectionListener(showAnnotationsLinkSelectionAdapter);
- DiffViewer diffText = new DiffViewer(diffComposite, null, SWT.NONE,
- false);
- diffText.setEditable(false);
+ DiffViewer diffText = new DiffViewer(diffComposite, null, SWT.NONE);
+ diffText.configure(
+ new DiffViewer.Configuration(EditorsUI.getPreferenceStore()));
diffText.getControl().setLayoutData(
GridDataFactory.fillDefaults().grab(true, true).create());
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditor.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditor.java
index aa5bf0a61b..8970773b0e 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditor.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2015 GitHub Inc. and others.
+ * Copyright (c) 2011, 2016 GitHub Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -49,6 +49,7 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IEditorActionBarContributor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
@@ -56,6 +57,7 @@ import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.IFormColors;
import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.editor.IFormPage;
import org.eclipse.ui.forms.editor.SharedHeaderFormEditor;
import org.eclipse.ui.forms.events.HyperlinkAdapter;
import org.eclipse.ui.forms.events.HyperlinkEvent;
@@ -67,6 +69,8 @@ import org.eclipse.ui.menus.CommandContributionItem;
import org.eclipse.ui.menus.CommandContributionItemParameter;
import org.eclipse.ui.menus.IMenuService;
import org.eclipse.ui.part.IShowInSource;
+import org.eclipse.ui.part.IShowInTargetList;
+import org.eclipse.ui.part.MultiPageEditorSite;
import org.eclipse.ui.part.ShowInContext;
import org.eclipse.ui.progress.UIJob;
@@ -74,7 +78,7 @@ import org.eclipse.ui.progress.UIJob;
* Editor class to view a commit in a form editor.
*/
public class CommitEditor extends SharedHeaderFormEditor implements
- RefsChangedListener, IShowInSource {
+ RefsChangedListener, IShowInSource, IShowInTargetList {
/**
* ID - editor id
@@ -146,19 +150,45 @@ public class CommitEditor extends SharedHeaderFormEditor implements
private ListenerHandle refListenerHandle;
+ private static class CommitEditorNestedSite extends MultiPageEditorSite {
+
+ public CommitEditorNestedSite(CommitEditor topLevelEditor,
+ IEditorPart nestedEditor) {
+ super(topLevelEditor, nestedEditor);
+ }
+
+ @Override
+ public IEditorActionBarContributor getActionBarContributor() {
+ IEditorActionBarContributor globalContributor = getMultiPageEditor()
+ .getEditorSite().getActionBarContributor();
+ if (globalContributor instanceof CommitEditorActionBarContributor) {
+ return ((CommitEditorActionBarContributor) globalContributor)
+ .getTextEditorActionContributor();
+ }
+ return super.getActionBarContributor();
+ }
+
+ }
+
+ @Override
+ protected IEditorSite createSite(IEditorPart editor) {
+ return new CommitEditorNestedSite(this, editor);
+ }
+
/**
* @see org.eclipse.ui.forms.editor.FormEditor#addPages()
*/
@Override
protected void addPages() {
try {
- if (getCommit().isStash())
+ if (getCommit().isStash()) {
commitPage = new StashEditorPage(this);
- else
+ } else {
commitPage = new CommitEditorPage(this);
+ }
addPage(commitPage);
diffPage = new DiffEditorPage(this);
- addPage(diffPage);
+ addPage(diffPage, getEditorInput());
if (getCommit().getNotes().length > 0) {
notePage = new NotesEditorPage(this);
addPage(notePage);
@@ -404,9 +434,23 @@ public class CommitEditor extends SharedHeaderFormEditor implements
@Override
public ShowInContext getShowInContext() {
- if (commitPage != null && commitPage.isActive())
- return commitPage.getShowInContext();
- else
- return null;
+ IFormPage currentPage = getActivePageInstance();
+ IShowInSource showInSource = AdapterUtils.adapt(currentPage,
+ IShowInSource.class);
+ if (showInSource != null) {
+ return showInSource.getShowInContext();
+ }
+ return null;
+ }
+
+ @Override
+ public String[] getShowInTargetIds() {
+ IFormPage currentPage = getActivePageInstance();
+ IShowInTargetList targetList = AdapterUtils.adapt(currentPage,
+ IShowInTargetList.class);
+ if (targetList != null) {
+ return targetList.getShowInTargetIds();
+ }
+ return null;
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorActionBarContributor.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorActionBarContributor.java
new file mode 100644
index 0000000000..1a8ea575d1
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorActionBarContributor.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (C) 2016 Thomas Wolf <thomas.wolf@paranor.ch>.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.commit;
+
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorActionBarContributor;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.SubActionBars;
+import org.eclipse.ui.editors.text.TextEditorActionContributor;
+import org.eclipse.ui.forms.editor.IFormPage;
+import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+/**
+ * An {@link IEditorActionBarContributor} for the {@link CommitEditor} that
+ * provides and properly activates and deactivates a
+ * {@link TextEditorActionContributor} for any page that is an
+ * {@link ITextEditor}.
+ */
+public class CommitEditorActionBarContributor
+ extends MultiPageEditorActionBarContributor {
+
+ private TextEditorActionContributor textActionContributor = new TextEditorActionContributor();
+
+ private SubActionBars textEditorBars;
+
+ private IFormPage currentPage;
+
+ @Override
+ public void init(IActionBars bars) {
+ super.init(bars);
+ textEditorBars = new SubActionBars(bars);
+ textActionContributor.init(textEditorBars);
+ }
+
+ @Override
+ public void dispose() {
+ textActionContributor.dispose();
+ textEditorBars.dispose();
+ super.dispose();
+ }
+
+ @Override
+ public void setActivePage(IEditorPart activeEditor) {
+ IFormPage formerPage = currentPage;
+ if (activeEditor instanceof IFormPage) {
+ currentPage = (IFormPage) activeEditor;
+ } else {
+ currentPage = null;
+ }
+ if (formerPage != null && !formerPage.isEditor()
+ && currentPage != null && !currentPage.isEditor()) {
+ getActionBars().updateActionBars();
+ return;
+ }
+ boolean isTextEditor = currentPage instanceof ITextEditor;
+ if (isTextEditor && currentPage == formerPage) {
+ return;
+ }
+ getTextEditorActionContributor().setActiveEditor(currentPage);
+ updateTextEditorContributions(isTextEditor);
+ getActionBars().updateActionBars();
+ }
+
+ private void updateTextEditorContributions(boolean activate) {
+ if (activate) {
+ textEditorBars.activate();
+ } else {
+ textEditorBars.deactivate();
+ }
+ }
+
+ /**
+ * Gets the nested contributor for {@link ITextEditor}s.
+ *
+ * @return the {@link IEditorActionBarContributor}
+ */
+ public IEditorActionBarContributor getTextEditorActionContributor() {
+ return textActionContributor;
+ }
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java
index 48222c1e51..74ab91bbca 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java
@@ -84,13 +84,15 @@ import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Hyperlink;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
+import org.eclipse.ui.part.IShowInSource;
import org.eclipse.ui.part.ShowInContext;
/**
* Commit editor page class displaying author, committer, parent commits,
* message, and file information in form sections.
*/
-public class CommitEditorPage extends FormPage implements ISchedulingRule {
+public class CommitEditorPage extends FormPage
+ implements ISchedulingRule, IShowInSource {
private static final String SIGNED_OFF_BY = "Signed-off-by: {0} <{1}>"; //$NON-NLS-1$
@@ -621,11 +623,12 @@ public class CommitEditorPage extends FormPage implements ISchedulingRule {
return rule == this;
}
- ShowInContext getShowInContext() {
- if (diffViewer != null && diffViewer.getControl().isFocusControl())
+ @Override
+ public ShowInContext getShowInContext() {
+ if (diffViewer != null && diffViewer.getControl().isFocusControl()) {
return diffViewer.getShowInContext();
- else
- return null;
+ }
+ return null;
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorPage.java
index 22c23f47bf..6d9ad2f050 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorPage.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ * Thomas Wolf <thomas.wolf@paranor.ch> - turn it into a real text editor
*******************************************************************************/
package org.eclipse.egit.ui.internal.commit;
@@ -15,8 +16,12 @@ import static java.util.Arrays.asList;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@@ -24,93 +29,273 @@ import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.egit.core.AdapterUtils;
import org.eclipse.egit.ui.UIUtils;
import org.eclipse.egit.ui.internal.UIText;
+import org.eclipse.egit.ui.internal.commit.DiffStyleRangeFormatter.FileDiffRange;
import org.eclipse.egit.ui.internal.history.FileDiff;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.action.Separator;
-import org.eclipse.jface.layout.GridDataFactory;
-import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.jface.text.ITextOperationTarget;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.source.CompositeRuler;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.egit.ui.internal.repository.RepositoriesView;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.reconciler.IReconciler;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.AnnotationModel;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.IVerticalRuler;
+import org.eclipse.jface.text.source.projection.ProjectionAnnotation;
+import org.eclipse.jface.text.source.projection.ProjectionSupport;
+import org.eclipse.jface.text.source.projection.ProjectionViewer;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.ui.IEditorSite;
-import org.eclipse.ui.IWorkbenchCommandConstants;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.team.ui.history.IHistoryView;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
-import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.editor.IFormPage;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.part.IShowInSource;
+import org.eclipse.ui.part.IShowInTargetList;
+import org.eclipse.ui.part.ShowInContext;
import org.eclipse.ui.progress.UIJob;
-import org.eclipse.ui.texteditor.AbstractTextEditor;
-import org.eclipse.ui.texteditor.IUpdate;
+import org.eclipse.ui.texteditor.AbstractDocumentProvider;
+import org.eclipse.ui.texteditor.ITextEditorActionConstants;
/**
- * Diff editor page class for displaying a {@link DiffViewer}.
+ * A {@link TextEditor} wrapped as an {@link IFormPage} and specialized to
+ * showing a unified diff of a whole commit.
*/
-public class DiffEditorPage extends FormPage {
+public class DiffEditorPage extends TextEditor
+ implements IFormPage, IShowInSource, IShowInTargetList {
- private static class TextViewerAction extends Action implements IUpdate {
+ private static final String[] SHOW_IN_TARGETS = {
+ IHistoryView.VIEW_ID, RepositoriesView.VIEW_ID };
- private int code = -1;
+ private FormEditor formEditor;
- private ITextOperationTarget target;
+ private String title;
- public TextViewerAction(ITextViewer viewer, int operationCode) {
- code = operationCode;
- target = viewer.getTextOperationTarget();
- update();
- }
-
- @Override
- public void update() {
- if (code == ITextOperationTarget.REDO)
- return;
+ private String pageId;
- boolean wasEnabled = isEnabled();
- boolean isEnabled = target.canDoOperation(code);
- setEnabled(isEnabled);
+ private int pageIndex = -1;
- if (wasEnabled != isEnabled)
- firePropertyChange(ENABLED, wasEnabled ? Boolean.TRUE
- : Boolean.FALSE, isEnabled ? Boolean.TRUE
- : Boolean.FALSE);
- }
+ private Control textControl;
- @Override
- public void run() {
- if (code != -1)
- target.doOperation(code);
- }
- }
- private DiffViewer viewer;
-
- private DiffStyleRangeFormatter formatter;
+ private Annotation[] currentFoldingAnnotations;
/**
+ * Creates a new {@link DiffEditorPage} with the given id and title, which
+ * is shown on the page's tab.
+ *
* @param editor
+ * containing this page
* @param id
+ * of the page
* @param title
+ * of the page
*/
public DiffEditorPage(FormEditor editor, String id, String title) {
- super(editor, id, title);
+ pageId = id;
+ this.title = title;
+ setPartName(title);
+ initialize(editor);
}
/**
+ * Creates a new {@link DiffEditorPage} with default id and title.
+ *
* @param editor
+ * containing the page
*/
public DiffEditorPage(FormEditor editor) {
this(editor, "diffPage", UIText.DiffEditorPage_Title); //$NON-NLS-1$
}
+ // TextEditor specifics:
+
+ @Override
+ protected ISourceViewer createSourceViewer(Composite parent,
+ IVerticalRuler ruler, int styles) {
+ DiffViewer viewer = new DiffViewer(parent, ruler, getOverviewRuler(),
+ isOverviewRulerVisible(), styles);
+ getSourceViewerDecorationSupport(viewer);
+ ProjectionSupport projector = new ProjectionSupport(viewer,
+ getAnnotationAccess(), getSharedColors());
+ projector.install();
+ return viewer;
+ }
+
+ @Override
+ protected void initializeEditor() {
+ super.initializeEditor();
+ setDocumentProvider(new DiffDocumentProvider());
+ setSourceViewerConfiguration(
+ new DiffViewer.Configuration(getPreferenceStore()) {
+ @Override
+ public IReconciler getReconciler(
+ ISourceViewer sourceViewer) {
+ // Switch off spell-checking
+ return null;
+ }
+ });
+ }
+
+ @Override
+ protected void doSetInput(IEditorInput input) throws CoreException {
+ super.doSetInput(input);
+ if (input instanceof DiffEditorInput) {
+ setFolding();
+ } else if (input instanceof CommitEditorInput) {
+ formatDiff();
+ }
+ }
+
+ @Override
+ protected void editorContextMenuAboutToShow(IMenuManager menu) {
+ super.editorContextMenuAboutToShow(menu);
+ addAction(menu, ITextEditorActionConstants.GROUP_COPY,
+ ITextEditorActionConstants.SELECT_ALL);
+ // TextEditor always adds these, even if the document is not editable.
+ menu.remove(ITextEditorActionConstants.SHIFT_RIGHT);
+ menu.remove(ITextEditorActionConstants.SHIFT_LEFT);
+ }
+
+ // FormPage specifics:
+
+ @Override
+ public void initialize(FormEditor editor) {
+ formEditor = editor;
+ }
+
+ @Override
+ public FormEditor getEditor() {
+ return formEditor;
+ }
+
+ @Override
+ public IManagedForm getManagedForm() {
+ return null;
+ }
+
+ @Override
+ public void setActive(boolean active) {
+ // Nothing to do.
+ }
+
+ @Override
+ public boolean isActive() {
+ return this.equals(formEditor.getActivePageInstance());
+ }
+
+ @Override
+ public boolean canLeaveThePage() {
+ return true;
+ }
+
+ @Override
+ public Control getPartControl() {
+ return textControl;
+ }
+
+ @Override
+ public String getId() {
+ return pageId;
+ }
+
+ @Override
+ public int getIndex() {
+ return pageIndex;
+ }
+
+ @Override
+ public void setIndex(int index) {
+ pageIndex = index;
+ }
+
+ @Override
+ public boolean isEditor() {
+ return true;
+ }
+
+ @Override
+ public boolean selectReveal(Object object) {
+ if (object instanceof IMarker) {
+ IDE.gotoMarker(this, (IMarker) object);
+ return true;
+ }
+ return false;
+ }
+
+ // WorkbenchPart specifics:
+
+ @Override
+ public String getTitle() {
+ return title;
+ }
+
+ @Override
+ public void createPartControl(Composite parent) {
+ super.createPartControl(parent);
+ Control[] children = parent.getChildren();
+ textControl = children[children.length - 1];
+ }
+
+ // "Show In..." specifics:
+
+ @Override
+ public ShowInContext getShowInContext() {
+ RepositoryCommit commit = AdapterUtils.adapt(getEditorInput(),
+ RepositoryCommit.class);
+ if (commit != null) {
+ return new ShowInContext(getEditorInput(),
+ new StructuredSelection(commit));
+ }
+ return null;
+ }
+
+ @Override
+ public String[] getShowInTargetIds() {
+ return SHOW_IN_TARGETS;
+ }
+
+ // Diff specifics:
+
+ private void setFolding() {
+ ProjectionViewer viewer = (ProjectionViewer) getSourceViewer();
+ IDocument document = viewer.getDocument();
+ if (document instanceof DiffDocument) {
+ FileDiffRange[] ranges = ((DiffDocument) document).getFileRanges();
+ if (ranges == null || ranges.length <= 1) {
+ viewer.disableProjection();
+ return;
+ }
+ viewer.enableProjection();
+ Map<Annotation, Position> newAnnotations = new HashMap<>();
+ for (FileDiffRange range : ranges) {
+ newAnnotations.put(new ProjectionAnnotation(),
+ new Position(range.getStartOffset(),
+ range.getEndOffset() - range.getStartOffset()));
+ }
+ viewer.getProjectionAnnotationModel().modifyAnnotations(
+ currentFoldingAnnotations, newAnnotations, null);
+ currentFoldingAnnotations = newAnnotations.keySet()
+ .toArray(new Annotation[newAnnotations.size()]);
+ } else {
+ viewer.disableProjection();
+ }
+ }
+
/**
+ * Gets the full unified diff of a {@link RepositoryCommit}.
+ *
* @param commit
- * @return diffs for changes of of a commit
+ * to get the diff
+ * @return the diff as a sorted (by file path) array of {@link FileDiff}s
*/
protected FileDiff[] getDiffs(RepositoryCommit commit) {
List<FileDiff> diffResult = new ArrayList<>();
@@ -118,18 +303,26 @@ public class DiffEditorPage extends FormPage {
diffResult.addAll(asList(commit.getDiffs()));
if (commit.getRevCommit().getParentCount() > 2) {
- RevCommit untrackedCommit = commit.getRevCommit().getParent(
- StashEditorPage.PARENT_COMMIT_UNTRACKED);
- diffResult.addAll(asList(new RepositoryCommit(commit
- .getRepository(), untrackedCommit).getDiffs()));
+ RevCommit untrackedCommit = commit.getRevCommit()
+ .getParent(StashEditorPage.PARENT_COMMIT_UNTRACKED);
+ diffResult
+ .addAll(asList(new RepositoryCommit(commit.getRepository(),
+ untrackedCommit).getDiffs()));
}
Collections.sort(diffResult, FileDiff.PATH_COMPARATOR);
- return diffResult.toArray(new FileDiff[0]);
+ return diffResult.toArray(new FileDiff[diffResult.size()]);
}
+ /**
+ * Asynchronously gets the diff of the commit set on our
+ * {@link CommitEditorInput}, formats it into a {@link DiffDocument}, and
+ * then re-sets this editors's input to a {@link DiffEditorInput} which will
+ * cause this document to be shown.
+ */
private void formatDiff() {
final DiffDocument document = new DiffDocument();
- formatter = new DiffStyleRangeFormatter(document);
+ final DiffStyleRangeFormatter formatter = new DiffStyleRangeFormatter(
+ document);
Job job = new Job(UIText.DiffEditorPage_TaskGeneratingDiff) {
@@ -159,9 +352,9 @@ public class DiffEditorPage extends FormPage {
@Override
public IStatus runInUIThread(IProgressMonitor uiMonitor) {
- if (UIUtils.isUsable(viewer)) {
+ if (UIUtils.isUsable(getPartControl())) {
document.connect(formatter);
- viewer.setDocument(document);
+ setInput(new DiffEditorInput(commit, document));
}
return Status.OK_STATUS;
}
@@ -173,63 +366,70 @@ public class DiffEditorPage extends FormPage {
}
/**
- * Add editor actions to menu manager
- *
- * @param manager
+ * An editor input that gives access to the document created by the diff
+ * formatter.
*/
- protected void addEditorActions(MenuManager manager) {
- final TextViewerAction copyAction = new TextViewerAction(viewer,
- ITextOperationTarget.COPY);
- copyAction.setText(UIText.SpellCheckingMessageArea_copy);
- copyAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_COPY);
+ private static class DiffEditorInput extends CommitEditorInput {
- final TextViewerAction selectAllAction = new TextViewerAction(viewer,
- ITextOperationTarget.SELECT_ALL);
- selectAllAction.setText(UIText.SpellCheckingMessageArea_selectAll);
- selectAllAction
- .setActionDefinitionId(IWorkbenchCommandConstants.EDIT_SELECT_ALL);
+ private IDocument document;
- manager.add(copyAction);
- manager.add(selectAllAction);
- manager.add(new Separator());
+ public DiffEditorInput(RepositoryCommit commit, DiffDocument diff) {
+ super(commit);
+ document = diff;
+ }
- viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public IDocument getDocument() {
+ return document;
+ }
- @Override
- public void selectionChanged(SelectionChangedEvent event) {
- copyAction.update();
- selectAllAction.update();
- }
- });
+ @Override
+ public String getName() {
+ return UIText.DiffEditorPage_Title;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return super.equals(obj) && (obj instanceof DiffEditorInput)
+ && document.equals(((DiffEditorInput) obj).document);
+ }
+
+ @Override
+ public int hashCode() {
+ return super.hashCode() ^ document.hashCode();
+ }
}
/**
- * @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
+ * A document provider that knows about {@link DiffEditorInput}.
*/
- @Override
- protected void createFormContent(IManagedForm managedForm) {
- Composite body = managedForm.getForm().getBody();
- GridLayoutFactory.fillDefaults().numColumns(1).applyTo(body);
-
- viewer = new DiffViewer(body, new CompositeRuler(), SWT.V_SCROLL
- | SWT.H_SCROLL, true);
- viewer.setEditable(false);
- GridDataFactory.fillDefaults().grab(true, true)
- .applyTo(viewer.getControl());
-
- MenuManager manager = new MenuManager();
- addEditorActions(manager);
- Menu menu = manager.createContextMenu(viewer.getTextWidget());
- IEditorSite site = getEditorSite();
- site.setSelectionProvider(viewer);
- site.registerContextMenu(
- AbstractTextEditor.COMMON_EDITOR_CONTEXT_MENU_ID, manager,
- viewer, true);
- site.registerContextMenu(
- AbstractTextEditor.DEFAULT_EDITOR_CONTEXT_MENU_ID, manager,
- viewer, true);
- viewer.getTextWidget().setMenu(menu);
-
- formatDiff();
+ private static class DiffDocumentProvider extends AbstractDocumentProvider {
+
+ @Override
+ protected IDocument createDocument(Object element)
+ throws CoreException {
+ if (element instanceof DiffEditorInput) {
+ return ((DiffEditorInput) element).getDocument();
+ }
+ return new Document();
+ }
+
+ @Override
+ protected IAnnotationModel createAnnotationModel(Object element)
+ throws CoreException {
+ return new AnnotationModel();
+ }
+
+ @Override
+ protected void doSaveDocument(IProgressMonitor monitor, Object element,
+ IDocument document, boolean overwrite) throws CoreException {
+ // Cannot save
+ }
+
+ @Override
+ protected IRunnableContext getOperationRunner(
+ IProgressMonitor monitor) {
+ return null;
+ }
+
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffStyleRangeFormatter.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffStyleRangeFormatter.java
index 5ac5de71fc..aa35f6e0b7 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffStyleRangeFormatter.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffStyleRangeFormatter.java
@@ -23,14 +23,13 @@ import org.eclipse.egit.ui.internal.commit.DiffStyleRangeFormatter.DiffStyleRang
import org.eclipse.egit.ui.internal.history.FileDiff;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.diff.DiffFormatter;
import org.eclipse.jgit.diff.EditList;
import org.eclipse.jgit.diff.RawText;
-import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.custom.StyleRange;
-import org.eclipse.swt.graphics.Color;
/**
* Diff style range formatter class that builds up a list of
@@ -96,11 +95,6 @@ public class DiffStyleRangeFormatter extends DiffFormatter {
*/
public Type diffType = Type.OTHER;
- /**
- * Line background
- */
- public Color lineBackground = null;
-
@Override
public boolean similarTo(StyleRange style) {
return super.similarTo(style) && style instanceof DiffStyleRange
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java
index 3400815428..3223efbd65 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java
@@ -29,11 +29,13 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.compare.ITypedElement;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -74,10 +76,10 @@ import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.ITokenScanner;
import org.eclipse.jface.text.rules.Token;
-import org.eclipse.jface.text.source.CompositeRuler;
+import org.eclipse.jface.text.source.IOverviewRuler;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.IVerticalRuler;
-import org.eclipse.jface.text.source.LineNumberRulerColumn;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jgit.diff.DiffEntry;
@@ -98,9 +100,7 @@ import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.editors.text.EditorsUI;
-import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
import org.eclipse.ui.texteditor.AbstractTextEditor;
-import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
import org.eclipse.ui.themes.IThemeManager;
/**
@@ -117,8 +117,6 @@ public class DiffViewer extends HyperlinkSourceViewer {
private final Map<String, Color> backgroundColors = new HashMap<>();
- private LineNumberRulerColumn lineNumberRuler;
-
private IPropertyChangeListener themeListener = new IPropertyChangeListener() {
@Override
@@ -149,12 +147,67 @@ public class DiffViewer extends HyperlinkSourceViewer {
};
/**
- * Creates a new {@link DiffViewer} and
- * {@link #configure(org.eclipse.jface.text.source.SourceViewerConfiguration)
- * configures} it with a {@link PresentationReconciler} and syntax coloring,
- * and an {@link IHyperlinkDetector} to provide hyperlinks to open the files
- * being diff'ed if the document used with the viewer is a
- * {@link DiffDocument}.
+ * A configuration to use with a {@link DiffViewer}, setting up the syntax
+ * coloring for a diff and adding the {@link IHyperlinkDetector} for the
+ * links.
+ */
+ public static class Configuration
+ extends HyperlinkSourceViewer.Configuration {
+
+ /**
+ * Creates a new {@link Configuration} connected to the given
+ * {@link IPreferenceStore}.
+ *
+ * @param preferenceStore
+ * to connect to
+ */
+ public Configuration(IPreferenceStore preferenceStore) {
+ super(preferenceStore);
+ }
+
+ @Override
+ public int getHyperlinkStateMask(ISourceViewer sourceViewer) {
+ return SWT.NONE;
+ }
+
+ @Override
+ protected IHyperlinkDetector[] internalGetHyperlinkDetectors(
+ ISourceViewer sourceViewer) {
+ Assert.isTrue(sourceViewer instanceof DiffViewer);
+ IHyperlinkDetector[] result = { new HyperlinkDetector() };
+ return result;
+ }
+
+ @Override
+ public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
+ Assert.isTrue(sourceViewer instanceof DiffViewer);
+ DiffViewer viewer = (DiffViewer) sourceViewer;
+ return viewer.tokens.keySet()
+ .toArray(new String[viewer.tokens.size()]);
+ }
+
+ @Override
+ public IPresentationReconciler getPresentationReconciler(
+ ISourceViewer sourceViewer) {
+ Assert.isTrue(sourceViewer instanceof DiffViewer);
+ DiffViewer viewer = (DiffViewer) sourceViewer;
+ PresentationReconciler reconciler = new PresentationReconciler();
+ reconciler.setDocumentPartitioning(
+ getConfiguredDocumentPartitioning(viewer));
+ for (String contentType : viewer.tokens.keySet()) {
+ DefaultDamagerRepairer damagerRepairer = new DefaultDamagerRepairer(
+ new SingleTokenScanner(
+ () -> viewer.tokens.get(contentType)));
+ reconciler.setDamager(damagerRepairer, contentType);
+ reconciler.setRepairer(damagerRepairer, contentType);
+ }
+ return reconciler;
+ }
+
+ }
+
+ /**
+ * Creates a new {@link DiffViewer}.
*
* @param parent
* to contain the viewer
@@ -162,33 +215,39 @@ public class DiffViewer extends HyperlinkSourceViewer {
* for the viewer (left side)
* @param styles
* for the viewer
- * @param showCursorLine
- * if {@code true},the current line is highlighted
*/
- public DiffViewer(Composite parent, IVerticalRuler ruler, int styles,
- boolean showCursorLine) {
- super(parent, ruler, styles);
- setDocument(new Document());
- SourceViewerDecorationSupport support = new SourceViewerDecorationSupport(
- this, null, null, EditorsUI.getSharedTextColors());
- if (showCursorLine) {
- support.setCursorLinePainterPreferenceKeys(
- AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE,
- AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR);
- }
- support.install(EditorsUI.getPreferenceStore());
- if (ruler instanceof CompositeRuler) {
- lineNumberRuler = new LineNumberRulerColumn();
- ((CompositeRuler) ruler).addDecorator(0, lineNumberRuler);
- }
+ public DiffViewer(Composite parent, IVerticalRuler ruler, int styles) {
+ this(parent, ruler, null, false, styles);
+ }
+
+ /**
+ * Creates a new {@link DiffViewer}.
+ *
+ * @param parent
+ * to contain the viewer
+ * @param ruler
+ * for the viewer (left side)
+ * @param overviewRuler
+ * ruler for overview annotations
+ * @param showsAnnotationOverview
+ * whether to show overview annotations
+ * @param styles
+ * for the viewer
+ */
+ public DiffViewer(Composite parent, IVerticalRuler ruler,
+ IOverviewRuler overviewRuler, boolean showsAnnotationOverview,
+ int styles) {
+ super(parent, ruler, overviewRuler, showsAnnotationOverview, styles);
getTextWidget().setAlwaysShowScrollBars(false);
+ setEditable(false);
+ setDocument(new Document());
initListeners();
getControl().addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
- EditorsUI.getPreferenceStore().removePropertyChangeListener(
- editorPrefListener);
+ EditorsUI.getPreferenceStore()
+ .removePropertyChangeListener(editorPrefListener);
PlatformUI.getWorkbench().getThemeManager()
.removePropertyChangeListener(themeListener);
colors.dispose();
@@ -196,42 +255,12 @@ public class DiffViewer extends HyperlinkSourceViewer {
});
refreshDiffStyles();
styleViewer();
- configure(new HyperlinkSourceViewer.Configuration(
- EditorsUI.getPreferenceStore()) {
-
- @Override
- public int getHyperlinkStateMask(ISourceViewer sourceViewer) {
- return SWT.NONE;
- }
-
- @Override
- protected IHyperlinkDetector[] internalGetHyperlinkDetectors(
- ISourceViewer sourceViewer) {
- IHyperlinkDetector[] result = { new HyperlinkDetector() };
- return result;
- }
-
- @Override
- public String[] getConfiguredContentTypes(
- ISourceViewer sourceViewer) {
- return tokens.keySet().toArray(new String[tokens.size()]);
- }
+ }
- @Override
- public IPresentationReconciler getPresentationReconciler(
- ISourceViewer viewer) {
- PresentationReconciler reconciler = new PresentationReconciler();
- reconciler.setDocumentPartitioning(
- getConfiguredDocumentPartitioning(viewer));
- for (String contentType : tokens.keySet()) {
- DefaultDamagerRepairer damagerRepairer = new DefaultDamagerRepairer(
- new SingleTokenScanner(contentType));
- reconciler.setDamager(damagerRepairer, contentType);
- reconciler.setRepairer(damagerRepairer, contentType);
- }
- return reconciler;
- }
- });
+ @Override
+ public void configure(SourceViewerConfiguration config) {
+ Assert.isTrue(config instanceof Configuration);
+ super.configure(config);
}
private void refreshDiffStyles() {
@@ -276,8 +305,11 @@ public class DiffViewer extends HyperlinkSourceViewer {
IDocument document = getDocument();
if (document instanceof DiffDocument) {
try {
+ // We are in SWT land here: we get widget offsets.
+ int modelOffset = widgetOffset2ModelOffset(
+ event.lineOffset);
ITypedRegion partition = ((DiffDocument) document)
- .getPartition(event.lineOffset);
+ .getPartition(modelOffset);
if (partition != null) {
Color color = backgroundColors.get(partition.getType());
if (color != null) {
@@ -328,16 +360,11 @@ public class DiffViewer extends HyperlinkSourceViewer {
text.setSelectionForeground(selectionForeground);
text.setSelectionBackground(selectionBackground);
text.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));
- if (lineNumberRuler != null) {
- lineNumberRuler.setFont(text.getFont());
- lineNumberRuler.setForeground(foreground);
- lineNumberRuler.setBackground(background);
- }
}
- private class SingleTokenScanner implements ITokenScanner {
+ private static class SingleTokenScanner implements ITokenScanner {
- private final String contentType;
+ private final Supplier<IToken> token;
private int currentOffset;
@@ -345,8 +372,8 @@ public class DiffViewer extends HyperlinkSourceViewer {
private int tokenStart;
- public SingleTokenScanner(String contentType) {
- this.contentType = contentType;
+ public SingleTokenScanner(Supplier<IToken> supplier) {
+ this.token = supplier;
}
@Override
@@ -361,7 +388,7 @@ public class DiffViewer extends HyperlinkSourceViewer {
tokenStart = currentOffset;
if (currentOffset < end) {
currentOffset = end;
- return tokens.get(contentType);
+ return token.get();
}
return Token.EOF;
}
@@ -378,7 +405,7 @@ public class DiffViewer extends HyperlinkSourceViewer {
}
- private class HyperlinkDetector extends AbstractHyperlinkDetector
+ private static class HyperlinkDetector extends AbstractHyperlinkDetector
implements IHyperlinkDetectorExtension2 {
private final Pattern HUNK_LINE_PATTERN = Pattern
@@ -388,8 +415,7 @@ public class DiffViewer extends HyperlinkSourceViewer {
public IHyperlink[] detectHyperlinks(ITextViewer textViewer,
IRegion region, boolean canShowMultipleHyperlinks) {
IDocument document = textViewer.getDocument();
- if (textViewer != DiffViewer.this
- || !(document instanceof DiffDocument)
+ if (!(document instanceof DiffDocument)
|| document.getLength() == 0) {
return null;
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/HyperlinkSourceViewer.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/HyperlinkSourceViewer.java
index 346936aad6..8b6766a734 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/HyperlinkSourceViewer.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/HyperlinkSourceViewer.java
@@ -24,8 +24,8 @@ import org.eclipse.jface.text.hyperlink.IHyperlinkDetectorExtension2;
import org.eclipse.jface.text.source.IOverviewRuler;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.IVerticalRuler;
-import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jgit.annotations.Nullable;
@@ -38,13 +38,16 @@ import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.ui.texteditor.HyperlinkDetectorDescriptor;
/**
- * A {@link SourceViewer} that automatically reacts to changes in the
+ * A {@link ProjectionViewer} that automatically reacts to changes in the
* hyperlinking preferences.
*/
-public class HyperlinkSourceViewer extends SourceViewer {
+public class HyperlinkSourceViewer extends ProjectionViewer {
// The default SourceViewer doesn't do this and instead AbstractTextEditor
// has code that does all that. For our uses it is much more convenient if
// the viewer itself handles this.
+ //
+ // Note: although ProjectionViewer is marked as noextend, there are already
+ // a number of subclasses.
private Configuration configuration;
@@ -68,7 +71,7 @@ public class HyperlinkSourceViewer extends SourceViewer {
*/
public HyperlinkSourceViewer(Composite parent, IVerticalRuler ruler,
int styles) {
- super(parent, ruler, styles);
+ this(parent, ruler, null, false, styles);
}
/**
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/SpellcheckableMessageArea.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/SpellcheckableMessageArea.java
index 846778836e..bbabb3c22a 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/SpellcheckableMessageArea.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/SpellcheckableMessageArea.java
@@ -266,12 +266,12 @@ public class SpellcheckableMessageArea extends Composite {
setLayout(new FillLayout());
AnnotationModel annotationModel = new AnnotationModel();
- sourceViewer = new HyperlinkSourceViewer(this, null, null, true,
+ sourceViewer = new HyperlinkSourceViewer(this, null,
SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
getTextWidget().setAlwaysShowScrollBars(false);
getTextWidget().setFont(UIUtils
.getFont(UIPreferences.THEME_CommitMessageEditorFont));
-
+ sourceViewer.setDocument(new Document());
int endSpacing = 2;
int textWidth = getCharWidth() * MAX_LINE_WIDTH + endSpacing;
int textHeight = getLineHeight() * 7;
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
index 4cee73347e..f2d857f63e 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
@@ -1224,10 +1224,11 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
commentViewer.configure(configuration);
- diffViewer = new DiffViewer(commentAndDiffComposite, null, SWT.NONE, false);
+ diffViewer = new DiffViewer(commentAndDiffComposite, null, SWT.NONE);
+ diffViewer.configure(
+ new DiffViewer.Configuration(EditorsUI.getPreferenceStore()));
diffViewer.getControl().setLayoutData(
GridDataFactory.fillDefaults().grab(true, false).create());
- diffViewer.setEditable(false);
setWrap(store
.getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_COMMENT_WRAP));
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java
index d2cf63b5f5..cdadac93f1 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2015 SAP AG and others.
+ * Copyright (c) 2010, 2016 SAP AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -796,7 +796,8 @@ public class RepositoriesView extends CommonNavigator implements IShowInSource,
@Override
public boolean show(ShowInContext context) {
ISelection selection = context.getSelection();
- if (selection instanceof IStructuredSelection) {
+ if ((selection instanceof IStructuredSelection)
+ && !selection.isEmpty()) {
IStructuredSelection ss = (IStructuredSelection) selection;
List<IPath> paths = new ArrayList<>();
for (Iterator it = ss.iterator(); it.hasNext();) {
@@ -823,6 +824,13 @@ public class RepositoriesView extends CommonNavigator implements IShowInSource,
if(context.getInput() instanceof IFileEditorInput) {
IFileEditorInput input = (IFileEditorInput) context.getInput();
showResource(input.getFile());
+ return true;
+ }
+ Repository repository = AdapterUtils.adapt(context.getInput(),
+ Repository.class);
+ if (repository != null) {
+ showRepository(repository);
+ return true;
}
return false;
}

Back to the top