Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrandon Dong2016-03-10 18:53:09 -0500
committerSam Davis2016-03-24 13:54:08 -0400
commit4de0e3b0ba052151709d1d52ce52cb21417b9a28 (patch)
tree158b2a11bacae14fca8109962fdc399aba014912 /org.eclipse.mylyn.reviews.ui/src
parent85b9eb4498da5cf8b9b114c4a34971b5f6d94c1b (diff)
downloadorg.eclipse.mylyn.reviews-4de0e3b0ba052151709d1d52ce52cb21417b9a28.tar.gz
org.eclipse.mylyn.reviews-4de0e3b0ba052151709d1d52ce52cb21417b9a28.tar.xz
org.eclipse.mylyn.reviews-4de0e3b0ba052151709d1d52ce52cb21417b9a28.zip
489395: Clicking on comments should bring you directly to that line
Change-Id: I4b3106f98d3385602959c0dbf013d97233d08853 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=489395 Signed-off-by: Brandon Dong <brandon.dong@tasktop.com>
Diffstat (limited to 'org.eclipse.mylyn.reviews.ui/src')
-rw-r--r--org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareAnnotationSupport.java38
-rw-r--r--org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewItemCompareEditorInput.java25
2 files changed, 53 insertions, 10 deletions
diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareAnnotationSupport.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareAnnotationSupport.java
index ba8360e8..6d76a659 100644
--- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareAnnotationSupport.java
+++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareAnnotationSupport.java
@@ -47,6 +47,7 @@ import org.eclipse.mylyn.internal.reviews.ui.annotations.CommentPopupDialog;
import org.eclipse.mylyn.internal.reviews.ui.annotations.ReviewAnnotationModel;
import org.eclipse.mylyn.reviews.core.model.IFileItem;
import org.eclipse.mylyn.reviews.core.model.IReviewItem;
+import org.eclipse.mylyn.reviews.internal.core.model.Comment;
import org.eclipse.mylyn.reviews.ui.ReviewBehavior;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
@@ -54,6 +55,10 @@ import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.texteditor.AbstractTextEditor;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterators;
+
/**
* Manages annotation models for compare viewers.
*
@@ -218,6 +223,32 @@ public class ReviewCompareAnnotationSupport {
return null;
}
+ public void gotoAnnotationWithComment(final Comment comment) {
+ CommentAnnotation rightAnnotation = findComment(rightAnnotationModel, comment);
+ if (rightAnnotation != null) {
+ selectAndReveal(rightSourceViewer, rightAnnotation.getPosition());
+ } else {
+ CommentAnnotation leftAnnotation = findComment(leftAnnotationModel, comment);
+ if (leftAnnotation != null) {
+ selectAndReveal(leftSourceViewer, leftAnnotation.getPosition());
+ }
+ }
+ }
+
+ private CommentAnnotation findComment(ReviewAnnotationModel annotationModel, final Comment comment) {
+ Optional<Annotation> annotation = Iterators.tryFind(annotationModel.getAnnotationIterator(),
+ new Predicate<Annotation>() {
+ public boolean apply(Annotation annotation) {
+ return annotation instanceof CommentAnnotation
+ && ((CommentAnnotation) annotation).getComment().getId().equals(comment.getId());
+ }
+ });
+ if (annotation.isPresent()) {
+ return (CommentAnnotation) annotation.get();
+ }
+ return null;
+ }
+
private int getLineOffset(ReviewAnnotationModel annotationModel, int offset) {
try {
int line = annotationModel.getDocument().getLineOfOffset(offset);
@@ -340,11 +371,10 @@ public class ReviewCompareAnnotationSupport {
commentPopupDialog.create();
commentPopupDialog.setInput(input);
- commentPopupDialog.setHeightBasedOnMouse(Display.getCurrent().getCursorLocation().y);
+ commentPopupDialog.setHeightBasedOnMouse(sourceViewer.getSourceViewer().getControl().toDisplay(0, 0).y);
- Point location = sourceViewer.getSourceViewer().getControl().getLocation();
- location = Display.getCurrent().getCursorLocation();
- location.y = location.y + (sourceViewer.getViewportHeight() / 2);
+ Point location = sourceViewer.getSourceViewer().getControl().toDisplay(
+ sourceViewer.getSourceViewer().getControl().getSize().x, sourceViewer.getViewportHeight() / 3);
commentPopupDialog.setLocation(location);
commentPopupDialog.open();
commentPopupDialog.setFocus();
diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewItemCompareEditorInput.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewItemCompareEditorInput.java
index edb68b2d..0d8ad6f9 100644
--- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewItemCompareEditorInput.java
+++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewItemCompareEditorInput.java
@@ -32,6 +32,7 @@ import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.internal.reviews.ui.Messages;
import org.eclipse.mylyn.internal.reviews.ui.ReviewsImages;
import org.eclipse.mylyn.internal.reviews.ui.ReviewsUiPlugin;
+import org.eclipse.mylyn.reviews.internal.core.model.Comment;
import org.eclipse.mylyn.reviews.ui.ReviewBehavior;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
@@ -53,6 +54,8 @@ public abstract class ReviewItemCompareEditorInput extends CompareEditorInput {
final ReviewBehavior behavior;
+ private ReviewCompareAnnotationSupport currentSupport;
+
public ReviewItemCompareEditorInput(CompareConfiguration configuration, ReviewBehavior behavior) {
super(configuration);
this.behavior = behavior;
@@ -97,14 +100,20 @@ public abstract class ReviewItemCompareEditorInput extends CompareEditorInput {
public Viewer findContentViewer(Viewer oldViewer, ICompareInput input, Composite parent) {
Viewer contentViewer = super.findContentViewer(oldViewer, input, parent);
if (input instanceof FileItemNode && ((FileItemNode) input).getFileItem() != null) {
- ReviewCompareAnnotationSupport support = ReviewCompareAnnotationSupport.getAnnotationSupport(contentViewer);
- support.setReviewItem(((FileItemNode) input).getFileItem(), behavior);
- initializeGotoCommentHandlers(parent, support);
+ currentSupport = ReviewCompareAnnotationSupport.getAnnotationSupport(contentViewer);
+ currentSupport.setReviewItem(((FileItemNode) input).getFileItem(), behavior);
+ initializeGotoCommentHandlers(parent);
}
return contentViewer;
}
- private void initializeGotoCommentHandlers(Composite parent, final ReviewCompareAnnotationSupport support) {
+ public void gotoComment(Comment comment) {
+ if (currentSupport != null) {
+ currentSupport.gotoAnnotationWithComment(comment);
+ }
+ }
+
+ private void initializeGotoCommentHandlers(Composite parent) {
ToolBarManager tbm = CompareViewerPane.getToolBarManager(parent);
if (tbm != null) {
if (tbm.find(NAVIGATION_GROUP) != null) {
@@ -112,7 +121,9 @@ public abstract class ReviewItemCompareEditorInput extends CompareEditorInput {
Action goToNextAction = new Action(Messages.Reviews_NextComment, ReviewsImages.NEXT_COMMENT) {
@Override
public void run() {
- support.gotoAnnotation(Direction.FORWARDS);
+ if (currentSupport != null) {
+ currentSupport.gotoAnnotation(Direction.FORWARDS);
+ }
}
};
goToNextAction.setId(ID_NEXT_COMMENT);
@@ -125,7 +136,9 @@ public abstract class ReviewItemCompareEditorInput extends CompareEditorInput {
ReviewsImages.PREVIOUS_COMMENT) {
@Override
public void run() {
- support.gotoAnnotation(Direction.BACKWARDS);
+ if (currentSupport != null) {
+ currentSupport.gotoAnnotation(Direction.BACKWARDS);
+ }
}
};
goToPreviousAction.setId(ID_PREVIOUS_COMMENT);

Back to the top