Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-05-22 18:50:12 -0400
committerMichael Keppler2019-05-25 09:07:22 -0400
commitf8a4f483852b331c90600b1c7c96c43ac9b1c682 (patch)
treef533d4fdd4119837f16dd3615efbce42ceb19d90
parent744a12abb1bd3c6922fe7758ce426b273551445c (diff)
downloadegit-f8a4f483852b331c90600b1c7c96c43ac9b1c682.tar.gz
egit-f8a4f483852b331c90600b1c7c96c43ac9b1c682.tar.xz
egit-f8a4f483852b331c90600b1c7c96c43ac9b1c682.zip
History: show whitespace in the diff viewer
Give the diff viewer in the history view a little context menu, shown only when there is actually some content. The context menu contains copy, select all, and show whitespace. The latter enables the user to switch on and off showing whitespace, and it makes the viewer respect the global editor preference for showing whitespace. Bug: 462509 Change-Id: Iad75ffb10d539f9913a85a6d1382bb6ef307511b Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ShowWhitespaceAction.java10
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java30
2 files changed, 40 insertions, 0 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ShowWhitespaceAction.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ShowWhitespaceAction.java
index dbdd042af..6ce0acdfc 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ShowWhitespaceAction.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ShowWhitespaceAction.java
@@ -33,6 +33,16 @@ public class ShowWhitespaceAction extends TextEditorPropertyAction {
*
* @param viewer
* to operate on
+ */
+ public ShowWhitespaceAction(ITextViewer viewer) {
+ this(viewer, false);
+ }
+
+ /**
+ * Creates a new {@link ShowWhitespaceAction}.
+ *
+ * @param viewer
+ * to operate on
* @param initiallyOff
* whether to show whitespace initially
*/
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 ee1deea7d..8b99e743b 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
@@ -45,6 +45,7 @@ import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.JobFamilies;
import org.eclipse.egit.ui.UIPreferences;
import org.eclipse.egit.ui.UIUtils;
+import org.eclipse.egit.ui.internal.ActionUtils;
import org.eclipse.egit.ui.internal.CompareUtils;
import org.eclipse.egit.ui.internal.UIIcons;
import org.eclipse.egit.ui.internal.UIText;
@@ -55,6 +56,7 @@ import org.eclipse.egit.ui.internal.commit.FocusTracker;
import org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction;
import org.eclipse.egit.ui.internal.dialogs.HyperlinkSourceViewer;
import org.eclipse.egit.ui.internal.dialogs.HyperlinkTokenScanner;
+import org.eclipse.egit.ui.internal.dialogs.ShowWhitespaceAction;
import org.eclipse.egit.ui.internal.fetch.FetchHeadChangedEvent;
import org.eclipse.egit.ui.internal.history.FindToolbar.StatusListener;
import org.eclipse.egit.ui.internal.repository.tree.AdditionalRefNode;
@@ -90,6 +92,7 @@ import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextListener;
+import org.eclipse.jface.text.ITextOperationTarget;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.TextEvent;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
@@ -1290,6 +1293,33 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
diffViewer.getControl().setLayoutData(
GridDataFactory.fillDefaults().grab(true, false).create());
+ ActionUtils.UpdateableAction selectAll = ActionUtils.createGlobalAction(
+ ActionFactory.SELECT_ALL,
+ () -> diffViewer.doOperation(ITextOperationTarget.SELECT_ALL),
+ () -> diffViewer
+ .canDoOperation(ITextOperationTarget.SELECT_ALL));
+ ActionUtils.UpdateableAction copy = ActionUtils.createGlobalAction(
+ ActionFactory.COPY,
+ () -> diffViewer.doOperation(ITextOperationTarget.COPY),
+ () -> diffViewer.canDoOperation(ITextOperationTarget.COPY));
+ ActionUtils.setGlobalActions(diffViewer.getControl(), copy, selectAll);
+ ShowWhitespaceAction showWhitespaceAction = new ShowWhitespaceAction(
+ diffViewer);
+ diffViewer.addSelectionChangedListener(e -> copy.update());
+ MenuManager contextMenu = new MenuManager();
+ contextMenu.setRemoveAllWhenShown(true);
+ contextMenu.addMenuListener(manager -> {
+ if (diffViewer.getDocument().getLength() > 0) {
+ manager.add(copy);
+ manager.add(selectAll);
+ manager.add(new Separator());
+ manager.add(showWhitespaceAction);
+ }
+ });
+ StyledText diffWidget = diffViewer.getTextWidget();
+ diffWidget.setMenu(contextMenu.createContextMenu(diffWidget));
+ diffWidget.addDisposeListener(e -> showWhitespaceAction.dispose());
+
setWrap(store
.getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_COMMENT_WRAP));

Back to the top